> ## Documentation Index
> Fetch the complete documentation index at: https://docs.open-metadata.org/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Deploy a Lineage Workflow

> Build data lineage using workflows to extract upstream and downstream dependencies.

# How to Deploy a Lineage Workflow

Lineage data can be ingested from your data sources right from the OpenMetadata UI. Currently, the lineage workflow is supported for a limited set of connectors, like [BigQuery](https://docs.open-metadata.org/v2.1.x/connectors/database/bigquery.md), [Snowflake](https://docs.open-metadata.org/v2.1.x/connectors/database/snowflake.md), [MSSQL](https://docs.open-metadata.org/v2.1.x/connectors/database/mssql.md), [Redshift](https://docs.open-metadata.org/v2.1.x/connectors/database/redshift.md), [Clickhouse](https://docs.open-metadata.org/v2.1.x/connectors/database/clickhouse.md), [PostgreSQL](https://docs.open-metadata.org/v2.1.x/connectors/database/postgres.md), [Databricks](https://docs.open-metadata.org/v2.1.x/connectors/database/databricks.md).

> [!TIP]
>
> **Tip:** Trace the upstream and downstream dependencies with Lineage.

## View Lineage from Metadata Ingestion

Once the metadata ingestion runs correctly, and we are able to explore the service Entities, we can add the view lineage information for the data assets. This will populate the Lineage tab in the data asset page. During the Metadata Ingestion workflow we differentiate if a Table is a View. For those sources, where we can obtain the query that generates the View, we bring in the view lineage along with the metadata. After all Tables have been ingested in the workflow, it's time to parse all the queries generating Views. During the query parsing, we will obtain the source and target tables, search if the Tables exist in OpenMetadata, and finally create the lineage relationship between the involved Entities.

If the database has views, then the view lineage would be generated automatically, along with the column-level lineage. In such a case, the table type is **View** as shown in the example below.

![View Lineage through Metadata Ingestion](https://mintcdn.com/openmetadata/AdVLfc7GKtiOkV7v/public/images/how-to-guides/lineage/view.png?fit=max\&auto=format\&n=AdVLfc7GKtiOkV7v\&q=85\&s=9c72db3d1c643658480b13e9aa1b2193)

## Lineage Agent from UI

Apart from the Metadata ingestion, we can create a workflow that will obtain the query log and table creation information from the underlying database and feed it to OpenMetadata. The Lineage Agent will be in charge of obtaining this data. The metadata ingestion will only bring in the View lineage queries, whereas the Lineage Agent workflow will be bring in all those queries that can be used to generate lineage information.

### 1. Add a Lineage Agent

1. Navigate to **Connections** > **Databases**.

2. Select the database service.

   ![Connections page with Databases selected](https://mintcdn.com/openmetadata/GIhJhQEz-bXdMLzp/public/images/v2.1.x/connectors/connections/connections-databases.png?fit=max\&auto=format\&n=GIhJhQEz-bXdMLzp\&q=85\&s=8eb483ce68574f1a2c4c903897df3981)

3. Go to the **Agents** tab.

4. Select **Add Agent** > **Lineage**.

   ![Add Agent menu with Lineage highlighted](https://mintcdn.com/openmetadata/GIhJhQEz-bXdMLzp/public/images/v2.1.x/connectors/agents/add-agent-lineage.png?fit=max\&auto=format\&n=GIhJhQEz-bXdMLzp\&q=85\&s=4fb21b7b790ce4acf491ae63461caba3)

### 2. Configure the Lineage Agent

Here you can enter the Lineage Agent details:

![Configure Ingestion step of the Add Lineage Agent page](https://mintcdn.com/openmetadata/GIhJhQEz-bXdMLzp/public/images/v2.1.x/how-to-guides/lineage/configure-lineage-agent.png?fit=max\&auto=format\&n=GIhJhQEz-bXdMLzp\&q=85\&s=7b0fbf28a7fb6fc693e45d080b1d0e44)

#### Lineage Options

![Lineage options, including query parser type, filter condition, and number of threads](https://mintcdn.com/openmetadata/GIhJhQEz-bXdMLzp/public/images/v2.1.x/how-to-guides/lineage/lineage-options.png?fit=max\&auto=format\&n=GIhJhQEz-bXdMLzp\&q=85\&s=f6d99e252668256facb3331ef6251dc9)

* **Query Log Duration**: Specify the duration in days to look back in the query logs when capturing lineage data. For example, if you specify 2 as the value for the duration, the Lineage Agent captures lineage information for 2 **days** or 48 hours prior to when the ingestion workflow is run.

* **Parsing Timeout Limit**: Specify the timeout limit, in **seconds**, for parsing SQL queries during lineage analysis.

* **Result Limit**: Set the maximum number of query-log rows to process at a time.

* **Filter Condition**: Enter a SQL condition to filter the data source's query-history results before OpenMetadata analyzes them for lineage and usage. For more information, see [Usage Query Filtering](https://docs.open-metadata.org/v2.1.x/connectors/ingestion/workflows/usage/filter-query-set.md).

* **Process Cross Database Lineage**: Enable this toggle to build lineage across tables in different databases or projects (for example, across BigQuery projects or databases in other supported connectors). Also set **Cross Database Service Names** when enabling this option.

* **Cross Database Service Names**: Names of other services to search when resolving table references during lineage extraction. Use this when a query, view, or stored procedure references tables in a different service than the one currently being ingested—for example, when BigQuery projects are configured as separate services. List the specific service names to search. The underlying search returns a limited number of matches per lookup, so `*` can resolve to the wrong table or miss the correct service when many services or tables share names. This applies to query, view, and stored-procedure lineage when the corresponding processing options are enabled.

### 3. Schedule and Deploy

1. Click **Next** to open the **Schedule Interval** step.
2. Select the desired schedule.
3. Click **Add & Deploy** to add the lineage agent under the **Agents** tab.

   ![Schedule Interval step with Add & Deploy button](https://mintcdn.com/openmetadata/GIhJhQEz-bXdMLzp/public/images/v2.1.x/how-to-guides/lineage/schedule-lineage-agent.png?fit=max\&auto=format\&n=GIhJhQEz-bXdMLzp\&q=85\&s=d7a318e277eb9ca5abbb8ccc53173b59)

## Run Lineage Workflow Externally

## Lineage

After running a Metadata Ingestion workflow, we can run Lineage workflow.
While the `serviceName` will be the same to that was used in Metadata Ingestion, so the ingestion bot can get the `serviceConnection` details from the server.

### 1. Define the YAML Config

This is a sample config for bigquery Lineage:

**Source Configuration**

Configure the source type and service name for your lineage workflow.

You can find all the definitions and types for the `sourceConfig` [here](https://github.com/open-metadata/OpenMetadata/blob/main/openmetadata-spec/src/main/resources/json/schema/metadataIngestion/databaseServiceQueryLineagePipeline.json).

**Lineage Config Type**

**type**: Set to `DatabaseLineage` for database lineage ingestion.

**Query Log Duration**

**queryLogDuration**: Configuration to tune how far we want to look back in query logs to process lineage data in days.

**Parsing Timeout Limit**

**parsingTimeoutLimit**: Configuration to set the timeout for parsing the query in seconds.

**Filter Condition**

**filterCondition**: Condition to filter the query history.

**Result Limit**

**resultLimit**: Configuration to set the limit for query logs.

**Query Log File Path**

**queryLogFilePath**: Configuration to set the file path for query logs. If instead of getting the query logs from the database we want to pass a file with the queries.

**Database Filter Pattern**

**databaseFilterPattern**: Regex to only fetch databases that matches the pattern.

**Schema Filter Pattern**

**schemaFilterPattern**: Regex to only fetch tables or databases that matches the pattern.

**Table Filter Pattern**

**tableFilterPattern**: Regex to only fetch tables or databases that matches the pattern.

**Override View Lineage**

**overrideViewLineage**: Set the 'Override View Lineage' toggle to control whether to override the existing view lineage.

**Process View Lineage**

**processViewLineage**: Set the 'Process View Lineage' toggle to control whether to process view lineage.

**Process Query Lineage**

**processQueryLineage**: Set the 'Process Query Lineage' toggle to control whether to process query lineage.

**Process Stored Procedure Lineage**

**processStoredProcedureLineage**: Set the 'Process Stored ProcedureLog Lineage' toggle to control whether to process stored procedure lineage.

**Threads**

**threads**: Number of Threads to use in order to parallelize lineage ingestion.

**Sink Configuration**

To send the metadata to OpenMetadata, it needs to be specified as `type: metadata-rest`.

```yaml theme={null}
source:
  type: bigquery-lineage
  serviceName: bigquery
  sourceConfig:
    config:
      type: DatabaseLineage
      # Number of days to look back
      queryLogDuration: 1
      parsingTimeoutLimit: 300
      # filterCondition: query_text not ilike '--- metabase query %'
      resultLimit: 1000
      # If instead of getting the query logs from the database we want to pass a file with the queries
      # queryLogFilePath: /tmp/query_log/file_path
      # databaseFilterPattern:
      #   includes:
      #     - database1
      #     - database2
      #   excludes:
      #     - database3
      # schemaFilterPattern:
      #   includes:
      #     - schema1
      #     - schema2
      #   excludes:
      #     - schema3
      # tableFilterPattern:
      #   includes:
      #     - table1
      #     - table2
      #   excludes:
      #     - table3
      #     - table4
      overrideViewLineage: false
      processViewLineage: true
      processQueryLineage: true
      processStoredProcedureLineage: true
      threads: 1
sink:
  type: metadata-rest
  config: {}
```

* You can learn more about how to configure and run the Lineage Workflow to extract Lineage data from [here](https://docs.open-metadata.org/connectors/ingestion/workflows/lineage)

### 2. Run with the CLI

After saving the YAML config, we will run the command the same way we did for the metadata ingestion:

```bash theme={null}
metadata ingest -c <path-to-yaml>
```

## dbt Ingestion

We can also generate lineage through [dbt ingestion](https://docs.open-metadata.org/v2.1.x/connectors/database/dbt/configure-dbt-workflow.md). The dbt workflow can fetch queries that carry lineage information. For a dbt ingestion pipeline, the path to the Catalog and Manifest files must be specified. We also fetch the column level lineage through dbt.

You can learn more about [lineage ingestion here](https://docs.open-metadata.org/v2.1.x/connectors/ingestion/lineage.md).

## Query Logs using CSV File

Lineage ingestion is supported for a few connectors as mentioned earlier. For the unsupported connectors, you can set up [Lineage Workflows using Query Logs](https://docs.open-metadata.org/v2.1.x/connectors/ingestion/workflows/lineage/lineage-workflow-query-logs.md) using a CSV file.

## Manual Lineage

Lineage can also be added and edited manually in OpenMetadata. Refer for more information on [adding lineage manually](https://docs.open-metadata.org/v2.1.x/how-to-guides/data-lineage/manual.md).

> [card] [Explore the Lineage View](https://docs.open-metadata.org/v2.1.x/how-to-guides/data-lineage/explore.md)
>
> Explore the rich lineage view in OpenMetadata.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.