目录
1.创建一个cow类型的表
2.创建一个cow类型,主键为ID的表
3.创建mor类型主键更新的表
4. 创建分区表
5.CTAS(Create table as select) 创建表
5.1 CTAS创建非分区表
5.2 CTAS创建分区、主键表
参数名称 | 描述 | 可选项:默认值 |
---|---|---|
primaryKey | 表的主键名称,组合主键使用逗号分隔; | (Optional) : id |
type | 表类型:cow’ 或 ‘mor’,默认是cow; | (Optional) : cow |
preCombineField | 当数据的主键相同时,会根据这个字段判断是否要更新此主键的数据。不指定默认保留最新 ; | (Optional) : ts |
-- create a non-primary key table
create table if not exists hudi_table2(id int,name string,price double
) using hudi
options (type = 'cow'
);
-- create a managed cow table
create table if not exists hudi_table0 (id int,name string,price double
) using hudi
options (type = 'cow',primaryKey = 'id'
);
create table if not exists hudi_table1 (id int,name string,price double,ts bigint
) using hudi
options (type = 'mor',primaryKey = 'id,name',preCombineField = 'ts'
);
create table if not exists hudi_table_p0 (
id bigint,
name string,
dt string,
hh string
) using hudi
options (type = 'cow',primaryKey = 'id',preCombineField = 'ts'
)
partitioned by (dt, hh);
create table h3 using hudi
as
select 1 as id, 'a1' as name, 10 as price;
create table h2 using hudi
options (type = 'cow', primaryKey = 'id')
partitioned by (dt)
as
select 1 as id, 'a1' as name, 10 as price, 1000 as dt;
更多的 ddl 参考 SQL DDL | Apache Hudi