---
title: Create a query-based ingestion pipeline
description: Learn how to create a query-based ingestion pipeline in Lakeflow Connect using the Databricks UI or Declarative Automation Bundles.
canonical_url: https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/query-based-pipeline
---

# Create a query-based ingestion pipeline

This page shows how to create a query-based ingestion pipeline in Lakeflow Connect.

## <a id="requirements" />Requirements

Before you create a query-based ingestion pipeline, you must meet the following requirements:

* Unity Catalog is enabled for your Databricks workspace.
* Your serverless compute environment allows network connectivity to the source database. See [Networking](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/index.md#networking) and [Networking recommendations for Lakehouse Federation](https://docs.databricks.com/aws/en/query-federation/networking.md).
* For **foreign connection ingestion**: You have an existing connection to the source database or `CREATE CONNECTION` privileges on the metastore. See [Connect to managed ingestion sources](https://docs.databricks.com/aws/en/connect/managed-ingestion.md).
* For **foreign catalog ingestion**: You have an existing foreign catalog registered in [Lakehouse Federation](https://docs.databricks.com/aws/en/query-federation/index.md) or the privileges to create one.
* You have `CREATE` and `USE SCHEMA` privileges on the destination catalog and schema.

## <a id="foreign-connection" />Option 1: Foreign connection ingestion

Use this approach when you have a connection that stores authentication credentials for the source database. Supported sources include Oracle, Teradata, SQL Server, MySQL, MariaDB, and PostgreSQL.

### Databricks UI

The Databricks UI deploys query-based pipelines to serverless compute. To deploy on classic compute instead, see the **Declarative Automation Bundles** tab.

1. In the Databricks workspace sidebar, click **Data Ingestion**.

2. On the **Add data** page, under **Databricks connectors**, click your source (for example, **Oracle** or **SQL Server**). The ingestion wizard opens.

3. On the **Ingestion pipeline** page, enter a name for the pipeline.

4. For **Destination catalog**, select a Unity Catalog catalog to store the ingested data.

5. Select the Unity Catalog connection that stores the credentials required to access the source database.

   If there's no existing connection, click **Create connection** and enter the connection details. You must have `CREATE CONNECTION` privileges on the metastore.

6. Click **Create pipeline and continue**.

7. On the **Source** page, select the schemas and tables to ingest.

8. For each table, specify the **cursor column**. This must be a single column with values that increase monotonically (for example, `updated_at` or `row_id`). If you don't select a monotonically increasing cursor column, the connector performs a full load on each run.

9. Optionally, change the default history tracking setting. For more information, see [Enable history tracking (SCD type 2)](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/scd.md).

10. Click **Next**.

11. On the **Destination** page, select the Unity Catalog catalog and schema to write to.

    If you don't want to use an existing schema, click **Create schema**. You must have `USE CATALOG` and `CREATE SCHEMA` privileges on the parent catalog.

12. Click **Save and continue**.

13. (Optional) On the **Settings** page, click **Create schedule** and set the refresh frequency.

14. (Optional) Set email notifications for pipeline success or failure.

15. Click **Save and run pipeline**.

### Declarative Automation Bundles

Deploy a query-based ingestion pipeline using Declarative Automation Bundles with the direct deployment engine. Bundles contain YAML definitions of pipelines and jobs, are managed with the Databricks CLI, and can be deployed to multiple target workspaces. The direct deployment engine deploys bundles without Terraform and honors compute settings such as `serverless` and `photon`. For more information, see [What are Declarative Automation Bundles?](https://docs.databricks.com/aws/en/dev-tools/bundles/index.md) and [Migrate to the direct deployment engine](https://docs.databricks.com/aws/en/dev-tools/bundles/direct.md).

This example deploys the pipeline to serverless compute (default). To deploy on classic compute instead, see the classic compute example.

1. Create a bundle:

   ```bash
   databricks bundle init
   ```

2. Enable the direct deployment engine. New bundles created with Databricks CLI version 1.3.0 and above use the direct deployment engine by default. If your bundle was created with an earlier version, set the top-level `bundle.engine` field in `databricks.yml` (not a per-target setting):

   ```yaml
   bundle:
     engine: direct
   ```

   If the bundle was previously deployed with the Terraform deployment engine, migrate the deployment state for each target before you deploy. Otherwise, deployment silently falls back to the Terraform engine. Run `databricks bundle deployment migrate -t <target>` for each target. For more information, see [databricks bundle deployment migrate](https://docs.databricks.com/aws/en/dev-tools/cli/bundle-commands.md#migrate).

3. Add a pipeline definition file to the bundle (for example, `resources/query_based_pipeline.yml`):

   ```yaml
   variables:
     dest_catalog:
       default: main
     dest_schema:
       default: ingest_destination_schema

   resources:
     pipelines:
       pipeline_query_based:
         name: query-based-ingestion-pipeline
         ingestion_definition:
           connection_name: <your-uc-connection-name>
           objects:
             - table:
                 source_catalog: <source-catalog>
                 source_schema: <source-schema>
                 source_table: <source-table>
                 table_configuration:
                   query_based_connector_config:
                     cursor_columns:
                       - updated_at
                 destination_catalog: ${var.dest_catalog}
                 destination_schema: ${var.dest_schema}
         target: ${var.dest_schema}
         catalog: ${var.dest_catalog}
   ```

4. Add a job definition file that controls the ingestion schedule (for example, `resources/query_based_job.yml`):

   ```yaml
   resources:
     jobs:
       query_based_job:
         name: query_based_job

         trigger:
           periodic:
             interval: 1
             unit: HOURS

         email_notifications:
           on_failure:
             - <email-address>

         tasks:
           - task_key: refresh_pipeline
             pipeline_task:
               pipeline_id: ${resources.pipelines.pipeline_query_based.id}
   ```

5. Deploy the bundle:

   ```bash
   databricks bundle deploy
   ```

**Classic compute (Beta) example**

> [!NOTE]
> **Beta**
>
> Classic compute for query-based ingestion pipelines is in [Beta](https://docs.databricks.com/aws/en/release-notes/release-types.md). Databricks recommends serverless compute for most workloads.

To deploy on classic compute, set `serverless: false` and add a `clusters` block to the pipeline definition. The direct deployment engine honors the `serverless` field and other compute settings such as `photon`. After deployment, `serverless: false` no longer appears in the pipeline spec, but the `clusters` block is retained and the pipeline runs on classic compute. For the full set of supported cluster fields, see [Configure classic compute for pipelines](https://docs.databricks.com/aws/en/ldp/configure-compute.md).

1. Create a bundle:

   ```bash
   databricks bundle init
   ```

2. Enable the direct deployment engine. New bundles created with Databricks CLI version 1.3.0 and above use the direct deployment engine by default. If your bundle was created with an earlier version, set the top-level `bundle.engine` field in `databricks.yml` (not a per-target setting):

   ```yaml
   bundle:
     engine: direct
   ```

   If the bundle was previously deployed with the Terraform deployment engine, migrate the deployment state for each target before you deploy. Otherwise, deployment silently falls back to the Terraform engine. Run `databricks bundle deployment migrate -t <target>` for each target. For more information, see [databricks bundle deployment migrate](https://docs.databricks.com/aws/en/dev-tools/cli/bundle-commands.md#migrate).

3. Add a pipeline definition file to the bundle (for example, `resources/query_based_pipeline.yml`):

   ```yaml
   variables:
     dest_catalog:
       default: main
     dest_schema:
       default: ingest_destination_schema

   resources:
     pipelines:
       pipeline_query_based:
         name: query-based-ingestion-pipeline
         serverless: false
         clusters:
           - label: default
             node_type_id: r6i.xlarge
             driver_node_type_id: i3.large
             autoscale:
               min_workers: 1
               max_workers: 5
         ingestion_definition:
           connection_name: <your-uc-connection-name>
           objects:
             - table:
                 source_catalog: <source-catalog>
                 source_schema: <source-schema>
                 source_table: <source-table>
                 table_configuration:
                   query_based_connector_config:
                     cursor_columns:
                       - updated_at
                 destination_catalog: ${var.dest_catalog}
                 destination_schema: ${var.dest_schema}
         target: ${var.dest_schema}
         catalog: ${var.dest_catalog}
   ```

4. Add a job definition file that controls the ingestion schedule (for example, `resources/query_based_job.yml`):

   ```yaml
   resources:
     jobs:
       query_based_job:
         name: query_based_job

         trigger:
           periodic:
             interval: 1
             unit: HOURS

         email_notifications:
           on_failure:
             - <email-address>

         tasks:
           - task_key: refresh_pipeline
             pipeline_task:
               pipeline_id: ${resources.pipelines.pipeline_query_based.id}
   ```

5. Deploy the bundle:

   ```bash
   databricks bundle deploy
   ```

## <a id="foreign-catalog" />Option 2: Foreign catalog ingestion

Use this approach when you want to ingest from a foreign catalog registered in [Lakehouse Federation](https://docs.databricks.com/aws/en/query-federation/index.md). Foreign catalog ingestion supports all Lakehouse Federation data sources and deletion tracking.

### Databricks UI

The Databricks UI deploys query-based pipelines to serverless compute. To deploy on classic compute instead, see the **Direct Bundles** tab.

1. In the Databricks workspace sidebar, click **Data Ingestion**.

2. On the **Add data** page, under **Databricks connectors**, click your source. The ingestion wizard opens.

3. On the **Ingestion pipeline** page, enter a name for the pipeline.

4. For **Destination catalog**, select a Unity Catalog catalog to store the ingested data.

5. For **Connection type**, select **Foreign catalog**, then select the foreign catalog registered in Lakehouse Federation.

6. Click **Create pipeline and continue**.

7. On the **Source** page, select the schemas and tables to ingest.

8. For each table, specify the **cursor column**. This must be a single column with values that increase monotonically (for example, `updated_at` or `row_id`).

9. Optionally, change the default history tracking setting. For more information, see [Enable history tracking (SCD type 2)](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/scd.md).

10. Click **Next**.

11. On the **Destination** page, select the Unity Catalog catalog and schema to write to.

    If you don't want to use an existing schema, click **Create schema**. You must have `USE CATALOG` and `CREATE SCHEMA` privileges on the parent catalog.

12. Click **Save and continue**.

13. (Optional) On the **Settings** page, click **Create schedule** and set the refresh frequency.

14. (Optional) Set email notifications for pipeline success or failure.

15. Click **Save and run pipeline**.

### Direct Bundles

Deploy a foreign catalog ingestion pipeline using Declarative Automation Bundles with the direct deployment engine. Bundles contain YAML definitions of pipelines and jobs, are managed with the Databricks CLI, and can be deployed to multiple target workspaces. The direct deployment engine deploys bundles without Terraform and honors compute settings such as `serverless` and `photon`. For more information, see [What are Declarative Automation Bundles?](https://docs.databricks.com/aws/en/dev-tools/bundles/index.md) and [Migrate to the direct deployment engine](https://docs.databricks.com/aws/en/dev-tools/bundles/direct.md).

This example deploys the pipeline to serverless compute (default). To deploy on classic compute instead, see the classic compute example.

1. Create a bundle:

   ```bash
   databricks bundle init
   ```

2. Enable the direct deployment engine. New bundles created with Databricks CLI version 1.3.0 and above use the direct deployment engine by default. If your bundle was created with an earlier version, set the top-level `bundle.engine` field in `databricks.yml` (not a per-target setting):

   ```yaml
   bundle:
     engine: direct
   ```

   If the bundle was previously deployed with the Terraform deployment engine, migrate the deployment state for each target before you deploy. Otherwise, deployment silently falls back to the Terraform engine. Run `databricks bundle deployment migrate -t <target>` for each target. For more information, see [databricks bundle deployment migrate](https://docs.databricks.com/aws/en/dev-tools/cli/bundle-commands.md#migrate).

3. Add a pipeline definition file to the bundle (for example, `resources/foreign_catalog_pipeline.yml`):

   ```yaml
   variables:
     dest_catalog:
       default: main
     dest_schema:
       default: ingest_destination_schema

   resources:
     pipelines:
       pipeline_foreign_catalog:
         name: foreign-catalog-ingestion-pipeline
         ingestion_definition:
           ingest_from_uc_foreign_catalog: true
           objects:
             - table:
                 source_catalog: <foreign-catalog-name>
                 source_schema: <source-schema>
                 source_table: <source-table>
                 table_configuration:
                   primary_keys:
                     - id
                   query_based_connector_config:
                     cursor_columns:
                       - updated_at
                     deletion_condition: 'deleted_at IS NOT NULL'
                 destination_catalog: ${var.dest_catalog}
                 destination_schema: ${var.dest_schema}
         target: ${var.dest_schema}
         catalog: ${var.dest_catalog}
   ```

4. Add a job definition file (for example, `resources/foreign_catalog_job.yml`):

   ```yaml
   resources:
     jobs:
       foreign_catalog_job:
         name: foreign_catalog_job

         trigger:
           periodic:
             interval: 1
             unit: HOURS

         email_notifications:
           on_failure:
             - <email-address>

         tasks:
           - task_key: refresh_pipeline
             pipeline_task:
               pipeline_id: ${resources.pipelines.pipeline_foreign_catalog.id}
   ```

5. Deploy the bundle:

   ```bash
   databricks bundle deploy
   ```

**Classic compute (Beta) example**

> [!NOTE]
> **Beta**
>
> Classic compute for query-based ingestion pipelines is in [Beta](https://docs.databricks.com/aws/en/release-notes/release-types.md). Databricks recommends serverless compute for most workloads.

To deploy on classic compute, set `serverless: false` and add a `clusters` block to the pipeline definition. The direct deployment engine honors the `serverless` field and other compute settings such as `photon`. After deployment, `serverless: false` no longer appears in the pipeline spec, but the `clusters` block is retained and the pipeline runs on classic compute. For the full set of supported cluster fields, see [Configure classic compute for pipelines](https://docs.databricks.com/aws/en/ldp/configure-compute.md).

1. Create a bundle:

   ```bash
   databricks bundle init
   ```

2. Enable the direct deployment engine. New bundles created with Databricks CLI version 1.3.0 and above use the direct deployment engine by default. If your bundle was created with an earlier version, set the top-level `bundle.engine` field in `databricks.yml` (not a per-target setting):

   ```yaml
   bundle:
     engine: direct
   ```

   If the bundle was previously deployed with the Terraform deployment engine, migrate the deployment state for each target before you deploy. Otherwise, deployment silently falls back to the Terraform engine. Run `databricks bundle deployment migrate -t <target>` for each target. For more information, see [databricks bundle deployment migrate](https://docs.databricks.com/aws/en/dev-tools/cli/bundle-commands.md#migrate).

3. Add a pipeline definition file to the bundle (for example, `resources/foreign_catalog_pipeline.yml`):

   ```yaml
   variables:
     dest_catalog:
       default: main
     dest_schema:
       default: ingest_destination_schema

   resources:
     pipelines:
       pipeline_foreign_catalog:
         name: foreign-catalog-ingestion-pipeline
         serverless: false
         clusters:
           - label: default
             node_type_id: r6i.xlarge
             driver_node_type_id: i3.large
             autoscale:
               min_workers: 1
               max_workers: 5
         ingestion_definition:
           ingest_from_uc_foreign_catalog: true
           objects:
             - table:
                 source_catalog: <foreign-catalog-name>
                 source_schema: <source-schema>
                 source_table: <source-table>
                 table_configuration:
                   primary_keys:
                     - id
                   query_based_connector_config:
                     cursor_columns:
                       - updated_at
                     deletion_condition: 'deleted_at IS NOT NULL'
                 destination_catalog: ${var.dest_catalog}
                 destination_schema: ${var.dest_schema}
         target: ${var.dest_schema}
         catalog: ${var.dest_catalog}
   ```

4. Add a job definition file (for example, `resources/foreign_catalog_job.yml`):

   ```yaml
   resources:
     jobs:
       foreign_catalog_job:
         name: foreign_catalog_job

         trigger:
           periodic:
             interval: 1
             unit: HOURS

         email_notifications:
           on_failure:
             - <email-address>

         tasks:
           - task_key: refresh_pipeline
             pipeline_task:
               pipeline_id: ${resources.pipelines.pipeline_foreign_catalog.id}
   ```

5. Deploy the bundle:

   ```bash
   databricks bundle deploy
   ```

## <a id="cursor-column" />Configure incremental tracking

Query-based connectors use a cursor column to determine which rows are new or updated after the last pipeline run. Your choice of cursor column is critical for effective incremental ingestion.

Consider the following when you select a cursor column:

* Use a timestamp column, if possible. Columns like `updated_at` or `last_modified` are ideal because they directly reflect when a row was last changed.
* Integer IDs work for append-only sources. If rows are never updated, you can use an auto-incrementing ID column (such as `id` or `row_id`) as the cursor. Don't use an integer ID as a cursor if rows can be updated without changing the ID.
* The column must increase monotonically. Values must never decrease. If a process such as a backfill sets the column to a past value, the connector doesn't reingest rows written before the previous high-water mark.
* You can only specify a single cursor column. You can't specify multiple columns as a composite cursor.

After the connector stores the cursor high-water mark, it uses the high-water mark as the lower bound filter (`cursor_column > last_value`) on the next run. For `SCD_TYPE_1` and `SCD_TYPE_2` ingestion with a timestamp cursor, the connector lowers the bound by a short lookback window. It captures late-arriving rows near the high-water mark and reconciles them by primary key. The connector doesn't ingest rows with a NULL cursor value.

## <a id="history-tracking" />Configure history tracking (SCD)

To track the full history of row changes in destination tables, configure SCD type 2. See [Enable history tracking (SCD type 2)](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/scd.md).

## <a id="common-patterns" />Common patterns

For advanced pipeline configurations, see [Common patterns for managed ingestion pipelines](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/common-patterns.md).

## <a id="additional-resources" />Additional resources

* [Query-based connector limitations](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/query-based-limits.md)
* [Query-based connector reference](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/query-based-reference.md)
* [Troubleshoot query-based connectors](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/query-based-troubleshoot.md)
