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) ]
參數描述
表1 CREATE TABLE參數描述
表2 CREATE TABLE Options描述
示例
?創建非分區表-- 創建一個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_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);
?以SQL方式創建一個hudi表的外表,與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類型。