Ingest data from Reddit Ads

Important

This feature is in Beta. Workspace admins can control access to this feature from the Previews page. See Manage Azure Databricks previews.

Learn how to create a managed ingestion pipeline to ingest data from Reddit Ads into Azure 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 CONNECTION privileges 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 CONNECTION privileges or ALL PRIVILEGES on the connection object.

    • You must have USE CATALOG privileges on the target catalog.

    • You must have USE SCHEMA and CREATE TABLE privileges on an existing schema or CREATE SCHEMA privileges 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_account entity table lives in the special default schema (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

  1. In the sidebar of the Azure Databricks workspace, click Data Ingestion.
  2. On the Add data page, under Databricks connectors, click Reddit Ads.
  3. On the Connection page of the ingestion wizard, select the connection that stores your Reddit Ads access credentials. If you have the CREATE CONNECTION privilege on the metastore, you can click Plus icon. Create connection to create a new connection with the authentication details in Create a Reddit Ads connection.
  4. Click Next.
  5. On the Ingestion setup page, enter a unique name for the pipeline.
  6. Select a catalog and a schema to write event logs to. If you have USE CATALOG and CREATE SCHEMA privileges on the catalog, you can click Plus icon. Create schema in the drop-down menu to create a new schema.
  7. Click Create pipeline and continue.
  8. On the Source page, select the tables to ingest.
  9. Click Save and continue.
  10. On the Destination page, select a catalog and a schema to load data into. If you have USE CATALOG and CREATE SCHEMA privileges on the catalog, you can click Plus icon. Create schema in the drop-down menu to create a new schema.
  11. Click Save and continue.
  12. (Optional) On the Schedules and notifications page, click Plus icon. Create schedule. Set the frequency to refresh the destination tables.
  13. (Optional) Click Plus icon. Add notification to set email notifications for pipeline operation success or failure, then click Save and run pipeline.

Declarative Automation Bundles

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?.

  1. Create a bundle using the Databricks CLI:

    databricks bundle init
    
  2. 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.

  3. Deploy the pipeline using the Databricks CLI:

    databricks bundle deploy
    

Databricks notebook

  1. Import the following notebook into your Azure Databricks workspace:

    Get notebook

  2. Leave cell one as-is.

  3. Modify cell two with your pipeline configuration details, depending on your use case. See Examples.

  4. Click Run all.

Examples

Declarative Automation Bundles

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}

Databricks notebook

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 example CAMPAIGN_ID, DATE, COUNTRY. You must include at least one time dimension — DATE or HOUR — which becomes the table's incremental cursor.
  • fields: The metric fields to select, for example IMPRESSIONS, CLICKS, SPEND.

For supported breakdowns and fields, see Custom report breakdowns and fields.

Declarative Automation Bundles

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

Databricks notebook

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.

Additional resources