Deployment 設定
本文說明 Cortex Framework 在下列領域的部署設定選項:
- 部署設定 (
config/config.yaml):定義全域變數、建構環境和模組對應 (資料基礎和資料產品目標)。 - 資料表設定 (
table_settings.yaml):模組專屬的效能和結構定義規格,說明如何在 BigQuery 中編譯及符合基本資料表。
本指南也提供操作指南,針對常見的部署用途和情境,提供逐步說明。
設定檔:config/config.yaml
config/config.yaml 檔案 (通常是從 config/config.yaml.example 範本初始化) 是 Cortex Framework 部署作業的主要設定。這個檔案定義重要參數,包括目標執行專案、來源和目的地 BigQuery 資料集,以及 Dataform 規格,例如存放區和工作區名稱。 Google Cloud
以下各節將詳細說明 config/config.yaml 結構。
建構環境
建構環境專案是指會針對建構動作 (例如 BigQuery 工作 (讀取 DD03L)) 收費的專案。
buildEnvironment:
buildProjectId: YOUR_BUILD_PROJECT_ID
下表說明建構環境參數。
| 參數 | 意義 | 預設值 | 說明 |
|---|---|---|---|
buildEnvironment.buildProjectId |
建立專案 ID | YOUR_BUILD_PROJECT_ID |
Google Cloud 執行建構作業的專案 ID。 |
「資料」專區總覽
設定檔的 data: 區段會定義資料來源、目標,以及資料基礎和資料產品的特定模組。
一般結構如下:
data:
# Geographic location for BigQuery datasets (for example: US, EU, us-central1)
# For full list see: https://docs.cloud.google.com/cortex/docs/supported-locations
bigQueryLocation: US
# List of namespaces for data foundation and product modules.
namespaces:
- name: cortex
path: cortex
# List of source datasets.
sources:
- ...
# List of target datasets.
targets:
- ...
# Configuration for data foundation and product modules.
modules:
# List of foundation modules.
foundation:
- ...
# List of data product modules.
product:
- ...
資料:BigQuery 位置
定義 BigQuery 來源和目標資料集的位置。
| 參數 | 意義 | 預設值 | 說明 |
|---|---|---|---|
data.bigQueryLocation |
BigQuery 位置 | US |
BigQuery 資料集位置 (例如 US、us-central1 或 europe-west1)。
|
資料:Cortex 命名空間
定義 Cortex Framework 命名空間。
| 參數 | 意義 | 預設值 | 說明 |
|---|---|---|---|
data.namespaces.name |
命名空間名稱 | - | Cortex Framework 命名空間名稱。例如 cortex。 |
data.namespaces.path |
命名空間路徑 | - | src 和 config 資料夾中使用的子目錄 Cortex Framework 命名空間路徑。例如 cortex。 |
資料:BigQuery 來源和目標資料集
來源清單會定義 BigQuery 資料集,其中包含從來源系統複製或串流的原始資料。
目標會定義 BigQuery 資料集清單,用來儲存 Dataform 處理的資料集。
模組會使用專屬 ID 參照來源和目標。
# Data source and target mapping
sources:
- id: sap_raw
projectId: YOUR_SOURCE_PROJECT_ID
datasetId: cortex_sap_raw
targets:
- id: sap_foundation
projectId: YOUR_TARGET_PROJECT_ID
datasetId: cortex7_sap_data_foundation
下表說明資料來源和目標對應參數。
| 參數 | 意義 | 預設值 | 說明 |
|---|---|---|---|
data.sources.id |
來源 ID | - |
定義要從中提取資料的來源資料集「ID」。例如 sap_raw。 |
data.sources.projectId |
來源專案 ID | YOUR_SOURCE_PROJECT_ID |
參照具有來源資料的 Google Cloud 專案 ID。 |
data.sources.datasetId |
來源 BigQuery 資料集 ID | - |
參照含有來源資料的 BigQuery 資料集 ID。例如 cortex_sap_raw。 |
data.targets.id |
目標 ID | - | 定義目標資料集的「id」。例如 sap_foundation。 |
data.targets.projectId |
目標專案 ID | YOUR_TARGET_PROJECT_ID |
參照目標資料的 Google Cloud 專案 ID。 |
data.targets.datasetId |
目標 BigQuery 資料集 ID | - |
參照目標資料的 BigQuery 資料集 ID。例如 cortex7_sap_data_foundation。 |
資料:模組
模組會定義 Dataform 資料管道的結構和元件。
資料:模組:基礎
本節會設定資料基礎層模組,將原始層 (CDC 串流) 的資料處理為來源資料的標準化最新記錄表示法。如果來源直接提供最新記錄的檢視畫面,或這類轉換是由來源系統連接器執行,則可將模組設定為外部資料基礎來源。
modules:
# List of foundation modules.
foundation:
# Unique identifier for the module instance.
- moduleId: erp
# Type of the module (namespaced, for example, cortex.sap).
type: cortex.sap
# Reference to the source dataset ID.
dataSourceId: sap_raw
# Reference to the target dataset ID.
dataTargetId: sap_foundation
# Module-specific configuration settings.
moduleSettings:
# SAP version (for example, ecc, s4).
sapVersion: ecc
# SAP client number.
mandt: "100"
# Whether the module is enabled.
# enabled: true
# Whether the foundation is external (does not create target dataset).
# external: false
# Custom table settings file, relative to 'config/' file directory
# Recommended path: '{namespace}/data_foundation/{data_foundation_module_type}/table_settings.yaml'
# Default path: '../src/data_modules/{namespace}/data_foundation/{data_foundation_module_type}/table_settings.default.yaml'
# tableSettings: "custom_datafoundation_table_settings.yaml"
下表說明 modules.foundation 設定的資料基礎模組參數。
| 參數 | 意義 | 預設值 | 說明 |
|---|---|---|---|
moduleId |
模組 ID | erp |
特定資料基礎轉換模組執行個體的專屬 ID。 |
type |
模組邏輯類型 | cortex.sap |
定義套用的商業邏輯或範本 (例如 cortex.sap)。 |
dataSourceId |
來源連結 | sap_raw |
參照 data.sources 清單中的「id」,從中提取資料。 |
dataTargetId |
目標連結 | sap_foundation |
從目標清單參照「id」,將資料推送至該目標。 |
moduleSettings.sapVersion |
SAP 系統版本 | ecc |
僅適用於 SAP 資料來源。決定 ecc (ECC) 或 s4 (S/4HANA) 系統的來源專屬邏輯。 |
moduleSettings.mandt |
SAP 用戶端 (Mandant) | 100 |
僅適用於 SAP 資料來源。用於篩選資料列的 3 位數 SAP 用戶端 ID。 |
enabled |
啟用模組 | true |
指定是否啟用模組。 |
external |
外部基礎 | false |
指定基礎是否為外部 (不會建立目標資料集)。 |
tableSettings |
資料表設定 | src/data_modules/{namespace}/data_foundation/{data_foundation_module_type}/table_settings.default.yaml |
自訂表格設定設定檔的路徑 (相對於這個設定檔)。 建議路徑:相對於 `config/` 目錄:'{namespace}/data_foundation/{data_foundation_module_type}/table_settings.yaml' 預設路徑:'../src/data_modules/{namespace}/data_foundation/{data_foundation_module_type}/table_settings.default.yaml' |
資料:模組:產品
資料產品模組會定義轉換原始資料所需的匯總、計算和聯結,以產生可滿足特定業務用途的洞察資料。
設定資料產品時,可以設定專屬 ID、定義依附元件,以及參照資料基礎模組和目標資料集 (結果會儲存在其中)。
特定資料產品的詳細設定定義在鍵參照的檔案中:tableSettings。
modules:
# List of data product modules.
product:
# Unique identifier for the data product instance.
- moduleId: sap_purchasing_organizational_structure
# Type of the data product (namespaced).
type: cortex.purchasing_organizational_structure
# Map of module dependencies.
dependsOn:
sapModule: erp
# Reference to the target dataset ID.
dataTargetId: product_target
# Whether the module is enabled.
# enabled: true
# Custom table settings file, relative to 'config/' file directory
# Recommended path: '{namespace}/data_product/{data_product_module_type}/table_settings.yaml'
# If omitted, defaults to '../src/data_modules/{namespace}/data_product/{data_product_module_type}/table_settings.default.yaml'
# tableSettings: "custom_dataproduct_table_settings.yaml"
下表說明 modules.product 設定的資料產品模組參數。
| 參數 | 意義 | 預設值 | 說明 |
|---|---|---|---|
moduleId |
模組 ID | - | 特定轉換模組執行個體的專屬 ID。 |
type |
模組邏輯類型 | - | 定義套用的商業邏輯或範本,定義於 src/data_modules/{namespace}/data_product/{data_product_module_type} 資料夾中。 |
dataTargetId |
目標連結 | product_target |
從目標清單參照「id」,將資料推送至該目標。 |
dependsOn |
上游依附元件 | sapModule: erp |
指定產品模組建構前必須存在的基礎模組。 |
enabled |
啟用模組 | true |
指定是否啟用模組。 |
tableSettings |
資料表設定 | src/data_modules/{namespace}/data_product/{data_product_module_type}/table_settings.default.yaml |
自訂表格設定設定檔的路徑 (相對於這個設定檔)。 建議路徑:相對於 `config/` 目錄:'{namespace}/data_product/{data_product_module_type}/table_settings.yaml' 預設路徑:'../src/data_modules/{namespace}/data_product/{data_product_module_type}/table_settings.default.yaml' |
部署環境
Cortex Framework 會使用 Dataform,在 BigQuery 中協調 SQL 轉換作業。deployment: 區塊會定義 Dataform 設定,負責執行資料管道,包括存放區專案、位置、存放區名稱和 Dataform 工作區名稱。
deployment:
targets:
- type: dataform
enabled: true
targetSettings:
repositoryProjectId: YOUR_REPO_PROJECT_ID
repositoryRegion: us-central1
repositoryName: cortex-repository
workspaceName: dev
# serviceAccount: "example@example.com"
下表說明部署目標位置參數 (deployment.targets:)。
| 參數 | 意義 | 預設值 | 說明 |
|---|---|---|---|
type |
部署作業類型 | dataform |
部署目標的類型。 |
enabled |
啟用/ 停用 | true |
指定是否啟用或停用指定部署目標。 |
targetSettings.repositoryProjectId |
存放區專案 ID | YOUR_REPO_PROJECT_ID |
管理 Dataform 存放區的 Google Cloud 專案 ID。 |
targetSettings.repositoryRegion |
存放區區域 | us-central1 |
Dataform 存放區的 Google Cloud 區域 (例如 us-central1 或 europe-west1)。 |
targetSettings.repositoryName |
存放區名稱 | cortex-repository |
Dataform 存放區的特定名稱。 |
targetSettings.workspaceName |
工作區名稱 | dev |
用於部署週期的特定 Dataform 工作區。 |
targetSettings.serviceAccount |
服務帳戶電子郵件地址 | - |
用於執行 Dataform 存放區的預設服務帳戶電子郵件地址。 |
設定檔:table_settings.yaml
本指南說明如何使用 table_settings.yaml 檔案,在 Google Cloud Cortex Framework 中設定資料基礎和資料產品資料表。
資料模組專屬的 table_settings.yaml 檔案會控管原始來源資料表的調整方式,以及 BigQuery 中分析資料模型的具體化方式。您可以使用這個檔案設定標記、具體化策略,以及分區或叢集等進階 BigQuery 效能功能。
動態解析依附元件
根據預設,Cortex Framework 只會部署及編譯已啟用資料產品的必要基礎資料表 (做為依附元件),藉此盡量減少部署足跡和執行時間。如果 table_settings.yaml 中設定的表格沒有任何依附於該表格的有效下游資料產品,系統就不會部署該表格。
如要覆寫這項最佳化設定並強制部署基礎表格,您可以將 deployAlways 屬性設為 true (請參閱資料基礎樣式參數參考資料)。
在 Google Cloud Cortex Framework 中,每個模組 (基礎或產品) 都可以在部署設定檔中指派特定表格設定檔:使用 tableSettings 屬性 config/config.yaml。
設定路徑
- 自訂設定 (建議):如要自訂表格行為,請將預設檔案複製到設定目錄,然後修改該檔案,並在
config/config.yaml中參照其路徑。建議使用的路徑 (相對於config/目錄) 如下:- 基礎模組:
namespace/data_foundation/data_foundation/custom_table_settings.yaml(例如config/cortex/data_foundation/sap/table_settings.yaml) - 產品模組:
namespace/data_product/data_product/custom_table_settings.yaml(例如config/cortex/data_product/accounting_documents/table_settings.yaml)
- 基礎模組:
- 預設備援:如果省略
tableSettings,架構會自動備援至:- 基礎模組:
../src/data_modules/namespace/data_foundation/data_foundation/table_settings.default.yaml - 產品模組:
../src/data_modules/namespace/data_product/data_product/table_settings.default.yaml
- 基礎模組:
設定樣式
視模組類別而定,table_settings.yaml 有兩種不同的結構定義樣式:
- 資料基礎樣式:以清單為基礎的對應,定義來源到目標的結構定義關係、變更資料擷取 (CDC) 處理方式和 BigQuery 版面配置。
- 資料產品樣式:以地圖為基礎的對應 (字典),定義分析檢視區塊或資料表的具體化方式 (例如檢視區塊、資料表或遞增資料表),以及最佳化方式。
這兩種樣式都支援三個根層級區段,可依來源系統版本區隔設定 (主要用於 SAP Data Foundation 和 SAP 相關產品):
ecc:只有在部署 SAP ECC 來源系統時,才會套用設定。s4:僅在部署 SAP S/4HANA 來源系統時套用的設定。common:無論 SAP 版本為何,都會套用設定 (適用於相容或通用設定)。
資料基礎樣式
在 Data Foundation 模組中,table_settings.yaml 檔案會以 ecc、s4 和 common 鍵下方的資料表項目清單形式呈現。每個項目都會將原始來源資料表對應至符合規範的目標資料表,並設定其 BigQuery 設定。
YAML 語法範例
common:
- source:
tableName: bkpf
isCdc: true
target:
tableName: bkpf # Optional: defaults to source tableName if omitted
tags: [sap, common, finance, hourly]
clusterDetails:
columns: [bukrs, gjahr]
partitionDetails:
column: budat
partitionType: time
timeGrain: day
deployAlways: false
參數參照
| 參數 | 類型 | 必填 | 預設 / 範例 | 說明 |
|---|---|---|---|---|
ecc | s4 | common |
string |
否 | [] |
來源系統版本或方言。 |
[].deployAlways |
boolean |
否 | false |
如果為 true,系統一律會部署及建構表格,即使最佳化規則可能會略過表格也一樣。另請參閱「動態依附元件解析」。 |
來源設定
定義原始的傳入資料表特徵。
| 參數 | 類型 | 必填 | 預設 / 範例 | 說明 |
|---|---|---|---|---|
tableName |
string |
是 | bkpf |
BigQuery 中原始來源資料表的名稱 (不區分大小寫)。 |
isCdc |
boolean |
否 | true |
指出來源資料表是否包含變更資料擷取 (CDC) 記錄。
• • |
指定目標設定
定義目標資料集中的輸出一致性資料表版面配置。
| 參數 | 類型 | 必填 | 預設 / 範例 | 說明 |
|---|---|---|---|---|
tableName |
string |
否 | *(與來源相同)* | 要建立的目標已調整一致資料表名稱。如果省略,架構會預設為來源 tableName。 |
tags |
array[string] |
否 | [sap, finance] |
這是指附加至 Dataform 中已調整動作的中繼資料標記清單。這些是任意字串,不需要預先註冊或在其他設定中定義,可立即用於篩選管道執行作業 (例如使用 dataform run --tags ...)。 |
clusterDetails |
map |
否 | — | 選用。BigQuery 分群設定。請參閱「叢集詳細資料」。 |
partitionDetails |
map |
否 | — | 選用。BigQuery 分區設定。請參閱分區詳細資料。 |
資料產品樣式
在資料產品模組中,table_settings.yaml 檔案會以字典 (對應) 形式,結構化為 ecc、s4 和 common 鍵。字典的鍵代表分析資料表或檢視區塊名稱,值則定義具體化和效能設定。
YAML 語法範例
s4:
customers:
materializationType: incremental
tags: [sap, dataproduct, masterdata]
clusterDetails:
columns: [mandt, ktokd]
參數參照
| 參數 | 類型 | 必填 | 預設 / 範例 | 說明 |
|---|---|---|---|---|
ecc | s4 | common |
map |
否 | {} |
目標分析資產 (資料表或檢視區塊) 對應設定的地圖。 |
[table_name].materializationType |
string |
否 | incremental |
如何在 BigQuery 中建構分析資產。
允許值:
|
[table_name].tags |
array[string] |
否 | [sap, dataproduct] |
附加至 Dataform 中分析資產的中繼資料標記。這些是任意字串,不需要預先註冊,可立即用於選擇性管道執行。 |
[table_name].clusterDetails |
map |
否 | — | 選用。BigQuery 分群設定。請參閱「叢集詳細資料」。 |
[table_name].partitionDetails |
map |
否 | — | 選用。BigQuery 分區設定。請參閱分區詳細資料。 |
進階 BigQuery 設定
這兩種樣式都採用相同的結構,透過叢集和分區功能,最佳化 BigQuery 儲存空間和查詢效能。
叢集詳細資料
叢集處理會根據特定資料欄中的值,將資料並置。BigQuery 會使用這些資料欄排序每個儲存區塊中的資料,大幅加快篩選 (WHERE) 或聯結 (JOIN) 這些資料欄的查詢。
clusterDetails:
columns: [bukrs, gjahr]
參數參照
| 參數 | 類型 | 必填 | 範例 | 說明 |
|---|---|---|---|---|
columns |
array[string] |
是 | [bukrs, gjahr] |
最多四個資料欄名稱的排序清單,用來對資料表進行分群。 限制:欄位必須是英數字元,且只能包含底線。清單中的資料欄順序會決定排序階層。 |
分區詳細資料
分區程序會根據日期、時間戳記或整數欄位的值,將大型資料表切分成較小的實體區段。這樣一來,當查詢只要求特定範圍的天數、月份或 ID 時,BigQuery 就不會掃描整個資料表。
partitionDetails:
column: budat
partitionType: time
timeGrain: day
參數參照
| 參數 | 類型 | 必填 | 範例 | 說明 |
|---|---|---|---|---|
column |
string |
是 | budat |
用於對資料表進行分區的資料欄名稱。只能使用英數字元和底線,資料欄類型必須與 partitionType 相符。 |
partitionType |
string |
是 | time |
分區策略。
允許值:
|
timeGrain |
string |
否 | day |
如果 partitionType 為 time 或 DATE,則為必要屬性。定義時間分區的精細程度。
允許的值: |
rangeStart |
integer |
否 | 1 |
如果 partitionType 為 integer,則為必要。第一個分區的起始值 (含)。 |
rangeEnd |
integer |
否 | 1000 |
如果 partitionType 為 integer,則為必要。最後一個分區的結尾值 (不含)。 |
rangeInterval |
integer |
否 | 10 |
如果 partitionType 為 integer,則為必要。每個分區間隔的寬度。 |
範例
下列範例顯示資料基礎和資料產品模組的設定範本,說明如何自訂目標資料表、在 BigQuery 中最佳化儲存空間配置,以及設定具體化類型。
1. 自訂資料基礎表格設定範例
這個範例說明如何設定基礎層,其中包含叢集和分區交易資料表 (例如 bseg 和 ekbe),以及標準資料表:
# ==============================================================================
# S/4HANA-Specific Tables
# ==============================================================================
s4:
# ACDOCA is a massive table in S/4HANA; clustering is vital
- source:
tableName: acdoca
target:
tags: [sap, s4, finance, transactional, hourly]
clusterDetails:
columns: [rclnt, rbukrs, gjahr]
# ==============================================================================
# ECC-Specific Tables
# ==============================================================================
ecc:
- source:
tableName: faglflexa
target:
tags: [sap, ecc, finance, transactional, hourly]
# ==============================================================================
# Common Tables (ECC & S/4HANA)
# ==============================================================================
common:
# Financial document header (partitioned by posting date)
- source:
tableName: bkpf
isCdc: true
target:
tags: [sap, common, finance, hourly]
clusterDetails:
columns: [bukrs, gjahr]
partitionDetails:
column: budat
partitionType: time
timeGrain: day
# Purchasing document items (partitioned by creation date)
- source:
tableName: ekpo
target:
tags: [sap, common, logistics, purchasing, hourly]
clusterDetails:
columns: [mandt, ebeln]
partitionDetails:
column: aedat
partitionType: time
timeGrain: month
# Standard master data table (no partitioning/clustering needed)
- source:
tableName: lfa1
target:
tags: [sap, common, masterdata, vendor, daily]
2. 自訂資料產品表格設定範例
這個範例說明如何為下游分析資料產品設定具體化類型。我們將交易式 sales_documents 設為遞增,以盡可能提升建構效能並節省費用,而 customers 等非交易式資料表則會建構為標準資料表:
# settings applied for both ECC and S/4HANA pipelines
common:
# Transactional data product - incremental build
sales_documents:
materializationType: incremental
tags: [sap, dataproduct, sales, transactional]
clusterDetails:
columns: [vkorg, vbeln]
partitionDetails:
column: audat
partitionType: time
timeGrain: day
# Master data product - full table rebuild
customers:
materializationType: table
tags: [sap, dataproduct, masterdata]
clusterDetails:
columns: [mandt, ktokd]
# Aggregated reporting view - virtual view
sales_performance_summary:
materializationType: view
tags: [sap, dataproduct, sales, reporting]
使用指南
本節提供常見設定工作和自訂部署情境的逐步指南。
在資料基礎模組中自訂表格範圍
如要在現有的資料基礎模組中新增或移除表格,而不需建立新模組或執行個別管道例項,請按照下列步驟操作:
- 將預設
table_settings.default.yaml設定複製到工作區設定目錄 (例如config/cortex/data_foundation/sap/custom_table_settings.yaml)。 - 在新檔案中,視需要新增自訂表格,或移除
ecc、s4或common鍵下未使用的標準表格:
common:
- source:
tableName: custom_table_name
target:
tags: [custom_tag]
- 更新
config/config.yaml,在模組的tableSettings屬性下參照自訂表格設定的路徑:
data:
modules:
foundation:
- moduleId: erp
type: cortex.sap
# Custom table settings file, relative to configuration file directory
# Recommended path: '{namespace}/data_foundation/{data_foundation_module_type}/table_settings.yaml'
tableSettings: 'cortex/data_foundation/sap/custom_table_settings.yaml'
設定資料基礎模組的多個執行個體
如要部署相同模組類型的兩個以上獨立管道執行個體 (例如支援多個 SAP 執行個體,以區隔表格、隔離環境或指定不同目標資料集):
事前準備:
* 確認來源資料表位於來源原始資料集中。
* 確認已設定目標資料集架構。
* 使用 SAP 資料基礎模組時,請確認中繼資料表 DD03L 包含您要擷取的自訂資料表欄和描述元資訊。詳情請參閱「SAP ERP 需求條件」。
操作說明:
- 在
config/config.yaml檔案中,於data.targets下方新增目標設定,為每個管道例項定義目標資料集:
data:
targets:
- id: data_foundation_core
projectId: target_project_id
datasetId: data_foundation_sap_core
- id: data_foundation_custom
projectId: target_project_id
datasetId: data_foundation_sap_custom
- 在
data.modules.foundation清單下定義模組的多個執行個體。為每個執行個體提供專屬的moduleId、各自的目標資料集 ID,以及選用的tableSettings設定:
data:
modules:
foundation:
# Core SAP ERP foundation module instance
- moduleId: erp_core
type: cortex.sap
dataSourceId: sap_raw
dataTargetId: data_foundation_core
# If omitted, defaults to "../src/data_modules/{namespace}/data_foundation/{data_foundation_module_type}/table_settings.default.yaml"
# tableSettings: "../src/data_modules/cortex/data_foundation/sap/table_settings.default.yaml"
# Custom tables pipeline instance
- moduleId: erp_custom
type: cortex.sap
dataSourceId: sap_raw
dataTargetId: data_foundation_custom
# Custom table settings file, relative to configuration file directory
# Recommended path: 'config/{namespace}/data_foundation/{data_foundation_module_type}/table_settings.yaml'
tableSettings: "cortex/data_foundation/sap/custom_datafoundation_table_settings.yaml"
- 建立
config/cortex/data_foundation/sap/custom_datafoundation_table_settings.yaml檔案,指定自訂範圍。E.g.:
common:
- source:
tableName: custom_sap_table_name
target:
tags: [sap, s4, hourly]
clusterDetails:
columns: [carrid, connid]
partitionDetails:
column: fldate
partitionType: time
timeGrain: day
- 執行部署指令碼 (
uv run cortex-build-and-deploy) 來套用變更,然後按照「部署後步驟」說明執行 Dataform 動作。