sqlprove 0.1.0__tar.gz → 0.3.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.3.0/PKG-INFO +183 -0
- sqlprove-0.3.0/README.md +157 -0
- {sqlprove-0.1.0 → sqlprove-0.3.0}/pyproject.toml +1 -1
- {sqlprove-0.1.0 → sqlprove-0.3.0}/src/sqlprove/__init__.py +21 -3
- {sqlprove-0.1.0 → sqlprove-0.3.0}/src/sqlprove/audit.py +155 -6
- {sqlprove-0.1.0 → sqlprove-0.3.0}/src/sqlprove/cli.py +232 -7
- {sqlprove-0.1.0 → sqlprove-0.3.0}/src/sqlprove/dbt_manifest.py +7 -0
- {sqlprove-0.1.0 → sqlprove-0.3.0}/src/sqlprove/rewrites.py +4 -4
- {sqlprove-0.1.0 → sqlprove-0.3.0}/src/sqlprove/schema.py +181 -0
- {sqlprove-0.1.0 → sqlprove-0.3.0}/src/sqlprove/targets.py +317 -0
- sqlprove-0.3.0/src/sqlprove.egg-info/PKG-INFO +183 -0
- {sqlprove-0.1.0 → sqlprove-0.3.0}/src/sqlprove.egg-info/SOURCES.txt +3 -1
- sqlprove-0.3.0/tests/test_v02_check_and_pr.py +223 -0
- sqlprove-0.3.0/tests/test_v03_stats_and_pr_polish.py +189 -0
- sqlprove-0.1.0/PKG-INFO +0 -93
- sqlprove-0.1.0/README.md +0 -67
- sqlprove-0.1.0/src/sqlprove.egg-info/PKG-INFO +0 -93
- {sqlprove-0.1.0 → sqlprove-0.3.0}/LICENSE +0 -0
- {sqlprove-0.1.0 → sqlprove-0.3.0}/MANIFEST.in +0 -0
- {sqlprove-0.1.0 → sqlprove-0.3.0}/setup.cfg +0 -0
- {sqlprove-0.1.0 → sqlprove-0.3.0}/src/sqlprove/algebra.py +0 -0
- {sqlprove-0.1.0 → sqlprove-0.3.0}/src/sqlprove/corpus.py +0 -0
- {sqlprove-0.1.0 → sqlprove-0.3.0}/src/sqlprove/cost.py +0 -0
- {sqlprove-0.1.0 → sqlprove-0.3.0}/src/sqlprove/fuzzer.py +0 -0
- {sqlprove-0.1.0 → sqlprove-0.3.0}/src/sqlprove/prover.py +0 -0
- {sqlprove-0.1.0 → sqlprove-0.3.0}/src/sqlprove.egg-info/dependency_links.txt +0 -0
- {sqlprove-0.1.0 → sqlprove-0.3.0}/src/sqlprove.egg-info/entry_points.txt +0 -0
- {sqlprove-0.1.0 → sqlprove-0.3.0}/src/sqlprove.egg-info/requires.txt +0 -0
- {sqlprove-0.1.0 → sqlprove-0.3.0}/src/sqlprove.egg-info/top_level.txt +0 -0
- {sqlprove-0.1.0 → sqlprove-0.3.0}/tests/test_corpus.py +0 -0
- {sqlprove-0.1.0 → sqlprove-0.3.0}/tests/test_prover.py +0 -0
- {sqlprove-0.1.0 → sqlprove-0.3.0}/tests/test_rewrites_and_schema.py +0 -0
- {sqlprove-0.1.0 → sqlprove-0.3.0}/tests/test_targets_and_manifest.py +0 -0
sqlprove-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: sqlprove
|
|
3
|
+
Version: 0.3.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
|
+
**Formally verified SQL cost optimizer for BigQuery, Snowflake, and dbt — 100% local, zero PII.**
|
|
30
|
+
|
|
31
|
+
Blind LLM SQL rewrites look clean in PR reviews — and silently break dashboards. In our [120-rewrite blind benchmark](https://github.com/MarklarSystems/sqlprove/blob/main/benchmarks/day5-llm-bug-catch.json) across 40 real dbt-derived queries, unverified LLMs introduced **17.5%–34.4% silent semantic bugs** (`NULL` traps, duplicate-row fan-out, dropped all-`NULL` groups).
|
|
32
|
+
|
|
33
|
+
`sqlprove` pairs rewrite discovery with **unbounded algebraic proofs (`A0`–`A9`)**, a **Z3 SMT equivalence prover** (bag semantics + 3-valued `NULL` logic + dbt `schema.yml`/`manifest.json` constraints), **DuckDB counterexample confirmation**, and **warehouse-specific cost gating** measured live on Google BigQuery and Snowflake.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Try in 10 Seconds (Zero Config, No dbt Needed)
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install sqlprove
|
|
41
|
+
|
|
42
|
+
# 1. Watch Z3 + DuckDB catch subtle NULL & join-multiplication bugs live
|
|
43
|
+
sqlprove demo
|
|
44
|
+
|
|
45
|
+
# 2. Check any raw query on the spot (conservative inferred schema)
|
|
46
|
+
sqlprove check "SELECT event_id, amount FROM events WHERE EXTRACT(YEAR FROM created_at) = 2025 AND EXTRACT(MONTH FROM created_at) = 12" \
|
|
47
|
+
--target bigquery-ondemand --table-gb 500 --runs-per-month 30
|
|
48
|
+
|
|
49
|
+
# 3. Watch Z3 refuse an unsafe dead-join drop with a concrete DuckDB counterexample,
|
|
50
|
+
# then unlock an unbounded proof once you declare --unique customers.id:
|
|
51
|
+
sqlprove check "SELECT o.id, o.amount FROM orders o LEFT JOIN customers c ON o.customer_id = c.id" --target snowflake
|
|
52
|
+
sqlprove check "SELECT o.id, o.amount FROM orders o LEFT JOIN customers c ON o.customer_id = c.id" --target snowflake --unique customers.id
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Live Cloud Benchmark Summary (Cold Runs, Zero Cache)
|
|
58
|
+
|
|
59
|
+
Measured on live **Google BigQuery** (2M rows/table, 365 partitions, clustered) and **Snowflake** (6M rows/table, ~100 micro-partitions, `USE_CACHED_RESULT = FALSE`). Full data & reproducible SQL scripts: [`benchmarks/week2-cloud-validation.md`](https://github.com/MarklarSystems/sqlprove/blob/main/benchmarks/week2-cloud-validation.md).
|
|
60
|
+
|
|
61
|
+
| Formally Proven Rewrite Pattern | BigQuery On-Demand (`$/TB`) | BigQuery Editions (`slot_ms`) | Snowflake Scan (`MB`) | Snowflake Compute (`ms`) |
|
|
62
|
+
|---|---:|---:|---:|---:|
|
|
63
|
+
| Cross-view dead `LEFT JOIN` + nested `DISTINCT` (`A4`) | `-20.0%` | `-5.8%` | `-13.1%` | **-95.9%** (24.4×) |
|
|
64
|
+
| Redundant `DISTINCT` via dbt `unique`+`not_null` (`A3b`) | `-10.3%` | **-79.7%** | `0.0%` | **-60.7%** |
|
|
65
|
+
| Dead `INNER JOIN` via dbt `relationships` FK (`A2`) | `-4.3%` | **-65.6%** | `-13.1%` | **-31.6%** |
|
|
66
|
+
| `COALESCE(bool, FALSE)` / `NOT COALESCE` / `<> sentinel` (`A5`) | **-76.9% to -87.1%** | **-21% to -37.5%** | `0%` / `+4.1%` | **-10% to -31.3%** |
|
|
67
|
+
| `EXTRACT(YEAR/MONTH)` → `[lo, hi)` range (`A7`) | **-91.3%** | **-92.5%** | `-3.1%` | `-12.3%` |
|
|
68
|
+
| 2× repeated CTE `UNION ALL` → single pass (`A8`) | `0.0%` | **-61.2%** | `0.0%` | **-70.4%** (3.4×) |
|
|
69
|
+
| 4× disjoint `UNION ALL` `GROUP BY` → 1 scan (`A9`) | `0.0%` | **-74.8%** | **-75.0%** | **-62.7%** |
|
|
70
|
+
| Cross-col `OR` → disjoint `UNION ALL` w/ `IS NULL` (`A6`) | `0.0%` | **-75.6%** | `+16.5%` *(auto-blocked on Snowflake!)* | `+1.9%` |
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Audit a dbt Project (`target/manifest.json`)
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
dbt compile
|
|
78
|
+
|
|
79
|
+
# Audit compiled models + automatically unfold upstream logical views (`view`/`ephemeral`)
|
|
80
|
+
sqlprove audit . --target snowflake --format github-pr
|
|
81
|
+
sqlprove audit . --target bigquery-ondemand --table-stats table_stats.json --format github-pr
|
|
82
|
+
sqlprove audit . --target bigquery-editions --show-all
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Per-Model Cost Calibration (`table_stats.json` or dbt `meta:`)
|
|
86
|
+
|
|
87
|
+
Instead of applying one uniform `--table-gb` across every model, you can calibrate monthly `$/mo` estimates per model via either dbt `meta:` tags in `schema.yml` / `config(meta=...)`:
|
|
88
|
+
|
|
89
|
+
```yaml
|
|
90
|
+
models:
|
|
91
|
+
- name: fct_events
|
|
92
|
+
meta:
|
|
93
|
+
table_gb: 1200
|
|
94
|
+
runs_per_month: 60
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
or a lightweight `--table-stats table_stats.json`:
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"cost_per_tb": 6.25,
|
|
102
|
+
"credit_price": 3.0,
|
|
103
|
+
"models": {
|
|
104
|
+
"fct_events": { "table_gb": 1200, "runs_per_month": 60 },
|
|
105
|
+
"tides_publication_organizations": { "avg_runtime_sec": 95, "warehouse_size": "L", "runs_per_month": 30 }
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Drop-in GitHub Action (Sticky PR Comment, Zero Spam on Clean PRs)
|
|
111
|
+
|
|
112
|
+
Save as `.github/workflows/sqlprove.yml` in your dbt repo:
|
|
113
|
+
|
|
114
|
+
```yaml
|
|
115
|
+
name: sqlprove SQL Cost Audit
|
|
116
|
+
on:
|
|
117
|
+
pull_request:
|
|
118
|
+
paths: ["models/**/*.sql", "models/**/*.yml"]
|
|
119
|
+
|
|
120
|
+
permissions:
|
|
121
|
+
pull-requests: write
|
|
122
|
+
|
|
123
|
+
jobs:
|
|
124
|
+
sqlprove:
|
|
125
|
+
runs-on: ubuntu-latest
|
|
126
|
+
steps:
|
|
127
|
+
- uses: actions/checkout@v4
|
|
128
|
+
- uses: actions/setup-python@v5
|
|
129
|
+
with:
|
|
130
|
+
python-version: "3.12"
|
|
131
|
+
- run: pip install sqlprove
|
|
132
|
+
# Run your existing `dbt compile` step (or point sqlprove at a cached target/manifest.json)
|
|
133
|
+
- name: Run sqlprove audit
|
|
134
|
+
run: |
|
|
135
|
+
sqlprove audit . \
|
|
136
|
+
--target bigquery-ondemand \
|
|
137
|
+
--format github-pr \
|
|
138
|
+
--skip-if-clean > sqlprove-report.md
|
|
139
|
+
- name: Post or update sticky PR comment
|
|
140
|
+
if: always()
|
|
141
|
+
env:
|
|
142
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
143
|
+
run: |
|
|
144
|
+
if [ -s sqlprove-report.md ]; then
|
|
145
|
+
gh pr comment "${{ github.event.pull_request.number }}" \
|
|
146
|
+
--body-file sqlprove-report.md \
|
|
147
|
+
--edit-last --create-if-none
|
|
148
|
+
fi
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Verification Tiers (Fail-Closed)
|
|
154
|
+
|
|
155
|
+
- **`ALGEBRAICALLY_PROVEN`** — Unbounded equivalence established by a sound schema-aware rule (`A0`–`A9`).
|
|
156
|
+
- **`BOUNDED_VERIFIED`** — Z3 proved `UNSAT` for every symbolic database up to `bound` rows per table (including arbitrary `NULL`s and duplicates).
|
|
157
|
+
- **`COUNTEREXAMPLE_FOUND`** — Z3 synthesized concrete input tables where the queries return different multisets, independently confirmed in DuckDB.
|
|
158
|
+
- **`UNSUPPORTED` / `UNKNOWN`** — Fails closed; never emitted as a proven rewrite.
|
|
159
|
+
- **0 false positives across 35,900 randomized `NULL`/duplicate/FK DuckDB fuzz trials.**
|
|
160
|
+
|
|
161
|
+
## Zero-PII Top-20 Warehouse Spend Audit (Pilot)
|
|
162
|
+
|
|
163
|
+
Spending **$10k+/mo on BigQuery or Snowflake**? Send your `target/manifest.json` + a 30-day query cost rollup (`model_name, bytes_billed/credits, runs_per_month` — zero customer rows or PII) to **`marklar@marklar.systems`** for a free audit returning formally verified PR diffs ranked by real monthly spend.
|
|
164
|
+
|
|
165
|
+
## Layout
|
|
166
|
+
|
|
167
|
+
```text
|
|
168
|
+
sqlprove/
|
|
169
|
+
src/sqlprove/
|
|
170
|
+
cli.py # CLI: demo, check, audit, rewrite, prove, scan
|
|
171
|
+
audit.py # Compiled dbt manifest audit & github-pr / markdown / json / text formatters
|
|
172
|
+
dbt_manifest.py # target/manifest.json loader, constraint extractor & sound view unfolder
|
|
173
|
+
targets.py # Live-benchmarked warehouse cost gating & parameterized $/mo estimator
|
|
174
|
+
algebra.py # Unbounded sound algebraic equivalence rules (A0-A9)
|
|
175
|
+
prover.py # Z3 SMT 3-valued NULL + bag-semantics equivalence checker
|
|
176
|
+
rewrites.py # Dialect-native candidate rewrites + CTE congruence verification
|
|
177
|
+
schema.py # Schema constraints, conservative inference & dbt schema.yml parser
|
|
178
|
+
fuzzer.py # DuckDB counterexample confirmer & randomized differential fuzzer
|
|
179
|
+
corpus.py # Raw dbt/SQL repository pattern scanner
|
|
180
|
+
cost.py # DuckDB EXPLAIN (ANALYZE, FORMAT JSON) profiler
|
|
181
|
+
benchmarks/ # Corpus audit, blind LLM bug-catch, 1M-row scale, and $0 live BQ/SF scripts & results
|
|
182
|
+
tests/ # Unit, soundness, manifest, view-unfolding, PR formatter & fuzz tests
|
|
183
|
+
```
|
sqlprove-0.3.0/README.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# sqlprove
|
|
2
|
+
|
|
3
|
+
**Formally verified SQL cost optimizer for BigQuery, Snowflake, and dbt — 100% local, zero PII.**
|
|
4
|
+
|
|
5
|
+
Blind LLM SQL rewrites look clean in PR reviews — and silently break dashboards. In our [120-rewrite blind benchmark](https://github.com/MarklarSystems/sqlprove/blob/main/benchmarks/day5-llm-bug-catch.json) across 40 real dbt-derived queries, unverified LLMs introduced **17.5%–34.4% silent semantic bugs** (`NULL` traps, duplicate-row fan-out, dropped all-`NULL` groups).
|
|
6
|
+
|
|
7
|
+
`sqlprove` pairs rewrite discovery with **unbounded algebraic proofs (`A0`–`A9`)**, a **Z3 SMT equivalence prover** (bag semantics + 3-valued `NULL` logic + dbt `schema.yml`/`manifest.json` constraints), **DuckDB counterexample confirmation**, and **warehouse-specific cost gating** measured live on Google BigQuery and Snowflake.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Try in 10 Seconds (Zero Config, No dbt Needed)
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install sqlprove
|
|
15
|
+
|
|
16
|
+
# 1. Watch Z3 + DuckDB catch subtle NULL & join-multiplication bugs live
|
|
17
|
+
sqlprove demo
|
|
18
|
+
|
|
19
|
+
# 2. Check any raw query on the spot (conservative inferred schema)
|
|
20
|
+
sqlprove check "SELECT event_id, amount FROM events WHERE EXTRACT(YEAR FROM created_at) = 2025 AND EXTRACT(MONTH FROM created_at) = 12" \
|
|
21
|
+
--target bigquery-ondemand --table-gb 500 --runs-per-month 30
|
|
22
|
+
|
|
23
|
+
# 3. Watch Z3 refuse an unsafe dead-join drop with a concrete DuckDB counterexample,
|
|
24
|
+
# then unlock an unbounded proof once you declare --unique customers.id:
|
|
25
|
+
sqlprove check "SELECT o.id, o.amount FROM orders o LEFT JOIN customers c ON o.customer_id = c.id" --target snowflake
|
|
26
|
+
sqlprove check "SELECT o.id, o.amount FROM orders o LEFT JOIN customers c ON o.customer_id = c.id" --target snowflake --unique customers.id
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Live Cloud Benchmark Summary (Cold Runs, Zero Cache)
|
|
32
|
+
|
|
33
|
+
Measured on live **Google BigQuery** (2M rows/table, 365 partitions, clustered) and **Snowflake** (6M rows/table, ~100 micro-partitions, `USE_CACHED_RESULT = FALSE`). Full data & reproducible SQL scripts: [`benchmarks/week2-cloud-validation.md`](https://github.com/MarklarSystems/sqlprove/blob/main/benchmarks/week2-cloud-validation.md).
|
|
34
|
+
|
|
35
|
+
| Formally Proven Rewrite Pattern | BigQuery On-Demand (`$/TB`) | BigQuery Editions (`slot_ms`) | Snowflake Scan (`MB`) | Snowflake Compute (`ms`) |
|
|
36
|
+
|---|---:|---:|---:|---:|
|
|
37
|
+
| Cross-view dead `LEFT JOIN` + nested `DISTINCT` (`A4`) | `-20.0%` | `-5.8%` | `-13.1%` | **-95.9%** (24.4×) |
|
|
38
|
+
| Redundant `DISTINCT` via dbt `unique`+`not_null` (`A3b`) | `-10.3%` | **-79.7%** | `0.0%` | **-60.7%** |
|
|
39
|
+
| Dead `INNER JOIN` via dbt `relationships` FK (`A2`) | `-4.3%` | **-65.6%** | `-13.1%` | **-31.6%** |
|
|
40
|
+
| `COALESCE(bool, FALSE)` / `NOT COALESCE` / `<> sentinel` (`A5`) | **-76.9% to -87.1%** | **-21% to -37.5%** | `0%` / `+4.1%` | **-10% to -31.3%** |
|
|
41
|
+
| `EXTRACT(YEAR/MONTH)` → `[lo, hi)` range (`A7`) | **-91.3%** | **-92.5%** | `-3.1%` | `-12.3%` |
|
|
42
|
+
| 2× repeated CTE `UNION ALL` → single pass (`A8`) | `0.0%` | **-61.2%** | `0.0%` | **-70.4%** (3.4×) |
|
|
43
|
+
| 4× disjoint `UNION ALL` `GROUP BY` → 1 scan (`A9`) | `0.0%` | **-74.8%** | **-75.0%** | **-62.7%** |
|
|
44
|
+
| Cross-col `OR` → disjoint `UNION ALL` w/ `IS NULL` (`A6`) | `0.0%` | **-75.6%** | `+16.5%` *(auto-blocked on Snowflake!)* | `+1.9%` |
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Audit a dbt Project (`target/manifest.json`)
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
dbt compile
|
|
52
|
+
|
|
53
|
+
# Audit compiled models + automatically unfold upstream logical views (`view`/`ephemeral`)
|
|
54
|
+
sqlprove audit . --target snowflake --format github-pr
|
|
55
|
+
sqlprove audit . --target bigquery-ondemand --table-stats table_stats.json --format github-pr
|
|
56
|
+
sqlprove audit . --target bigquery-editions --show-all
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Per-Model Cost Calibration (`table_stats.json` or dbt `meta:`)
|
|
60
|
+
|
|
61
|
+
Instead of applying one uniform `--table-gb` across every model, you can calibrate monthly `$/mo` estimates per model via either dbt `meta:` tags in `schema.yml` / `config(meta=...)`:
|
|
62
|
+
|
|
63
|
+
```yaml
|
|
64
|
+
models:
|
|
65
|
+
- name: fct_events
|
|
66
|
+
meta:
|
|
67
|
+
table_gb: 1200
|
|
68
|
+
runs_per_month: 60
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
or a lightweight `--table-stats table_stats.json`:
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"cost_per_tb": 6.25,
|
|
76
|
+
"credit_price": 3.0,
|
|
77
|
+
"models": {
|
|
78
|
+
"fct_events": { "table_gb": 1200, "runs_per_month": 60 },
|
|
79
|
+
"tides_publication_organizations": { "avg_runtime_sec": 95, "warehouse_size": "L", "runs_per_month": 30 }
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Drop-in GitHub Action (Sticky PR Comment, Zero Spam on Clean PRs)
|
|
85
|
+
|
|
86
|
+
Save as `.github/workflows/sqlprove.yml` in your dbt repo:
|
|
87
|
+
|
|
88
|
+
```yaml
|
|
89
|
+
name: sqlprove SQL Cost Audit
|
|
90
|
+
on:
|
|
91
|
+
pull_request:
|
|
92
|
+
paths: ["models/**/*.sql", "models/**/*.yml"]
|
|
93
|
+
|
|
94
|
+
permissions:
|
|
95
|
+
pull-requests: write
|
|
96
|
+
|
|
97
|
+
jobs:
|
|
98
|
+
sqlprove:
|
|
99
|
+
runs-on: ubuntu-latest
|
|
100
|
+
steps:
|
|
101
|
+
- uses: actions/checkout@v4
|
|
102
|
+
- uses: actions/setup-python@v5
|
|
103
|
+
with:
|
|
104
|
+
python-version: "3.12"
|
|
105
|
+
- run: pip install sqlprove
|
|
106
|
+
# Run your existing `dbt compile` step (or point sqlprove at a cached target/manifest.json)
|
|
107
|
+
- name: Run sqlprove audit
|
|
108
|
+
run: |
|
|
109
|
+
sqlprove audit . \
|
|
110
|
+
--target bigquery-ondemand \
|
|
111
|
+
--format github-pr \
|
|
112
|
+
--skip-if-clean > sqlprove-report.md
|
|
113
|
+
- name: Post or update sticky PR comment
|
|
114
|
+
if: always()
|
|
115
|
+
env:
|
|
116
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
117
|
+
run: |
|
|
118
|
+
if [ -s sqlprove-report.md ]; then
|
|
119
|
+
gh pr comment "${{ github.event.pull_request.number }}" \
|
|
120
|
+
--body-file sqlprove-report.md \
|
|
121
|
+
--edit-last --create-if-none
|
|
122
|
+
fi
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Verification Tiers (Fail-Closed)
|
|
128
|
+
|
|
129
|
+
- **`ALGEBRAICALLY_PROVEN`** — Unbounded equivalence established by a sound schema-aware rule (`A0`–`A9`).
|
|
130
|
+
- **`BOUNDED_VERIFIED`** — Z3 proved `UNSAT` for every symbolic database up to `bound` rows per table (including arbitrary `NULL`s and duplicates).
|
|
131
|
+
- **`COUNTEREXAMPLE_FOUND`** — Z3 synthesized concrete input tables where the queries return different multisets, independently confirmed in DuckDB.
|
|
132
|
+
- **`UNSUPPORTED` / `UNKNOWN`** — Fails closed; never emitted as a proven rewrite.
|
|
133
|
+
- **0 false positives across 35,900 randomized `NULL`/duplicate/FK DuckDB fuzz trials.**
|
|
134
|
+
|
|
135
|
+
## Zero-PII Top-20 Warehouse Spend Audit (Pilot)
|
|
136
|
+
|
|
137
|
+
Spending **$10k+/mo on BigQuery or Snowflake**? Send your `target/manifest.json` + a 30-day query cost rollup (`model_name, bytes_billed/credits, runs_per_month` — zero customer rows or PII) to **`marklar@marklar.systems`** for a free audit returning formally verified PR diffs ranked by real monthly spend.
|
|
138
|
+
|
|
139
|
+
## Layout
|
|
140
|
+
|
|
141
|
+
```text
|
|
142
|
+
sqlprove/
|
|
143
|
+
src/sqlprove/
|
|
144
|
+
cli.py # CLI: demo, check, audit, rewrite, prove, scan
|
|
145
|
+
audit.py # Compiled dbt manifest audit & github-pr / markdown / json / text formatters
|
|
146
|
+
dbt_manifest.py # target/manifest.json loader, constraint extractor & sound view unfolder
|
|
147
|
+
targets.py # Live-benchmarked warehouse cost gating & parameterized $/mo estimator
|
|
148
|
+
algebra.py # Unbounded sound algebraic equivalence rules (A0-A9)
|
|
149
|
+
prover.py # Z3 SMT 3-valued NULL + bag-semantics equivalence checker
|
|
150
|
+
rewrites.py # Dialect-native candidate rewrites + CTE congruence verification
|
|
151
|
+
schema.py # Schema constraints, conservative inference & dbt schema.yml parser
|
|
152
|
+
fuzzer.py # DuckDB counterexample confirmer & randomized differential fuzzer
|
|
153
|
+
corpus.py # Raw dbt/SQL repository pattern scanner
|
|
154
|
+
cost.py # DuckDB EXPLAIN (ANALYZE, FORMAT JSON) profiler
|
|
155
|
+
benchmarks/ # Corpus audit, blind LLM bug-catch, 1M-row scale, and $0 live BQ/SF scripts & results
|
|
156
|
+
tests/ # Unit, soundness, manifest, view-unfolding, PR formatter & fuzz tests
|
|
157
|
+
```
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "sqlprove"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.3.0"
|
|
8
8
|
description = "Proof-carrying SQL cost optimizer for BigQuery, Snowflake, and dbt using Z3 SMT and DuckDB verification"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = {text = "MIT"}
|
|
@@ -3,26 +3,44 @@
|
|
|
3
3
|
from sqlprove.audit import ManifestAuditReport, audit_dbt_manifest
|
|
4
4
|
from sqlprove.dbt_manifest import DbtManifest, load_dbt_manifest, unfold_upstream_views
|
|
5
5
|
from sqlprove.prover import ProofStatus, VerificationResult, prove_equivalence
|
|
6
|
-
from sqlprove.schema import ColumnSpec, Schema, TableSpec
|
|
7
|
-
from sqlprove.targets import
|
|
6
|
+
from sqlprove.schema import ColumnSpec, Schema, TableSpec, infer_conservative_schema
|
|
7
|
+
from sqlprove.targets import (
|
|
8
|
+
CostEstimate,
|
|
9
|
+
CostParams,
|
|
10
|
+
TableStatsCatalog,
|
|
11
|
+
TargetDecision,
|
|
12
|
+
TargetRuleAdvice,
|
|
13
|
+
WarehouseTarget,
|
|
14
|
+
estimate_monthly_savings,
|
|
15
|
+
evaluate_rule_for_target,
|
|
16
|
+
load_table_stats,
|
|
17
|
+
resolve_model_cost_params,
|
|
18
|
+
)
|
|
8
19
|
|
|
9
|
-
__version__ = "0.
|
|
20
|
+
__version__ = "0.3.0"
|
|
10
21
|
|
|
11
22
|
__all__ = [
|
|
12
23
|
"__version__",
|
|
13
24
|
"ColumnSpec",
|
|
25
|
+
"CostEstimate",
|
|
26
|
+
"CostParams",
|
|
14
27
|
"DbtManifest",
|
|
15
28
|
"ManifestAuditReport",
|
|
16
29
|
"ProofStatus",
|
|
17
30
|
"Schema",
|
|
18
31
|
"TableSpec",
|
|
32
|
+
"TableStatsCatalog",
|
|
19
33
|
"TargetDecision",
|
|
20
34
|
"TargetRuleAdvice",
|
|
21
35
|
"VerificationResult",
|
|
22
36
|
"WarehouseTarget",
|
|
23
37
|
"audit_dbt_manifest",
|
|
38
|
+
"estimate_monthly_savings",
|
|
24
39
|
"evaluate_rule_for_target",
|
|
40
|
+
"infer_conservative_schema",
|
|
25
41
|
"load_dbt_manifest",
|
|
42
|
+
"load_table_stats",
|
|
26
43
|
"prove_equivalence",
|
|
44
|
+
"resolve_model_cost_params",
|
|
27
45
|
"unfold_upstream_views",
|
|
28
46
|
]
|