数据湖计算 DLC DDL 语法(Iceberg 表语法)

CREATE TABLE [ IF NOT EXISTS ] table_identifier( col_name[:] col_type [ COMMENT col_comment ], … )[ COMMENT table_comment ][ PARTITIONED BY ( col_name1, transform(col_name2), … ) ]。

相关产品
数据湖计算 DLC 产品页,含版本规格、价格与购买入口。

注意:说明:

注意:以下语法说明为 DLC 原生表语法,DLC 原生表默认为 Iceberg 表。如果你使用 Iceberg 外部表,在 DDL 语法上会有细节差异,可参考文档 Iceberg 外部表与原生表语法差异。

四、table_identifier

table_identifier 支持三段式:catalog.db.name。

五、Schemas and Data Types

col_type: primitive_type | nested_typeprimitive_type: boolean| int/integer| long/bigint| float| double| decimal(p,s),p=最大位数,s=最大小数点位数, s<=p<=38| date| timestamp,timestamp with timezone,不支持time和without timezone| string,也可对应Iceberg uuid类型| binary,也可对应Iceberg fixed类型nested_type: struct| list| map

六、Partition Transforms

transform: identity,支持任意类型, DLC不支持该转换| bucket[N],hash mod N分桶,支持col_type: int,long, decimal, date, timestamp, string, binary| truncate[L],L截取分桶,支持col_type: int,long,decimal,string| years,年份,支持col_type: date,timestamp| months,月份,支持col_type: date,timestamp| days/date,日期,支持col_type: date,timestamp| hours/date_hour,小时,支持col_type: timestamp

七、示例

CREATE TABLE dempts( id bigint COMMENT 'id number', num int, eno float, dno double, cno decimal(9,3), flag boolean, data string, ts_year timestamp, date_month date, bno binary, point struct<x: double, y: double>, points array<struct<x: double, y: double>>, pointmaps map<struct<x: int>, struct<a: int>>)COMMENT 'table documentation'PARTITIONED BY (bucket(16,id), years(ts_year), months(date_month), identity(bno), bucket(3,num),truncate(10,data));

九、语法

CREATE TABLE [ IF NOT EXISTS ] table_identifier [ COMMENT table_comment ] [ PARTITIONED BY ( col_name1, transform(col_name2), … ) ] [ TBLPROPERTIES ( property_name=property_value, … ) ]AS select_statement

十、示例

CREATE TABLE dempts_copyCOMMENT 'table create as select' PARTITIONED BY (eno, dno) AS SELECT * from dempts;

十一、REPLACE TABLE AS SELECT

保留表历史 History 的情况下,用 SELECT 查询的结果生成一个快照 Snapshot 来更新表。

十二、语法

CREATE [OR REPLACE] TABLE table_identifier [ COMMENT table_comment ] [ PARTITIONED BY ( col_name1, transform(col_name2), … ) ]AS select_statement

十三、示例

CREATE OR REPLACE TABLE dempts_replace COMMENT 'table create as replace' PARTITIONED BY (eno, dno) AS SELECT * from dempts;

十五、语法

DROP TABLE [ IF EXISTS ] table_identifier

十六、ALTER TABLE

变更表语法。

十七、ALTER TABLE … RENAME TO

变更表名称。

十八、语法

ALTER TABLE table_identifier RENAME TO new_table_identifier

十九、ALTER TABLE … SET / UNSET TBLPROPERTIES

更新/删除数据表属性。

20、语法

— SET 更新属性配置ALTER TABLE table_identifier SET TBLPROPERTIES (property_name=property_value, …)– UNSET 删除属性配置ALTER TABLE table_identifier UNSET TBLPROPERTIES (property_name, …)

21、示例

— SET 更新属性配置ALTER TABLE dempts SET TBLPROPERTIES ('read.split.target-size'='268435456');– UNSET 删除属性配置ALTER TABLE dempts UNSET TBLPROPERTIES ('read.split.target-size'='268435456');

22、ALTER TABLE … WRITE ORDERED BY

设置表数据插入时的排序方式。

23、语法

ALTER TABLE table_identifier WRITE [LOCALLY] ORDERED BY {col_name [ASC|DESC] [NULLS FIRST|LAST]}[, …]

24、示例

