> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# Semantic View OpenLineage

> Export semantic view OpenLineage from a saved name or DDL, choose lineage depth, and interpret dataset and column dependencies.

Use `EXPLAIN OPENLINEAGE` to export a semantic view's declared dataset and column dependencies as standard OpenLineage JSON. It includes facts, dimensions, metrics and the computation definitions that connect them to source datasets. This is design-time lineage: the statement does not execute or materialize the computation, create an SV, or modify catalog metadata.

## Syntax

```sql theme={null}
EXPLAIN OPENLINEAGE [BRIEF | VERBOSE | FULL] [<db>.]<sv_name>;
EXPLAIN OPENLINEAGE [BRIEF | VERBOSE | FULL] CREATE SEMANTIC VIEW ...;
```

The default level is **BRIEF**. Input is either a saved semantic-view name or a `CREATE SEMANTIC VIEW` declaration.

## Usage

### Export a saved semantic view

For an existing `example_db.sales_sv`:

```sql theme={null}
EXPLAIN OPENLINEAGE example_db.sales_sv;
EXPLAIN OPENLINEAGE FULL example_db.sales_sv;
```

Named input reads the saved SV DDL automatically. You do not need to retrieve and resubmit it. The exported target follows the current SV identity after rename. Saved declarations are interpreted using their creation SQL mode rather than the inspecting session's SQL mode.

### Analyze a declaration without creating the semantic view

Suppose `example_db.orders` already has columns `id`, `amount` and `discount`:

```sql theme={null}
EXPLAIN OPENLINEAGE FULL
CREATE SEMANTIC VIEW example_db.sales_preview
TABLES (o AS example_db.orders PRIMARY KEY (id))
FACTS (o.net AS amount - discount)
DIMENSIONS (o.order_id AS id)
METRICS (o.total AS SUM(o.net));
```

This analyzes the definition without registering `sales_preview`. The database and referenced sources must already exist. A dry-run declaration does not require `CREATE_VIEW`; SELECT privileges are checked on every exposed source. Named input additionally requires SELECT on the target SV.

## Choose the lineage depth

| Level | Expansion boundary |
| - | - |
| BRIEF | Stop at the SV's direct source datasets. Keep a source View/MV/SV as a Dataset without expanding its computation. |
| VERBOSE | Expand each direct nonphysical source once, to the datasets it depends on. Do not expand a View/MV/SV encountered at that next layer. |
| FULL | Recursively expand View/MV/SV definitions until physical tables are reached, retaining intermediate datasets and computation definitions. |

Physical tables are leaves in every mode. Missing sources, insufficient privileges, unsupported expansion or cyclic dependencies are errors, not permission to guess a partial physical pipeline. Depth controls expansion, not SQL execution or materialization.

## Interpret the output

Each SQL result row is one standard OpenLineage JSON event, not a private wrapper:

* A table, View, MV or SV is a **Dataset**. DatasetEvents carry schema and lineage metadata.
* An expanded computation declaration is a **Job** with a JobEvent containing declared inputs/outputs and SQL.
* No **Run** or RunEvent is emitted: analyzing a declaration is not an execution instance.
* Facts, dimensions and metrics appear in `schema.fields`, with their semantic role in standard field tags (`semantic_role`) and their expression in the field description.
* `lineage.fields` records direct column dependencies; `lineage.inputs` also records dataset-wide controls such as FILTER and JOIN. Job SQL preserves the declaration's computation.
* A constant or `COUNT(*)` can have no direct input column while still depending on source datasets. An empty field-input list does not mean there is no lineage.

The export uses standard OpenLineage events/facets. A consumer must support the emitted event/facet types to build its own graph; standard compliance does not guarantee every historical consumer's native UI supports design-time column lineage. See the [OpenLineage object model](https://openlineage.io/docs/spec/object-model/) and [lineage facet](https://openlineage.io/docs/spec/facets/dataset-facets/lineage).

## Save the JSON

Adjust the connection options for your cluster. The MySQL client's raw batch output preserves one JSON event per line (NDJSON).

```bash theme={null}
mysql -h 127.0.0.1 -P 9030 -u root --batch --skip-column-names --raw \
  -e 'EXPLAIN OPENLINEAGE BRIEF example_db.sales_sv' > brief.ndjson
mysql -h 127.0.0.1 -P 9030 -u root --batch --skip-column-names --raw \
  -e 'EXPLAIN OPENLINEAGE VERBOSE example_db.sales_sv' > verbose.ndjson
mysql -h 127.0.0.1 -P 9030 -u root --batch --skip-column-names --raw \
  -e 'EXPLAIN OPENLINEAGE FULL example_db.sales_sv' > full.ndjson
```

