BigQuery 共用整合

Google Cloud Cortex Framework 可讓您將 BigQuery 共用中已訂閱的連結資料集,註冊為外部 analytics_hub 目錄模組。連結零複製共用資料集後,您就能直接在 BigQuery 中,將外部商業、環境、合作夥伴或跨組織資料,與預先建構的 SAP ERP、SAP Business Data Cloud (SAP BDC) 和 Salesforce 業務資料產品混合,不必建構或維護擷取管道。

支援的共用情境

您可以註冊透過 BigQuery sharing 訂閱的任何連結 BigQuery 資料集,只要該資料集位於 data.modules.catalogs (type: analytics_hub) 即可,包括:

  • 環境和地理空間預測:結合天氣系集預報 (例如 Google WeatherNext) 與工廠、倉庫和進貨時間表,模擬供應鏈中斷風險。
  • 商業和物流情報:將第三方風險、信用和海事遙測動態饋給 (例如鄧白氏全球航運洞察),與供應商和訂購單模型彙整。
  • 公開和合作夥伴資料交換:運用 Google Cloud Marketplace 和公開資料交換平台發布的總體經濟指標、客層參考表格或業界基準,充實企業指標。
  • 跨組織和客戶 360 共用:連結跨 Google Cloud 組織共用的內部資料網格清單,或免複製 Salesforce Data 360 共用。

比較外部目錄類型

Cortex Framework 支援兩種外部零複製目錄模組類型。請參閱下表,比較兩者的基礎架構需求:

維度 BigQuery sharing (analytics_hub) BigLake Delta Sharing (lakehouse_delta_share)
主要來源 已訂閱的 BigQuery 連結資料集 (商業產品資訊、WeatherNext、Dun & Bradstreet、公開資料集、跨組織共用、Salesforce Data 360) 匯入 BigLake 的 Delta Sharing 共用項目 (例如 SAP Business Data Cloud)
必要 Google Cloud API bigquery.googleapis.com 和 analyticshub.googleapis.com bigquery.googleapis.com、biglake.googleapis.com、bigqueryreservation.googleapis.com 和 cloudresourcemanager.googleapis.com
BigQuery 版本需求 標準隨選或版本運算資源 (不需預留 Enterprise Plus) 必須具備有效的 BigQuery Enterprise Plus 預留項目指派作業
來源資料表探索 在 inlineTableSettings.tables (或 inlineTableSettings.variants) 中宣告的確定性資料表和檢視表許可清單 從 BigLake 目錄中匯入的 connectionSettings.shares 探索 (可選擇使用 tableSettings 或 inlineTableSettings 篩選)

事前準備

在 Cortex Framework 中註冊 analytics_hub 目錄模組之前,請先完成下列必要條件。

啟用 Google Cloud API

在託管訂閱連結資料集的專案和部署專案中,啟用必要的 Google Cloud API:

gcloud services enable bigquery.googleapis.com \
    analyticshub.googleapis.com \
    dataform.googleapis.com \
    --project=PROJECT_ID

更改下列內容:

  • PROJECT_ID:託管連結資料集或執行 Dataform 管道的 Google Cloud 專案 ID,例如:my-cortex-project。

訂閱產品資訊

在 Google Cloud中,訂閱 BigQuery sharing 中的產品資訊,在消費者專案中建立唯讀連結資料集。確認連結的資料集 (或設定的跨區域資料集副本) 與 config/config.yaml 中的 data.bigQueryLocation 位於相同位置,並記錄要納入 inlineTableSettings.tables (或 inlineTableSettings.variants) 的共用資料表或檢視表名稱。

取得必要角色

如要取得訂閱產品資訊及在 BigQuery Sharing 目錄中建構資料產品所需的權限,請要求管理員授予您下列 IAM 角色:

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

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

註冊 analytics_hub 目錄

在 config/config.yaml 中,使用 type: analytics_hub 註冊 data.modules.catalogs 下的每個訂閱連結資料集。請在 connectionSettings.datasetId 中僅指定簡短的 BigQuery 資料集 ID (英文字母、數字和底線),並在 inlineTableSettings.tables 中宣告非空白的共用資料表或檢視表名稱清單 (或 inlineTableSettings.variants 下選用的變異基因段專屬清單,與目錄項目上的 variants 配對)。在uv run cortex-build期間,AnalyticsHubCatalogBuilder會專門為列出的資料表產生 Dataform 來源宣告 (definitions/sources/<project>_<dataset>_sources.js),不會掃描不相關的物件或複製資料。

buildEnvironment:
  buildProjectId: BUILD_PROJECT_ID

