建立資料基礎模組
只有在需要定義自訂建構行為,或將支援範圍擴展至不支援的全新來源系統 (例如 Salesforce) 時,才需要建立自訂資料基礎模組。
開始前,請確認您打算處理的來源資料表位於原始層資料集。
處理 SAP 資料基礎模組時,請確保複製的 DD03L 資料表包含您打算擷取的所有資料表 (包括自訂或補充資料表) 的必要中繼資料記錄。如需詳細規定,請參閱「SAP ERP 中繼資料規定」。
建立自訂資料基礎模組或命名空間時,建議使用專屬的自訂命名空間,將擴充功能和自訂項目與 Cortex Framework 構件分開,提升生命週期管理效率。
建立新的資料基礎模組
如要定義資料基礎模組,請按照下列步驟操作:
- 在
config/config.yaml檔案中,將目標資料集設定新增至data.targets。這會準備專屬的 BigQuery 資料集,以便部署基礎資料表:
[...]
data:
[...]
targets:
- id: data_foundation_sap_custom_namespace
# Google Cloud Project ID for the target dataset.
projectId: target_project_id
# BigQuery dataset ID for the target.
datasetId: data_foundation_sap_custom_namespace
- 如要定義資料基礎模組,請在
config/config.yaml檔案的modules.foundation區段中新增下列內容:
[...]
data:
[...]
modules:
foundation:
[...]
- moduleId: foundation_module_id
type: cortex.sap
dataSourceId: sap_raw_s4
dataTargetId: data_foundation_sap_custom_namespace
moduleSettings:
sapVersion: s4
mandt: "100"
tableSettings: "table_settings.yaml"
# Optional. Path to custom table settings configuration relative to this config file, e.g., `config/custom_namespace_path/data_foundation/sap/table_settings.yaml`
# If omitted, defaults to src/data_modules/cortex/data_foundation/sap/table_settings.default.yaml.
- 替代做法:如果使用外部處理的 CDC 資料表做為資料基礎,請在
config/config.yaml檔案中調整modules.foundation區段,並移除dataTargetId:external: true
[...]
data:
[...]
modules:
foundation:
[...]
- moduleId: foundation_module_id
type: cortex.sap
dataSourceId: sap_raw_s4
external: true
moduleSettings:
sapVersion: s4
mandt: "100"
tableSettings: "table_settings.yaml"
# Optional. Path to custom table settings configuration relative to this config file, e.g., `config/custom_namespace_path/data_foundation/sap/table_settings.yaml`
# If omitted, defaults to src/data_modules/cortex/data_foundation/sap/table_settings.default.yaml.
- 在參照的設定
tableSettings檔案中建立,定義要將原始層資料集中的哪些資料表轉換為資料基礎層。
common:
- source:
tableName: custom_sap_table_name
target:
tags: [sap, s4, hourly]
clusterDetails:
columns: [carrid, connid]
partitionDetails:
column: fldate
partitionType: time
timeGrain: day
資料基礎模組範例
以下範例會註冊新的自訂資料基礎模組,處理自訂命名空間 sap_bookingdatamodel 的 sflight 資料表。
註冊新的資料基礎模組。
data:
targets:
- id: data_foundation_sap_bookingdatamodel
projectId: target_project_id
datasetId: data_foundation_sap_bookingdatamodel
modules:
foundation:
- moduleId: sap_bookingdatamodel
type: sap_bookingdatamodel.sap
dataSourceId: sap_raw_s4
dataTargetId: data_foundation_sap_sap_bookingdatamodel
moduleSettings:
sapVersion: s4
mandt: "100"
tableSettings: "table_settings.yaml"
建立 table_settings.yaml
建立資料表設定檔:config/sap_bookingdatamodel/data_foundation/sap/table_settings.yaml,內容如下:
common:
- source:
tableName: sflight
target:
tags: [sap, s4, hourly]
clusterDetails:
columns: [carrid, connid]
partitionDetails:
column: fldate
partitionType: time
timeGrain: day
由於資料表在 SAP ECC 和 S/4HANA 方言中具有相同的版面配置,因此是 common: 區段的子項元素。
為每個資料表建立註解檔案,用於以中繼資料擴充結構定義。
在範例情境中,我們建立 src/data_modules/sap_bookingdatamodel/data_foundation/sap/annotations/sflight.yaml,並加入以下內容:
description: "transparent table FLIGHT, part of the Basis Components Module, BC-DWB-TND (Training and Demo)."
fields:
- name: "mandt"
description: "Client"
- name: "carrid"
description: "Airline Code"
- name: "connid"
description: "Flight Connection Number"
- name: "fldate"
description: "Flight date"
- name: "price"
description: "Airfare"
- name: "currency"
description: "Local currency of airline"
- name: "planetype"
description: "Aircraft Type"
- name: "seatsmax"
description: "Maximum capacity in economy class"
- name: "seatsocc"
description: "Occupied seats in economy class"
- name: "paymentsum"
description: "Total of current bookings"
- name: "seatsmax_b"
description: "Maximum capacity in business class"
- name: "seatsocc_b"
description: "Occupied seats in business class"
- name: "seatsmax_f"
description: "Maximum capacity in first class"
- name: "seatsocc_f"
description: "Occupied seats in first class"
如要確認自訂資料基礎模組是否編譯及部署成功,請參閱資料產品擴充性頁面的「驗證」部分。