## Example: a semantic view over logical views

This case uses `sv_recommendation/tpcds_test/query06`. The linked JSON files are actual exports archived on **October 23, 2026**, not hand-written examples or a fresh run of the latest implementation. Empty physical tables were sufficient for metadata/lineage verification; these files do not prove populated-data query equivalence.

### Definitions

The five physical tables are `store_sales`, `customer`, `customer_address`, `date_dim`, and `item`. Two logical views filter the date and item inputs. The SV declares **12 dimensions, one metric, and no facts**.

Full source files, including the original empty semantic-metadata placeholders:

* [SV DDL](/documents/downloads/9b3d63aae0092e36094ba237.sql)
* [Date view DDL](/documents/downloads/5a3c973a1730bb05655ebe5c.sql)
* [Item view DDL](/documents/downloads/786485b21aaad2a9a9beccbb.sql)
* Physical table DDL: [store\_sales](/documents/downloads/50eadb666b5f8b78918b369a.sql), [customer](/documents/downloads/d63a853f13a1a946a21ca454.sql), [customer\_address](/documents/downloads/efcd4a9e495f81b08a391134.sql), [date\_dim](/documents/downloads/01dd62fd7f4388c2b573c7ec.sql), [item](/documents/downloads/7ac382daa7c26bb05d79d51e.sql).

The view computations are:

```sql theme={null}
CREATE VIEW tpcds_1g.v_d_06_1 AS
SELECT d.d_date_sk, d.d_month_seq, d.d_year, d.d_moy
FROM tpcds_1g.date_dim d
WHERE d.d_month_seq = (
    SELECT DISTINCT d_month_seq
    FROM tpcds_1g.date_dim
    WHERE d_year = 2001 AND d_moy = 1
);

CREATE VIEW tpcds_1g.v_i_06_1 AS
SELECT i.i_item_sk, i.i_item_id, i.i_current_price,
       i.i_category, i.i_brand, i.i_class
FROM tpcds_1g.item i
WHERE i.i_current_price > 1.2 * (
    SELECT avg(j.i_current_price)
    FROM tpcds_1g.item j
    WHERE j.i_category = i.i_category
);
```

The SV definition below omits only empty synonyms, comments, sample values, and AI instruction placeholders. The linked original DDL retains them.

```sql theme={null}
CREATE SEMANTIC VIEW tpcds_1g.sv_06
TABLES (
    store_sales AS tpcds_1g.store_sales,
    customer AS tpcds_1g.customer PRIMARY KEY (c_customer_sk),
    customer_address AS tpcds_1g.customer_address PRIMARY KEY (ca_address_sk),
    v_d_06_1 AS tpcds_1g.v_d_06_1 PRIMARY KEY (d_date_sk),
    v_i_06_1 AS tpcds_1g.v_i_06_1 PRIMARY KEY (i_item_sk)
)
RELATIONSHIPS (
    rel_ss_customer AS store_sales (ss_customer_sk) INNER REFERENCES customer (c_customer_sk),
    rel_customer_addr AS customer (c_current_addr_sk) INNER REFERENCES customer_address (ca_address_sk),
    rel_ss_date AS store_sales (ss_sold_date_sk) INNER REFERENCES v_d_06_1 (d_date_sk),
    rel_ss_item AS store_sales (ss_item_sk) INNER REFERENCES v_i_06_1 (i_item_sk)
)
DIMENSIONS (
    customer_address.customer_state AS ca_state,
    customer_address.customer_county AS ca_county,
    customer_address.customer_city AS ca_city,
    customer.customer_id AS c_customer_id,
    v_d_06_1.date_key AS d_date_sk,
    v_d_06_1.calendar_year AS d_year,
    v_d_06_1.month_of_year AS d_moy,
    v_d_06_1.month_sequence AS d_month_seq,
    v_i_06_1.item_key AS i_item_sk,
    v_i_06_1.item_category AS i_category,
    v_i_06_1.brand_name AS i_brand,
    v_i_06_1.item_class AS i_class
)
METRICS (store_sales.sales_line_count AS count(*));
```

