Ingest data from Reddit Ads
This feature is in Beta. Workspace admins can control access to this feature from the Previews page. See Manage Databricks previews.
Learn how to create a managed ingestion pipeline to ingest data from Reddit Ads into Databricks.
Requirements
-
To create an ingestion pipeline, you must meet the following requirements:
-
Your workspace must be enabled for Unity Catalog.
-
Serverless compute must be enabled for your workspace. See Serverless compute requirements.
-
To create a new connection, you must have
CREATE CONNECTIONprivileges on the metastore. See Manage privileges in Unity Catalog.If the connector supports UI-based pipeline authoring, an admin can create the connection and the pipeline at the same time by completing the steps on this page. However, if the users who create pipelines use API-based pipeline authoring or are non-admin users, an admin must first create the connection in Catalog Explorer. See Connect to managed ingestion sources.
-
To use an existing connection, you must have
USE CONNECTIONprivileges orALL PRIVILEGESon the connection object. -
You must have
USE CATALOGprivileges on the target catalog. -
You must have
USE SCHEMAandCREATE TABLEprivileges on an existing schema orCREATE SCHEMAprivileges on the target catalog.
-
-
To ingest from Reddit Ads, you must complete the steps in Create a Reddit Ads connection.
Source schemas
Reddit Ads organizes tables into source schemas (namespaces):
- The
ad_accountentity table lives in the specialdefaultschema (source_schema: "default"). It lists the ad accounts accessible to the authenticated user. - All account-scoped tables —
campaign,ad_group,ad, and all report tables — live under a schema named by the ad account ID (source_schema: "<ad_account_id>").
Create an ingestion pipeline
- Databricks UI
- Declarative Automation Bundles
- Databricks notebook
- In the sidebar of the Databricks workspace, click Data Ingestion.
- On the Add data page, under Databricks connectors, click Reddit Ads.
- On the Connection page of the ingestion wizard, select the connection that stores your Reddit Ads access credentials. If you have the
CREATE CONNECTIONprivilege on the metastore, you can clickCreate connection to create a new connection with the authentication details in Create a Reddit Ads connection.
- Click Next.
- On the Ingestion setup page, enter a unique name for the pipeline.
- Select a catalog and a schema to write event logs to. If you have
USE CATALOGandCREATE SCHEMAprivileges on the catalog, you can clickCreate schema in the drop-down menu to create a new schema.
- Click Create pipeline and continue.
- On the Source page, select the tables to ingest.
- Click Save and continue.
- On the Destination page, select a catalog and a schema to load data into. If you have
USE CATALOGandCREATE SCHEMAprivileges on the catalog, you can clickCreate schema in the drop-down menu to create a new schema.
- Click Save and continue.
- (Optional) On the Schedules and notifications page, click
Create schedule. Set the frequency to refresh the destination tables.
- (Optional) Click
Add notification to set email notifications for pipeline operation success or failure, then click Save and run pipeline.
This tab describes how to deploy an ingestion pipeline using Declarative Automation Bundles. Bundles can contain YAML definitions of jobs and tasks, are managed using the Databricks CLI, and can be shared and run in different target workspaces (such as development, staging, and production). For more information, see What are Declarative Automation Bundles?.
-
Create a bundle using the Databricks CLI:
Bashdatabricks bundle init -
Add two new resource files to the bundle:
- A pipeline definition file (for example,
resources/reddit_ads_pipeline.yml). - A job definition file that controls the frequency of data ingestion (for example,
resources/reddit_ads_job.yml).
See pipeline.ingestion_definition and Examples.
- A pipeline definition file (for example,
-
Deploy the pipeline using the Databricks CLI:
Bashdatabricks bundle deploy
-
Import the following notebook into your Databricks workspace:
-
Leave cell one as-is.
-
Modify cell two with your pipeline configuration details, depending on your use case. See Examples.
-
Click Run all.
Examples
- Declarative Automation Bundles
- Databricks notebook
The following pipeline definition file ingests all current and future account-scoped tables from one ad account:
resources:
pipelines:
pipeline_reddit_ads:
name: <pipeline-name>
catalog: <destination-catalog>
target: <destination-schema>
ingestion_definition:
connection_name: <connection-name>
objects:
- schema:
source_schema: <ad-account-id>
destination_catalog: <destination-catalog>
destination_schema: <destination-schema>
connector_options:
reddit_ads_options:
sync_start_date: <sync-start-date>
lookback_window_days: <lookback-window-days>
The following pipeline definition file selects specific tables from an account:
resources:
pipelines:
pipeline_reddit_ads:
name: <pipeline-name>
catalog: <destination-catalog>
target: <destination-schema>
ingestion_definition:
connection_name: <connection-name>
objects:
- table:
source_schema: default
source_table: ad_account
destination_catalog: <destination-catalog>
destination_schema: <destination-schema>
- table:
source_schema: <ad-account-id>
source_table: campaign_report
destination_catalog: <destination-catalog>
destination_schema: <destination-schema>
destination_table: <destination-table>
connector_options:
reddit_ads_options:
sync_start_date: <sync-start-date>
lookback_window_days: <lookback-window-days>
The following is an example job definition file:
resources:
jobs:
reddit_ads_dab_job:
name: reddit_ads_dab_job
trigger:
periodic:
interval: 1
unit: DAYS
email_notifications:
on_failure:
- <email-address>
tasks:
- task_key: refresh_pipeline
pipeline_task:
pipeline_id: ${resources.pipelines.pipeline_reddit_ads.id}
The following pipeline specification ingests all current and future account-scoped tables from one ad account. To also ingest the ad_account table, add a second object with "source_schema": "default".
pipeline_spec = {
"name": "<pipeline-name>",
"ingestion_definition": {
"connection_name": "<connection-name>",
"objects": [
{
"schema": {
"source_schema": "<ad-account-id>",
"destination_catalog": "<destination-catalog>",
"destination_schema": "<destination-schema>",
"connector_options": {
"reddit_ads_options": {
"sync_start_date": "2024-01-01",
"lookback_window_days": 30
}
}
}
}
]
}
}
json_payload = json.dumps(pipeline_spec, indent=2)
create_pipeline(json_payload)
The following pipeline specification selects specific tables from an account:
pipeline_spec = {
"name": "<pipeline-name>",
"ingestion_definition": {
"connection_name": "<connection-name>",
"objects": [
{
"table": {
"source_schema": "default",
"source_table": "ad_account",
"destination_catalog": "<destination-catalog>",
"destination_schema": "<destination-schema>"
}
},
{
"table": {
"source_schema": "<ad-account-id>",
"source_table": "campaign_report",
"destination_catalog": "<destination-catalog>",
"destination_schema": "<destination-schema>",
"destination_table": "<destination-table>",
"connector_options": {
"reddit_ads_options": {
"sync_start_date": "2024-01-01",
"lookback_window_days": 30
}
}
}
}
]
}
}
json_payload = json.dumps(pipeline_spec, indent=2)
create_pipeline(json_payload)
Custom reports
In addition to the prebuilt tables, you can define a custom report that lets you choose the exact breakdown dimensions and metric fields you want. Set source_table to custom_report and provide the report definition under connector_options.reddit_ads_options.custom_report_options. The destination_table name is required for custom reports.
breakdowns: The dimensions to group by, for exampleCAMPAIGN_ID,DATE,COUNTRY. You must include at least one time dimension —DATEorHOUR— which becomes the table's incremental cursor.fields: The metric fields to select, for exampleIMPRESSIONS,CLICKS,SPEND.
For supported breakdowns and fields, see Custom report breakdowns and fields.
- Declarative Automation Bundles
- Databricks notebook
resources:
pipelines:
pipeline_reddit_ads_custom:
name: <pipeline-name>
catalog: <destination-catalog>
target: <destination-schema>
ingestion_definition:
connection_name: <connection-name>
objects:
- table:
source_schema: <ad-account-id>
source_table: custom_report
destination_catalog: <destination-catalog>
destination_schema: <destination-schema>
destination_table: my_ad_group_custom_report
connector_options:
reddit_ads_options:
sync_start_date: <sync-start-date>
lookback_window_days: 30
custom_report_options:
breakdowns:
- AD_GROUP_ID
- DATE
fields:
- IMPRESSIONS
- CLICKS
- SPEND
- CTR
pipeline_spec = {
"name": "<pipeline-name>",
"ingestion_definition": {
"connection_name": "<connection-name>",
"objects": [
{
"table": {
"source_schema": "<ad-account-id>",
"source_table": "custom_report",
"destination_catalog": "<destination-catalog>",
"destination_schema": "<destination-schema>",
"destination_table": "my_ad_group_custom_report",
"connector_options": {
"reddit_ads_options": {
"sync_start_date": "2024-01-01",
"lookback_window_days": 30,
"custom_report_options": {
"breakdowns": ["AD_GROUP_ID", "DATE"],
"fields": ["IMPRESSIONS", "CLICKS", "SPEND", "CTR"]
}
}
}
}
}
]
}
}
json_payload = json.dumps(pipeline_spec, indent=2)
create_pipeline(json_payload)
Common patterns
For advanced pipeline configurations, see Common patterns for managed ingestion pipelines.
Next steps
Start, schedule, and set alerts on your pipeline. See Common pipeline maintenance tasks.