建立Table

更新時間:
Copy as MD

在指定的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

表格式,目前僅支援ICEBERG

--metadata

string

表中繼資料,JSON格式。用於定義Iceberg表的Schema,包括欄位資訊。

--name

string

表名稱。只能包含小寫字母、數字和底線。

--namespace

string

表所在的命名空間名稱。

--table-bucket-arn

string

Table BucketARN,格式為acs:osstables:{region}:{uid}:bucket/{bucket-name}

說明
  • 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:欄位資料類型,支援longstringintbooleanfloatdoubletimestampIceberg支援的類型。

  • required:是否為必要欄位,布爾類型。設定為true表示該欄位不允許為空白。

使用樣本

  • 在命名空間my_namespace下建立名為my_tableIceberg表,通過內聯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