See [CREATE SEMANTIC VIEW](/documents/4.2/sql-reference/sql-statements/semantic-view/CREATE_SEMANTIC_VIEW.md) for the declaration syntax and the meaning of relationships. This is a graph of declared dependencies, not a claim that every query must execute every declared join.

### JSON output

Each SQL result row is **one standard JSON event**. The downloadable `.ndjson` files preserve these rows verbatim, without a private wrapper. In the archived test, the database qualifier was changed from `tpcds_1g` to isolated database `ol_corpus_3be7062938_tpcds`; the namespace is `starrocks://582847750/default_catalog`. Business expressions are unchanged. The metadata-only fixture also reduced physical bucket counts and replication; these storage settings do not affect the lineage shown here.

| Level | Expansion boundary | DatasetEvents | JobEvents | Raw JSON |
| - | - | -: | -: | - |
| BRIEF | Direct SV sources only | 6 | 1 | [brief.ndjson](/documents/downloads/f82138cfefc8e8559d892f21.ndjson) |
| VERBOSE | One layer below direct sources | 8 | 3 | [verbose.ndjson](/documents/downloads/1ce21b6bea2259efb1b8237c.ndjson) |
| FULL | Continue to physical tables | 8 | 3 | [full.ndjson](/documents/downloads/7143e4d5020838039aca664a.ndjson) |

**VERBOSE and FULL are identical after removing only `eventTime`** in this case: both views directly depend on physical tables. FULL preserves intermediate views rather than flattening away their definitions.

The SV's standard schema has 13 fields. Standard field tags identify `DIMENSION` or `METRIC` through `semantic_role`; no custom facet is needed. For example, this is an extracted fragment of `dataset.facets.lineage.fields`, **not a complete standalone event**:

```json theme={null}
{
  "v_i_06_1.item_category": {
    "inputs": [
      {
        "namespace": "starrocks://582847750/default_catalog",
        "name": "ol_corpus_3be7062938_tpcds.v_i_06_1",
        "type": "DATASET",
        "field": "i_category",
        "transformations": [{"type": "DIRECT", "subtype": "IDENTITY"}]
      }
    ]
  },
  "store_sales.sales_line_count": {"inputs": []}
}
```

In VERBOSE/FULL, the view's own event adds `item.i_category → v_i_06_1.i_category`, completing the two-edge physical-to-semantic path. Its standard Job SQL facet retains the correlated average-price filter. The standard legacy `columnLineage` facet is also present for consumers that support it.

`COUNT(*)` reads a row set, not the value of an individual column. Its empty direct field inputs are intentional; its expression is retained in the schema description and Job SQL. Dataset inputs and indirect controls describe the surrounding dependencies. Do not fabricate a physical-column-to-count edge.

### Dataset and column lineage

Rectangular nodes in dataset graphs are Datasets; rounded nodes are definition Jobs, not execution Runs. Column graphs show every exported field dependency: solid blue edges are direct identity mappings; dashed edges terminate at dataset-wide FILTER/JOIN controls, not at invented per-field dependencies. Database qualifiers are omitted from image labels only; the raw JSON is unchanged.

The column graphs contain all 13 SV fields. VERBOSE/FULL additionally show all four date-view fields and six item-view fields, including view output columns not selected as SV dimensions.

#### BRIEF

