数据仓库服务 GAUSSDB(DWS)-ALTER FOREIGN TABLE (For HDFS or OBS):示例

时间:2024-12-24 10:32:38

示例

  1. 创建HDFS_Server,对应的foreign data wrapper为HDFS_FDW或者DFS_FDW。
    1
    CREATE SERVER hdfs_server FOREIGN DATA WRAPPER HDFS_FDW OPTIONS (address '10.10.0.100:25000,10.10.0.101:25000',hdfscfgpath '/opt/hadoop_client/HDFS/hadoop/etc/hadoop',type'HDFS');
    
  2. 创建不包含分区列的HDFS外表:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    DROP FOREIGN TABLE IF EXISTS ft_region;
    CREATE FOREIGN TABLE ft_region
    (
        R_REGIONKEY INT4,
        R_NAME TEXT,
        R_COMMENT TEXT
    )
    SERVER
        hdfs_server
    OPTIONS
    (
        FORMAT 'orc',
        encoding 'utf8',
        FOLDERNAME '/user/hive/warehouse/gauss.db/region_orc11_64stripe/'
    )
    DISTRIBUTE BY 
         roundrobin;
    
  3. 修改外表ft_region的r_name字段类型为text:
    1
    ALTER FOREIGN TABLE ft_region ALTER r_name TYPE TEXT;
    
  4. 标记外表ft_region的r_name列为not null:
    1
    ALTER FOREIGN TABLE ft_region ALTER r_name SET NOT NULL;
    
support.huaweicloud.com/sqlreference-dws/dws_06_0124.html