Unity Catalog REST API 和 Iceberg Catalog REST API
元数据服务实现了 Iceberg REST 目录和 Unity 目录开放 API 规范中选定的 API。 您可以从标准 REST 客户端利用这些 API。 使用 REST 客户端的好处是可以直接与元数据库交互,而无需使用引擎。
Unity 目录 REST API
以下是包含的应用程序接口:
目录
- POST /catalogs
- GET /catalogs
- GET {name}
- PATCH {name}
- DELETE {name}
模式
- POST /schemas
- GET /schemas
- GET {full_name}
- PATCH {full_name}
- DELETE {full_name} (模式/{full_name})
Tables
- POST /tables
- GET /tables
- GET {full_name}
- DELETE {full_name} (删除表/{full_name})
用于 GET 目录的 Unity API 示例
curl -k -X GET "https://80e7cce9-c14f-4aa8-8a3b-c52adc25efac.cdc406pd09pasng7elgg.lakehouse.dev.appdomain.cloud:32230/api/2.1/unity-catalog/catalogs" --header "Authorization: Bearer $token" --header 'Content-Type: application/json'
{
"catalogs": [
{
"name": "ad_catalog",
"comment": "",
"properties": {
"catalogType": "delta",
"storageName": "func-test-bucket"
},
"created_at": 1733724384000,
"updated_at": 0,
"id": "3186f83a-8879-46c4-b48e-125741c34e88",
"owner": "anurag",
"created_by": "anurag",
"updated_by": null
},
{
"name": "testth",
"comment": "",
"properties": {
"catalogType": "iceberg",
"storageName": "mdshms"
},
"created_at": 1733724482000,
"updated_at": 0,
"id": "9ce30ab7-1321-4189-bb10-765093d1932c",
"owner": "antony",
"created_by": "antony",
"updated_by": null
}
],
"next-page-token": null
}
用于 GET 目录模式的 Unity API 示例
curl -k -X GET "https://80e7cce9-c14f-4aa8-8a3b-c52adc25efac.cdc406pd09pasng7elgg.lakehouse.dev.appdomain.cloud:32230/api/2.1/unity-catalog/schemas?catalog_name=mrmadira_hive_catalog" --header "Authorization: Bearer $token" --header 'Content-Type: application/json'
{
"schemas": [
{
"name": "dec92024",
"catalog_name": "mrmadira_hive_catalog",
"comment": null,
"properties": {
"locationUri": "s3a://testbucket/dec92024"
},
"full_name": "mrmadira_hive_catalog.dec92024",
"created_at": 0,
"updated_at": 0,
"schema_id": "135"
}
]
}
行为和限制
由于不能修改模式,Unity REST 规范的 properties
字段中必须包含一些必填字段。
创建目录时,locationUri
、数据桶名称(通过 watsonx.data 注册)和 catalogType
字段是必填字段,必须在 properties
字段中提供:
"properties": {
"locationUri": "s3a://func-test-bucket/unity_schema",
"bucket": "func-test-bucket",
"catalogType": "ICEBERG"
}
创建模式时,locationUri 是必填字段,必须包含在 properties
字段中:
"properties": {
"locationUri": "s3a://func-test-bucket/unity_schema"
}
在创建表格时,Unity 规范中还有一些额外的字段没有提供。 元数据服务会忽略为这些字段提供的任何信息,这些信息也不会存储在数据库中:
"columns": [
{
"type_json": "string",
"type_name": "string",
"type_precision": 0,
"type_scale": 0,
"type_interval_type": "string",
"position": 0,
"nullable": true,
"partition_index": 0
}
]
如果在请求对象的属性中传递了额外值,由于遵守当前的 HMS 模式,这些值不会存储在任何表中。 今后如有需要,您可以在 properties
字段中添加更多详细信息。
更多信息,请参阅 API 文档。
冰山目录 REST API
以下是包含的应用程序接口:
名称空间
- 列出命名空间
- 创建名称空间
- 为命名空间加载元数据属性
- 检查命名空间是否存在
- 删除命名空间
冰山表格相关
- 在给定的命名空间中创建表格
- 使用元数据位置注册表
- 加载表格
- 检查表是否存在
- 重命名表格
- 在原子事务中提交对多个表的更新
- 提交对表格的更新
- 删除表
视图
- 列出所有视图标识符
- 加载视图
- 检查视图是否存在
- 重命名视图
- 删除视图
配置
- 将目录配置为前缀的配置端点
冰山 API 示例
获取目录的命名空间
curl -k --request GET --url 'https://80e7cce9-c14f-4aa8-8a3b-c52adc25efac.cdc406pd09pasng7elgg.lakehouse.dev.appdomain.cloud:32230/mds/iceberg/v1/hemant_test/namespaces' --header 'Accept: application/json' --header "Authorization: Bearer $token" --header 'Content-Type: application/json' | jq
{
"namespaces": [
[
"hemant_test"
],
[
"order_schema_ad"
],
[
"schema1150850f-ece4-4c27-8794-e05b984adff5"
]
],
"next-page-token": null
}
为模式获取表格
curl -k --request GET --url 'https://80e7cce9-c14f-4aa8-8a3b-c52adc25efac.cdc406pd09pasng7elgg.lakehouse.dev.appdomain.cloud:32230/mds/iceberg/v1/hemant_test/namespaces/schema_cpd' --header 'Accept: application/json' --header "Authorization: Bearer $token" --header 'Content-Type: application/json' | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 74 0 74 0 0 52 0 --:--:-- 0:00:01 --:--:-- 52
{
"namespace": [
"schema_cpd"
],
"properties": {
"owner": "hemant"
}
}
行为和限制
由于不能修改模式,因此不支持以下功能:
- 创建多级命名空间
- 由于 Hive 是 DBS 表中所有数据库或命名空间的目录,因此即使命名空间存在于 Iceberg 以外的目录中,也不支持创建命名空间。
- 如果列出模式,则只返回当前目录中带有指定前缀的命名空间。 但是,如果尝试创建存在于其他目录中的命名空间,则会返回
Namespace Already Exists
异常。 - 列出表格时,只返回冰山表格。 如果尝试创建的表名称与同一数据库或命名空间中的 Hive 表或 Delta 表名称相同,则不允许创建同名的 Iceberg 表。
- 不支持 X-Iceberg-Access-Delegation。
- 指标端点仅作为虚拟端点添加。
- Presto 由于编码不兼容,无法查询使用 Iceberg REST 目录 API 创建的视图。 这种不兼容性同样会影响从 Spark 创建的视图,而 Presto 也无法查询这些视图。 不过,Spark 可以顺利查询通过 REST 目录 API 创建的视图。
更多信息,请参阅 API 文档。
常见限制:在创建目录和表格时不支持某些属性
由于当前架构的限制,创建目录和表格时,以下属性将不会被保存:
- 目录:
- 备注
- 表格(列阵列内):
- 类型精度
- 类型比例
- 类型间隔类型
- 位置
- 可空
- 分区索引
- 表格(列阵列之外):
- 备注