【Hudi-SQL DDL创建表语法】

CREATE TABLE

命令功能

CREATE TABLE命令通过指定带有表属性的字段列表来创建Hudi Table。

命令格式

bash 复制代码
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内部表

bash 复制代码
create table if not exists hudi_table0 (
id int,
name string,
price double
)  using hudi
options (
type = 'cow',
primaryKey = 'id'
);

-- 创建一个mor外部表

bash 复制代码
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'
);

•创建分区表

bash 复制代码
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外表相同

bash 复制代码
create table h_p1
using hudi
options (
primaryKey = 'id',
preCombineField = 'ts'
)
partitioned by (dt)
location '/path/to/hudi';

•创建表指定表属性

bash 复制代码
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类型。

相关推荐
猫猫姐姐5 天前
Flink基于Paimon的实时湖仓解决方案的演进
大数据·flink·湖仓一体
北邮-吴怀玉9 天前
1.4.2 大数据方法论与实践指南-质量治理(准确性&及时性)
大数据·数据治理
北邮-吴怀玉9 天前
6.1.1.3 大数据方法论与实践指南-SparkStreaming 任务优化实践
大数据·flink·spark·数据治理
北邮-吴怀玉9 天前
8.1.1 大数据方法论与实践指南-埋点需求流程
大数据·数据治理
北邮-吴怀玉9 天前
1.4.5 大数据方法论与实践指南-安全&合规
大数据·运维·网络·数据治理
北邮-吴怀玉9 天前
7.1.5 大数据方法论与实践指南-日志系统+监控报警
大数据·数据治理
北邮-吴怀玉9 天前
7.1.1 大数据方法论与实践指南-数仓元数据平台(数据地图)
大数据·数据治理
北邮-吴怀玉9 天前
7.1.3 大数据方法论与实践指南-查询平台
大数据·数据治理
北邮-吴怀玉10 天前
6.1.2.1 大数据方法论与实践指南-离线任务分类
大数据·数据治理
半路_出家ren10 天前
图书销售系统数据库设计方案
数据库·mysql·子查询·ddl·dml·数据库设计·分组查询