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

相关推荐
老徐电商数据笔记2 天前
电商实时数仓开发规范
starrocks·数据治理·实时数仓·selectdb·电商数据仓库
科技小花3 天前
数据治理平台架构演进观察:AI原生设计如何重构企业数据管理范式
数据库·重构·架构·数据治理·ai-native·ai原生
Trouvaille ~3 天前
【MySQL篇】数据库操作:从创建到管理
linux·数据库·mysql·oracle·xshell·ddl
Trouvaille ~5 天前
【MySQL篇】表的操作:数据的容器
linux·数据库·mysql·oracle·xshell·ddl·表的操作
科技小花5 天前
AI重塑与全球合规:2026年主流数据治理平台差异化解析
大数据·运维·人工智能·数据治理
Lab_AI7 天前
科研数据管理革命:SDH科学数据基因组破局企业研发瓶颈
数据治理·数据融合·数据智能·科研数据管理·研发数据管理
大大大大晴天️8 天前
Hudi 生产问题排障-乱序Upsert入湖数据丢失
大数据·flink·hudi
红薯大哥9 天前
项目管理系统迁移的字段映射与状态流差异如何处理更省返工
项目管理·数据治理·系统迁移
唐可盐9 天前
【数据治理实践】第 15 期:数据质量提升实战——从“问题发现”走向“根因根治”
大数据·人工智能·数据治理·数字化转型·数据资产·数据资产入表
F36_9_10 天前
中大型企业项目管理系统选 SaaS 还是私有部署更合适
数据治理·企业软件·云部署