SQL feature lineage analysis and unified vector SQL generation toolkit
Project description
feature-sql-tool
feature_sql_tool is a Python library for:
- parsing SQL feature definitions with
sqlglot - extracting feature lineage down to physical source columns
- tracking intermediate computed aliases
- classifying filter-only intermediate features
- building a unified SQL query for multiple features with safe reusable CTE detection
Main ideas
The library treats SQL as a dependency graph rather than plain text. It separates:
- value dependencies
- filter dependencies
- join dependencies
- computed intermediate aliases
- physical source columns
This makes it possible to:
- explain how a final feature is computed
- detect shared computation between multiple features
- generate a reusable SQL plan for model input vectors
Quick example
from pathlib import Path
from feature_sql_tool import FeatureSpec, FeatureSqlTool
features = [
FeatureSpec(
feature_name="avg_payment_30d",
sql_file_path=Path("sql_samples/feature_avg_payment_30d.sql"),
final_alias="avg_paid_amount_per_payment_30d",
entity_key="client_id",
dialect="spark",
grain="client_id",
),
FeatureSpec(
feature_name="cnt_paid_txn_30d",
sql_file_path=Path("sql_samples/feature_cnt_paid_txn_30d.sql"),
final_alias="cnt_paid_txn_30d",
entity_key="client_id",
dialect="spark",
grain="client_id",
),
]
tool = FeatureSqlTool()
results = tool.analyze_features(features)
for result in results:
print(result.feature_spec.feature_name)
print(result.source_columns)
print(result.intermediate_features)
print(result.filter_only_intermediate_features)
sql = tool.build_unified_sql(features)
print(sql)
Package structure
models/– dataclasses and domain modelsparser/– file loading, SQL parsing, AST normalizationscope/– scope, relation and alias registrieslineage/– recursive column resolution and lineage extractiongraph/– graph container, classifiers and graph mergeplanner/– reusable subgraph detection and execution planninggenerator/– final SQL renderingreporting/– JSON reportssql_samples/– example SQL filesexamples/– runnable example scripts
Current scope
This version implements the second-iteration architecture in a practical way:
- recursive resolution through CTE and alias sources
- computed vs passthrough aliases
- filter-only intermediate feature classification
- safe grouping of features with identical execution signatures
- unified SQL generation with reusable aggregate CTEs
It is still a best-effort engineering implementation and should be validated on your real SQL corpus before production use.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file feature_sql_tool-0.2.1.tar.gz.
File metadata
- Download URL: feature_sql_tool-0.2.1.tar.gz
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfc22ca8c07362a1a5a85324a520beac937cbfb1aa9aeab56ec05bd57bb388ee
|
|
| MD5 |
1014c677edc0d8cf4d1cb13383c4e3d8
|
|
| BLAKE2b-256 |
c4b23badb6f6c7e84d25f722df61ba0327bb1c554bbdb70f1979f0dd81ea614f
|
File details
Details for the file feature_sql_tool-0.2.1-py3-none-any.whl.
File metadata
- Download URL: feature_sql_tool-0.2.1-py3-none-any.whl
- Upload date:
- Size: 29.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
507864d9e4fa96cadbec7c1e885ac673919d6ccf6e0132e8b9b6322dfc92675f
|
|
| MD5 |
1d46aa29d524228240d000ce82f0483c
|
|
| BLAKE2b-256 |
244a5ccee339a44c81b5a02e8da7f249c4df2bce9b49337b8a099eb4fcb81702
|