bricksentry 0.1.23__tar.gz → 0.1.25__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.
- {bricksentry-0.1.23 → bricksentry-0.1.25}/CHANGELOG.md +16 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/PKG-INFO +5 -3
- {bricksentry-0.1.23 → bricksentry-0.1.25}/README.md +4 -2
- bricksentry-0.1.25/deploy/databricks-app/requirements.txt +1 -0
- bricksentry-0.1.25/examples/databricks/bricksentry_validation.ipynb +152 -0
- bricksentry-0.1.25/examples/databricks/bricksentry_validation.py +95 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/pyproject.toml +1 -1
- {bricksentry-0.1.23 → bricksentry-0.1.25}/scripts/build_notebook.py +1 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/server.json +2 -2
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/__init__.py +1 -1
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/cli.py +1 -1
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/diff.py +5 -2
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/history.py +24 -1
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/job.py +5 -0
- bricksentry-0.1.25/src/bricksentry/validation.py +290 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/templates/job-check/databricks_template_schema.json +2 -2
- {bricksentry-0.1.23 → bricksentry-0.1.25}/tests/test_0123.py +105 -0
- bricksentry-0.1.23/deploy/databricks-app/requirements.txt +0 -1
- {bricksentry-0.1.23 → bricksentry-0.1.25}/.gitignore +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/CONTRIBUTING.md +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/LICENSE +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/SECURITY.md +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/action.yml +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/deploy/container/Dockerfile +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/deploy/databricks-app/README.md +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/deploy/databricks-app/app.yaml +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/deploy/databricks-app/bricksentry.yml +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/deploy/databricks-app/databricks.yml +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/deploy/databricks-app/grants.sql +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/examples/databricks/bricksentry.yml +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/examples/databricks/bricksentry_check_my_table.ipynb +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/examples/databricks/bricksentry_check_my_table.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/examples/databricks/bricksentry_hr_walkthrough.ipynb +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/examples/databricks/bricksentry_hr_walkthrough.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/examples/databricks/bricksentry_quickstart.ipynb +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/examples/databricks/bricksentry_quickstart.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/examples/databricks/github-workflow.yml +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/examples/databricks/policy.yml +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/examples/demo/agent_loop_demo.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/scripts/render_demo_image.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/__main__.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/agent_tools.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/assess.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/backends/__init__.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/backends/base.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/backends/databricks_backend.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/backends/duckdb_backend.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/changes.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/config.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/demo.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/explain.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/github.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/job_demo.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/lineage.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/mcp_server.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/measures.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/models.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/netguard.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/notify.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/policy.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/policy_templates.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/preview.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/py.typed +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/src/bricksentry/report.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/templates/job-check/README.md +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/templates/job-check/template/{{.project_name}}/.gitignore +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/templates/job-check/template/{{.project_name}}/README.md.tmpl +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/templates/job-check/template/{{.project_name}}/databricks.yml.tmpl +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/templates/job-check/template/{{.project_name}}/resources/bricksentry_check.job.yml.tmpl +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/templates/job-check/template/{{.project_name}}/src/bricksentry_check.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/templates/job-check/template/{{.project_name}}/src/bricksentry_demo.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/tests/conftest.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/tests/test_0110.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/tests/test_0112.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/tests/test_0114.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/tests/test_0120.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/tests/test_0121.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/tests/test_0122.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/tests/test_018.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/tests/test_019.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/tests/test_assess_policy.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/tests/test_check_notebook.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/tests/test_databricks_and_uc.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/tests/test_demo.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/tests/test_diff.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/tests/test_hr_notebook.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/tests/test_notebook.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/tests/test_notify_templates.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/tests/test_preview_agents.py +0 -0
- {bricksentry-0.1.23 → bricksentry-0.1.25}/tests/test_sample_guard_and_store.py +0 -0
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.25 (2026-11-16)
|
|
4
|
+
|
|
5
|
+
- **Validation you can reproduce.** `VALIDATION.md` records every live test on Databricks with its numbers, the results that weren't perfect and the bugs each test found. `bricksentry.validation.run_validation()` and the new notebook `examples/databricks/bricksentry_validation.py` run the same ten risky changes on your own workspace in a scratch schema and drop everything afterwards. A new issue form, "Validation report", collects results from other setups.
|
|
6
|
+
- Fix: a sampled diff (`sample_pct`) skipped the full-table check when the schema had also changed, so changed values in a retyped column outside the sample could go uncounted. The verdict still flagged the type change. The check now runs whenever the sample shows no row changes. Found by the new validation battery.
|
|
7
|
+
- The battery passed 10 of 10 on Databricks (111 s on a 2X-Small serverless warehouse), including the two scenarios that need Delta history. The certified-table scenario now keeps the column type, so its strict verdict comes from `certified-table-changed` alone (on Databricks, doubling a decimal widened its type).
|
|
8
|
+
|
|
9
|
+
## 0.1.24 (2026-11-16)
|
|
10
|
+
|
|
11
|
+
Small fixes from two adversarial live tests of 0.1.23 on Databricks, including the job task running inside a real Databricks job.
|
|
12
|
+
|
|
13
|
+
- The job task log no longer ends with IPython's "To exit: use 'exit', 'quit', or Ctrl-D." after a failing verdict (Databricks runs `spark_python_task` scripts inside IPython). The exit code is unchanged.
|
|
14
|
+
- `check-last-change` and the job task report a mistyped or missing table in one line ("Table main.hr.employes not found. Check the catalog, schema and table name…"), and a missing permission as "No permission to read …", instead of the engine's full error with the echoed SQL and unrelated hints. Other history errors keep only their first line. Found in a live test of 0.1.23.
|
|
15
|
+
- `bricksentry test-alert --help` said it exits 1 when no webhook is configured; it exits 2 (configuration error), which the help now says. Found in the live test of 0.1.23.
|
|
16
|
+
- README: "Validated on" covers the live run of 0.1.23.
|
|
17
|
+
- README: the default policy is lenient on changes to a certified table itself (a doubled total only warns); use `builtin:certified` or `builtin:finance` to require a human. From an adversarial live test of 0.1.23.
|
|
18
|
+
|
|
3
19
|
## 0.1.23 (2026-11-16)
|
|
4
20
|
|
|
5
21
|
From a review of accuracy, auditability and documentation:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: bricksentry
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.25
|
|
4
4
|
Summary: Change impact analysis and deployment guardrails for data changes on Databricks, for pipelines and the AI agents that edit them: data diffs, Unity Catalog blast radius, policy verdicts and rollback plans.
|
|
5
5
|
Project-URL: Homepage, https://bricksentry.org
|
|
6
6
|
Project-URL: Documentation, https://bricksentry.org/docs
|
|
@@ -55,7 +55,7 @@ Description-Content-Type: text/markdown
|
|
|
55
55
|
|
|
56
56
|
Change-safety for Databricks pipelines and the AI agents that edit them: know what a change does to your data before it ships.
|
|
57
57
|
|
|
58
|
-
**[Try it in 30 seconds](#1-try-it-in-30-seconds-on-your-laptop)** · **[Check every change on Databricks](#2-check-every-change-to-your-tables-on-databricks)** · **[Docs: bricksentry.org](https://bricksentry.org)** · **[LinkedIn](https://www.linkedin.com/company/bricksentry-org/)**
|
|
58
|
+
**[Try it in 30 seconds](#1-try-it-in-30-seconds-on-your-laptop)** · **[Check every change on Databricks](#2-check-every-change-to-your-tables-on-databricks)** · **[Docs: bricksentry.org](https://bricksentry.org)** · **[Validated live: what we tested and found](VALIDATION.md)** · **[LinkedIn](https://www.linkedin.com/company/bricksentry-org/)**
|
|
59
59
|
|
|
60
60
|
Built by Brahmareddy, Databricks Champion. Open source under Apache-2.0.
|
|
61
61
|
|
|
@@ -422,6 +422,8 @@ Start from a ready-made policy instead of writing one:
|
|
|
422
422
|
|
|
423
423
|
Use one directly with `policy: builtin:finance`, or write an editable copy with `bricksentry init --policy finance`. `bricksentry policies finance` prints it. Tags come from Unity Catalog, so tag your tables `pii` or `certified` for those templates to apply.
|
|
424
424
|
|
|
425
|
+
**The default policy is lenient on certified tables themselves.** It asks a human when a change reaches something *downstream* that's tagged `certified`, but a change *to* a certified table is treated like any other: doubling its totals only warns (`numeric-total-moved`), because many certified marts are rebuilt every day and their totals move for good reasons. If a certified table must not change quietly, use `builtin:certified` (any change to it needs a human, a type change blocks), `builtin:finance` for money tables, or tag the columns that matter so `changed_column_tag` rules apply.
|
|
426
|
+
|
|
425
427
|
### Policy conditions
|
|
426
428
|
|
|
427
429
|
`table` (glob) · `tag` · `downstream_tag` · `downstream_kind` · `downstream_count_gt` · `removed_pct_gt` · `added_pct_gt` · `changed_pct_gt` · `row_count_change_pct_gt` · `row_count_drop_pct_gt` · `column_removed` · `column_added` · `column_type_changed` · `duplicate_keys` · `null_keys` · `sum_change_pct_gt` / `null_increase_gt` (optionally with `column`) · `changed_column` (glob) · `changed_column_tag` · `downstream_column_tag` · `any_change` · `diff_error` · `lineage_error`
|
|
@@ -459,7 +461,7 @@ Every assessment records when it ran (UTC), the bricksentry version, a SHA-256 f
|
|
|
459
461
|
- **Lineage is recorded at runtime.** Brand-new tables have no downstream history yet. Unity Catalog doesn't capture RDD operations, and UDFs hide column-level mapping; column lineage records source-to-target derivations, so a column used only in a filter or join may not appear.
|
|
460
462
|
- **Keys are required.** Tables without a stable key can't be diffed row by row yet (an aggregate-profile mode is planned).
|
|
461
463
|
- **Changed-table detection uses path globs** from config. It doesn't parse Asset Bundles yet.
|
|
462
|
-
- **Validated on Databricks** (serverless, November 2026): a 2-million-row table with 0.1.4 (lineage, rollback plans, previews on shallow clones, every verdict level, the sampling guard catching a single changed row), then live runs of every release up to 0.1.
|
|
464
|
+
- **Validated on Databricks** (serverless, November 2026): a 2-million-row table with 0.1.4 (lineage, rollback plans, previews on shallow clones, every verdict level, the sampling guard catching a single changed row), then live runs of every release up to 0.1.23 on a Free Edition workspace with an HR pipeline: pull-request gating with comment updates, the bundle demo job, `check-last-change` and the newer-changes warning in the CLI, report, JSON and Slack, the refused-statement guards, outbound-URL checks, one-to-one matching of 2,000 NULL keys, exact totals over a million decimal rows, the audit trail, an AI agent attempting six risky changes on the live pipeline, and the job task blocking a bad MERGE inside a real Databricks job. Every run, with its numbers and the bugs it found, is in [VALIDATION.md](VALIDATION.md). The automated tests use DuckDB and a mocked SDK, so please run the [validation notebook](examples/databricks/bricksentry_validation.py) on your workspace and [share a validation report](https://github.com/bricksentry/bricksentry/issues/new?template=validation_report.yml), whether it passes or not.
|
|
463
465
|
|
|
464
466
|
## Roadmap
|
|
465
467
|
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
Change-safety for Databricks pipelines and the AI agents that edit them: know what a change does to your data before it ships.
|
|
10
10
|
|
|
11
|
-
**[Try it in 30 seconds](#1-try-it-in-30-seconds-on-your-laptop)** · **[Check every change on Databricks](#2-check-every-change-to-your-tables-on-databricks)** · **[Docs: bricksentry.org](https://bricksentry.org)** · **[LinkedIn](https://www.linkedin.com/company/bricksentry-org/)**
|
|
11
|
+
**[Try it in 30 seconds](#1-try-it-in-30-seconds-on-your-laptop)** · **[Check every change on Databricks](#2-check-every-change-to-your-tables-on-databricks)** · **[Docs: bricksentry.org](https://bricksentry.org)** · **[Validated live: what we tested and found](VALIDATION.md)** · **[LinkedIn](https://www.linkedin.com/company/bricksentry-org/)**
|
|
12
12
|
|
|
13
13
|
Built by Brahmareddy, Databricks Champion. Open source under Apache-2.0.
|
|
14
14
|
|
|
@@ -375,6 +375,8 @@ Start from a ready-made policy instead of writing one:
|
|
|
375
375
|
|
|
376
376
|
Use one directly with `policy: builtin:finance`, or write an editable copy with `bricksentry init --policy finance`. `bricksentry policies finance` prints it. Tags come from Unity Catalog, so tag your tables `pii` or `certified` for those templates to apply.
|
|
377
377
|
|
|
378
|
+
**The default policy is lenient on certified tables themselves.** It asks a human when a change reaches something *downstream* that's tagged `certified`, but a change *to* a certified table is treated like any other: doubling its totals only warns (`numeric-total-moved`), because many certified marts are rebuilt every day and their totals move for good reasons. If a certified table must not change quietly, use `builtin:certified` (any change to it needs a human, a type change blocks), `builtin:finance` for money tables, or tag the columns that matter so `changed_column_tag` rules apply.
|
|
379
|
+
|
|
378
380
|
### Policy conditions
|
|
379
381
|
|
|
380
382
|
`table` (glob) · `tag` · `downstream_tag` · `downstream_kind` · `downstream_count_gt` · `removed_pct_gt` · `added_pct_gt` · `changed_pct_gt` · `row_count_change_pct_gt` · `row_count_drop_pct_gt` · `column_removed` · `column_added` · `column_type_changed` · `duplicate_keys` · `null_keys` · `sum_change_pct_gt` / `null_increase_gt` (optionally with `column`) · `changed_column` (glob) · `changed_column_tag` · `downstream_column_tag` · `any_change` · `diff_error` · `lineage_error`
|
|
@@ -412,7 +414,7 @@ Every assessment records when it ran (UTC), the bricksentry version, a SHA-256 f
|
|
|
412
414
|
- **Lineage is recorded at runtime.** Brand-new tables have no downstream history yet. Unity Catalog doesn't capture RDD operations, and UDFs hide column-level mapping; column lineage records source-to-target derivations, so a column used only in a filter or join may not appear.
|
|
413
415
|
- **Keys are required.** Tables without a stable key can't be diffed row by row yet (an aggregate-profile mode is planned).
|
|
414
416
|
- **Changed-table detection uses path globs** from config. It doesn't parse Asset Bundles yet.
|
|
415
|
-
- **Validated on Databricks** (serverless, November 2026): a 2-million-row table with 0.1.4 (lineage, rollback plans, previews on shallow clones, every verdict level, the sampling guard catching a single changed row), then live runs of every release up to 0.1.
|
|
417
|
+
- **Validated on Databricks** (serverless, November 2026): a 2-million-row table with 0.1.4 (lineage, rollback plans, previews on shallow clones, every verdict level, the sampling guard catching a single changed row), then live runs of every release up to 0.1.23 on a Free Edition workspace with an HR pipeline: pull-request gating with comment updates, the bundle demo job, `check-last-change` and the newer-changes warning in the CLI, report, JSON and Slack, the refused-statement guards, outbound-URL checks, one-to-one matching of 2,000 NULL keys, exact totals over a million decimal rows, the audit trail, an AI agent attempting six risky changes on the live pipeline, and the job task blocking a bad MERGE inside a real Databricks job. Every run, with its numbers and the bugs it found, is in [VALIDATION.md](VALIDATION.md). The automated tests use DuckDB and a mocked SDK, so please run the [validation notebook](examples/databricks/bricksentry_validation.py) on your workspace and [share a validation report](https://github.com/bricksentry/bricksentry/issues/new?template=validation_report.yml), whether it passes or not.
|
|
416
418
|
|
|
417
419
|
## Roadmap
|
|
418
420
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bricksentry[databricks,mcp]==0.1.25
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cells": [
|
|
3
|
+
{
|
|
4
|
+
"cell_type": "markdown",
|
|
5
|
+
"metadata": {},
|
|
6
|
+
"source": [
|
|
7
|
+
"# Validate bricksentry on your own workspace\n",
|
|
8
|
+
"\n",
|
|
9
|
+
"**10 risky changes, about 2 minutes, nothing outside a scratch schema touched.** This notebook runs the same\n",
|
|
10
|
+
"validation battery we publish in [VALIDATION.md](https://github.com/bricksentry/bricksentry/blob/main/VALIDATION.md),\n",
|
|
11
|
+
"so you can check the results yourself instead of taking our word for them.\n",
|
|
12
|
+
"\n",
|
|
13
|
+
"It generates an HR-style employees table (200,000 rows) and a department mart in the scratch schema, then tries the\n",
|
|
14
|
+
"changes that go wrong in real pipelines: silent row loss, a MERGE that duplicates a department, one change with\n",
|
|
15
|
+
"everything wrong, five bad rows hidden outside a 5% sample, a doubled total on a certified table, 2,000 NULL keys,\n",
|
|
16
|
+
"exact totals over a million decimal rows, a bad change that already landed in Delta, and a mistyped table name.\n",
|
|
17
|
+
"Every table it creates is dropped at the end.\n",
|
|
18
|
+
"\n",
|
|
19
|
+
"**You need:** a SQL warehouse you can use and `CREATE TABLE` on the scratch schema (it is created if missing).\n",
|
|
20
|
+
"\n",
|
|
21
|
+
"Please share what you see, whether everything passes or not:\n",
|
|
22
|
+
"[open a validation report](https://github.com/bricksentry/bricksentry/issues/new?template=validation_report.yml).\n",
|
|
23
|
+
"Results from other clouds, classic compute and bigger tables are the most useful."
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"cell_type": "code",
|
|
28
|
+
"execution_count": null,
|
|
29
|
+
"metadata": {},
|
|
30
|
+
"outputs": [],
|
|
31
|
+
"source": [
|
|
32
|
+
"%pip install --quiet --upgrade \"bricksentry[databricks]\""
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"cell_type": "code",
|
|
37
|
+
"execution_count": null,
|
|
38
|
+
"metadata": {},
|
|
39
|
+
"outputs": [],
|
|
40
|
+
"source": [
|
|
41
|
+
"dbutils.library.restartPython()"
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"cell_type": "markdown",
|
|
46
|
+
"metadata": {},
|
|
47
|
+
"source": [
|
|
48
|
+
"## Settings\n",
|
|
49
|
+
"- **warehouse_id:** SQL Warehouses → your warehouse → Connection details.\n",
|
|
50
|
+
"- **scratch_schema:** `catalog.schema` where the test tables are created and dropped. Use a schema with nothing else in it.\n",
|
|
51
|
+
"- **rows:** size of the generated employees table (default 200,000)."
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"cell_type": "code",
|
|
56
|
+
"execution_count": null,
|
|
57
|
+
"metadata": {},
|
|
58
|
+
"outputs": [],
|
|
59
|
+
"source": [
|
|
60
|
+
"import re\n",
|
|
61
|
+
"\n",
|
|
62
|
+
"dbutils.widgets.text(\"warehouse_id\", \"\")\n",
|
|
63
|
+
"dbutils.widgets.text(\"scratch_schema\", \"main.bricksentry_validation\")\n",
|
|
64
|
+
"dbutils.widgets.text(\"rows\", \"200000\")\n",
|
|
65
|
+
"\n",
|
|
66
|
+
"WAREHOUSE_ID = dbutils.widgets.get(\"warehouse_id\").strip()\n",
|
|
67
|
+
"SCRATCH = dbutils.widgets.get(\"scratch_schema\").strip()\n",
|
|
68
|
+
"ROWS = int(dbutils.widgets.get(\"rows\").strip() or \"200000\")\n",
|
|
69
|
+
"\n",
|
|
70
|
+
"NAME = r\"[A-Za-z0-9_]+\"\n",
|
|
71
|
+
"if not re.fullmatch(r\"[A-Za-z0-9]+\", WAREHOUSE_ID):\n",
|
|
72
|
+
" raise ValueError(\"Set the 'warehouse_id' widget to your SQL warehouse ID (SQL Warehouses → Connection details).\")\n",
|
|
73
|
+
"if not re.fullmatch(rf\"{NAME}\\.{NAME}\", SCRATCH):\n",
|
|
74
|
+
" raise ValueError(f\"Set 'scratch_schema' to catalog.schema; got {SCRATCH!r}\")\n",
|
|
75
|
+
"\n",
|
|
76
|
+
"import bricksentry\n",
|
|
77
|
+
"from bricksentry.backends.base import make_backend\n",
|
|
78
|
+
"\n",
|
|
79
|
+
"backend = make_backend({\"type\": \"databricks\", \"warehouse_id\": WAREHOUSE_ID})\n",
|
|
80
|
+
"print(f\"bricksentry {bricksentry.__version__}, scratch schema {SCRATCH}, {ROWS:,} rows\")"
|
|
81
|
+
]
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"cell_type": "markdown",
|
|
85
|
+
"metadata": {},
|
|
86
|
+
"source": [
|
|
87
|
+
"## Run the battery"
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"cell_type": "code",
|
|
92
|
+
"execution_count": null,
|
|
93
|
+
"metadata": {},
|
|
94
|
+
"outputs": [],
|
|
95
|
+
"source": [
|
|
96
|
+
"from bricksentry.validation import print_results, run_validation\n",
|
|
97
|
+
"\n",
|
|
98
|
+
"results = run_validation(backend, SCRATCH, rows=ROWS)\n",
|
|
99
|
+
"print_results(results)"
|
|
100
|
+
]
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"cell_type": "markdown",
|
|
104
|
+
"metadata": {},
|
|
105
|
+
"source": [
|
|
106
|
+
"## Results as a table\n",
|
|
107
|
+
"Copy this into a [validation report](https://github.com/bricksentry/bricksentry/issues/new?template=validation_report.yml),\n",
|
|
108
|
+
"with your cloud and compute type. Leave out anything private (workspace URLs, warehouse IDs, emails)."
|
|
109
|
+
]
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"cell_type": "code",
|
|
113
|
+
"execution_count": null,
|
|
114
|
+
"metadata": {},
|
|
115
|
+
"outputs": [],
|
|
116
|
+
"source": [
|
|
117
|
+
"import pandas as pd\n",
|
|
118
|
+
"\n",
|
|
119
|
+
"display(pd.DataFrame([r.to_dict() for r in results])[[\"scenario\", \"result\", \"expected\", \"actual\", \"seconds\"]])"
|
|
120
|
+
]
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"cell_type": "markdown",
|
|
124
|
+
"metadata": {},
|
|
125
|
+
"source": [
|
|
126
|
+
"## What the results mean\n",
|
|
127
|
+
"- **PASS** on every row means bricksentry caught each change the way VALIDATION.md describes.\n",
|
|
128
|
+
"- `certified_totals_default` passes when the verdict is only a **warning**: that's the documented default for a\n",
|
|
129
|
+
" certified table itself. `certified_totals_strict` shows the same change under `policy: builtin:certified`.\n",
|
|
130
|
+
"- Any **FAIL** is a bug we want to hear about. Please include the `actual` column in your report.\n",
|
|
131
|
+
"\n",
|
|
132
|
+
"The scratch tables were dropped when the battery finished. The scratch schema itself is left in place."
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
],
|
|
136
|
+
"metadata": {
|
|
137
|
+
"kernelspec": {
|
|
138
|
+
"display_name": "Python 3",
|
|
139
|
+
"language": "python",
|
|
140
|
+
"name": "python3"
|
|
141
|
+
},
|
|
142
|
+
"language_info": {
|
|
143
|
+
"name": "python"
|
|
144
|
+
},
|
|
145
|
+
"application/vnd.databricks.v1+notebook": {
|
|
146
|
+
"notebookName": "bricksentry_validation",
|
|
147
|
+
"language": "python"
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
"nbformat": 4,
|
|
151
|
+
"nbformat_minor": 5
|
|
152
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Databricks notebook source
|
|
2
|
+
# MAGIC %md
|
|
3
|
+
# MAGIC # Validate bricksentry on your own workspace
|
|
4
|
+
# MAGIC
|
|
5
|
+
# MAGIC **10 risky changes, about 2 minutes, nothing outside a scratch schema touched.** This notebook runs the same
|
|
6
|
+
# MAGIC validation battery we publish in [VALIDATION.md](https://github.com/bricksentry/bricksentry/blob/main/VALIDATION.md),
|
|
7
|
+
# MAGIC so you can check the results yourself instead of taking our word for them.
|
|
8
|
+
# MAGIC
|
|
9
|
+
# MAGIC It generates an HR-style employees table (200,000 rows) and a department mart in the scratch schema, then tries the
|
|
10
|
+
# MAGIC changes that go wrong in real pipelines: silent row loss, a MERGE that duplicates a department, one change with
|
|
11
|
+
# MAGIC everything wrong, five bad rows hidden outside a 5% sample, a doubled total on a certified table, 2,000 NULL keys,
|
|
12
|
+
# MAGIC exact totals over a million decimal rows, a bad change that already landed in Delta, and a mistyped table name.
|
|
13
|
+
# MAGIC Every table it creates is dropped at the end.
|
|
14
|
+
# MAGIC
|
|
15
|
+
# MAGIC **You need:** a SQL warehouse you can use and `CREATE TABLE` on the scratch schema (it is created if missing).
|
|
16
|
+
# MAGIC
|
|
17
|
+
# MAGIC Please share what you see, whether everything passes or not:
|
|
18
|
+
# MAGIC [open a validation report](https://github.com/bricksentry/bricksentry/issues/new?template=validation_report.yml).
|
|
19
|
+
# MAGIC Results from other clouds, classic compute and bigger tables are the most useful.
|
|
20
|
+
|
|
21
|
+
# COMMAND ----------
|
|
22
|
+
|
|
23
|
+
# MAGIC %pip install --quiet --upgrade "bricksentry[databricks]"
|
|
24
|
+
|
|
25
|
+
# COMMAND ----------
|
|
26
|
+
|
|
27
|
+
dbutils.library.restartPython()
|
|
28
|
+
|
|
29
|
+
# COMMAND ----------
|
|
30
|
+
|
|
31
|
+
# MAGIC %md
|
|
32
|
+
# MAGIC ## Settings
|
|
33
|
+
# MAGIC - **warehouse_id:** SQL Warehouses → your warehouse → Connection details.
|
|
34
|
+
# MAGIC - **scratch_schema:** `catalog.schema` where the test tables are created and dropped. Use a schema with nothing else in it.
|
|
35
|
+
# MAGIC - **rows:** size of the generated employees table (default 200,000).
|
|
36
|
+
|
|
37
|
+
# COMMAND ----------
|
|
38
|
+
|
|
39
|
+
import re
|
|
40
|
+
|
|
41
|
+
dbutils.widgets.text("warehouse_id", "")
|
|
42
|
+
dbutils.widgets.text("scratch_schema", "main.bricksentry_validation")
|
|
43
|
+
dbutils.widgets.text("rows", "200000")
|
|
44
|
+
|
|
45
|
+
WAREHOUSE_ID = dbutils.widgets.get("warehouse_id").strip()
|
|
46
|
+
SCRATCH = dbutils.widgets.get("scratch_schema").strip()
|
|
47
|
+
ROWS = int(dbutils.widgets.get("rows").strip() or "200000")
|
|
48
|
+
|
|
49
|
+
NAME = r"[A-Za-z0-9_]+"
|
|
50
|
+
if not re.fullmatch(r"[A-Za-z0-9]+", WAREHOUSE_ID):
|
|
51
|
+
raise ValueError("Set the 'warehouse_id' widget to your SQL warehouse ID (SQL Warehouses → Connection details).")
|
|
52
|
+
if not re.fullmatch(rf"{NAME}\.{NAME}", SCRATCH):
|
|
53
|
+
raise ValueError(f"Set 'scratch_schema' to catalog.schema; got {SCRATCH!r}")
|
|
54
|
+
|
|
55
|
+
import bricksentry
|
|
56
|
+
from bricksentry.backends.base import make_backend
|
|
57
|
+
|
|
58
|
+
backend = make_backend({"type": "databricks", "warehouse_id": WAREHOUSE_ID})
|
|
59
|
+
print(f"bricksentry {bricksentry.__version__}, scratch schema {SCRATCH}, {ROWS:,} rows")
|
|
60
|
+
|
|
61
|
+
# COMMAND ----------
|
|
62
|
+
|
|
63
|
+
# MAGIC %md
|
|
64
|
+
# MAGIC ## Run the battery
|
|
65
|
+
|
|
66
|
+
# COMMAND ----------
|
|
67
|
+
|
|
68
|
+
from bricksentry.validation import print_results, run_validation
|
|
69
|
+
|
|
70
|
+
results = run_validation(backend, SCRATCH, rows=ROWS)
|
|
71
|
+
print_results(results)
|
|
72
|
+
|
|
73
|
+
# COMMAND ----------
|
|
74
|
+
|
|
75
|
+
# MAGIC %md
|
|
76
|
+
# MAGIC ## Results as a table
|
|
77
|
+
# MAGIC Copy this into a [validation report](https://github.com/bricksentry/bricksentry/issues/new?template=validation_report.yml),
|
|
78
|
+
# MAGIC with your cloud and compute type. Leave out anything private (workspace URLs, warehouse IDs, emails).
|
|
79
|
+
|
|
80
|
+
# COMMAND ----------
|
|
81
|
+
|
|
82
|
+
import pandas as pd
|
|
83
|
+
|
|
84
|
+
display(pd.DataFrame([r.to_dict() for r in results])[["scenario", "result", "expected", "actual", "seconds"]])
|
|
85
|
+
|
|
86
|
+
# COMMAND ----------
|
|
87
|
+
|
|
88
|
+
# MAGIC %md
|
|
89
|
+
# MAGIC ## What the results mean
|
|
90
|
+
# MAGIC - **PASS** on every row means bricksentry caught each change the way VALIDATION.md describes.
|
|
91
|
+
# MAGIC - `certified_totals_default` passes when the verdict is only a **warning**: that's the documented default for a
|
|
92
|
+
# MAGIC certified table itself. `certified_totals_strict` shows the same change under `policy: builtin:certified`.
|
|
93
|
+
# MAGIC - Any **FAIL** is a bug we want to hear about. Please include the `actual` column in your report.
|
|
94
|
+
# MAGIC
|
|
95
|
+
# MAGIC The scratch tables were dropped when the battery finished. The scratch schema itself is left in place.
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "bricksentry"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.25"
|
|
8
8
|
description = "Change impact analysis and deployment guardrails for data changes on Databricks, for pipelines and the AI agents that edit them: data diffs, Unity Catalog blast radius, policy verdicts and rollback plans."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -15,6 +15,7 @@ SOURCES = [
|
|
|
15
15
|
ROOT / "examples" / "databricks" / "bricksentry_quickstart.py",
|
|
16
16
|
ROOT / "examples" / "databricks" / "bricksentry_check_my_table.py",
|
|
17
17
|
ROOT / "examples" / "databricks" / "bricksentry_hr_walkthrough.py",
|
|
18
|
+
ROOT / "examples" / "databricks" / "bricksentry_validation.py",
|
|
18
19
|
]
|
|
19
20
|
SRC = SOURCES[0]
|
|
20
21
|
OUT = SRC.with_suffix(".ipynb")
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"source": "github"
|
|
9
9
|
},
|
|
10
10
|
"websiteUrl": "https://bricksentry.org",
|
|
11
|
-
"version": "0.1.
|
|
11
|
+
"version": "0.1.25",
|
|
12
12
|
"packages": [
|
|
13
13
|
{
|
|
14
14
|
"registryType": "pypi",
|
|
15
15
|
"identifier": "bricksentry-mcp",
|
|
16
|
-
"version": "0.1.
|
|
16
|
+
"version": "0.1.25",
|
|
17
17
|
"runtimeHint": "uvx",
|
|
18
18
|
"transport": {
|
|
19
19
|
"type": "stdio"
|
|
@@ -395,7 +395,7 @@ def policies(name):
|
|
|
395
395
|
def test_alert(verdict, owner, config_path):
|
|
396
396
|
"""Send a clearly labelled sample alert to your Slack / Teams webhooks.
|
|
397
397
|
|
|
398
|
-
Reads no tables. Exits 1 if a webhook failed or none is configured."""
|
|
398
|
+
Reads no tables. Exits 1 if a webhook failed or was skipped, 2 if none is configured."""
|
|
399
399
|
from bricksentry.notify import NotifySettings, sample_assessment, send
|
|
400
400
|
|
|
401
401
|
cfg = _config(config_path)
|
|
@@ -47,7 +47,10 @@ def diff_tables(
|
|
|
47
47
|
"""
|
|
48
48
|
d = _diff(backend, base, candidate, keys, table=table, sample_pct=sample_pct,
|
|
49
49
|
segment_by=segment_by, max_samples=max_samples, columns=columns)
|
|
50
|
-
|
|
50
|
+
# Re-check the whole table whenever the sample shows no row changes, even if the
|
|
51
|
+
# schema changed: a retyped column can still hide changed values outside the sample.
|
|
52
|
+
rows_look_unchanged = d.added_rows == 0 and d.removed_rows == 0 and d.changed_rows == 0
|
|
53
|
+
if not (sample_pct and sample_guard and rows_look_unchanged):
|
|
51
54
|
return d
|
|
52
55
|
cols = list(d.keys) + [c.column for c in d.columns]
|
|
53
56
|
full = _full_fingerprints(backend, base, candidate, cols)
|
|
@@ -56,7 +59,7 @@ def diff_tables(
|
|
|
56
59
|
full_d = _diff(backend, base, candidate, keys, table=table, sample_pct=None,
|
|
57
60
|
segment_by=segment_by, max_samples=max_samples, columns=columns)
|
|
58
61
|
full_d.sample_note = (
|
|
59
|
-
f"The {sample_pct:g}% sample showed no changes, but the full tables differ, "
|
|
62
|
+
f"The {sample_pct:g}% sample showed no row changes, but the full tables differ, "
|
|
60
63
|
"so the diff was re-run on all rows."
|
|
61
64
|
)
|
|
62
65
|
return full_d
|
|
@@ -177,6 +177,29 @@ def _ensure_scratch(db: Any, schema: str) -> None:
|
|
|
177
177
|
raise
|
|
178
178
|
|
|
179
179
|
|
|
180
|
+
_NOT_FOUND = re.compile(
|
|
181
|
+
r"TABLE_OR_VIEW_NOT_FOUND|cannot be found|does not exist|not found|no such table", re.IGNORECASE)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _read_history(db: Any, table: str, limit: int) -> list[dict[str, Any]]:
|
|
185
|
+
"""DESCRIBE HISTORY, with a one-line message for the common mistakes instead of the
|
|
186
|
+
engine's full error (which echoes the SQL and adds unrelated hints)."""
|
|
187
|
+
try:
|
|
188
|
+
return db.history(table, limit)
|
|
189
|
+
except Exception as e:
|
|
190
|
+
msg = str(e)
|
|
191
|
+
if _NOT_FOUND.search(msg):
|
|
192
|
+
raise ValueError(
|
|
193
|
+
f"Table {table} not found. Check the catalog, schema and table name (they must match "
|
|
194
|
+
"Unity Catalog exactly) and that you have SELECT on it.") from None
|
|
195
|
+
if "PERMISSION_DENIED" in msg or "INSUFFICIENT_PERMISSIONS" in msg:
|
|
196
|
+
raise ValueError(
|
|
197
|
+
f"No permission to read {table}: check-last-change needs SELECT on the table "
|
|
198
|
+
"(and its Delta history).") from None
|
|
199
|
+
first = (msg.strip().splitlines() or [type(e).__name__])[0][:300]
|
|
200
|
+
raise RuntimeError(f"Could not read the history of {table}: {first}") from None
|
|
201
|
+
|
|
202
|
+
|
|
180
203
|
def check_change(
|
|
181
204
|
sentry: Sentry,
|
|
182
205
|
table: str,
|
|
@@ -195,7 +218,7 @@ def check_change(
|
|
|
195
218
|
if not _NAME.fullmatch(table):
|
|
196
219
|
raise ValueError(f"table must be schema.table or catalog.schema.table; got {table!r}")
|
|
197
220
|
|
|
198
|
-
history = db
|
|
221
|
+
history = _read_history(db, table, history_limit)
|
|
199
222
|
change = pick_change(table, history, version=version, since=since)
|
|
200
223
|
keys = keys or sentry.config.spec(table).keys or db.primary_key(table)
|
|
201
224
|
if not keys:
|
|
@@ -17,6 +17,7 @@ import argparse
|
|
|
17
17
|
import json
|
|
18
18
|
import os
|
|
19
19
|
import sys
|
|
20
|
+
import warnings
|
|
20
21
|
from datetime import datetime, timedelta, timezone
|
|
21
22
|
from typing import Any
|
|
22
23
|
|
|
@@ -185,6 +186,10 @@ def main(argv: list[str] | None = None) -> None:
|
|
|
185
186
|
even ``SystemExit(0)``, as a task error, so a clean run must simply return."""
|
|
186
187
|
code = run(argv)
|
|
187
188
|
if code:
|
|
189
|
+
# In a spark_python_task the script runs inside IPython, which follows a
|
|
190
|
+
# SystemExit with "To exit: use 'exit', 'quit', or Ctrl-D." at the end of the
|
|
191
|
+
# task log. The exit code is what matters, so keep that line out of the log.
|
|
192
|
+
warnings.filterwarnings("ignore", message="To exit: use")
|
|
188
193
|
sys.exit(code)
|
|
189
194
|
|
|
190
195
|
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
"""A reproducible validation battery: the risky changes bricksentry is expected to catch.
|
|
2
|
+
|
|
3
|
+
Run it on your own workspace to see the same results we publish in VALIDATION.md::
|
|
4
|
+
|
|
5
|
+
from bricksentry.validation import run_validation, print_results
|
|
6
|
+
results = run_validation(backend, scratch="main.bricksentry_validation")
|
|
7
|
+
print_results(results)
|
|
8
|
+
|
|
9
|
+
Everything happens in ``scratch``: an HR-style employees table and a department mart
|
|
10
|
+
are generated there, each scenario writes a candidate table next to them, and every
|
|
11
|
+
table is dropped at the end. Nothing outside ``scratch`` is read or written.
|
|
12
|
+
|
|
13
|
+
Lineage and tags are fixed in code (the mart is ``certified`` and reads the employees
|
|
14
|
+
table, which is ``pii``), so the verdicts don't depend on your workspace's lineage
|
|
15
|
+
history. Unity Catalog lineage itself is exercised by the check-my-table notebook.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import re
|
|
21
|
+
import time
|
|
22
|
+
from dataclasses import dataclass, field
|
|
23
|
+
from typing import Any
|
|
24
|
+
|
|
25
|
+
from bricksentry.assess import Sentry
|
|
26
|
+
from bricksentry.backends.base import Backend
|
|
27
|
+
from bricksentry.config import Config
|
|
28
|
+
from bricksentry.lineage import StaticLineage
|
|
29
|
+
from bricksentry.models import Verdict
|
|
30
|
+
from bricksentry.policy import Policy
|
|
31
|
+
from bricksentry.policy_templates import get_template
|
|
32
|
+
|
|
33
|
+
_NAME = re.compile(r"[A-Za-z0-9_]+(\.[A-Za-z0-9_]+)?")
|
|
34
|
+
DEPARTMENTS = ["Sales", "Engineering", "Finance", "Marketing", "Support", "HR", "Legal", "Operations"]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@dataclass
|
|
38
|
+
class ScenarioResult:
|
|
39
|
+
name: str
|
|
40
|
+
attack: str
|
|
41
|
+
expected: str
|
|
42
|
+
actual: str
|
|
43
|
+
passed: bool | None # None: skipped (e.g. needs Delta history)
|
|
44
|
+
seconds: float = 0.0
|
|
45
|
+
details: dict[str, Any] = field(default_factory=dict)
|
|
46
|
+
|
|
47
|
+
def to_dict(self) -> dict[str, Any]:
|
|
48
|
+
return {"scenario": self.name, "attack": self.attack, "expected": self.expected,
|
|
49
|
+
"actual": self.actual, "result": _status(self.passed), "seconds": round(self.seconds, 2),
|
|
50
|
+
**self.details}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _status(p: bool | None) -> str:
|
|
54
|
+
return "SKIP" if p is None else ("PASS" if p else "FAIL")
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def run_validation(
|
|
58
|
+
backend: Backend,
|
|
59
|
+
scratch: str,
|
|
60
|
+
rows: int = 200_000,
|
|
61
|
+
exact_rows: int = 1_000_000,
|
|
62
|
+
keep_tables: bool = False,
|
|
63
|
+
) -> list[ScenarioResult]:
|
|
64
|
+
"""Run every scenario in ``scratch`` (``catalog.schema`` or ``schema``) and return
|
|
65
|
+
the results. ``rows`` sizes the employees table; ``exact_rows`` the exact-totals table."""
|
|
66
|
+
if not _NAME.fullmatch(scratch):
|
|
67
|
+
raise ValueError(f"scratch must be schema or catalog.schema; got {scratch!r}")
|
|
68
|
+
v = _Validation(backend, scratch, rows, exact_rows)
|
|
69
|
+
try:
|
|
70
|
+
v.setup()
|
|
71
|
+
return v.run_all()
|
|
72
|
+
finally:
|
|
73
|
+
if not keep_tables:
|
|
74
|
+
v.cleanup()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def print_results(results: list[ScenarioResult], out=print) -> None:
|
|
78
|
+
passed = sum(1 for r in results if r.passed)
|
|
79
|
+
failed = sum(1 for r in results if r.passed is False)
|
|
80
|
+
skipped = sum(1 for r in results if r.passed is None)
|
|
81
|
+
for r in results:
|
|
82
|
+
out(f"[{_status(r.passed)}] {r.name} ({r.seconds:.1f}s)")
|
|
83
|
+
out(f" attack: {r.attack}")
|
|
84
|
+
out(f" expected: {r.expected}")
|
|
85
|
+
out(f" actual: {r.actual}")
|
|
86
|
+
out("")
|
|
87
|
+
out(f"{passed} passed, {failed} failed, {skipped} skipped")
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class _Validation:
|
|
91
|
+
def __init__(self, backend: Backend, scratch: str, rows: int, exact_rows: int):
|
|
92
|
+
self.db = backend
|
|
93
|
+
self.s = scratch
|
|
94
|
+
self.rows = rows
|
|
95
|
+
self.exact_rows = exact_rows
|
|
96
|
+
self.made: list[str] = []
|
|
97
|
+
self.emp = self.t("bsv_employees")
|
|
98
|
+
self.mart = self.t("bsv_dept_mart")
|
|
99
|
+
lineage = StaticLineage(
|
|
100
|
+
edges={self.emp: [self.mart, "notebook:/Shared/hr_report"]},
|
|
101
|
+
owners={self.mart: "hr-analytics"},
|
|
102
|
+
tags={self.mart: {"certified": "true"}, self.emp: {"pii": "true"}},
|
|
103
|
+
)
|
|
104
|
+
cfg = Config.from_dict({
|
|
105
|
+
"assessment_store": False,
|
|
106
|
+
"sandbox_schema": scratch,
|
|
107
|
+
"tables": {self.emp: {"keys": ["emp_id"]}, self.mart: {"keys": ["department"]}},
|
|
108
|
+
})
|
|
109
|
+
self.sentry = Sentry(cfg, backend=backend, lineage=lineage)
|
|
110
|
+
self.certified = Sentry(cfg, backend=backend, lineage=lineage, policy=Policy(get_template("certified")))
|
|
111
|
+
|
|
112
|
+
# --- helpers --------------------------------------------------------------
|
|
113
|
+
def t(self, name: str) -> str:
|
|
114
|
+
return f"{self.s}.{name}"
|
|
115
|
+
|
|
116
|
+
def q(self, name: str) -> str:
|
|
117
|
+
return self.db.qualified(name)
|
|
118
|
+
|
|
119
|
+
def ids(self, n: int) -> str:
|
|
120
|
+
if self.db.name == "duckdb":
|
|
121
|
+
return f"SELECT i FROM range(1, {int(n) + 1}) t(i)"
|
|
122
|
+
return f"SELECT id AS i FROM range(1, {int(n) + 1})"
|
|
123
|
+
|
|
124
|
+
def create(self, name: str, select: str) -> str:
|
|
125
|
+
full = self.t(name)
|
|
126
|
+
self.db.execute(f"DROP TABLE IF EXISTS {self.q(full)}")
|
|
127
|
+
self.db.execute(f"CREATE TABLE {self.q(full)} AS {select}")
|
|
128
|
+
self.made.append(full)
|
|
129
|
+
return full
|
|
130
|
+
|
|
131
|
+
def setup(self) -> None:
|
|
132
|
+
self.db.ensure_schema(self.s)
|
|
133
|
+
dept = "CASE " + " ".join(f"WHEN i % 9 = {k} THEN '{d}'" for k, d in enumerate(DEPARTMENTS)) + " END"
|
|
134
|
+
self.create("bsv_employees",
|
|
135
|
+
f"SELECT i AS emp_id, {dept} AS department, "
|
|
136
|
+
f"CAST(40000 + (i % 1000) * 50 AS DECIMAL(12, 2)) AS salary, "
|
|
137
|
+
f"CONCAT('user', CAST(i AS STRING), '@example.com') AS email FROM ({self.ids(self.rows)}) ids"
|
|
138
|
+
.replace("AS STRING", f"AS {self.db.string_type}"))
|
|
139
|
+
self.create("bsv_dept_mart",
|
|
140
|
+
f"SELECT department, COUNT(*) AS headcount, CAST(SUM(salary) AS DECIMAL(18, 2)) AS total_salary, "
|
|
141
|
+
f"CAST(AVG(salary) AS DECIMAL(12, 2)) AS avg_salary FROM {self.q(self.emp)} GROUP BY department")
|
|
142
|
+
|
|
143
|
+
def cleanup(self) -> None:
|
|
144
|
+
for name in reversed(self.made):
|
|
145
|
+
try:
|
|
146
|
+
self.db.drop(name)
|
|
147
|
+
except Exception: # pragma: no cover - best effort
|
|
148
|
+
pass
|
|
149
|
+
|
|
150
|
+
def assess(self, table: str, candidate: str, sentry: Sentry | None = None, sample_pct: float | None = None):
|
|
151
|
+
s = sentry or self.sentry
|
|
152
|
+
if sample_pct:
|
|
153
|
+
d = s.diff(table, candidate, table=table, sample_pct=sample_pct)
|
|
154
|
+
return s.assess([table], diffs={table: d})
|
|
155
|
+
return s.assess([table], candidates={table: candidate})
|
|
156
|
+
|
|
157
|
+
def run_all(self) -> list[ScenarioResult]:
|
|
158
|
+
out = []
|
|
159
|
+
for fn in (self.row_loss, self.bad_merge, self.everything_wrong, self.hidden_in_sample,
|
|
160
|
+
self.certified_totals_default, self.certified_totals_strict, self.null_keys,
|
|
161
|
+
self.exact_totals, self.landed_change, self.typo_table):
|
|
162
|
+
t0 = time.time()
|
|
163
|
+
try:
|
|
164
|
+
r = fn()
|
|
165
|
+
except Exception as e: # a scenario that errors is a failure, not a crash
|
|
166
|
+
r = ScenarioResult(fn.__name__, "", "runs without error", f"error: {str(e).strip()[:300]}", False)
|
|
167
|
+
r.seconds = time.time() - t0
|
|
168
|
+
out.append(r)
|
|
169
|
+
return out
|
|
170
|
+
|
|
171
|
+
# --- scenarios --------------------------------------------------------------
|
|
172
|
+
def row_loss(self) -> ScenarioResult:
|
|
173
|
+
cand = self.create("bsv_c_row_loss", f"SELECT * FROM {self.q(self.mart)} WHERE department IS NOT NULL")
|
|
174
|
+
a = self.assess(self.mart, cand)
|
|
175
|
+
rules = {h.rule for h in a.hits}
|
|
176
|
+
ok = a.verdict.rank >= Verdict.NEEDS_HUMAN.rank and "row-loss" in rules
|
|
177
|
+
return ScenarioResult("row_loss", "delete the aggregate row for employees with no department",
|
|
178
|
+
"needs_human or worse, row-loss fires", f"{a.verdict.value}: {sorted(rules)}", ok)
|
|
179
|
+
|
|
180
|
+
def bad_merge(self) -> ScenarioResult:
|
|
181
|
+
cand = self.create("bsv_c_bad_merge", f"SELECT * FROM {self.q(self.mart)} UNION ALL "
|
|
182
|
+
f"SELECT * FROM {self.q(self.mart)} WHERE department = 'Sales'")
|
|
183
|
+
a = self.assess(self.mart, cand)
|
|
184
|
+
d = a.tables[0].diff
|
|
185
|
+
ok = a.verdict == Verdict.BLOCK and d.added_rows == 1 and d.duplicate_keys_candidate == 1
|
|
186
|
+
return ScenarioResult("bad_merge", "a MERGE re-inserts a whole department",
|
|
187
|
+
"block (duplicate-keys); the extra copy counts as 1 added row",
|
|
188
|
+
f"{a.verdict.value}, added={d.added_rows}, duplicate keys={d.duplicate_keys_candidate}", ok)
|
|
189
|
+
|
|
190
|
+
def everything_wrong(self) -> ScenarioResult:
|
|
191
|
+
st = self.db.string_type
|
|
192
|
+
cand = self.create(
|
|
193
|
+
"bsv_c_everything",
|
|
194
|
+
f"SELECT department, CAST(headcount AS DOUBLE) AS headcount, CAST(0 AS DECIMAL(18, 2)) AS total_salary "
|
|
195
|
+
f"FROM {self.q(self.mart)} WHERE department IS NULL OR department <> 'Finance' "
|
|
196
|
+
f"UNION ALL SELECT department, CAST(headcount AS DOUBLE), CAST(0 AS DECIMAL(18, 2)) "
|
|
197
|
+
f"FROM {self.q(self.mart)} WHERE department = 'Sales' "
|
|
198
|
+
f"UNION ALL SELECT CAST(NULL AS {st}), CAST(1 AS DOUBLE), CAST(0 AS DECIMAL(18, 2))")
|
|
199
|
+
a = self.assess(self.mart, cand)
|
|
200
|
+
rules = {h.rule for h in a.hits}
|
|
201
|
+
want = {"duplicate-keys", "dropped-column", "row-loss", "type-change", "numeric-total-moved"}
|
|
202
|
+
ok = a.verdict == Verdict.BLOCK and want <= rules
|
|
203
|
+
return ScenarioResult("everything_wrong",
|
|
204
|
+
"one change: drop a department, duplicate one, add a NULL key, drop a column, "
|
|
205
|
+
"change a type, zero the totals",
|
|
206
|
+
f"block, with at least {sorted(want)}", f"{a.verdict.value}: {len(rules)} rules {sorted(rules)}", ok)
|
|
207
|
+
|
|
208
|
+
def hidden_in_sample(self) -> ScenarioResult:
|
|
209
|
+
pred = self.db.sample_predicate(["emp_id"], 5)
|
|
210
|
+
picked = [int(r["emp_id"]) for r in self.db.query(
|
|
211
|
+
f"SELECT emp_id FROM {self.q(self.emp)} WHERE NOT ({pred}) ORDER BY emp_id LIMIT 5")]
|
|
212
|
+
ids = ", ".join(map(str, picked))
|
|
213
|
+
cand = self.create("bsv_c_hidden", f"SELECT emp_id, department, CASE WHEN emp_id IN ({ids}) "
|
|
214
|
+
f"THEN CAST(salary * 5 AS DECIMAL(12, 2)) ELSE salary END AS salary, email "
|
|
215
|
+
f"FROM {self.q(self.emp)}")
|
|
216
|
+
a = self.assess(self.emp, cand, sample_pct=5)
|
|
217
|
+
d = a.tables[0].diff
|
|
218
|
+
ok = d.changed_rows == 5 and bool(d.sample_note) and a.verdict.rank >= Verdict.NEEDS_HUMAN.rank
|
|
219
|
+
return ScenarioResult("hidden_in_sample", f"multiply 5 of {self.rows:,} salaries by 5, all outside a 5% sample",
|
|
220
|
+
"the full-table checksum catches it: 5 changed rows, needs_human or worse",
|
|
221
|
+
f"{a.verdict.value}, changed={d.changed_rows}, re-ran on all rows={bool(d.sample_note)}", ok)
|
|
222
|
+
|
|
223
|
+
def certified_totals_default(self) -> ScenarioResult:
|
|
224
|
+
cand = self._double_sales("bsv_c_cert_default")
|
|
225
|
+
a = self.assess(self.mart, cand)
|
|
226
|
+
ok = a.verdict == Verdict.WARN
|
|
227
|
+
return ScenarioResult("certified_totals_default", "double the Sales totals in the certified mart (default policy)",
|
|
228
|
+
"warn only: the default policy is lenient on a certified table itself (documented)",
|
|
229
|
+
f"{a.verdict.value}: {sorted({h.rule for h in a.hits})}", ok)
|
|
230
|
+
|
|
231
|
+
def certified_totals_strict(self) -> ScenarioResult:
|
|
232
|
+
cand = self._double_sales("bsv_c_cert_strict")
|
|
233
|
+
a = self.assess(self.mart, cand, sentry=self.certified)
|
|
234
|
+
rules = {h.rule for h in a.hits}
|
|
235
|
+
ok = a.verdict.rank >= Verdict.NEEDS_HUMAN.rank and "certified-table-changed" in rules and not (
|
|
236
|
+
a.tables[0].diff and a.tables[0].diff.schema.type_changed)
|
|
237
|
+
return ScenarioResult("certified_totals_strict", "the same change under policy builtin:certified",
|
|
238
|
+
"needs_human or worse from certified-table-changed (same column types)",
|
|
239
|
+
f"{a.verdict.value}: {sorted(rules)}", ok)
|
|
240
|
+
|
|
241
|
+
def _double_sales(self, name: str) -> str:
|
|
242
|
+
return self.create(name, f"SELECT department, headcount, CASE WHEN department = 'Sales' "
|
|
243
|
+
f"THEN CAST(total_salary * 2 AS DECIMAL(18, 2)) ELSE total_salary END AS total_salary, avg_salary "
|
|
244
|
+
f"FROM {self.q(self.mart)}")
|
|
245
|
+
|
|
246
|
+
def null_keys(self) -> ScenarioResult:
|
|
247
|
+
base = self.create("bsv_nulls", f"SELECT CASE WHEN i <= 2000 THEN NULL ELSE i END AS id, i AS v "
|
|
248
|
+
f"FROM ({self.ids(3000)}) ids")
|
|
249
|
+
cand = self.create("bsv_c_nulls", f"SELECT * FROM {self.q(base)}")
|
|
250
|
+
d = self.sentry.diff(base, cand, keys=["id"], table=base)
|
|
251
|
+
ok = (d.added_rows, d.removed_rows, d.changed_rows, d.unchanged_rows) == (0, 0, 0, 3000) and d.is_identical
|
|
252
|
+
return ScenarioResult("null_keys", "2,000 rows with a NULL key on each side of an unchanged table",
|
|
253
|
+
"matched one to one: 3,000 unchanged, nothing added or removed",
|
|
254
|
+
f"unchanged={d.unchanged_rows}, added={d.added_rows}, removed={d.removed_rows}", ok)
|
|
255
|
+
|
|
256
|
+
def exact_totals(self) -> ScenarioResult:
|
|
257
|
+
base = self.create("bsv_exact", f"SELECT i AS id, CAST(0.10 AS DECIMAL(18, 2)) AS amount "
|
|
258
|
+
f"FROM ({self.ids(self.exact_rows)}) ids")
|
|
259
|
+
cand = self.create("bsv_c_exact", f"SELECT * FROM {self.q(base)}")
|
|
260
|
+
d = self.sentry.diff(base, cand, keys=["id"], table=base)
|
|
261
|
+
want = round(self.exact_rows * 0.10, 2)
|
|
262
|
+
c = d.columns[0]
|
|
263
|
+
ok = c.base_sum == want and c.candidate_sum == want and c.sum_change_pct == 0
|
|
264
|
+
return ScenarioResult("exact_totals", f"add 0.10 {self.exact_rows:,} times (DECIMAL)",
|
|
265
|
+
f"exactly {want:,}", f"base={c.base_sum!r}, candidate={c.candidate_sum!r}", ok)
|
|
266
|
+
|
|
267
|
+
def landed_change(self) -> ScenarioResult:
|
|
268
|
+
attack = "a bad MERGE is committed to a Delta table; check-last-change runs afterwards"
|
|
269
|
+
if not self.db.supports_time_travel:
|
|
270
|
+
return ScenarioResult("landed_change", attack, "block + RESTORE", "skipped: needs Delta history", None)
|
|
271
|
+
tbl = self.create("bsv_landed", f"SELECT * FROM {self.q(self.mart)}")
|
|
272
|
+
self.db.execute(f"INSERT INTO {self.q(tbl)} SELECT * FROM {self.q(tbl)} WHERE department = 'Sales'")
|
|
273
|
+
a, change = self.sentry.check_change(tbl, keys=["department"])
|
|
274
|
+
t = a.tables[0]
|
|
275
|
+
ok = a.verdict == Verdict.BLOCK and (t.rollback or "").startswith("RESTORE") and t.diff.added_rows == 1
|
|
276
|
+
return ScenarioResult("landed_change", attack, "block, 1 added row, and the RESTORE to undo it",
|
|
277
|
+
f"{a.verdict.value}, added={t.diff.added_rows}, rollback={t.rollback}", ok)
|
|
278
|
+
|
|
279
|
+
def typo_table(self) -> ScenarioResult:
|
|
280
|
+
attack = "check-last-change on a mistyped table name"
|
|
281
|
+
if not self.db.supports_time_travel:
|
|
282
|
+
return ScenarioResult("typo_table", attack, "one-line 'not found'", "skipped: needs Delta history", None)
|
|
283
|
+
name = self.t("bsv_no_such_tabel")
|
|
284
|
+
try:
|
|
285
|
+
self.sentry.check_change(name, keys=["department"])
|
|
286
|
+
except ValueError as e:
|
|
287
|
+
msg = str(e)
|
|
288
|
+
ok = msg.startswith(f"Table {name} not found.") and "\n" not in msg
|
|
289
|
+
return ScenarioResult("typo_table", attack, "one clear line: 'Table … not found'", msg, ok)
|
|
290
|
+
return ScenarioResult("typo_table", attack, "one clear line: 'Table … not found'", "no error raised", False)
|
{bricksentry-0.1.23 → bricksentry-0.1.25}/templates/job-check/databricks_template_schema.json
RENAMED
|
@@ -86,10 +86,10 @@
|
|
|
86
86
|
},
|
|
87
87
|
"bricksentry_version": {
|
|
88
88
|
"type": "string",
|
|
89
|
-
"default": "0.1.
|
|
89
|
+
"default": "0.1.25",
|
|
90
90
|
"description": "bricksentry version to install in the job (pinned; change it and redeploy to upgrade)",
|
|
91
91
|
"pattern": "^\\d+\\.\\d+\\.\\d+$",
|
|
92
|
-
"pattern_match_failure_message": "Use a version like 0.1.
|
|
92
|
+
"pattern_match_failure_message": "Use a version like 0.1.25.",
|
|
93
93
|
"order": 10
|
|
94
94
|
}
|
|
95
95
|
},
|
|
@@ -119,3 +119,108 @@ def test_old_saved_assessments_still_load():
|
|
|
119
119
|
old = {"id": "abc", "verdict": "pass", "tables": [], "notify": []}
|
|
120
120
|
a = Assessment.from_dict(old)
|
|
121
121
|
assert a.created_at is None and a.policy_sha256 is None
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
# --- friendly errors for a mistyped table (found in a live test of 0.1.23) ---------
|
|
125
|
+
class _HistoryFails:
|
|
126
|
+
"""A Delta-like backend whose DESCRIBE HISTORY raises the given engine error."""
|
|
127
|
+
|
|
128
|
+
name = "fake"
|
|
129
|
+
supports_time_travel = True
|
|
130
|
+
|
|
131
|
+
def __init__(self, message):
|
|
132
|
+
self.message = message
|
|
133
|
+
|
|
134
|
+
def history(self, table, limit=50):
|
|
135
|
+
raise RuntimeError(self.message)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _check(message):
|
|
139
|
+
import pytest
|
|
140
|
+
|
|
141
|
+
from bricksentry.history import _read_history
|
|
142
|
+
|
|
143
|
+
with pytest.raises((ValueError, RuntimeError)) as e:
|
|
144
|
+
_read_history(_HistoryFails(message), "main.hr.employes", 50)
|
|
145
|
+
return e.value
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def test_typo_in_table_name_is_one_clear_line():
|
|
149
|
+
raw = ("[TABLE_OR_VIEW_NOT_FOUND] The table or view `main`.`hr`.`employes` cannot be found. "
|
|
150
|
+
"Verify the spelling and correctness of the schema and catalog.\nIf you did not qualify the "
|
|
151
|
+
"name with a schema, verify the current_schema() output, or qualify the name with the correct "
|
|
152
|
+
"schema and catalog.\nTo tolerate the error on drop use DROP VIEW IF EXISTS or DROP TABLE IF "
|
|
153
|
+
"EXISTS. SQLSTATE: 42P01; line 1 pos 17;\n'DescribeDeltaHistory ...")
|
|
154
|
+
e = _check(raw)
|
|
155
|
+
assert isinstance(e, ValueError)
|
|
156
|
+
assert str(e).startswith("Table main.hr.employes not found.")
|
|
157
|
+
assert "DROP VIEW" not in str(e) and "\n" not in str(e)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def test_permission_and_other_errors():
|
|
161
|
+
e = _check("[INSUFFICIENT_PERMISSIONS] User does not have SELECT on table")
|
|
162
|
+
assert isinstance(e, ValueError) and "No permission to read main.hr.employes" in str(e)
|
|
163
|
+
e = _check("something odd happened\nwith a long second line")
|
|
164
|
+
assert isinstance(e, RuntimeError)
|
|
165
|
+
assert str(e) == "Could not read the history of main.hr.employes: something odd happened"
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def test_job_task_reports_a_typo_cleanly():
|
|
169
|
+
from bricksentry.job import run
|
|
170
|
+
|
|
171
|
+
lines = []
|
|
172
|
+
raw = ("[TABLE_OR_VIEW_NOT_FOUND] The table or view `main`.`hr`.`employes` cannot be found.\n"
|
|
173
|
+
"To tolerate the error on drop use DROP VIEW IF EXISTS. SQLSTATE: 42P01")
|
|
174
|
+
code = run(["--tables", "main.hr.employes", "--key", "id"], backend=_HistoryFails(raw), out=lines.append)
|
|
175
|
+
assert code == 2
|
|
176
|
+
err = [ln for ln in lines if "ERROR" in ln]
|
|
177
|
+
assert err == ["main.hr.employes: ERROR Table main.hr.employes not found. Check the catalog, schema and "
|
|
178
|
+
"table name (they must match Unity Catalog exactly) and that you have SELECT on it."]
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def test_job_main_exits_without_the_ipython_exit_hint(monkeypatch):
|
|
182
|
+
import warnings
|
|
183
|
+
|
|
184
|
+
import pytest
|
|
185
|
+
|
|
186
|
+
from bricksentry import job
|
|
187
|
+
|
|
188
|
+
monkeypatch.setattr(job, "run", lambda argv=None: 1)
|
|
189
|
+
with warnings.catch_warnings(record=True) as caught:
|
|
190
|
+
warnings.simplefilter("default")
|
|
191
|
+
with pytest.raises(SystemExit) as e:
|
|
192
|
+
job.main([])
|
|
193
|
+
warnings.warn("To exit: use 'exit', 'quit', or Ctrl-D.", UserWarning, stacklevel=2) # IPython's hint
|
|
194
|
+
assert e.value.code == 1
|
|
195
|
+
assert not [w for w in caught if "To exit" in str(w.message)]
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
# --- the sample guard also runs when only the schema changed ----------------------
|
|
199
|
+
def test_sample_guard_runs_when_a_retyped_column_hides_changes(backend):
|
|
200
|
+
pred = backend.sample_predicate(["order_id"], 5)
|
|
201
|
+
outside = [r["order_id"] for r in backend.query(
|
|
202
|
+
f"SELECT order_id FROM sales.orders WHERE NOT ({pred}) ORDER BY order_id LIMIT 3")]
|
|
203
|
+
ids = ", ".join(map(str, outside))
|
|
204
|
+
# amount becomes VARCHAR (a schema change) and 3 values outside the sample change.
|
|
205
|
+
backend.execute(f"CREATE TABLE sales_ci.orders AS SELECT order_id, region, CAST(CASE WHEN order_id IN ({ids}) "
|
|
206
|
+
f"THEN amount * 5 ELSE amount END AS VARCHAR) AS amount, status FROM sales.orders")
|
|
207
|
+
d = diff_tables(backend, "sales.orders", "sales_ci.orders", ["order_id"], sample_pct=5)
|
|
208
|
+
assert "amount" in d.schema.type_changed
|
|
209
|
+
assert d.changed_rows == 3 and d.sample_note and "re-run on all rows" in d.sample_note
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
# --- the published validation battery -------------------------------------------
|
|
213
|
+
def test_validation_battery_passes_on_duckdb(backend):
|
|
214
|
+
from bricksentry.validation import print_results, run_validation
|
|
215
|
+
|
|
216
|
+
results = run_validation(backend, "bsv_test", rows=5000, exact_rows=100_000)
|
|
217
|
+
by = {r.name: r for r in results}
|
|
218
|
+
failed = [r.to_dict() for r in results if r.passed is False]
|
|
219
|
+
assert not failed, failed
|
|
220
|
+
assert {n for n, r in by.items() if r.passed is None} == {"landed_change", "typo_table"} # need Delta
|
|
221
|
+
assert by["hidden_in_sample"].passed and by["certified_totals_default"].actual.startswith("warn")
|
|
222
|
+
lines = []
|
|
223
|
+
print_results(results, out=lines.append)
|
|
224
|
+
assert lines[-1].startswith("8 passed, 0 failed, 2 skipped")
|
|
225
|
+
left = backend.query("SELECT table_name FROM information_schema.tables WHERE table_schema = 'bsv_test'")
|
|
226
|
+
assert left == [] # everything it made is dropped
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
bricksentry[databricks,mcp]==0.1.23
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{bricksentry-0.1.23 → bricksentry-0.1.25}/examples/databricks/bricksentry_check_my_table.ipynb
RENAMED
|
File without changes
|
|
File without changes
|
{bricksentry-0.1.23 → bricksentry-0.1.25}/examples/databricks/bricksentry_hr_walkthrough.ipynb
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{bricksentry-0.1.23 → bricksentry-0.1.25}/templates/job-check/template/{{.project_name}}/.gitignore
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|