更新时间:2026-05-12 GMT+08:00
分享

执行数据导入

创建LakeFormation数据源

创建LakeFormation数据源,具体请参见《数据仓库服务用户指南》中的“管理LakeFormation数据源”章节。

创建External Schema

创建EXTERNAL SCHEMA。 SERVER名字填写创建的LakeFormation数据源名称,DATABASE填写要访问的LakeFormation的数据库,source填写内容为lakeformation,catalog填写为要访问的LakeFormation的catalog。
1
2
3
4
5
6
DROP SCHEMA IF EXISTS ex1;  
CREATE EXTERNAL SCHEMA ex1     
    WITH SOURCE lakeformation          
         DATABASE 'default'          
         SERVER lf_server          
         catalog 'hive';

角色授权

  1. 在DWS侧查询当前用户。

    1
    SELECT current_user; 
    

  2. 创建同名角色并授权。使用1获取的DWS用户名在lakeformation上创建同名角色。后续用户将通过对该角色的权限管理来实现对DWS用户的权限控制。

    1. 例如1查询的DWS侧用户名为dws_user,LakeFormation管理控制台创建同名角色。
    2. 授予角色对应的表权限和数据权限。

    具体请参见《湖仓构建用户指南》中的“创建LakeFormation角色并授权”章节。

查询表信息

DWS提供以下函数查询lakeformation数据信息。

  • 使用函数pg_get_external_schema_table_list(schema_name text)获取指定external schema下的全量表名信息。
    1
    SELECT * FROM pg_get_external_schema_table_list('ex1');
    
  • 使用函数pg_get_external_schema_table_options(schema_name text, table_name text)获取指定external schema、指定表的属性信息。
    1
    SELECT * FROM pg_get_external_schema_table_options('ex1','test_hudi');
    
  • 使用函数pg_get_external_schema_table_col(schema_name text, table_name text)获取指定external schema、指定表的字段信息。
    1
    SELECT * FROM pg_get_external_schema_table_col('ex1','test_hudi');
    

执行数据导入

  1. 创建本地目标表。
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    DROP TABLE IF EXISTS product_info;
    CREATE TABLE product_info
    (
        _hoodie_commit_time text,
        _hoodie_commit_seqno text,
        _hoodie_record_key text,
        _hoodie_partition_path text,
        _hoodie_file_name text,
        product_price                integer        ,
        product_id                   char(30)       ,
        product_time                 date           ,
        product_level                char(10)       ,
        product_name                 varchar(200)   ,
        product_type1                varchar(20)    ,
        product_type2                char(10)       ,
        product_monthly_sales_cnt    integer        ,
        product_comment_time         date           ,
        product_comment_num          integer        ,
        product_comment_content      varchar(200)                   
    ) ;
    
  2. 从Hudi表导入目标表。
    1
    INSERT INTO product_info SELECT * FROM ex1.test_hudi; 
    
  3. 查询导入结果。
    1
    SELECT * FROM product_info;
    

相关文档