ALTER TABLE dempts WRITE ORDERED BY category, id;– 使用可选的 ASC/DESC 关键字来指定每个字段的排序顺序(默认是 ASC)ALTER TABLE dempts WRITE ORDERED BY category ASC, id DESC;– 使用可选的 NULLS FIRST/NULLS LAST 关键字来指定每个字段的空值排序顺序(默认是 FIRST)ALTER TABLE dempts WRITE ORDERED BY category ASC NULLS LAST, id DESC NULLS FIRST;– 要在每个任务内部进行排序,而非跨任务排序ALTER TABLE dempts WRITE LOCALLY ORDERED BY category, id;

25、ALTER TABLE … WRITE DISTRIBUTED BY PARTITION

修改分区表的数据分配策略。

26、语法

ALTER TABLE table_identifier WRITE DISTRIBUTED BY PARTITION [ LOCALLY ORDERED BY {col_name [ASC|DESC] [NULLS FIRST|LAST]}[, …]]

27、示例

ALTER TABLE dempts WRITE DISTRIBUTED BY PARTITION;ALTER TABLE dempts WRITE DISTRIBUTED BY PARTITION LOCALLY ORDERED BY id;

28、ALTER TABLE COLUMNS

变更字段语法。

29、ALTER TABLE … ADD COLUMNS

新增多个字段。

30、语法

— 新增多个字段ALTER TABLE table_identifier ADD COLUMNS (col_name col_type [COMMENT col_comment], …)– 新增单个字段ALTER TABLE table_identifier ADD COLUMN col_name col_type [COMMENT col_comment] [FIRST | AFTER target_col_name]

31、示例

— 新增多个字段ALTER TABLE demptsADD COLUMNS ( new_column_1 string comment 'new_column_1 docs', new_column_2 int comment 'new_column_2 docs');– 新增单个字段ALTER TABLE dempts ADD COLUMN new_column_3 string comment 'new_column docs';

32、ALTER TABLE … RENAME COLUMN

变更字段名称。

33、语法

ALTER TABLE table_identifier RENAME COLUMN old_column_name TO new_column_name

34、ALTER TABLE … ALTER COLUMN

变更字段类型/备注信息。

35、语法

ALTER TABLE table_identifier ALTER COLUMN col_name {TYPE new_col_type | COMMENT col_comment}

目前Iceberg TYPE 变更,仅支持字段类型安全扩展:

·int/integer -> long/bigint

·float -> double

·decimal(P,S) -> decimal(P2,S),其中P2 > P,即精准度提升。

36、示例

ALTER TABLE dempts ALTER COLUMN new_column_2 TYPE bigint;ALTER TABLE dempts ALTER COLUMN new_column_2 comment 'alter docs';

37、ALTER TABLE … DROP COLUMN

删除表字段。

38、语法

ALTER TABLE table_identifier DROP COLUMN column_name

40、ALTER TABLE … ADD PARTITION FIELD

新增单个分区字段。

41、语法

ALTER TABLE table_identifier ADD PARTITION FIELD col_name|transform (col_name) [AS alias]

transform 参考 CREATE TABLE 说明。

42、示例

ALTER TABLE dempts ADD PARTITION FIELD new_column_1;ALTER TABLE dempts ADD PARTITION FIELD bucket(3,new_column_2);

43、ALTER TABLE … REPLACE PARTITION FIELD

替换单个分区字段。

44、语法

ALTER TABLE table_identifier REPLACE PARTITION FIELD col_name|transform (col_name) [AS alias]

45、ALTER TABLE … DROP PARTITION FIELD

删除单个分区字段。

46、语法

ALTER TABLE table_identifier DROP PARTITION FIELD col_name|transform (col_name);

transform 参考 CREATE TABLE 说明。

47、示例

ALTER TABLE dempts DROP PARTITION FIELD new_column_1;ALTER TABLE dempts DROP PARTITION FIELD bucket(3,new_column_2);

48、ALTER TABLE … SET IDENTIFIER FIELDS

添加 identifier fields 属性。

49、语法

ALTER TABLE dempts SET IDENTIFIER FIELDS empno, name

50、ALTER TABLE .. DROP IDENTIFIER FIELDS

添加 identifier fields 属性。

51、语法

ALTER TABLE dempts DROP IDENTIFIER FIELDS empno, name

赞 (0)
上一篇 4天前
下一篇 4天前