data:
  bigQueryLocation: US
  namespaces:
    - name: cortex
    - name: cortex_samples
    - name: custom
      path: ../src/data_modules/custom
  datasets:
    - id: custom_products
      projectId: TARGET_PROJECT_ID
      datasetId: custom_supply_chain_insights

  modules:
    catalogs:
      # Example 1: Google WeatherNext linked dataset subscribed from BigQuery sharing.
      - id: ah_weathernext_catalog
        type: analytics_hub
        enabled: true
        bindsNamespaces:
          - cortex.external.weathernext
        connectionSettings:
          projectId: LINKED_DATASET_PROJECT_ID
          datasetId: WEATHERNEXT_DATASET_ID
          location: US
          # Optional source listing ID (auto-discovered when omitted):
          listingId: projects/PROVIDER_PROJECT_ID/locations/US/dataExchanges/EXCHANGE_ID/listings/LISTING_ID
        inlineTableSettings:
          tables:
            - weathernext_3_0_0
            - weathernext_daily_forecast

      # Example 2: Dun & Bradstreet shipping insights linked dataset.
      - id: ah_dnb_catalog
        type: analytics_hub
        enabled: true
        bindsNamespaces:
          - cortex.external.dnb
        connectionSettings:
          projectId: LINKED_DATASET_PROJECT_ID
          datasetId: DNB_DATASET_ID
          location: US
        inlineTableSettings:
          tables:
            - shipping_insights
            - company_profile

    products:
      # Composite data product blending SAP or Salesforce models with shared catalog tables.
      - moduleId: custom_delivery_weather_risk
        modulePath: custom.sap.products.delivery_weather_risk
        dataTargetId: custom_products
        dependencyBindings:
          sapDeliveries: sap_delivery_documents
          sapCustomers: sap_customers
          weatherNext: ah_weathernext_catalog.weathernext_daily_forecast
          dnbCatalog: ah_dnb_catalog

更改下列內容:

  • BUILD_PROJECT_ID:用於建構驗證的 Google Cloud 專案 ID,例如:my-build-project。
  • TARGET_PROJECT_ID:具體化可寫入下游資料產品的 Google Cloud 專案 ID,例如:my-target-project。
  • LINKED_DATASET_PROJECT_ID:託管訂閱連結資料集的 Google Cloud 專案 ID,例如:my-subscriber-project。
  • WEATHERNEXT_DATASET_ID:訂閱的 WeatherNext 連結資料集 BigQuery 資料集 ID,例如:weathernext_linked。
  • DNB_DATASET_ID:訂閱的 Dun & Bradstreet 連結資料集 BigQuery 資料集 ID,例如:dnb_shipping_insights_linked。
  • PROVIDER_PROJECT_ID:connectionSettings.listingId 的選用發布者 Google Cloud 專案 ID,例如:weathernext-provider。
  • EXCHANGE_ID:connectionSettings.listingId 的選用 BigQuery 共用資料交換 ID,例如:weather_data_exchange。
  • LISTING_ID:connectionSettings.listingId 的選用 BigQuery sharing 資訊清單 ID,例如:weathernext_daily。您可以將 listingId 指定為標準資源路徑、完整商家資訊網址,或從 Google Cloud 控制台複製的四部分點分隔 ID (其中 LOCATION 是交換位置,例如 US):

    projects/PROVIDER_PROJECT_ID/locations/LOCATION/dataExchanges/EXCHANGE_ID/listings/LISTING_ID
    PROVIDER_PROJECT_ID.LOCATION.EXCHANGE_ID.LISTING_ID
    

    如果省略 listingId,Cortex Framework 會自動從連結資料集的訂閱中繼資料或資料集說明,探索來源清單。

如需完整的欄位規格,請參閱「資料:模組:目錄」。

繫結複合資料產品中的共用資料表

data.modules.products 下的下游資料產品可使用下列兩種格式之一,繫結至 dependencyBindings 中的 analytics_hub 目錄:

  • 兩部分繫結 (<catalog_id>.<table_name> 或 <catalog_id>.<dataset_id>):將邏輯依附元件索引鍵繫結至 inlineTableSettings.tables 中列出的特定資料表或檢視表 (例如 weatherNext: ah_weathernext_catalog.weathernext_daily_forecast),或繫結至目錄設定的 datasetId。在 includes/config.js 中,moduleConfig.sources.<dependencyKey> 會解析 { projectId, datasetId, tables: [...] } (不含 tableName 屬性),因此請將 projectId、datasetId 和宣告的資料表名稱字串傳遞至 ctx.ref(...)。
  • 單部分目錄繫結 (<catalog_id>):當模組的 manifest.yaml 在與 bindsNamespaces 相符的命名空間下宣告必要的資料表名稱時,將邏輯依附元件索引鍵繫結至整個目錄執行個體 (例如 dnbCatalog: ah_dnb_catalog)。

下列 Dataform .js 範例使用 includes/ 的 publish_config.getPublishConfig(...) 和 publisher.publish(...) (因此資料表設定和上游 blocking: true 斷言會自動附加),使用兩部分格式彙整預先建構的 sap_delivery_documents (cortex.sap.products.delivery_documents) 和 sap_customers (cortex.sap.products.customers) 資料產品與繫結的共用資料表:

// ___MODULE_CONTEXT___
// ___TABLE_CONFIG___

const publish_config = require("includes/publish_config.js");
const publisher = require("includes/publisher.js");

const moduleConfig = config.product[moduleContext.moduleId];
const sapDeliveriesDataset = moduleConfig.sources.sapDeliveries.datasetId;
const sapCustomersDataset = moduleConfig.sources.sapCustomers.datasetId;
const weatherSource = moduleConfig.sources.weatherNext;

