sql_lineage: Column-level lineage

View source: R/analysis.R

sql_lineageR Documentation

Column-level lineage

Description

Traces each output column of a query back to the tables and expressions it is derived from, following CTEs, subqueries and set operations.

Usage

sql_lineage(sql, dialect = "generic", schema = NULL, column = NULL)

Arguments

sql

A single character string with one or more SQL statements (separated by ⁠;⁠).

dialect

Dialect used for parsing.

schema

Optional schema specification (see as_polyglot_schema()); improves resolution of unqualified or ambiguous columns.

column

Optional single column name. By default, lineage is computed for every output column of the query.

Value

A polyglot_lineage object: a list with one entry per column, each containing

  • column — the output column name;

  • sources — character vector of source tables feeding this column;

  • tree — the lineage graph as nested lists with fields name, source_name, source_kind ("Table", "Cte", "DerivedTable", ...), expression (the SQL of the node's expression) and downstream.

Examples

sql_lineage("SELECT a + b AS total FROM t")
sql_lineage(
  "WITH base AS (SELECT id, amount FROM payments)
   SELECT id, amount * 2 AS doubled FROM base"
)

polyglotSQL documentation built on Sept. 27, 2026, 5:06 p.m.