在目录(例如 Apache Iceberg REST 目录或 Apache Hive 目录)中创建命名空间有助于您在 Lakehouse 运行时目录中整理表。
准备工作
- 请参阅关于 Lakehouse 运行时目录,了解 Lakehouse 运行时目录的运作方式以及该服务的限制。
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles. - Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
Verify that billing is enabled for your Google Cloud project.
Enable the BigLake API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM
role (roles/serviceusage.serviceUsageAdmin), which
contains the serviceusage.services.enable permission. Learn how to grant
roles.
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
Verify that billing is enabled for your Google Cloud project.
Enable the BigLake API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM
role (roles/serviceusage.serviceUsageAdmin), which
contains the serviceusage.services.enable permission. Learn how to grant
roles.
所需的角色
如需获得创建命名空间所需的权限,请让管理员向您授予项目的以下 IAM 角色:
- 全部:
- BigLake Admin (
roles/biglake.admin) - Storage Admin (
roles/storage.admin)
- BigLake Admin (
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
创建命名空间
在目录中创建命名空间。
注意事项
创建命名空间时,您可以选择指定要与该命名空间关联的 Cloud Storage 存储桶或路径:
- 多区域存储桶 (
bl://)(推荐):您可以设置任何自定义位置,只要该位置位于目录允许的位置(default_location或restricted_locations)下即可。如果您未指定位置,系统会在目录的默认位置(例如gs://{default_location}/{namespace_name})下创建命名空间。 单存储桶 (
gs://):命名空间位置会自动从目录的单个存储桶继承。
控制台
在 Google Cloud 控制台中,打开 Lakehouse 页面。
选择现有目录,或者创建目录(如果您还没有目录)。
在菜单栏中,点击 + 创建命名空间。
对于命名空间名称,为您的命名空间输入一个唯一的名称。
对于位置,您可以选择指定要与命名空间关联的 Cloud Storage 存储桶或路径。位置与仓库存储桶匹配。
点击创建。
您的命名空间已创建,并显示在目录详情列表中。
gcloud
在多存储桶 (bl://) 目录中创建命名空间(推荐)
如需在多存储桶目录中创建命名空间(您可以选择性地指定自定义位置),请运行带有 --properties 标志的 gcloud biglake iceberg namespaces create 命令:
gcloud biglake iceberg namespaces create NAMESPACE_NAME \ --project="PROJECT_ID" \ --catalog="CATALOG_ID" \ [--properties="location=LOCATION"]
替换以下内容:
NAMESPACE_NAME:命名空间的名称。PROJECT_ID:您的 Google Cloud 项目 ID。CATALOG_ID:目录的 ID。LOCATION:(可选)要与命名空间关联的自定义 Cloud Storage 存储桶或路径(例如gs://my-bucket/my-path)。
在单存储桶 (gs://) 目录中创建命名空间
如需在单存储桶目录中创建命名空间,请省略 --properties 标志。命名空间位置会自动从目录的单个存储桶继承。
gcloud biglake iceberg namespaces create NAMESPACE_NAME \ --project="PROJECT_ID" \ --catalog="CATALOG_ID"
REST
如需使用 REST API 创建命名空间,请向 CreateIcebergNamespace 端点发出 POST 请求:
POST /iceberg/v1/restcatalog/v1/projects/PROJECT_ID/catalogs/CATALOG_ID/namespaces
请求正文必须包含有效的 Iceberg CreateNamespaceRequest JSON 载荷,用于定义命名空间标识符和属性:
{
"namespace": [
"NAMESPACE_NAME"
],
"properties": {
"location": "LOCATION"
}
}
替换以下内容:
PROJECT_ID:您的 Google Cloud 项目 ID。CATALOG_ID:目录的 ID。NAMESPACE_NAME:命名空间的名称。LOCATION:(可选)要与命名空间关联的自定义 Cloud Storage 存储桶或路径(例如gs://my-bucket/my-path)。