Skip to main content
100%

Use `sqlfluff` to build a lineage tree in D2

✓ Published0🌍 Public
HHugoberry
Last edited Oct 7, 2024
Created on Oct 7, 2024

This visualization parses T-SQL view definitions from `vwMarket.sql` and renders a lineage tree showing table and column dependencies, using `sqlfluff` to generate a parse tree and `D2` to draw the diagram. The code extracts aliases from `from_clause` nodes to list source tables as SQL-table shapes, and pulls column-to-column mappings from `expression` segments where comparisons use the `=` operator, outputting edges like `alias.column -> other.column`. It relies on `sqlfluff.parse` for T-SQL grammar analysis and recursive JSON traversal via `get_json_segment` to locate `from_expression_element` and `column_reference` structures, printing D2 syntax directly to standard output. The example demonstrates how to bridge SQL parsing with declarative diagramming for dependency visualization.

AI-generated description

Similar vizzes