在指定的Table Bucket和命名空间下创建一个Iceberg表。
注意事项
表名称只能包含小写字母、数字和下划线(_),且必须以小写字母或数字开头和结尾。
同一个Namespace下的表名称不能重复。
--metadata参数需要传入JSON格式的表元数据,定义Iceberg表的Schema。可以通过命令行内联JSON或使用
file://指定本地JSON文件。目前--format参数仅支持
ICEBERG。
命令格式
ossutil tables-api create-table --table-bucket-arn value --namespace value --name value --format value [flags]参数 | 类型 | 说明 |
--encryption-configuration | string | 表的加密配置,JSON格式。用于指定服务端加密方式。 |
--format | string | 表格式,目前仅支持 |
--metadata | string | 表元数据,JSON格式。用于定义Iceberg表的Schema,包括字段信息。 |
--name | string | 表名称。只能包含小写字母、数字和下划线。 |
--namespace | string | 表所在的命名空间名称。 |
--table-bucket-arn | string | Table Bucket的ARN,格式为 |
create-table命令对应API接口CreateTable。关于API中的具体参数含义,请参见CreateTable。
关于支持的全局命令行选项,请参见ossutil全局选项。
--metadata参数的JSON语法如下:
{
"iceberg": {
"schema": {
"fields": [
{
"id": 1,
"name": "id",
"type": "long",
"required": true
},
{
"id": 2,
"name": "name",
"type": "string",
"required": false
},
{
"id": 3,
"name": "created_at",
"type": "timestamp",
"required": false
}
]
}
}
}其中,每个字段(field)的属性说明如下:
id:字段编号,整数类型,必须唯一且递增。
name:字段名称,字符串类型。
type:字段数据类型,支持
long、string、int、boolean、float、double、timestamp等Iceberg支持的类型。required:是否为必填字段,布尔类型。设置为
true表示该字段不允许为空。
使用示例
在命名空间
my_namespace下创建名为my_table的Iceberg表,通过内联JSON指定表的Schema。ossutil tables-api create-table --table-bucket-arn acs:osstables:cn-hangzhou:1234567890:bucket/my-table-bucket --namespace my_namespace --name my_table --format ICEBERG --metadata '{"iceberg":{"schema":{"fields":[{"id":1,"name":"id","type":"long","required":true},{"id":2,"name":"data","type":"string"}]}}}'通过本地JSON文件创建Iceberg表。将表元数据保存为本地文件
table_metadata.json后,通过file://方式指定。ossutil tables-api create-table --table-bucket-arn acs:osstables:cn-hangzhou:1234567890:bucket/my-table-bucket --namespace my_namespace --name my_table --format ICEBERG --metadata file://table_metadata.json