const materializationType = tableConfig.materializationType || "table";
const publishConfig = publish_config.getPublishConfig(
  materializationType,
  tableConfig,
  moduleConfig
);

publisher.publish(moduleContext.moduleId + "_" + tableConfig.tableName, publishConfig).query(
  (ctx) => `
    SELECT
      d.document_number_vbeln,
      d.ship_to_party_kunnr,
      c.postal_code_pstlz,
      w.init_time,
      w.precipitation_total_mm
    FROM ${ctx.ref(sapDeliveriesDataset, "delivery_document_headers")} AS d
    LEFT JOIN ${ctx.ref(sapCustomersDataset, "customers")} AS c
      ON d.client_mandt = c.client_mandt
      AND d.ship_to_party_kunnr = c.customer_number_kunnr
    LEFT JOIN ${ctx.ref(
      weatherSource.projectId,
      weatherSource.datasetId,
      "weathernext_daily_forecast"
    )} AS w
      ON c.postal_code_pstlz = w.postal_code
  `
);

如要瞭解可部署的多來源參考實作,結合 SAP BDC 與 Google WeatherNext 3 和 Dun & Bradstreet Global Shipping Insights,請參閱「供應商和工廠天氣風險洞察」和「供應商入庫交貨天氣風險洞察」。

擷取及快取 Agentic Workflows 的中繼資料

使用代理技能建構自訂複合資料產品時,Cortex Framework 會自動檢查 BigQuery 實體資料表結構定義和 BigQuery 共用清單中繼資料,並在本機快取,讓 AI 程式設計助理生成準確的 SQL join,不必猜測資料欄名稱。

對設定的目錄 ID 執行 cortex-metadata fetch:

export CORTEX_CONFIG_FILE=config/config.yaml
uv run cortex-metadata fetch \
    --config $CORTEX_CONFIG_FILE \
    --module-id CATALOG_ID

更改下列內容:

  • CATALOG_ID:config/config.yaml 中 analytics_hub 目錄項目的 id,例如:ah_weathernext_catalog。

擷取器會擷取並快取:

  • 實體 BigQuery 中繼資料:inlineTableSettings.tables 中每個資料表的資料欄名稱、資料類型、說明、分區和分群定義、預估資料列數和位元組大小。
  • 產品資訊管理中繼資料:發布者、資料供應商、顯示名稱、類別、說明文件網址、來源產品資訊 URI,以及資料集連結狀態 (如有 listingId 或訂閱權限)。

預檢驗證和疑難排解

在uv run cortex-build和uv run cortex-build-and-deploy期間,GcpEnvironmentChecker會先根據 BigQuery 和 BigQuery 共用功能,驗證每個已啟用的analytics_hub目錄,然後才暫存 Dataform 程式碼 (獨立uv run cortex-deploy只會執行部署目標檢查)。下表彙整預檢驗證行為和解決方法:

檢查 條件 結果 解析度
資料集是否存在 在 connectionSettings.projectId 中找不到 connectionSettings.datasetId 錯誤 (CortexGcpError) 請驗證專案和資料集 ID、確認已成功訂閱 BigQuery sharing,並將 roles/bigquery.dataViewer 授予建構作業主體。
資料集連結狀態 「linkedDatasetMetadata.linkState」這個價格UNLINKED 錯誤 (CortexGcpError) 發布者撤銷或刪除基礎產品資訊連結。在 BigQuery sharing 中重新訂閱有效清單,並在建立新資料集時更新 datasetId。
複製或標準資料集 BigQuery 中有資料集,但沒有連結資料集中繼資料 警告 (繼續建構) 系統會略過連結和訂閱項目檢查。請注意,複製的快照資料集不會自動接收原始供應商的更新。
訂閱健康狀態 訂閱狀態為 STATE_STALE 或 STATE_INACTIVE 警告 (繼續建構) 請在 Google Cloud 控制台依序前往「BigQuery」>「Sharing」,查看訂閱項目,以便還原或續訂。如果呼叫端缺少 analyticshub.subscriptions.list,Cortex Framework 會記錄警告並繼續執行。
設定的位置不符 connectionSettings.location與實際的 BigQuery 資料集位置不同 警告 (使用實際資料集位置) 更新 config/config.yaml 中的 connectionSettings.location,使其與實體資料集區域相符。
跨區域相容性 (支援副本) 連結資料集的位置與data.bigQueryLocation不同,且產品資訊支援data.bigQueryLocation (或無法讀取產品資訊區域) 警告 (副本指南) 在 data.bigQueryLocation 中新增跨區域資料集副本 (需要 bigquery.datasets.update),讓 BigQuery 執行共置 join。
跨區域相容性 (不支援的區域) 連結資料集位置與data.bigQueryLocation不同,且偵測到或設定的listingId確認data.bigQueryLocation不提供該產品 錯誤 (CortexGcpError) 請將 data.bigQueryLocation 調整為清單支援的區域,或在供應商授權允許的情況下,將共用資料表複製到 data.bigQueryLocation 的標準資料集。

後續步驟