![BRIEF dataset and Job lineage for query06](https://mintcdn.com/mirrorship-docs/8FakUMFrFjmoxRt5/documents/images/eee5799c15a8f2c20d3dcf9d.png?fit=max\&auto=format\&n=8FakUMFrFjmoxRt5\&q=85\&s=0cc68bf5b3b93350b40cf9db47962b2e)

![BRIEF complete column lineage for query06](https://mintcdn.com/mirrorship-docs/8FakUMFrFjmoxRt5/documents/images/e9d4e4d98f45823ed776a1aa.png?fit=max\&auto=format\&n=8FakUMFrFjmoxRt5\&q=85\&s=7e5d848526ae8e5af1d979028365196c)

BRIEF has 12 direct field edges and eight dataset-wide JOIN control inputs. It stops at `v_d_06_1` and `v_i_06_1` and therefore does not export their underlying filters.

#### VERBOSE

![VERBOSE dataset and Job lineage for query06](https://mintcdn.com/mirrorship-docs/8FakUMFrFjmoxRt5/documents/images/d4243f0b9065963ae943736a.png?fit=max\&auto=format\&n=8FakUMFrFjmoxRt5\&q=85\&s=7983193207a1238e197d84104cf1b8d4)

![VERBOSE complete column lineage for query06](https://mintcdn.com/mirrorship-docs/sL46GVQByWEibCzI/documents/images/51a92c8f9ae091931143bc79.png?fit=max\&auto=format\&n=sL46GVQByWEibCzI\&q=85\&s=f89237ffd01a5200024355c49e40a788)

VERBOSE adds two physical tables, two definition Jobs, ten direct field edges, and five FILTER control inputs. The total is 22 direct field edges and 13 dataset-wide control inputs.

#### FULL

![FULL dataset and Job lineage for query06](https://mintcdn.com/mirrorship-docs/PYpCw6ZrekIEuuQL/documents/images/9bb3c4756c8a1a6388754a60.png?fit=max\&auto=format\&n=PYpCw6ZrekIEuuQL\&q=85\&s=ada20299826169e31c13c69c507524a5)

![FULL complete column lineage for query06](https://mintcdn.com/mirrorship-docs/sL46GVQByWEibCzI/documents/images/502a69be25aac7c44056b3b3.png?fit=max\&auto=format\&n=sL46GVQByWEibCzI\&q=85\&s=128fd7916812a3240e0a8a4f358c7ca4)

The FULL graph has the same topology and dependencies as VERBOSE for this example. It is shown separately so that each requested export has its own dataset and column image.

#### Indirect controls

The date view records FILTER dependencies on `date_dim.d_year`, `d_moy`, and `d_month_seq`. The item view records FILTER dependencies on `item.i_category` and `i_current_price`, including the correlated category comparison and the average-price expression in Job SQL. These controls influence row selection, not the direct value identity mappings.

The SV records eight JOIN endpoint dependencies for these four declared relationships:

| Left endpoint | Right endpoint |
| - | - |
| `store_sales.ss_customer_sk` | `customer.c_customer_sk` |
| `customer.c_current_addr_sk` | `customer_address.ca_address_sk` |
| `store_sales.ss_sold_date_sk` | `v_d_06_1.d_date_sk` |
| `store_sales.ss_item_sk` | `v_i_06_1.i_item_sk` |

These controls live in `lineage.inputs`; direct value mappings live in `lineage.fields`. A consumer must consider both, together with Job SQL, to interpret the declared computation.

## Check exported references

For exports of the same unchanged SV, the following inline Python example checks that dataset/column references resolve, including dataset-wide controls. It is a lightweight referential check, not a replacement for the official OpenLineage JSON Schemas. No repository-specific test utility is required.

```bash theme={null}
python3 - brief.ndjson verbose.ndjson full.ndjson <<'PY'
import json
import sys
from pathlib import Path

for filename in sys.argv[1:]:
    events = [json.loads(line) for line in Path(filename).read_text().splitlines() if line.strip()]
    assert events
    datasets = {}
    for event in events:
        assert all(key in event for key in ("eventTime", "producer", "schemaURL"))
        assert "run" not in event
        assert ("dataset" in event) != ("job" in event)
        if "dataset" in event:
            dataset = event["dataset"]
            key = (dataset["namespace"], dataset["name"])
            assert key not in datasets
            datasets[key] = dataset
    schemas = {
        key: {field["name"] for field in dataset["facets"]["schema"]["fields"]}
        for key, dataset in datasets.items()
    }

    def check_reference(source):
        key = (source["namespace"], source["name"])
        assert key in datasets, source
        if "field" in source:
            assert source["field"] in schemas[key], source

    for key, dataset in datasets.items():
        lineage = dataset["facets"].get("lineage", {})
        for source in lineage.get("inputs", []):
            check_reference(source)
        for name, field in lineage.get("fields", {}).items():
            assert name in schemas[key], name
            for source in field.get("inputs", []):
                check_reference(source)
    for event in events:
        if "job" in event:
            for source in event.get("inputs", []) + event.get("outputs", []):
                check_reference(source)
    jobs = sum("job" in event for event in events)
    print(f"{filename}: {len(datasets)} datasets, {jobs} jobs; field references OK")
PY
```

All three languages reference the same PNG, SQL and NDJSON files in `docs/_assets/semantic-view-openlineage-query06`. The `@site` resource alias resolves them through the Docusaurus site directory even when language trees are relocated. There are no localized copies, DOT sources or separate rendering/test scripts.


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