Skip to content

feat: column lineage API, SQL tags, and PyO3 bindings - #1

Open
suryaiyer95 wants to merge 1 commit into
mainfrom
feat/column-lineage-and-tags
Open

feat: column lineage API, SQL tags, and PyO3 bindings#1
suryaiyer95 wants to merge 1 commit into
mainfrom
feat/column-lineage-and-tags

Conversation

@suryaiyer95

Copy link
Copy Markdown
Owner

Summary

  • Column lineage API in lineage.rscolumn_lineage(sql, dialect) traces source→target column edges through CTEs, derived tables, UNIONs, and subqueries with lens classification (Unchanged/Alias/Transformation)
  • Star expansion through CTEs and derived tables — WITH cte AS (SELECT a FROM t) SELECT * FROM cte resolves to individual column edges
  • Depth guard (MAX_LINEAGE_DEPTH=50) prevents stack overflow on deeply nested queries and recursive CTEs
  • Zero-clone scope passing (&[&Scope]) eliminates AST cloning on recursive hot path — 2.5x speedup on CTE-heavy queries
  • SQL tag analysis crate (polyglot-sql-tags) with 6 tags: create_or_replace_table, select_star, filter_has_func, join_has_func, agg_before_join, select_without_limit
  • PyO3 bindings (polyglot-sql-python) exposing polyglot.column_lineage() and polyglot.analyze_tags()

Validation

Tested on 593K production Snowflake queries across 6 tenants:

Tenant Queries Edges Speed P99
Block 100K 160K 1,838 q/s 4.87ms
Cisco 100K 91K 1,327 q/s 11.87ms
Coinbase 100K 28K 990 q/s 1.34ms
Rakuten 100K 42K 3,001 q/s 2.32ms
Rubrik 93K 15K 4,689 q/s 3.29ms
SHS 100K 95K 1,642 q/s 3.45ms
  • 60-83x faster than Python sqlglot
  • 78% edge-level parity with Python sqlglot on Block queries (200 query sample)
  • 67% perfect match — identical edge sets on majority of queries
  • Zero crashes across all tenants
  • 738/738 Rust unit tests pass

Test plan

  • cargo test -p polyglot-sql --lib — 738 tests pass
  • maturin develop --release — Python bindings build
  • 593K production query benchmark — zero crashes
  • Rust vs Python sqlglot parity validation
  • Star expansion through CTEs validated on test patterns

🤖 Generated with Claude Code

Column Lineage (`lineage.rs`):
- Public `column_lineage(sql, dialect)` API that extracts all output columns,
  traces each through the AST, and returns structured edges with lens
  classification (Unchanged/Alias/Transformation)
- Star expansion through CTEs and derived tables — `SELECT * FROM cte`
  resolves to individual column edges instead of opaque star terminals
- Depth guard (`MAX_LINEAGE_DEPTH=50`) prevents stack overflow on deeply
  nested derived tables and recursive CTEs
- Zero-clone scope passing (`&[&Scope]` instead of `&[Scope]`) eliminates
  expensive AST cloning on the recursive hot path — 2.5x speedup on
  CTE-heavy queries, 60-83x faster than Python sqlglot overall

SQL Tag Analysis (`polyglot-sql-tags`):
- Standalone crate for static SQL analysis producing 6 tags:
  `create_or_replace_table`, `select_star`, `filter_has_func`,
  `join_has_func`, `agg_before_join`, `select_without_limit`
- Expression tree walker (`deep_dfs`) handles three-part column refs,
  `Expression::Exists`, `CountFunc` star detection
- 17x faster than equivalent Python/sqlglot implementation

PyO3 Bindings (`polyglot-sql-python`):
- `polyglot.column_lineage(sql, dialect)` → dict with edges and errors
- `polyglot.analyze_tags(sql, dialect)` → dict of boolean tags
- GIL-released execution via `py.allow_threads()`

Validated on 593K production Snowflake queries across 6 tenants:
- 430K edges, zero crashes, 1000-4700 queries/sec
- 78% edge-level parity with Python sqlglot on Block queries
- 738/738 Rust unit tests pass

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant