【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类型。

相关推荐
亿信华辰软件1 天前
某金融租赁公司数据治理实践
大数据·数据治理
StarRocks_labs3 天前
小红书湖仓架构的跃迁之路
大数据·架构·spark·湖仓一体·lakehouse
moton20178 天前
九、数据治理架构流程
大数据·架构·数据治理·数据架构·数据管控·主数据管理·数据根系
vx1530278236213 天前
CDGA|企业数据治理实战:从疏通“信息河”到打造优质“数据湖”
java·大数据·人工智能·cdga·数据治理
王百万_15 天前
【ClickHouse 特性及应用场景】
大数据·数据库·clickhouse·数据治理·数据库架构
moton201715 天前
一.数据治理理论架构
大数据·数据仓库·数据治理·etl·数据湖·元数据管理·主数据管理
shinelord明16 天前
【技术产品】DS三剑客:DeepSeek、DataSophon、DolphineSchduler浅析
大数据·人工智能·数据治理
胡耀超18 天前
小胡说技书博客分类(部分目录):服务治理、数据治理与安全治理对比表格
大数据·人工智能·安全·微服务·数据治理
数据媛20 天前
参考数据和主数据:构建数据管理的基石
cdga·cdgp·dama·数据治理·主数据·数据管理·参考数据