建立命名空間

在目錄 (例如 Apache Iceberg REST 目錄或 Apache Hive 目錄) 中建立命名空間,有助於在 Lakehouse 執行階段目錄中整理資料表。

事前準備

  1. 請參閱「關於 Lakehouse 執行階段目錄」,瞭解 Lakehouse 執行階段目錄的運作方式和服務限制。
  2. 登入 Google Cloud 帳戶。如果您是 Google Cloud新手,歡迎 建立帳戶,親自評估產品在實際工作環境中的成效。新客戶還能獲得價值 $300 美元的免費抵免額,可用於執行、測試及部署工作負載。

    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

    • 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

    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.

    Enable the API

    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

    • 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

    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.

    Enable the API

必要的角色

如要取得建立命名空間所需的權限,請要求管理員在專案中授予您下列 IAM 角色:

如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。

您或許也能透過自訂角色或其他預先定義的角色,取得必要權限。

建立命名空間

在目錄中建立命名空間。

注意事項

建立命名空間時,您可以選擇指定要與命名空間建立關聯的 Cloud Storage 值區或路徑:

  • 多值區 (bl://) (建議):只要自訂位置位於目錄允許的位置 (default_locationrestricted_locations),您就可以設定任何自訂位置。如果未指定位置,系統會在目錄的預設位置 (例如 gs://{default_location}/{namespace_name}) 下建立命名空間。
  • 單一 bucket (gs://):系統會自動從目錄的單一 bucket 繼承命名空間位置。

控制台

  1. 在 Google Cloud 控制台中開啟「Lakehouse」Lakehouse頁面。

    前往 Lakehouse

  2. 選取現有目錄,或建立目錄 (如果沒有的話)。

  3. 在選單列中,按一下「+ 建立命名空間」

  4. 在「命名空間名稱」欄位中,輸入命名空間的專屬名稱。

  5. 在「位置」部分,視需要指定要與命名空間建立關聯的 Cloud Storage 值區或路徑。位置與倉庫 bucket 相符。

  6. 點選「建立」

    系統會建立命名空間,並顯示在目錄詳細資料清單中。

gcloud

在多 bucket (bl://) 目錄中建立命名空間 (建議做法)

如要在多值區目錄中建立命名空間 (可選擇指定自訂位置),請執行 gcloud biglake iceberg namespaces create 指令並加上 --properties 旗標:

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 bucket 或路徑 (例如 gs://my-bucket/my-path)。

在單一 bucket (gs://) 目錄中建立命名空間

如要在單一 bucket 目錄中建立命名空間,請省略 --properties 旗標。命名空間位置會自動從目錄的單一 bucket 繼承。

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 酬載,定義命名空間 ID 和屬性:

{
  "namespace": [
    "NAMESPACE_NAME"
  ],
  "properties": {
    "location": "LOCATION"
  }
}

更改下列內容:

  • PROJECT_ID:您的 Google Cloud 專案 ID。
  • CATALOG_ID:目錄 ID。
  • NAMESPACE_NAME:命名空間名稱。
  • LOCATION:(選用) 要與命名空間建立關聯的自訂 Cloud Storage bucket 或路徑 (例如 gs://my-bucket/my-path)。

後續步驟