sqlprove 0.1.0__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.
sqlprove-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 sqlprove contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,9 @@
1
+ include LICENSE
2
+ include README.md
3
+ include pyproject.toml
4
+ recursive-include src/sqlprove *.py
5
+ recursive-include tests *.py
6
+ exclude AGENTS.md
7
+ exclude SPIKE_PLAN.md
8
+ prune corpus
9
+ prune benchmarks
@@ -0,0 +1,93 @@
1
+ Metadata-Version: 2.1
2
+ Name: sqlprove
3
+ Version: 0.1.0
4
+ Summary: Proof-carrying SQL cost optimizer for BigQuery, Snowflake, and dbt using Z3 SMT and DuckDB verification
5
+ License: MIT
6
+ Project-URL: Homepage, https://github.com/MarklarSystems/sqlprove
7
+ Project-URL: Repository, https://github.com/MarklarSystems/sqlprove
8
+ Project-URL: Issues, https://github.com/MarklarSystems/sqlprove/issues
9
+ Keywords: sql,dbt,bigquery,snowflake,duckdb,z3,smt,formal-verification,query-optimization,finops
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Database
21
+ Classifier: Topic :: Software Development :: Quality Assurance
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ Provides-Extra: dev
25
+ License-File: LICENSE
26
+
27
+ # sqlprove
28
+
29
+ Proof-carrying SQL cost optimizer for **BigQuery**, **Snowflake**, and **dbt** — 100% local, zero PII.
30
+
31
+ Instead of asking data teams to blindly trust LLM-rewritten SQL (which introduced **17.5%–34.4%** silent `NULL`, duplicate-row, and `LEFT JOIN` bugs in our 120-rewrite blind benchmark), `sqlprove` pairs rewrite discovery with **unbounded algebraic proofs**, a **Z3 SMT formal equivalence checker** (bag semantics + 3-valued `NULL` logic + dbt `schema.yml` / `manifest.json` constraints), **DuckDB counterexample confirmation**, and **warehouse-specific cost gating** backed by live BigQuery and Snowflake benchmarks.
32
+
33
+ ## Live Cloud Benchmark Summary (`$0` Reproducible Validation)
34
+
35
+ Measured cold (zero cache hits) on live **Google BigQuery** (2M rows/table, 365 partitions, clustered) and **Snowflake** (6M rows/table, ~100 micro-partitions, `USE_CACHED_RESULT = FALSE`). Full breakdown: [`benchmarks/week2-cloud-validation.md`](https://github.com/MarklarSystems/sqlprove/blob/main/benchmarks/week2-cloud-validation.md).
36
+
37
+ | Formally Proven Rewrite Pattern | BigQuery On-Demand (`$/TB`) | BigQuery Editions (`slot_ms`) | Snowflake Scan (`MB`) | Snowflake Compute (`ms`) |
38
+ |---|---:|---:|---:|---:|
39
+ | Cross-view dead `LEFT JOIN` + nested `DISTINCT` (`A4`) | `-20.0%` | `-5.8%` | `-13.1%` | **-95.9%** (24.4×) |
40
+ | Redundant `DISTINCT` via dbt `unique`+`not_null` (`A3b`) | `-10.3%` | **-79.7%** | `0.0%` | **-60.7%** |
41
+ | Dead `INNER JOIN` via dbt `relationships` FK (`A2`) | `-4.3%` | **-65.6%** | `-13.1%` | **-31.6%** |
42
+ | `COALESCE(bool, FALSE)` / `NOT COALESCE` / `<> sentinel` (`A5`) | **-76.9% to -87.1%** | **-21% to -37.5%** | `0%` / `+4.1%` | **-10% to -31.3%** |
43
+ | `EXTRACT(YEAR/MONTH)` → `[lo, hi)` range (`A7`) | **-91.3%** | **-92.5%** | `-3.1%` | `-12.3%` |
44
+ | 2× repeated CTE `UNION ALL` → single pass (`A8`) | `0.0%` | **-61.2%** | `0.0%` | **-70.4%** (3.4×) |
45
+ | 4× disjoint `UNION ALL` `GROUP BY` → 1 scan (`A9`) | `0.0%` | **-74.8%** | **-75.0%** | **-62.7%** |
46
+ | Cross-col `OR` → disjoint `UNION ALL` w/ `IS NULL` (`A6`) | `0.0%` | **-75.6%** | `+16.5%` *(auto-blocked on Snowflake!)* | `+1.9%` |
47
+
48
+ ## Quickstart
49
+
50
+ ```bash
51
+ pip install sqlprove
52
+
53
+ # Built-in Z3 + DuckDB bug-catch demo
54
+ sqlprove demo
55
+
56
+ # Audit a compiled dbt project (`dbt compile` -> target/manifest.json) with view unfolding + warehouse gating
57
+ sqlprove audit /path/to/dbt_project --target snowflake
58
+ sqlprove audit /path/to/dbt_project --target bigquery-ondemand --format markdown
59
+ sqlprove audit /path/to/dbt_project --target bigquery-editions --show-all
60
+
61
+ # Rewrite & verify a single SQL query for a specific warehouse target
62
+ sqlprove rewrite --sql "SELECT ..." --schema schema.json --dbt-schema models/ --target bigquery-ondemand
63
+
64
+ # Prove equivalence (or synthesize a DuckDB-confirmed counterexample) for any two SQL queries
65
+ sqlprove prove --q1 "..." --q2 "..." --schema schema.json --dbt-schema models/
66
+ ```
67
+
68
+ ## Verification Tiers (Fail-Closed)
69
+
70
+ - **`ALGEBRAICALLY_PROVEN`** — Unbounded equivalence established by a verified schema-aware algebraic rule (`A0`–`A9`).
71
+ - **`BOUNDED_VERIFIED`** — Z3 proved `UNSAT` (no counterexample) for all symbolic databases up to `bound` rows per table, including arbitrary `NULL`s and duplicates.
72
+ - **`COUNTEREXAMPLE_FOUND`** — Z3 synthesized concrete table rows where the two queries return different multisets, independently confirmed in DuckDB.
73
+ - **`UNSUPPORTED` / `UNKNOWN`** — Fails closed; never emitted as a proven rewrite.
74
+
75
+ ## Layout
76
+
77
+ ```text
78
+ sqlprove/
79
+ src/sqlprove/
80
+ cli.py # CLI: demo, audit, rewrite, prove, scan
81
+ audit.py # Compiled dbt manifest audit orchestrator (text/markdown/json)
82
+ dbt_manifest.py # target/manifest.json loader, constraint extractor & sound view unfolder
83
+ targets.py # Live-benchmarked warehouse cost gating (BQ On-Demand, BQ Editions, Snowflake, DuckDB)
84
+ algebra.py # Unbounded sound algebraic equivalence rules (A0-A9)
85
+ prover.py # Z3 SMT 3-valued NULL + bag-semantics equivalence checker
86
+ rewrites.py # Dialect-native candidate rewrites + CTE congruence verification
87
+ schema.py # Schema constraints & zero-dependency dbt schema.yml parser
88
+ fuzzer.py # DuckDB counterexample confirmer & randomized differential fuzzer
89
+ corpus.py # Raw dbt/SQL repository pattern scanner
90
+ cost.py # DuckDB EXPLAIN (ANALYZE, FORMAT JSON) profiler
91
+ benchmarks/ # Corpus audit, blind LLM bug-catch, 1M-row scale, and $0 live BQ/SF scripts & results
92
+ tests/ # 32 unit, soundness, manifest, view-unfolding & differential fuzz tests
93
+ ```
@@ -0,0 +1,67 @@
1
+ # sqlprove
2
+
3
+ Proof-carrying SQL cost optimizer for **BigQuery**, **Snowflake**, and **dbt** — 100% local, zero PII.
4
+
5
+ Instead of asking data teams to blindly trust LLM-rewritten SQL (which introduced **17.5%–34.4%** silent `NULL`, duplicate-row, and `LEFT JOIN` bugs in our 120-rewrite blind benchmark), `sqlprove` pairs rewrite discovery with **unbounded algebraic proofs**, a **Z3 SMT formal equivalence checker** (bag semantics + 3-valued `NULL` logic + dbt `schema.yml` / `manifest.json` constraints), **DuckDB counterexample confirmation**, and **warehouse-specific cost gating** backed by live BigQuery and Snowflake benchmarks.
6
+
7
+ ## Live Cloud Benchmark Summary (`$0` Reproducible Validation)
8
+
9
+ Measured cold (zero cache hits) on live **Google BigQuery** (2M rows/table, 365 partitions, clustered) and **Snowflake** (6M rows/table, ~100 micro-partitions, `USE_CACHED_RESULT = FALSE`). Full breakdown: [`benchmarks/week2-cloud-validation.md`](https://github.com/MarklarSystems/sqlprove/blob/main/benchmarks/week2-cloud-validation.md).
10
+
11
+ | Formally Proven Rewrite Pattern | BigQuery On-Demand (`$/TB`) | BigQuery Editions (`slot_ms`) | Snowflake Scan (`MB`) | Snowflake Compute (`ms`) |
12
+ |---|---:|---:|---:|---:|
13
+ | Cross-view dead `LEFT JOIN` + nested `DISTINCT` (`A4`) | `-20.0%` | `-5.8%` | `-13.1%` | **-95.9%** (24.4×) |
14
+ | Redundant `DISTINCT` via dbt `unique`+`not_null` (`A3b`) | `-10.3%` | **-79.7%** | `0.0%` | **-60.7%** |
15
+ | Dead `INNER JOIN` via dbt `relationships` FK (`A2`) | `-4.3%` | **-65.6%** | `-13.1%` | **-31.6%** |
16
+ | `COALESCE(bool, FALSE)` / `NOT COALESCE` / `<> sentinel` (`A5`) | **-76.9% to -87.1%** | **-21% to -37.5%** | `0%` / `+4.1%` | **-10% to -31.3%** |
17
+ | `EXTRACT(YEAR/MONTH)` → `[lo, hi)` range (`A7`) | **-91.3%** | **-92.5%** | `-3.1%` | `-12.3%` |
18
+ | 2× repeated CTE `UNION ALL` → single pass (`A8`) | `0.0%` | **-61.2%** | `0.0%` | **-70.4%** (3.4×) |
19
+ | 4× disjoint `UNION ALL` `GROUP BY` → 1 scan (`A9`) | `0.0%` | **-74.8%** | **-75.0%** | **-62.7%** |
20
+ | Cross-col `OR` → disjoint `UNION ALL` w/ `IS NULL` (`A6`) | `0.0%` | **-75.6%** | `+16.5%` *(auto-blocked on Snowflake!)* | `+1.9%` |
21
+
22
+ ## Quickstart
23
+
24
+ ```bash
25
+ pip install sqlprove
26
+
27
+ # Built-in Z3 + DuckDB bug-catch demo
28
+ sqlprove demo
29
+
30
+ # Audit a compiled dbt project (`dbt compile` -> target/manifest.json) with view unfolding + warehouse gating
31
+ sqlprove audit /path/to/dbt_project --target snowflake
32
+ sqlprove audit /path/to/dbt_project --target bigquery-ondemand --format markdown
33
+ sqlprove audit /path/to/dbt_project --target bigquery-editions --show-all
34
+
35
+ # Rewrite & verify a single SQL query for a specific warehouse target
36
+ sqlprove rewrite --sql "SELECT ..." --schema schema.json --dbt-schema models/ --target bigquery-ondemand
37
+
38
+ # Prove equivalence (or synthesize a DuckDB-confirmed counterexample) for any two SQL queries
39
+ sqlprove prove --q1 "..." --q2 "..." --schema schema.json --dbt-schema models/
40
+ ```
41
+
42
+ ## Verification Tiers (Fail-Closed)
43
+
44
+ - **`ALGEBRAICALLY_PROVEN`** — Unbounded equivalence established by a verified schema-aware algebraic rule (`A0`–`A9`).
45
+ - **`BOUNDED_VERIFIED`** — Z3 proved `UNSAT` (no counterexample) for all symbolic databases up to `bound` rows per table, including arbitrary `NULL`s and duplicates.
46
+ - **`COUNTEREXAMPLE_FOUND`** — Z3 synthesized concrete table rows where the two queries return different multisets, independently confirmed in DuckDB.
47
+ - **`UNSUPPORTED` / `UNKNOWN`** — Fails closed; never emitted as a proven rewrite.
48
+
49
+ ## Layout
50
+
51
+ ```text
52
+ sqlprove/
53
+ src/sqlprove/
54
+ cli.py # CLI: demo, audit, rewrite, prove, scan
55
+ audit.py # Compiled dbt manifest audit orchestrator (text/markdown/json)
56
+ dbt_manifest.py # target/manifest.json loader, constraint extractor & sound view unfolder
57
+ targets.py # Live-benchmarked warehouse cost gating (BQ On-Demand, BQ Editions, Snowflake, DuckDB)
58
+ algebra.py # Unbounded sound algebraic equivalence rules (A0-A9)
59
+ prover.py # Z3 SMT 3-valued NULL + bag-semantics equivalence checker
60
+ rewrites.py # Dialect-native candidate rewrites + CTE congruence verification
61
+ schema.py # Schema constraints & zero-dependency dbt schema.yml parser
62
+ fuzzer.py # DuckDB counterexample confirmer & randomized differential fuzzer
63
+ corpus.py # Raw dbt/SQL repository pattern scanner
64
+ cost.py # DuckDB EXPLAIN (ANALYZE, FORMAT JSON) profiler
65
+ benchmarks/ # Corpus audit, blind LLM bug-catch, 1M-row scale, and $0 live BQ/SF scripts & results
66
+ tests/ # 32 unit, soundness, manifest, view-unfolding & differential fuzz tests
67
+ ```
@@ -0,0 +1,63 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "sqlprove"
7
+ version = "0.1.0"
8
+ description = "Proof-carrying SQL cost optimizer for BigQuery, Snowflake, and dbt using Z3 SMT and DuckDB verification"
9
+ readme = "README.md"
10
+ license = {text = "MIT"}
11
+ requires-python = ">=3.10"
12
+ keywords = [
13
+ "sql",
14
+ "dbt",
15
+ "bigquery",
16
+ "snowflake",
17
+ "duckdb",
18
+ "z3",
19
+ "smt",
20
+ "formal-verification",
21
+ "query-optimization",
22
+ "finops",
23
+ ]
24
+ classifiers = [
25
+ "Development Status :: 4 - Beta",
26
+ "Environment :: Console",
27
+ "Intended Audience :: Developers",
28
+ "License :: OSI Approved :: MIT License",
29
+ "Operating System :: OS Independent",
30
+ "Programming Language :: Python :: 3",
31
+ "Programming Language :: Python :: 3.10",
32
+ "Programming Language :: Python :: 3.11",
33
+ "Programming Language :: Python :: 3.12",
34
+ "Programming Language :: Python :: 3.13",
35
+ "Topic :: Database",
36
+ "Topic :: Software Development :: Quality Assurance",
37
+ ]
38
+ dependencies = [
39
+ "sqlglot>=25.0.0",
40
+ "z3-solver>=4.13.0",
41
+ "duckdb>=1.1.0",
42
+ ]
43
+
44
+ [project.optional-dependencies]
45
+ dev = [
46
+ "pytest>=8.0.0",
47
+ "build>=1.0.0",
48
+ "twine>=5.0.0",
49
+ ]
50
+
51
+ [project.urls]
52
+ Homepage = "https://github.com/MarklarSystems/sqlprove"
53
+ Repository = "https://github.com/MarklarSystems/sqlprove"
54
+ Issues = "https://github.com/MarklarSystems/sqlprove/issues"
55
+
56
+ [project.scripts]
57
+ sqlprove = "sqlprove.cli:main"
58
+
59
+ [tool.setuptools.packages.find]
60
+ where = ["src"]
61
+
62
+ [tool.pytest.ini_options]
63
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,28 @@
1
+ """Proof-carrying SQL equivalence verifier and cost optimizer."""
2
+
3
+ from sqlprove.audit import ManifestAuditReport, audit_dbt_manifest
4
+ from sqlprove.dbt_manifest import DbtManifest, load_dbt_manifest, unfold_upstream_views
5
+ from sqlprove.prover import ProofStatus, VerificationResult, prove_equivalence
6
+ from sqlprove.schema import ColumnSpec, Schema, TableSpec
7
+ from sqlprove.targets import TargetDecision, TargetRuleAdvice, WarehouseTarget, evaluate_rule_for_target
8
+
9
+ __version__ = "0.1.0"
10
+
11
+ __all__ = [
12
+ "__version__",
13
+ "ColumnSpec",
14
+ "DbtManifest",
15
+ "ManifestAuditReport",
16
+ "ProofStatus",
17
+ "Schema",
18
+ "TableSpec",
19
+ "TargetDecision",
20
+ "TargetRuleAdvice",
21
+ "VerificationResult",
22
+ "WarehouseTarget",
23
+ "audit_dbt_manifest",
24
+ "evaluate_rule_for_target",
25
+ "load_dbt_manifest",
26
+ "prove_equivalence",
27
+ "unfold_upstream_views",
28
+ ]