Meta Ads取り込みパイプラインを作成する
ベータ版
この機能はベータ版です。ワークスペース管理者は、 プレビュー ページからこの機能へのアクセスを制御できます。「Databricks プレビューの管理」を参照してください。
Meta Ads から Databricks にデータを取り込むための管理された取り込みパイプラインを作成する方法を学びます。サポートされているオブジェクトの一覧については、 「サポートされているオブジェクト」を参照してください。
要件
取り込み パイプラインを作成するには、次の要件を満たす必要があります。
-
ワークスペースでUnity Catalogが有効になっている必要があります。
-
ワークスペースでサーバレスコンピュートを有効にする必要があります。 「サーバレス コンピュート要件」を参照してください。
-
新しい接続を作成する場合: メタストアに対する
CREATE CONNECTION権限が必要です。コネクタが UI ベースのパイプライン オーサリングをサポートしている場合、管理者はこのページのステップを完了することで、接続とパイプラインを同時に作成できます。 ただし、パイプラインを作成するユーザーが API ベースのパイプライン オーサリングを使用している場合、または管理者以外のユーザーである場合、管理者はまずカタログ エクスプローラーで接続を作成する必要があります。 「管理対象取り込みソースへの接続」を参照してください。
-
既存の接続を使用する場合: 接続オブジェクトに対する
USE CONNECTION権限またはALL PRIVILEGESが必要です。 -
ターゲット カタログに対する
USE CATALOG権限が必要です。 -
既存のスキーマに対する
USE SCHEMAおよびCREATE TABLE権限、またはターゲット カタログに対するCREATE SCHEMA権限が必要です。
メタ広告から取り込むには、 「メタ広告をデータソースとして設定する」のステップを完了する必要があります。
パイプラインを作成する
- Databricks Asset Bundles
- Databricks notebook
このタブでは、Databricks アセット バンドルを使用してインジェスト パイプラインをデプロイする方法について説明します。バンドルにはジョブとタスクの YAML 定義を含めることができ、 Databricks CLIを使用して管理でき、さまざまなターゲット ワークスペース (開発、ステージング、本番運用など) で共有して実行できます。 詳細については、 Databricksアセット バンドルとは何ですか?」を参照してください。 。
-
Databricks CLI を使用して新しいバンドルを作成します。
Bashdatabricks bundle init -
バンドルに 2 つの新しいリソース ファイルを追加します。
- パイプライン定義ファイル (
resources/meta_ads_pipeline.yml)。変更する値と例を参照してください。 - データ取り込みの頻度を制御するワークフロー ファイル (
resources/meta_ads_job.yml)。Databricks Asset Bundles ワークフロー ファイルを参照してください。
- パイプライン定義ファイル (
-
Databricks CLI を使用してパイプラインをデプロイします。
Bashdatabricks bundle deploy
- 次のノートブックを Databricks ワークスペースにインポートします。
変更する値
Value | 説明 |
|---|---|
| パイプラインの一意の名前。 |
| Meta Ads の認証詳細を保存するUnity Catalog接続の名前。 |
| Meta Ads アカウント ID。 |
| 取り込むオブジェクトの名前 (例: |
| Databricks に書き込むカタログの名前。 |
| Databricks に書き込むスキーマの名前。 |
| オプション。Databricks に書き込むテーブルの一意の名前。これを指定しない場合、コネクタは自動的にソーステーブル名を使用します。 |
| 使用する SCD メソッド: |
ad_insightsのみ:
ad_insightsから取り込む場合は、 metamarketing_parametersで次の追加設定を構成する必要があります。
Value | 説明 |
|---|---|
| 知識の粒度レベル: |
|
|
| オプション。内訳ディメンションのリスト (例: |
| オプション。アクション内訳ディメンションのリスト (例: |
例
アカウントから現在および将来のすべてのテーブルを取り込む
- Databricks Asset Bundles
- Databricks notebook
以下はresources/meta_ads_pipeline.ymlファイルの例です。
resources:
pipelines:
pipeline_meta_ads:
name: <pipeline-name>
catalog: <destination-catalog>
target: <destination-schema>
channel: PREVIEW
ingestion_definition:
connection_name: <connection-name>
objects:
- schema:
source_schema: <meta-ads-account-id>
destination_catalog: <destination-catalog>
destination_schema: <destination-schema>
table_configuration:
scd_type: SCD_TYPE_1
pipeline_spec = {
"name": "<pipeline-name>",
"channel": "PREVIEW",
"ingestion_definition": {
"connection_name": "<connection-name>",
"objects": [
{
"schema": {
"source_schema": "<meta-ads-account-id>",
"destination_catalog": "<destination-catalog>",
"destination_schema": "<destination-schema>",
"table_configuration": {
"scd_type": "SCD_TYPE_1"
}
}
}
]
}
}
json_payload = json.dumps(pipeline_spec, indent=2)
create_pipeline(json_payload)
アカウントから特定のテーブルを選択して取り込む
- Databricks Asset Bundles
- Databricks notebook
以下はresources/meta_ads_pipeline.ymlファイルの例です。
resources:
pipelines:
pipeline_meta_ads:
name: <pipeline-name>
catalog: <destination-catalog>
target: <destination-schema>
channel: PREVIEW
ingestion_definition:
connection_name: <connection-name>
objects:
- table:
source_schema: <meta-ads-account-id>
source_table: campaigns
destination_catalog: <destination-catalog>
destination_schema: <destination-schema>
table_configuration:
scd_type: SCD_TYPE_1
- table:
source_schema: <meta-ads-account-id>
source_table: ads
destination_catalog: <destination-catalog>
destination_schema: <destination-schema>
table_configuration:
scd_type: SCD_TYPE_1
pipeline_spec = {
"name": "<pipeline-name>",
"channel": "PREVIEW",
"ingestion_definition": {
"connection_name": "<connection-name>",
"objects": [
{
"table": {
"source_schema": "<meta-ads-account-id>",
"source_table": "campaigns",
"destination_catalog": "<destination-catalog>",
"destination_schema": "<destination-schema>",
"table_configuration": {
"scd_type": "SCD_TYPE_1"
}
}
},
{
"table": {
"source_schema": "<meta-ads-account-id>",
"source_table": "ads",
"destination_catalog": "<destination-catalog>",
"destination_schema": "<destination-schema>",
"table_configuration": {
"scd_type": "SCD_TYPE_1"
}
}
}
]
}
}
json_payload = json.dumps(pipeline_spec, indent=2)
create_pipeline(json_payload)
ad_insights摂取する metamarketing_parameters
- Databricks Asset Bundles
- Databricks notebook
以下はresources/meta_ads_pipeline.ymlファイルの例です。
resources:
pipelines:
pipeline_meta_ads:
name: <pipeline-name>
catalog: <destination-catalog>
target: <destination-schema>
channel: PREVIEW
ingestion_definition:
connection_name: <connection-name>
objects:
- table:
source_schema: <meta-ads-account-id>
source_table: ad_insights
destination_catalog: <destination-catalog>
destination_schema: <destination-schema>
table_configuration:
scd_type: SCD_TYPE_1
metamarketing_parameters:
level: ad
start_date: '2024-01-01'
breakdowns:
- age
- gender
action_breakdowns:
- action_type
pipeline_spec = {
"name": "<pipeline-name>",
"channel": "PREVIEW",
"ingestion_definition": {
"connection_name": "<connection-name>",
"objects": [
{
"table": {
"source_schema": "<meta-ads-account-id>",
"source_table": "ad_insights",
"destination_catalog": "<destination-catalog>",
"destination_schema": "<destination-schema>",
"table_configuration": {
"scd_type": "SCD_TYPE_1",
"metamarketing_parameters": {
"level": "ad",
"start_date": "2024-01-01",
"breakdowns": ["age", "gender"],
"action_breakdowns": ["action_type"]
}
}
}
}
]
}
}
json_payload = json.dumps(pipeline_spec, indent=2)
create_pipeline(json_payload)
Databricks アセットバンドルのワークフローファイル
以下はresources/meta_ads_job.ymlファイルの例です。
resources:
jobs:
meta_ads_dab_job:
name: meta_ads_dab_job
trigger:
# Run this job every day, exactly one day from the last run
# See https://docs.databricks.com/api/workspace/jobs/create#trigger
periodic:
interval: 1
unit: DAYS
email_notifications:
on_failure:
- <email-address>
tasks:
- task_key: refresh_pipeline
pipeline_task:
pipeline_id: <pipeline-id>
一般的なパターン
高度なパイプライン構成については、 「管理された取り込みパイプラインの一般的なパターン」を参照してください。