sql-dag-flow 0.5.1__tar.gz → 0.5.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sql_dag_flow-0.5.1/src/sql_dag_flow.egg-info → sql_dag_flow-0.5.3}/PKG-INFO +4 -2
- {sql_dag_flow-0.5.1 → sql_dag_flow-0.5.3}/README.md +3 -1
- {sql_dag_flow-0.5.1 → sql_dag_flow-0.5.3}/pyproject.toml +1 -1
- {sql_dag_flow-0.5.1 → sql_dag_flow-0.5.3}/src/sql_dag_flow/main.py +21 -3
- {sql_dag_flow-0.5.1 → sql_dag_flow-0.5.3}/src/sql_dag_flow/parser.py +86 -48
- sql_dag_flow-0.5.1/src/sql_dag_flow/static/assets/index-ZylJfG6u.js → sql_dag_flow-0.5.3/src/sql_dag_flow/static/assets/index-BEi2iL86.js +45 -45
- sql_dag_flow-0.5.3/src/sql_dag_flow/static/assets/index-HIS38g9M.css +1 -0
- {sql_dag_flow-0.5.1 → sql_dag_flow-0.5.3}/src/sql_dag_flow/static/index.html +2 -2
- {sql_dag_flow-0.5.1 → sql_dag_flow-0.5.3/src/sql_dag_flow.egg-info}/PKG-INFO +4 -2
- {sql_dag_flow-0.5.1 → sql_dag_flow-0.5.3}/src/sql_dag_flow.egg-info/SOURCES.txt +2 -2
- sql_dag_flow-0.5.1/src/sql_dag_flow/static/assets/index-BM6GPh_j.css +0 -1
- {sql_dag_flow-0.5.1 → sql_dag_flow-0.5.3}/LICENSE +0 -0
- {sql_dag_flow-0.5.1 → sql_dag_flow-0.5.3}/MANIFEST.in +0 -0
- {sql_dag_flow-0.5.1 → sql_dag_flow-0.5.3}/setup.cfg +0 -0
- {sql_dag_flow-0.5.1 → sql_dag_flow-0.5.3}/src/sql_dag_flow/__init__.py +0 -0
- {sql_dag_flow-0.5.1 → sql_dag_flow-0.5.3}/src/sql_dag_flow/static/vite.svg +0 -0
- {sql_dag_flow-0.5.1 → sql_dag_flow-0.5.3}/src/sql_dag_flow/test_api_endpoints.py +0 -0
- {sql_dag_flow-0.5.1 → sql_dag_flow-0.5.3}/src/sql_dag_flow/test_parser.py +0 -0
- {sql_dag_flow-0.5.1 → sql_dag_flow-0.5.3}/src/sql_dag_flow/verify_counts.py +0 -0
- {sql_dag_flow-0.5.1 → sql_dag_flow-0.5.3}/src/sql_dag_flow.egg-info/dependency_links.txt +0 -0
- {sql_dag_flow-0.5.1 → sql_dag_flow-0.5.3}/src/sql_dag_flow.egg-info/entry_points.txt +0 -0
- {sql_dag_flow-0.5.1 → sql_dag_flow-0.5.3}/src/sql_dag_flow.egg-info/requires.txt +0 -0
- {sql_dag_flow-0.5.1 → sql_dag_flow-0.5.3}/src/sql_dag_flow.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sql-dag-flow
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.3
|
|
4
4
|
Summary: A sophisticated SQL lineage visualization tool for Medallion Architectures.
|
|
5
5
|
Author-email: Flavio Sandoval <dsandovalflavio@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -65,6 +65,7 @@ Specially optimized for the **Medallion Architecture** (Bronze, Silver, Gold) an
|
|
|
65
65
|
* Powered by **ELK (Eclipse Layout Kernel)**.
|
|
66
66
|
* Minimizes edge crossings and optimizes flow direction.
|
|
67
67
|
* Intelligent "Port" handling for cleaner connections.
|
|
68
|
+
* **Startup Configuration Selector**: Instantly resume previous sessions by selecting any `.json` configuration file found in your project directory upon launching the app.
|
|
68
69
|
|
|
69
70
|
### 🎮 Interactive Graph
|
|
70
71
|
* **Smart Context Menu**:
|
|
@@ -99,6 +100,7 @@ Specially optimized for the **Medallion Architecture** (Bronze, Silver, Gold) an
|
|
|
99
100
|
* **Column-Level Lineage (New in v0.4.9 🆕)**: Traces how each output column derives from source columns. Shows transformation chain (e.g., `order_timestamp ← orders_raw.order_date via CAST(... AS DATETIME)`).
|
|
100
101
|
* **SQL Syntax Validation (New in v0.4.9 🆕)**: Detects SQL parse errors and displays structured warnings with line/column references. Shows ⚠️ badge on nodes with syntax issues.
|
|
101
102
|
* **Large DAG Support & Safe Cycle Detection (New in v0.5.1 🚀)**: Optimized cycle detection algorithm prevents backend hanging and "Failed to fetch" browser errors when analyzing massive projects (50+ nodes). Employs quick DAG verifications and bounded iterator loops.
|
|
103
|
+
* **Performance Optimizations (New in v0.5.2 ⚡)**: Includes backend parsing TTL caching and frontend request deduplication to prevent server overload when refreshing large numbers of un-cached SQL files simultaneously.
|
|
102
104
|
* **Batch Hide from Toolbar**: Select multiple nodes → click "Hide" in the selection toolbar to hide them all at once.
|
|
103
105
|
* **Discovery Mode Fix**: Ghost nodes from Discovery Mode are now hidden when their connected source nodes are hidden, preventing orphan ghost nodes.
|
|
104
106
|
|
|
@@ -145,7 +147,7 @@ Install easily via `pip`:
|
|
|
145
147
|
pip install sql-dag-flow
|
|
146
148
|
```
|
|
147
149
|
|
|
148
|
-
To update to the latest version (**v0.5.
|
|
150
|
+
To update to the latest version (**v0.5.3**):
|
|
149
151
|
|
|
150
152
|
```bash
|
|
151
153
|
pip install --upgrade sql-dag-flow
|
|
@@ -40,6 +40,7 @@ Specially optimized for the **Medallion Architecture** (Bronze, Silver, Gold) an
|
|
|
40
40
|
* Powered by **ELK (Eclipse Layout Kernel)**.
|
|
41
41
|
* Minimizes edge crossings and optimizes flow direction.
|
|
42
42
|
* Intelligent "Port" handling for cleaner connections.
|
|
43
|
+
* **Startup Configuration Selector**: Instantly resume previous sessions by selecting any `.json` configuration file found in your project directory upon launching the app.
|
|
43
44
|
|
|
44
45
|
### 🎮 Interactive Graph
|
|
45
46
|
* **Smart Context Menu**:
|
|
@@ -74,6 +75,7 @@ Specially optimized for the **Medallion Architecture** (Bronze, Silver, Gold) an
|
|
|
74
75
|
* **Column-Level Lineage (New in v0.4.9 🆕)**: Traces how each output column derives from source columns. Shows transformation chain (e.g., `order_timestamp ← orders_raw.order_date via CAST(... AS DATETIME)`).
|
|
75
76
|
* **SQL Syntax Validation (New in v0.4.9 🆕)**: Detects SQL parse errors and displays structured warnings with line/column references. Shows ⚠️ badge on nodes with syntax issues.
|
|
76
77
|
* **Large DAG Support & Safe Cycle Detection (New in v0.5.1 🚀)**: Optimized cycle detection algorithm prevents backend hanging and "Failed to fetch" browser errors when analyzing massive projects (50+ nodes). Employs quick DAG verifications and bounded iterator loops.
|
|
78
|
+
* **Performance Optimizations (New in v0.5.2 ⚡)**: Includes backend parsing TTL caching and frontend request deduplication to prevent server overload when refreshing large numbers of un-cached SQL files simultaneously.
|
|
77
79
|
* **Batch Hide from Toolbar**: Select multiple nodes → click "Hide" in the selection toolbar to hide them all at once.
|
|
78
80
|
* **Discovery Mode Fix**: Ghost nodes from Discovery Mode are now hidden when their connected source nodes are hidden, preventing orphan ghost nodes.
|
|
79
81
|
|
|
@@ -120,7 +122,7 @@ Install easily via `pip`:
|
|
|
120
122
|
pip install sql-dag-flow
|
|
121
123
|
```
|
|
122
124
|
|
|
123
|
-
To update to the latest version (**v0.5.
|
|
125
|
+
To update to the latest version (**v0.5.3**):
|
|
124
126
|
|
|
125
127
|
```bash
|
|
126
128
|
pip install --upgrade sql-dag-flow
|
|
@@ -36,6 +36,24 @@ STATIC_DIR = os.path.join(BASE_DIR, "static")
|
|
|
36
36
|
CURRENT_DIRECTORY = os.getcwd() # Default, updated by start()
|
|
37
37
|
DIAGRAM_FILE = "sql_diagram.json"
|
|
38
38
|
|
|
39
|
+
# Parse cache to avoid re-parsing on concurrent/rapid requests
|
|
40
|
+
_parse_cache = {"key": None, "tables": None, "time": 0}
|
|
41
|
+
PARSE_CACHE_TTL = 5 # seconds
|
|
42
|
+
|
|
43
|
+
def _cached_parse(directory, subfolders_tuple, dialect):
|
|
44
|
+
"""Parse with simple TTL cache. Prevents re-parsing on concurrent requests."""
|
|
45
|
+
cache_key = (directory, subfolders_tuple, dialect)
|
|
46
|
+
now = time.time()
|
|
47
|
+
if _parse_cache["key"] == cache_key and (now - _parse_cache["time"]) < PARSE_CACHE_TTL:
|
|
48
|
+
return _parse_cache["tables"]
|
|
49
|
+
|
|
50
|
+
subfolders_list = list(subfolders_tuple) if subfolders_tuple else None
|
|
51
|
+
tables = parse_sql_files(directory, allowed_subfolders=subfolders_list, dialect=dialect)
|
|
52
|
+
_parse_cache["key"] = cache_key
|
|
53
|
+
_parse_cache["tables"] = tables
|
|
54
|
+
_parse_cache["time"] = now
|
|
55
|
+
return tables
|
|
56
|
+
|
|
39
57
|
@app.get("/graph")
|
|
40
58
|
def get_graph(dialect: str = "bigquery", discovery: bool = False, expanded_nodes: str = ""):
|
|
41
59
|
"""Parses SQL files in the current directory and returns graph data."""
|
|
@@ -44,7 +62,7 @@ def get_graph(dialect: str = "bigquery", discovery: bool = False, expanded_nodes
|
|
|
44
62
|
|
|
45
63
|
exp_nodes_list = [n.strip() for n in expanded_nodes.split(",")] if expanded_nodes else []
|
|
46
64
|
try:
|
|
47
|
-
tables =
|
|
65
|
+
tables = _cached_parse(CURRENT_DIRECTORY, None, dialect)
|
|
48
66
|
nodes, edges, cycles = build_graph(tables, discovery_mode=discovery, expanded_nodes=exp_nodes_list)
|
|
49
67
|
return {"nodes": nodes, "edges": edges, "cycles": cycles}
|
|
50
68
|
except Exception as e:
|
|
@@ -61,8 +79,8 @@ def set_path(path_data: dict = Body(...)):
|
|
|
61
79
|
if not path or not os.path.exists(path):
|
|
62
80
|
raise HTTPException(status_code=400, detail="Directory does not exist")
|
|
63
81
|
|
|
64
|
-
|
|
65
82
|
CURRENT_DIRECTORY = path
|
|
83
|
+
_parse_cache["key"] = None # Invalidate cache on path change
|
|
66
84
|
return {"message": "Path updated", "path": CURRENT_DIRECTORY}
|
|
67
85
|
|
|
68
86
|
@app.post("/scan/folders")
|
|
@@ -105,7 +123,7 @@ def get_filtered_graph(data: dict = Body(...)):
|
|
|
105
123
|
expanded_nodes = data.get("expanded_nodes", [])
|
|
106
124
|
|
|
107
125
|
try:
|
|
108
|
-
tables =
|
|
126
|
+
tables = _cached_parse(CURRENT_DIRECTORY, tuple(subfolders) if subfolders else None, dialect)
|
|
109
127
|
nodes, edges, cycles = build_graph(tables, discovery_mode=discovery, expanded_nodes=expanded_nodes)
|
|
110
128
|
return {"nodes": nodes, "edges": edges, "cycles": cycles}
|
|
111
129
|
except Exception as e:
|
|
@@ -566,18 +566,28 @@ def parse_sql_files(directory, allowed_subfolders=None, dialect="bigquery"):
|
|
|
566
566
|
global_schema["default"][label] = col_dict
|
|
567
567
|
|
|
568
568
|
# Re-extract column_references using qualify_columns for precision
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
569
|
+
# Protected with per-table time budget to prevent hanging on large projects
|
|
570
|
+
qualify_tables = [(tid, tdata) for tid, tdata in tables.items()
|
|
571
|
+
if not tdata.get("error") and tdata.get("content")]
|
|
572
|
+
total_qualify = len(qualify_tables)
|
|
573
|
+
|
|
574
|
+
for idx, (tid, tdata) in enumerate(qualify_tables):
|
|
575
|
+
table_start = time.time()
|
|
576
|
+
if idx % 10 == 0 and total_qualify > 10:
|
|
577
|
+
print(f" Qualifying columns: {idx}/{total_qualify} tables...")
|
|
572
578
|
try:
|
|
573
579
|
parsed = sqlglot.parse_one(tdata["content"], read=dialect)
|
|
574
580
|
|
|
575
|
-
# Try to qualify columns using the global schema
|
|
581
|
+
# Try to qualify columns using the global schema (with 2s budget)
|
|
576
582
|
try:
|
|
577
583
|
qualified_ast = sqlglot_qualify_columns(parsed.copy(), schema=global_schema, dialect=dialect)
|
|
578
584
|
except Exception:
|
|
579
585
|
qualified_ast = parsed # Fallback to unqualified
|
|
580
586
|
|
|
587
|
+
# Check time budget
|
|
588
|
+
if time.time() - table_start > 2.0:
|
|
589
|
+
continue # Skip extraction if qualification took too long
|
|
590
|
+
|
|
581
591
|
# Re-extract column references from qualified AST
|
|
582
592
|
alias_map = {}
|
|
583
593
|
defined_ctes = set()
|
|
@@ -634,55 +644,83 @@ def parse_sql_files(directory, allowed_subfolders=None, dialect="bigquery"):
|
|
|
634
644
|
except Exception:
|
|
635
645
|
pass # Keep original column_references
|
|
636
646
|
|
|
647
|
+
if total_qualify > 10:
|
|
648
|
+
print(f" Qualifying columns: {total_qualify}/{total_qualify} done.")
|
|
649
|
+
|
|
637
650
|
# ===== Column-Level Lineage =====
|
|
638
651
|
# For each table, trace how each output column derives from source columns
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
+
# Protected: skip if project is very large (>100 tables) and cap columns per table
|
|
653
|
+
MAX_LINEAGE_TABLES = 100
|
|
654
|
+
MAX_COLS_PER_TABLE = 30
|
|
655
|
+
LINEAGE_TIME_BUDGET = 1.5 # seconds per table
|
|
656
|
+
|
|
657
|
+
lineage_tables = [(tid, tdata) for tid, tdata in tables.items()
|
|
658
|
+
if not tdata.get("error") and tdata.get("content") and tdata.get("schema")]
|
|
659
|
+
total_lineage = len(lineage_tables)
|
|
660
|
+
|
|
661
|
+
if total_lineage > MAX_LINEAGE_TABLES:
|
|
662
|
+
print(f" Skipping column lineage: {total_lineage} tables exceeds limit of {MAX_LINEAGE_TABLES}")
|
|
663
|
+
else:
|
|
664
|
+
for idx, (tid, tdata) in enumerate(lineage_tables):
|
|
665
|
+
table_start = time.time()
|
|
666
|
+
if idx % 10 == 0 and total_lineage > 10:
|
|
667
|
+
print(f" Column lineage: {idx}/{total_lineage} tables...")
|
|
668
|
+
|
|
669
|
+
schema_cols = tdata.get("schema", [])
|
|
670
|
+
if not schema_cols:
|
|
652
671
|
continue
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
source_table = ""
|
|
665
|
-
if child.source and isinstance(child.source, exp.Table):
|
|
666
|
-
source_table = child.source.name
|
|
667
|
-
if child.source.db:
|
|
668
|
-
source_table = f"{child.source.db}.{child.source.name}"
|
|
669
|
-
|
|
670
|
-
transform = ""
|
|
671
|
-
if child.expression and str(child.expression) != source_col:
|
|
672
|
-
transform = str(child.expression)
|
|
672
|
+
|
|
673
|
+
column_lineage = {} # col_name -> [{source_table, source_column, transform}]
|
|
674
|
+
sql_content = tdata["content"]
|
|
675
|
+
|
|
676
|
+
cols_processed = 0
|
|
677
|
+
for col_info in schema_cols:
|
|
678
|
+
# Check time budget
|
|
679
|
+
if time.time() - table_start > LINEAGE_TIME_BUDGET:
|
|
680
|
+
break
|
|
681
|
+
if cols_processed >= MAX_COLS_PER_TABLE:
|
|
682
|
+
break
|
|
673
683
|
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
684
|
+
col_name = col_info["name"]
|
|
685
|
+
if col_name == "*":
|
|
686
|
+
continue
|
|
687
|
+
cols_processed += 1
|
|
688
|
+
try:
|
|
689
|
+
from sqlglot.lineage import lineage as sqlglot_lineage
|
|
690
|
+
node = sqlglot_lineage(
|
|
691
|
+
col_name, sql_content,
|
|
692
|
+
schema=global_schema,
|
|
693
|
+
dialect=dialect
|
|
694
|
+
)
|
|
695
|
+
sources = []
|
|
696
|
+
for child in node.downstream:
|
|
697
|
+
source_col = child.name
|
|
698
|
+
# Extract the source table from the expression
|
|
699
|
+
source_table = ""
|
|
700
|
+
if child.source and isinstance(child.source, exp.Table):
|
|
701
|
+
source_table = child.source.name
|
|
702
|
+
if child.source.db:
|
|
703
|
+
source_table = f"{child.source.db}.{child.source.name}"
|
|
704
|
+
|
|
705
|
+
transform = ""
|
|
706
|
+
if child.expression and str(child.expression) != source_col:
|
|
707
|
+
transform = str(child.expression)
|
|
708
|
+
|
|
709
|
+
sources.append({
|
|
710
|
+
"source_table": source_table,
|
|
711
|
+
"source_column": source_col,
|
|
712
|
+
"transform": transform
|
|
713
|
+
})
|
|
714
|
+
if sources:
|
|
715
|
+
column_lineage[col_name] = sources
|
|
716
|
+
except Exception:
|
|
717
|
+
pass # Lineage not available for this column
|
|
718
|
+
|
|
719
|
+
if column_lineage:
|
|
720
|
+
tdata["column_lineage"] = column_lineage
|
|
683
721
|
|
|
684
|
-
if
|
|
685
|
-
|
|
722
|
+
if total_lineage > 10:
|
|
723
|
+
print(f" Column lineage: {total_lineage}/{total_lineage} done.")
|
|
686
724
|
|
|
687
725
|
return tables
|
|
688
726
|
|