CREATE TABLE
命令功能
CREATE TABLE命令通过指定带有表属性的字段列表来创建Hudi Table。
命令格式
CREATE TABLE [ IF NOT EXISTS] [database_name.]table_name
[ (columnTypeList)]
USING hudi
[ COMMENT table_comment ]
[ LOCATION location_path ]
[ OPTIONS (options_list) ]
参数描述
| 
        参数  | 
      
        描述  | 
     
|---|---|
| 
        database_name  | 
      
        Database名称,由字母、数字和下划线(_)组成。  | 
     
| 
        table_name  | 
      
        Database中的表名,由字母、数字和下划线(_)组成。  | 
     
| 
        columnTypeList  | 
      
        以逗号分隔的带数据类型的列表。列名由字母、数字和下划线(_)组成。  | 
     
| 
        using  | 
      
        参数hudi,定义和创建Hudi table。  | 
     
| 
        table_comment  | 
      
        表的描述信息。  | 
     
| 
        location_path  | 
      
        HDFS路径,指定该路径Hudi 表会创建为外表。  | 
     
| 
        options_list  | 
      
        Hudi table属性列表。  | 
     
| 
       参数  | 
     
       描述  | 
    
|---|---|
| 
       primaryKey  | 
     
       主键名,多个字段用逗号分隔。  | 
    
| 
       type  | 
     
       表类型。'cow' 表示 COPY-ON-WRITE 表,'mor' 表示 MERGE-ON-READ 表。未指定type的话,默认值为 'cow'。  | 
    
| 
       preCombineField  | 
     
       表的Pre-Combine字段。  | 
    
| 
       payloadClass  | 
     
       使用preCombineField字段进行数据过滤的逻辑,Hudi除了默认的OverwriteWithLatestAvroPayload外同时也提供了多种预置Payload供用户使用,如OverwriteNonDefaultsWithLatestAvroPayload、DefaultHoodieRecordPayload及EmptyHoodieRecordPayload。  | 
    
示例
- 创建非分区表
    
-- 创建一个cow内部表 create table if not exists hudi_table0 ( id int, name string, price double ) using hudi options ( type = 'cow', primaryKey = 'id' );
-- 创建一个mor外部表 create table if not exists hudi_table1 ( id int, name string, price double, ts bigint ) using hudi location '/tmp/hudi/hudi_table1' options ( type = 'mor', primaryKey = 'id,name', preCombineField = 'ts' );
-- 创建一个无主键表 create table if not exists hudi_table2( id int, name string, price double ) using hudi options ( type = 'cow' );
 
- 创建分区表
    
create table if not exists hudi_table_p0 ( id bigint, name string, ts bigint, dt string, hh string ) using hudi location '/tmp/hudi/hudi_table_p0' options ( type = 'cow', primaryKey = 'id', preCombineField = 'ts' ) partitioned by (dt, hh);
 - 创建一个hudi 0.9.0版本之前通过spark-shell or deltastreamer创建的hudi表的外表
    
create table h_p1 using hudi options ( primaryKey = 'id', preCombineField = 'ts' ) partitioned by (dt) location '/path/to/hudi';
 
- 创建表指定表属性
   
create table if not exists h3( id bigint, name string, price double ) using hudi options ( primaryKey = 'id', type = 'mor', hoodie.cleaner.fileversions.retained = '20', hoodie.keep.max.commits = '20' );
 
注意事项
Hudi当前不支持使用char、varchar、tinyint、smallint类型,建议使用string或int类型。
系统响应
Table创建成功,创建成功的消息将被记录在系统日志中。