truequery 0.1.0__tar.gz → 0.1.2__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.
- {truequery-0.1.0 → truequery-0.1.2}/PKG-INFO +1 -1
- {truequery-0.1.0 → truequery-0.1.2}/pyproject.toml +1 -1
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/__init__.py +1 -1
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/analyzers/project_checks.py +49 -4
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/analyzers/sql.py +6 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/cli.py +31 -9
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/engine.py +271 -9
- truequery-0.1.2/src/truequery/extractors/__init__.py +1 -0
- truequery-0.1.2/src/truequery/extractors/python_sql.py +1051 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/hook.py +39 -6
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/project.py +2 -2
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/report.py +66 -12
- {truequery-0.1.0 → truequery-0.1.2}/.gitignore +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/LICENSE +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/NOTICE +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/README.md +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/analyzers/__init__.py +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/checks/__init__.py +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/checks/sql.py +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/keylookup.py +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/models.py +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/registry_impl.json +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/schema.py +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/settings.py +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/README.md +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/adhoc-limit-required.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/aggregate-before-export.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/consumer-cost-guard.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/consumer-reads-marts.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/dashboard-query-budget.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/dashboard-refresh-schedule.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/deterministic-export-order.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/explicit-timezone-consumers.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/explore-answer-carries-reproducible-query.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/explore-caveats-and-unchecked-stated.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/explore-day-boundaries-and-partial-periods.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/explore-experiment-readout-follows-plan.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/explore-freshness-and-coverage-checked.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/explore-inspect-distributions-and-examples.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/explore-join-row-count-checks.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/explore-null-aware-negative-filters.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/explore-question-metric-grain-stated.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/explore-rates-not-counts-across-segments.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/explore-reconcile-to-known-total.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/explore-reuse-governed-metric.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/export-row-cap.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/freshness-displayed.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/no-deep-offset.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/parameterized-dashboard-filters.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/reverse-etl-idempotent-keys.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/reverse-etl-pii-consent.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/consume/reverse-etl-schema-contract.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/dq/README.md +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/dq/accuracy-proxy-or-unmeasurable.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/dq/audits-blocking-every-run.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/dq/checks-versioned-with-code.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/dq/completeness-declare-missing-sentinels.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/dq/completeness-fill-rate-thresholds.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/dq/completeness-not-null-required-columns.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/dq/completeness-table-not-empty.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/dq/consistency-cross-column-row-rules.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/dq/consistency-no-orphan-keys.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/dq/consistency-paired-aggregate-reconciliation.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/dq/schema-conformance-checked-on-read.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/dq/unenforced-constraints-are-tested.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/dq/uniqueness-composite-grain.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/dq/uniqueness-key-no-duplicates.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/dq/unit-tests-with-fixtures.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/dq/validity-allowed-value-sets.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/dq/validity-enforce-model-contracts.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/dq/validity-range-format-type-rules.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/gov/README.md +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/gov/audit-columns-or-snapshots.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/gov/column-grants-for-pii.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/gov/declared-model-owner.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/gov/description-coverage-for-shared-models.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/gov/erasure-path-documented.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/gov/exposures-registered.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/gov/group-private-access.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/gov/least-privilege-grants.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/gov/lineage-from-declared-sources.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/gov/mesh-public-contracts-only.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/gov/no-bypassrls-roles.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/gov/no-public-privileges.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/gov/no-raw-pii-in-seeds.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/gov/pii-classification-declared.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/gov/production-pii-not-in-dev.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/gov/redacting-views-for-pii.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/gov/retention-declared.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/gov/row-policy-for-sensitive-tables.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/README.md +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/cap-intake-cost-and-volume.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/cdc-replica-identity-required.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/checkpoint-streaming-intake.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/choose-batch-vs-streaming-deliberately.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/declare-source-freshness.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/dedupe-on-natural-key-before-append.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/handle-schema-drift-explicitly.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/idempotent-batch-loads.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/isolate-source-failures.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/landing-rebuildable-from-source.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/monitor-cdc-lag-and-slots.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/pin-connector-and-schema-versions.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/pin-file-format-options.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/propagate-deletes-explicitly.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/quarantine-invalid-rows-at-intake.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/raw-landing-append-only.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/reconcile-row-counts-per-load.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/record-file-lineage-at-intake.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/reference-sources-not-raw-tables.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/require-completeness-marker.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/scan-pii-at-landing.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/seeds-small-static-only.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/test-intake-against-fixtures.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ingest/watermark-and-late-data-policy.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/model/README.md +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/model/dbt-contract-enforced.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/model/delete-handling-incremental.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/model/explicit-column-lists.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/model/full-refresh-parity.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/model/grain-preserved-joins.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/model/idempotent-reexec.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/model/incremental-lookback-window.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/model/incremental-watermark-filter.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/model/jinja-macro-determinism.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/model/jinja-no-nested-curlies.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/model/materialization-choice.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/model/merge-source-deduped.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/model/microbatch-event-time.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/model/null-join-keys-excluded.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/model/snapshot-scd2-validity.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/model/snapshot-strategy-choice.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/model/staging-no-business-logic.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/model/surrogate-keys-stable.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/model/unique-key-merge-key.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ops/README.md +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ops/breaking-change-categorization.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ops/ci-pr-checks-required.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ops/ci-slim-builds-only-changed.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ops/cost-estimate-before-run.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ops/cost-guardrail-confidence-levels.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ops/dev-environment-expiry.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ops/disposable-dev-environments.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ops/drift-detection-history-first.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ops/full-refresh-approval.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ops/model-versioning-breaking-changes.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ops/plan-preview-before-apply.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ops/post-deploy-data-validation.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ops/pre-destructive-snapshot.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ops/prod-credentials-isolation.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ops/run-artifact-retention.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/ops/staged-upgrades-with-backup.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/orch/README.md +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/orch/concurrency-pools-and-limits.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/orch/dag-ci-parse-and-unit-tests.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/orch/data-aware-scheduling-over-polling.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/orch/declared-asset-lineage.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/orch/deferrable-sensors-with-timeout.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/orch/explicit-catchup-policy.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/orch/explicit-schedule-timezone.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/orch/failure-alert-routing.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/orch/idempotent-backfill-windowing.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/orch/idempotent-retries-with-limits.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/orch/light-dag-parse-no-heavy-top-level.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/orch/no-circular-dependencies.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/orch/partitioned-assets-windowing.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/orch/sla-deadline-alerts.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/orch/task-atomicity-no-partial-writes.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/orch/task-timeout-execution-limit.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/py/README.md +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/py/airflow-isolate-task-dependencies.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/py/dagster-asset-declared-dependencies.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/py/dagster-io-manager-not-manual-io.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/py/dagster-resources-for-external-clients.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/py/dbt-python-model-contract.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/py/deterministic-model-outputs.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/py/hook-adapter-connection-lifecycle.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/py/idempotent-task-logic.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/py/no-n-plus-one-queries-in-loops.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/py/pandas-filter-before-collect.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/py/pandas-no-chained-assignment.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/py/pandas-no-row-loop-mutations.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/py/pin-pipeline-dependencies.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/py/sqlmesh-audit-python-outputs.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/py/sqlmesh-python-model-execution-context.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/README.md +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/aggregation-type-matches-additivity.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/conversion-metrics-window-bounds.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/count-distinct-uses-entity-key.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/cumulative-metrics-time-spine.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/derived-metrics-compose-from-governed.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/description-and-ownership-per-metric.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/dimension-naming-conventions.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/entity-primary-key-declared.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/join-paths-declared-via-entities.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/metric-filters-declared-not-hidden.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/metric-grain-declaration.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/metric-smoke-test-on-change.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/no-fanout-double-counting.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/no-metric-defined-off-staging.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/null-handling-in-aggregations.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/percentile-metrics-use-approximate.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/ratio-metrics-divide-after-aggregation.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/saved-query-canonical-slices.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/semantic-model-validates.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/single-governed-metric-definition.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/time-dimension-standardized.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sem/unit-consistency.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/README.md +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/accidental-cross-join.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/average-of-ratios.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/between-date-on-timestamp.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/case-without-else-in-aggregate.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/count-star-after-left-join.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/distinct-dedup-bandaid.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/explore-limit-is-not-a-sample.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/explore-profile-filter-columns.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/fanout-join-pre-aggregation.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/group-by-bare-column.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/insert-explicit-column-list.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/integer-division-truncation.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/keyset-pagination.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/left-join-null-rejecting-where.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/limit-requires-order-by.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/natural-join-explicit-keys.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/negative-filter-drops-nulls.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/nondeterministic-merge-keys.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/not-in-nullable-subquery.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/null-equality-comparison.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/random-sampling-no-sort.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/row-number-dedupe-tiebreaker.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/sargable-filter-bare-column.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/set-operation-column-position.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/unguarded-update-delete.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/sql/union-all-default.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/store/README.md +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/store/cluster-on-frequent-filters-joins.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/store/compact-small-files-optimize.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/store/declare-not-null-check-constraints.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/store/declare-sort-order-for-range-queries.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/store/enable-change-feed-for-incremental-consumers.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/store/evolve-partitions-by-metadata-not-rewrite.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/store/explicit-physical-types-no-implicit-casts.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/store/full-refresh-by-replace-not-delete-insert.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/store/incremental-watermark-partition-alignment.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/store/no-high-cardinality-partition-column.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/store/partition-expiration-retention-policy.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/store/partition-on-filter-column.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/store/partition-predicate-required.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/store/prefer-auto-liquid-clustering-over-manual-tune.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/store/rewrite-manifests-and-stats-periodically.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/store/single-open-format-per-medallion-layer.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/store/time-travel-retention-explicit.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/store/use-transient-temporary-for-ephemeral.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/standard/store/vacuum-expire-snapshots-with-retention-floor.yaml +0 -0
- {truequery-0.1.0 → truequery-0.1.2}/src/truequery/std_registry.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: truequery
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: TrueQuery engine: offline, deterministic checks for SQL that silently returns the wrong answer
|
|
5
5
|
Project-URL: Homepage, https://github.com/Analytically-ai/truequery
|
|
6
6
|
Project-URL: Issues, https://github.com/Analytically-ai/truequery/issues
|
|
@@ -7,7 +7,7 @@ build-backend = "hatchling.build"
|
|
|
7
7
|
|
|
8
8
|
[project]
|
|
9
9
|
name = "truequery"
|
|
10
|
-
version = "0.1.
|
|
10
|
+
version = "0.1.2"
|
|
11
11
|
description = "TrueQuery engine: offline, deterministic checks for SQL that silently returns the wrong answer"
|
|
12
12
|
readme = "README.md"
|
|
13
13
|
requires-python = ">=3.11"
|
|
@@ -12,6 +12,8 @@ import re
|
|
|
12
12
|
|
|
13
13
|
import yaml
|
|
14
14
|
|
|
15
|
+
from truequery.extractors import python_sql
|
|
16
|
+
|
|
15
17
|
INCREMENTAL = re.compile(r"materialized\s*=\s*['\"]incremental['\"]")
|
|
16
18
|
UNIQUE_KEY = re.compile(r"unique_key\s*=")
|
|
17
19
|
|
|
@@ -168,13 +170,14 @@ def check_schema_yaml(text, path, mode="build", registry=None,
|
|
|
168
170
|
return out
|
|
169
171
|
|
|
170
172
|
|
|
171
|
-
def
|
|
172
|
-
"""
|
|
173
|
-
|
|
173
|
+
def _dag_calls(text):
|
|
174
|
+
"""Airflow DAG call nodes; the one detection check_python and
|
|
175
|
+
applies_to_file share so counting can't drift from checking."""
|
|
174
176
|
try:
|
|
175
177
|
tree = ast.parse(text)
|
|
176
178
|
except SyntaxError:
|
|
177
|
-
return
|
|
179
|
+
return []
|
|
180
|
+
out = []
|
|
178
181
|
for node in ast.walk(tree):
|
|
179
182
|
if not isinstance(node, ast.Call):
|
|
180
183
|
continue
|
|
@@ -183,6 +186,48 @@ def check_python(text, path, mode="build", registry=None, settings=None):
|
|
|
183
186
|
else func.attr if isinstance(func, ast.Attribute) else "")
|
|
184
187
|
if name not in ("DAG", "dag"): # DAG(...), models.DAG, @dag(...)
|
|
185
188
|
continue
|
|
189
|
+
out.append(node)
|
|
190
|
+
return out
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _schema_doc(text):
|
|
194
|
+
"""Parsed YAML mapping, or None when it isn't one."""
|
|
195
|
+
try:
|
|
196
|
+
doc = yaml.safe_load(text)
|
|
197
|
+
except Exception:
|
|
198
|
+
return None
|
|
199
|
+
return doc if isinstance(doc, dict) else None
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def applies_to_file(path, text):
|
|
203
|
+
"""True when a preview project check applies to this file.
|
|
204
|
+
|
|
205
|
+
A .py file counts only when it's an Airflow DAG; a YAML file
|
|
206
|
+
counts only when it's a dbt schema/sources file or dbt_project.yml.
|
|
207
|
+
Detection mirrors check_python/check_schema_yaml so the receipt
|
|
208
|
+
never counts a file no check reads.
|
|
209
|
+
"""
|
|
210
|
+
if path.endswith(".py"):
|
|
211
|
+
return bool(_dag_calls(text))
|
|
212
|
+
if path.endswith((".yml", ".yaml")):
|
|
213
|
+
if os.path.basename(path) == "dbt_project.yml":
|
|
214
|
+
return True
|
|
215
|
+
doc = _schema_doc(text)
|
|
216
|
+
return doc is not None and ("models" in doc or "sources" in doc)
|
|
217
|
+
return False
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
# SQL inside Python: detection and extraction live in one place
|
|
221
|
+
# (truequery.extractors.python_sql); re-exported for older callers.
|
|
222
|
+
SQL_KEYWORDS = python_sql.SQL_KEYWORDS
|
|
223
|
+
SQL_CALL_NAMES = python_sql.SQL_CALL_NAMES
|
|
224
|
+
has_embedded_sql = python_sql.has_embedded_sql
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def check_python(text, path, mode="build", registry=None, settings=None):
|
|
228
|
+
"""orch/explicit-catchup-policy: Airflow DAG without catchup."""
|
|
229
|
+
out = []
|
|
230
|
+
for node in _dag_calls(text):
|
|
186
231
|
kws = {k.arg for k in node.keywords if k.arg}
|
|
187
232
|
if "catchup" in kws:
|
|
188
233
|
continue
|
|
@@ -329,6 +329,9 @@ class Locator:
|
|
|
329
329
|
nth = self.used.get((rule, None), 0)
|
|
330
330
|
off = self._locate_anchor(rule, nth)
|
|
331
331
|
self.used[(rule, None)] = nth + 1
|
|
332
|
+
# Offset inside the statement text, for callers that map
|
|
333
|
+
# positions back to another file (SQL inside Python).
|
|
334
|
+
self.last_offset = off
|
|
332
335
|
pre = self.text[:off]
|
|
333
336
|
return (self.start_line + pre.count("\n"),
|
|
334
337
|
off - (pre.rfind("\n") + 1) + 1)
|
|
@@ -489,7 +492,9 @@ def check_text(text, dialect=None, path="<input>", mode="build", registry=None,
|
|
|
489
492
|
active = _active_checks(registry, settings, tiers, include_disabled)
|
|
490
493
|
ctx = checks.CheckContext(dialect=dialect, path=path, mode=mode,
|
|
491
494
|
keys=keylookup.declared_keys_for(path))
|
|
495
|
+
base = 0 # offset of the chunk in the cleaned text (chunks are contiguous)
|
|
492
496
|
for chunk, start_line in chunks:
|
|
497
|
+
chunk_base, base = base, base + len(chunk)
|
|
493
498
|
try:
|
|
494
499
|
stmts = sqlglot.parse(chunk, read=dialect or None)
|
|
495
500
|
except Exception as exc:
|
|
@@ -521,6 +526,7 @@ def check_text(text, dialect=None, path="<input>", mode="build", registry=None,
|
|
|
521
526
|
findings.append(_finding(
|
|
522
527
|
slug, _severity(record, setting, mode), mode, path,
|
|
523
528
|
chunk, start_line, line, col, why, fix))
|
|
529
|
+
findings[-1]["offset"] = chunk_base + loc.last_offset
|
|
524
530
|
for suppressed in loc.suppressed:
|
|
525
531
|
if suppressed not in key_lookups:
|
|
526
532
|
key_lookups.append(suppressed)
|
|
@@ -113,7 +113,8 @@ def _unverified_reason(results) -> str:
|
|
|
113
113
|
def _summary_line(results, findings) -> str:
|
|
114
114
|
"""Never print 'clean' unless every file was verified."""
|
|
115
115
|
macros = sum(1 for r in results if r.kind == "macro")
|
|
116
|
-
|
|
116
|
+
embedded = sum(1 for r in results if E.is_embedded(r))
|
|
117
|
+
results = [r for r in results if r.kind not in ("macro", "embedded")]
|
|
117
118
|
verified = sum(1 for r in results if r.verified)
|
|
118
119
|
unverified = len(results) - verified
|
|
119
120
|
checked = RP._plural(verified, "file")
|
|
@@ -122,12 +123,16 @@ def _summary_line(results, findings) -> str:
|
|
|
122
123
|
reason = _unverified_reason(results)
|
|
123
124
|
skipped = (f" · {RP._plural(macros, 'dbt macro file')} not checked "
|
|
124
125
|
"(macro definitions)") if macros else ""
|
|
126
|
+
embedded_note = (f" · SQL inside {RP._plural(embedded, 'Python file')} "
|
|
127
|
+
"not checked") if embedded else ""
|
|
125
128
|
if not findings:
|
|
126
129
|
if unverified:
|
|
127
130
|
return (f"no findings in {checked} checked{ignored} · "
|
|
128
|
-
f"{unverified} not checked ({reason})
|
|
129
|
-
|
|
130
|
-
|
|
131
|
+
f"{unverified} not checked ({reason})"
|
|
132
|
+
f"{skipped}{embedded_note}")
|
|
133
|
+
if skipped or embedded_note:
|
|
134
|
+
return (f"no findings in {checked} checked offline{ignored}"
|
|
135
|
+
f"{skipped}{embedded_note}")
|
|
131
136
|
if hidden:
|
|
132
137
|
return f"no findings in {checked} checked offline{ignored}"
|
|
133
138
|
return f"clean: {checked} checked offline, no findings"
|
|
@@ -139,7 +144,7 @@ def _summary_line(results, findings) -> str:
|
|
|
139
144
|
line = f"{', '.join(counts)} in {checked} checked offline{ignored}"
|
|
140
145
|
if unverified:
|
|
141
146
|
line += f" ({unverified} not checked: {reason})"
|
|
142
|
-
return line + skipped
|
|
147
|
+
return line + skipped + embedded_note
|
|
143
148
|
|
|
144
149
|
|
|
145
150
|
def _dialect_arg(value: str) -> str | None:
|
|
@@ -203,8 +208,18 @@ def cmd_detect(args: argparse.Namespace) -> int:
|
|
|
203
208
|
def _review_tables(results, dialect) -> list[str]:
|
|
204
209
|
# Only files the checker read: a skipped file (over the size limit,
|
|
205
210
|
# unparseable) is never opened again for the receipt.
|
|
206
|
-
|
|
207
|
-
|
|
211
|
+
tables = P.tables_in_files([r.path for r in results
|
|
212
|
+
if r.kind == "sql" and r.verified], dialect)
|
|
213
|
+
seen = {t.lower() for t in tables}
|
|
214
|
+
for result in results: # the SQL checked inside Python files
|
|
215
|
+
for frag in result.fragments:
|
|
216
|
+
if not frag.checked:
|
|
217
|
+
continue
|
|
218
|
+
for table in P.referenced_tables(frag.sql, dialect):
|
|
219
|
+
if table.lower() not in seen:
|
|
220
|
+
seen.add(table.lower())
|
|
221
|
+
tables.append(table)
|
|
222
|
+
return tables
|
|
208
223
|
|
|
209
224
|
|
|
210
225
|
def cmd_review(args: argparse.Namespace) -> int:
|
|
@@ -533,9 +548,12 @@ def cmd_ignore_add(args: argparse.Namespace) -> int:
|
|
|
533
548
|
except OSError:
|
|
534
549
|
print(f"truequery: no such file: {raw_path}", file=sys.stderr)
|
|
535
550
|
return EXIT_ERROR
|
|
536
|
-
spans = E.
|
|
551
|
+
spans = E.statement_spans(path, text, (config or {}).get("dialect"))
|
|
537
552
|
digest = E.stmt_hash_at(spans, line)
|
|
538
|
-
|
|
553
|
+
# Outside any SQL statement, only an Airflow DAG has findings a line
|
|
554
|
+
# ignore can cover (the DAG check).
|
|
555
|
+
if digest is None and not (path.endswith(".py") and
|
|
556
|
+
E.project_checks.applies_to_file(path, text)):
|
|
539
557
|
print(f"truequery: line {line} is not inside a SQL statement",
|
|
540
558
|
file=sys.stderr)
|
|
541
559
|
return EXIT_ERROR
|
|
@@ -553,6 +571,10 @@ def cmd_ignore_add(args: argparse.Namespace) -> int:
|
|
|
553
571
|
entry = {"rule": args.rule, "path": path, "line": line,
|
|
554
572
|
"stmt": digest, "offset": E.stmt_offset(spans, line),
|
|
555
573
|
"reason": args.reason.strip()}
|
|
574
|
+
if digest is None:
|
|
575
|
+
# A Python line outside its SQL (an Airflow DAG finding): that
|
|
576
|
+
# one line, matched by rule + file + line.
|
|
577
|
+
del entry["stmt"], entry["offset"]
|
|
556
578
|
if entry not in entries:
|
|
557
579
|
entries.append(entry)
|
|
558
580
|
with open(ignores_path, "w", encoding="utf-8") as handle:
|
|
@@ -7,6 +7,7 @@ results in a stable order. Zero network, zero LLM in this path.
|
|
|
7
7
|
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
10
|
+
import difflib
|
|
10
11
|
import fnmatch
|
|
11
12
|
import hashlib
|
|
12
13
|
import json
|
|
@@ -20,6 +21,7 @@ from truequery import settings as S
|
|
|
20
21
|
from truequery import std_registry
|
|
21
22
|
from truequery.analyzers import project_checks
|
|
22
23
|
from truequery.analyzers import sql as analyzer
|
|
24
|
+
from truequery.extractors import python_sql
|
|
23
25
|
from truequery.models import Diagnostic, Finding
|
|
24
26
|
|
|
25
27
|
ENGINE_VERSION = __version__
|
|
@@ -51,15 +53,50 @@ class FileResult:
|
|
|
51
53
|
diagnostics: list = field(default_factory=list)
|
|
52
54
|
suppressed: list = field(default_factory=list)
|
|
53
55
|
key_lookups: list = field(default_factory=list)
|
|
54
|
-
# "sql"; "project" for .py/.yml/.yaml files; "macro"
|
|
55
|
-
# dbt macro definitions
|
|
56
|
+
# "sql"; "project" for DAG/schema .py/.yml/.yaml files; "macro"
|
|
57
|
+
# for a file of dbt macro definitions; "python" for a .py file with
|
|
58
|
+
# at least one checked SQL fragment; "embedded" for a .py file whose
|
|
59
|
+
# SQL fragments were all left unchecked. Macro and embedded files are
|
|
60
|
+
# listed as not checked.
|
|
56
61
|
kind: str = "sql"
|
|
62
|
+
# True when a .py result holds SQL that wasn't checked (built at run
|
|
63
|
+
# time, or doesn't parse). A counted result (a DAG, a Python file
|
|
64
|
+
# with other checked SQL) stays counted and is also listed.
|
|
65
|
+
embedded_sql: bool = False
|
|
66
|
+
# SQL fragments of a .py file (python_sql.Fragment), by position.
|
|
67
|
+
fragments: list = field(default_factory=list)
|
|
57
68
|
|
|
58
69
|
@property
|
|
59
70
|
def verified(self) -> bool:
|
|
60
71
|
return not self.diagnostics
|
|
61
72
|
|
|
62
73
|
|
|
74
|
+
def is_embedded(result: "FileResult") -> bool:
|
|
75
|
+
"""One source of truth for "this result's SQL is not checked".
|
|
76
|
+
|
|
77
|
+
Covers the standalone embedded kind and any counted result (a DAG)
|
|
78
|
+
that also holds embedded SQL, so the receipt, JSON and summary
|
|
79
|
+
can't drift apart.
|
|
80
|
+
"""
|
|
81
|
+
return result.kind == "embedded" or result.embedded_sql
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def fragment_counts(result: "FileResult") -> dict:
|
|
85
|
+
"""{checked, dynamic, unparsed} fragment counts for a .py result."""
|
|
86
|
+
counts = {"checked": 0, "dynamic": 0, "unparsed": 0}
|
|
87
|
+
for frag in result.fragments:
|
|
88
|
+
counts["checked" if frag.checked else frag.status] += 1
|
|
89
|
+
return counts
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def unchecked_reasons(result: "FileResult") -> list[str]:
|
|
93
|
+
"""Why some of a .py result's SQL wasn't checked, in a fixed order."""
|
|
94
|
+
statuses = {frag.status for frag in result.fragments}
|
|
95
|
+
return [python_sql.REASONS[s] for s in (python_sql.DYNAMIC,
|
|
96
|
+
python_sql.UNPARSED)
|
|
97
|
+
if s in statuses]
|
|
98
|
+
|
|
99
|
+
|
|
63
100
|
def load_ignores(root: str) -> list[dict]:
|
|
64
101
|
"""Entries from .truequery/ignores.json: {rule, path, line?, reason?}.
|
|
65
102
|
|
|
@@ -198,6 +235,213 @@ def _aux_findings(text, path, mode, tiers, settings):
|
|
|
198
235
|
return kept
|
|
199
236
|
|
|
200
237
|
|
|
238
|
+
def python_dialect(dialect: str | None, extraction) -> str | None:
|
|
239
|
+
"""--dialect, then DATA.md (both already in `dialect`), then the
|
|
240
|
+
file's imports, then auto."""
|
|
241
|
+
return dialect or extraction.dialect
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
_FROM = re.compile(r"\bfrom\b", re.IGNORECASE)
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def _reads_as_prose(sql: str, dialect: str | None) -> bool:
|
|
248
|
+
"""True for text that parses only by accident: a lone SELECT of bare
|
|
249
|
+
words, no FROM and no other clause ("Select an option" is SELECT an
|
|
250
|
+
AS option). Columns with no table can't run, so it isn't SQL."""
|
|
251
|
+
if _FROM.search(sql):
|
|
252
|
+
return False
|
|
253
|
+
import sqlglot
|
|
254
|
+
from sqlglot import exp
|
|
255
|
+
try:
|
|
256
|
+
stmts = sqlglot.parse(analyzer.strip_comments(sql, "generic"),
|
|
257
|
+
read=dialect or None)
|
|
258
|
+
except Exception:
|
|
259
|
+
return False
|
|
260
|
+
placeholders = (python_sql.PLACEHOLDER, analyzer.JINJA_PH)
|
|
261
|
+
for stmt in stmts:
|
|
262
|
+
if not isinstance(stmt, exp.Select) or any(
|
|
263
|
+
stmt.args.get(k) for k in ("from", "where", "group",
|
|
264
|
+
"having", "order", "limit")):
|
|
265
|
+
continue
|
|
266
|
+
cols = []
|
|
267
|
+
for item in stmt.expressions:
|
|
268
|
+
item = item.this if isinstance(item, exp.Alias) else item
|
|
269
|
+
if not isinstance(item, exp.Column):
|
|
270
|
+
break
|
|
271
|
+
cols.append(item)
|
|
272
|
+
else:
|
|
273
|
+
if cols and not any(c.name.startswith(placeholders)
|
|
274
|
+
for c in cols):
|
|
275
|
+
return True
|
|
276
|
+
return False
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
# Rules that report something missing (a condition, a tiebreaker). Where
|
|
280
|
+
# a template placeholder stands for that whole part (`WHERE {cond}`,
|
|
281
|
+
# `ON {join}`, `OVER (ORDER BY {order})`), the real text is unknown, so
|
|
282
|
+
# these can't say it's missing.
|
|
283
|
+
_CONDITION_RULES = frozenset({"sql/unguarded-update-delete",
|
|
284
|
+
"sql/accidental-cross-join"})
|
|
285
|
+
_ORDER_RULES = frozenset({"sql/row-number-dedupe-tiebreaker"})
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
_TRAILING_PLACEHOLDER = re.compile(
|
|
289
|
+
re.escape(python_sql.PLACEHOLDER) + r"\d+(?=[\s;]*$)")
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def _is_placeholder(node) -> bool:
|
|
293
|
+
from sqlglot import exp
|
|
294
|
+
return (isinstance(node, exp.Column)
|
|
295
|
+
and node.name.startswith(python_sql.PLACEHOLDER))
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def _unknown_parts(sql: str, dialect: str | None) -> dict:
|
|
299
|
+
"""{rule: [(first, last) SQL lines]} of statements where a placeholder
|
|
300
|
+
stands for the part that rule looks for."""
|
|
301
|
+
import sqlglot
|
|
302
|
+
from sqlglot import exp
|
|
303
|
+
cleaned = analyzer.strip_comments(analyzer.strip_jinja(sql),
|
|
304
|
+
dialect or "generic")
|
|
305
|
+
out: dict[str, list] = {}
|
|
306
|
+
for chunk, start in analyzer.split_statements(cleaned):
|
|
307
|
+
try:
|
|
308
|
+
stmts = sqlglot.parse(chunk, read=dialect or None)
|
|
309
|
+
except Exception:
|
|
310
|
+
continue
|
|
311
|
+
span = (start, start + chunk.count("\n"))
|
|
312
|
+
for stmt in stmts:
|
|
313
|
+
if stmt is None:
|
|
314
|
+
continue
|
|
315
|
+
# A placeholder after the target, standing for a whole clause
|
|
316
|
+
# (`DELETE FROM t {where}`): it parses as a table alias, or it
|
|
317
|
+
# is the statement's last token without being a table name.
|
|
318
|
+
# A trailing placeholder that is a table name (`DELETE FROM
|
|
319
|
+
# {t}`) or a value (`SET a = {v}`) is not a clause.
|
|
320
|
+
tail = _TRAILING_PLACEHOLDER.search(chunk)
|
|
321
|
+
if tail:
|
|
322
|
+
name = tail.group(0)
|
|
323
|
+
if name in {t.name for t in stmt.find_all(exp.Table)} or any(
|
|
324
|
+
c.name == name and isinstance(
|
|
325
|
+
c.parent, (exp.Binary, exp.Func, exp.Tuple))
|
|
326
|
+
for c in stmt.find_all(exp.Column)):
|
|
327
|
+
tail = None
|
|
328
|
+
if tail or any(a.name.startswith(python_sql.PLACEHOLDER)
|
|
329
|
+
for a in stmt.find_all(exp.TableAlias)):
|
|
330
|
+
for rule in _CONDITION_RULES:
|
|
331
|
+
out.setdefault(rule, []).append(span)
|
|
332
|
+
for col in stmt.find_all(exp.Column):
|
|
333
|
+
if not _is_placeholder(col):
|
|
334
|
+
continue
|
|
335
|
+
parent = col.parent
|
|
336
|
+
while isinstance(parent, exp.Paren):
|
|
337
|
+
parent = parent.parent
|
|
338
|
+
if (isinstance(parent, (exp.Where, exp.Having, exp.And,
|
|
339
|
+
exp.Or, exp.Not))
|
|
340
|
+
or (isinstance(parent, exp.Join)
|
|
341
|
+
and parent.args.get("on") is col)):
|
|
342
|
+
for rule in _CONDITION_RULES:
|
|
343
|
+
out.setdefault(rule, []).append(span)
|
|
344
|
+
if isinstance(parent, exp.Ordered) and isinstance(
|
|
345
|
+
parent.parent, exp.Order) and isinstance(
|
|
346
|
+
parent.parent.parent, exp.Window):
|
|
347
|
+
for rule in _ORDER_RULES:
|
|
348
|
+
out.setdefault(rule, []).append(span)
|
|
349
|
+
return out
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
def _original_offset(sql: str, cleaned: str, offset: int) -> int:
|
|
353
|
+
"""Map an offset in the analyzer's cleaned text back to the fragment's
|
|
354
|
+
own text. Cleaning keeps every newline, so the line is exact; within
|
|
355
|
+
the line, Jinja (`{{ ds }}` -> one placeholder, `{{ ref('x') }}` ->
|
|
356
|
+
`x`) changes lengths, so the column is aligned on the unchanged text
|
|
357
|
+
around it. Inside a replaced tag, the tag's start."""
|
|
358
|
+
if len(sql) == len(cleaned) and "{" not in sql:
|
|
359
|
+
return offset # nothing changed length
|
|
360
|
+
offset = min(max(offset, 0), len(cleaned))
|
|
361
|
+
row = cleaned.count("\n", 0, offset)
|
|
362
|
+
c_start = cleaned.rfind("\n", 0, offset) + 1
|
|
363
|
+
starts = [0] + [i + 1 for i, ch in enumerate(sql) if ch == "\n"]
|
|
364
|
+
o_start = starts[min(row, len(starts) - 1)]
|
|
365
|
+
c_line = cleaned[c_start:].split("\n", 1)[0]
|
|
366
|
+
o_line = sql[o_start:].split("\n", 1)[0]
|
|
367
|
+
col = offset - c_start
|
|
368
|
+
if c_line == o_line:
|
|
369
|
+
return o_start + col
|
|
370
|
+
matcher = difflib.SequenceMatcher(None, c_line, o_line, autojunk=False)
|
|
371
|
+
for tag, i1, i2, j1, j2 in matcher.get_opcodes():
|
|
372
|
+
if i1 <= col < i2 or (col == i2 == len(c_line)):
|
|
373
|
+
return o_start + (j1 + (col - i1) if tag == "equal" else j1)
|
|
374
|
+
return o_start
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
def check_python_source(text: str, path: str, dialect: str | None = None,
|
|
378
|
+
mode: str = "build", tiers=None, settings=None,
|
|
379
|
+
extraction=None):
|
|
380
|
+
"""(findings, fragments, spans) for the SQL inside one .py file.
|
|
381
|
+
|
|
382
|
+
Each static/templated fragment goes through the same SQL checks as a
|
|
383
|
+
.sql file; one that doesn't parse becomes `unparsed` (listed, never
|
|
384
|
+
a parse failure: detection is a heuristic). Findings point at the
|
|
385
|
+
Python line and column where the SQL is written; spans are per
|
|
386
|
+
statement, in Python lines, so ignores stay attached when lines
|
|
387
|
+
above move. File-level dbt checks don't apply to fragments.
|
|
388
|
+
"""
|
|
389
|
+
if extraction is None:
|
|
390
|
+
extraction = python_sql.extract(text)
|
|
391
|
+
dialect = python_dialect(dialect, extraction)
|
|
392
|
+
findings, spans = [], []
|
|
393
|
+
for frag in extraction.fragments:
|
|
394
|
+
if not frag.checked:
|
|
395
|
+
continue
|
|
396
|
+
res = analyzer.check_text(frag.sql, dialect=dialect, path=path,
|
|
397
|
+
mode=mode, tiers=tiers, settings=settings)
|
|
398
|
+
prose = not res["diagnostics"] and _reads_as_prose(frag.sql, dialect)
|
|
399
|
+
if prose:
|
|
400
|
+
res["findings"] = [] # not SQL: nothing it says is a finding
|
|
401
|
+
if res["diagnostics"] or prose:
|
|
402
|
+
# Not checked (in full). Findings from statements of it that
|
|
403
|
+
# did parse are still real and still reported.
|
|
404
|
+
frag.status = python_sql.UNPARSED
|
|
405
|
+
frag.reason = python_sql.REASONS[python_sql.UNPARSED]
|
|
406
|
+
if frag.status == python_sql.TEMPLATED and any(
|
|
407
|
+
f["rule"] in _CONDITION_RULES | _ORDER_RULES
|
|
408
|
+
for f in res["findings"]):
|
|
409
|
+
unknown = _unknown_parts(frag.sql, dialect)
|
|
410
|
+
res["findings"] = [
|
|
411
|
+
f for f in res["findings"]
|
|
412
|
+
if not any(a <= f["line"] <= b
|
|
413
|
+
for a, b in unknown.get(f["rule"], ()))]
|
|
414
|
+
sql_spans = _chunk_hashes(frag.sql, dialect)
|
|
415
|
+
for first, last, digest in sql_spans:
|
|
416
|
+
spans.append((*frag.python_lines(first, last), digest))
|
|
417
|
+
cleaned = analyzer.strip_comments(analyzer.strip_jinja(frag.sql),
|
|
418
|
+
dialect or "generic")
|
|
419
|
+
for f in res["findings"]:
|
|
420
|
+
if "offset" in f:
|
|
421
|
+
line, col = frag.at_offset(
|
|
422
|
+
_original_offset(frag.sql, cleaned, f["offset"]))
|
|
423
|
+
else:
|
|
424
|
+
line, col = frag.at(f["line"], f["col"])
|
|
425
|
+
finding = Finding(rule=f["rule"], severity=f["severity"],
|
|
426
|
+
mode=f["mode"], evidence=f["evidence"],
|
|
427
|
+
file=path, line=line, col=col,
|
|
428
|
+
snippet=frag.show(f["snippet"]),
|
|
429
|
+
why=frag.show(f["why"]),
|
|
430
|
+
fix=frag.show(f["fix"]))
|
|
431
|
+
finding._stmt = stmt_hash_at(sql_spans, f["line"])
|
|
432
|
+
findings.append(finding)
|
|
433
|
+
findings.sort(key=Finding.sort_key)
|
|
434
|
+
return findings, extraction.fragments, spans
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
def statement_spans(path: str, text: str, dialect: str | None) -> list:
|
|
438
|
+
"""Statement spans for ignores and baselines: per SQL statement in a
|
|
439
|
+
SQL file, per statement of each SQL fragment in a .py file."""
|
|
440
|
+
if path.endswith(".py"):
|
|
441
|
+
return check_python_source(text, path, dialect)[2]
|
|
442
|
+
return _chunk_hashes(text, dialect)
|
|
443
|
+
|
|
444
|
+
|
|
201
445
|
def check_file(path: str, dialect: str | None = None,
|
|
202
446
|
mode: str = "build", tiers=None,
|
|
203
447
|
settings=None, text: str | None = None
|
|
@@ -264,7 +508,8 @@ def _apply_ignores(result: FileResult, findings: list, spans, ignores) -> None:
|
|
|
264
508
|
suppressed by .truequery/ignores.json."""
|
|
265
509
|
for finding in findings:
|
|
266
510
|
finding.file = result.rel
|
|
267
|
-
finding
|
|
511
|
+
if getattr(finding, "_stmt", None) is None:
|
|
512
|
+
finding._stmt = stmt_hash_at(spans, finding.line)
|
|
268
513
|
entry = _suppressed_by(finding, result.rel, ignores, spans)
|
|
269
514
|
if entry is None:
|
|
270
515
|
result.findings.append(finding)
|
|
@@ -335,12 +580,29 @@ def run(paths: list[str], root: str, dialect: str | None = None,
|
|
|
335
580
|
continue
|
|
336
581
|
rel = P._rel(path, root)
|
|
337
582
|
file_mode = P.resolve_mode(rel, config, mode)
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
583
|
+
findings, fragments, spans = [], [], []
|
|
584
|
+
if path.endswith(".py"):
|
|
585
|
+
findings, fragments, spans = check_python_source(
|
|
586
|
+
text, path, base_dialect, file_mode, tiers, settings)
|
|
587
|
+
unchecked = any(not f.checked for f in fragments)
|
|
588
|
+
if project_checks.applies_to_file(path, text):
|
|
589
|
+
# A DAG stays a project file (the project check really ran
|
|
590
|
+
# on it); its SQL is checked like any Python SQL, and SQL it
|
|
591
|
+
# couldn't check is also listed.
|
|
592
|
+
kind = "project"
|
|
593
|
+
findings += _aux_findings(text, path, file_mode, tiers, settings)
|
|
594
|
+
elif any(f.checked for f in fragments):
|
|
595
|
+
kind = "python"
|
|
596
|
+
elif fragments:
|
|
597
|
+
# Every fragment unchecked: listed as not checked, not counted.
|
|
598
|
+
kind = "embedded"
|
|
599
|
+
else:
|
|
600
|
+
continue # other .py and YAML files apply to no check
|
|
601
|
+
result = FileResult(path=path, rel=rel, mode=file_mode, kind=kind,
|
|
602
|
+
embedded_sql=unchecked, fragments=fragments)
|
|
603
|
+
# Python SQL matches ignores per statement; project findings
|
|
604
|
+
# (outside any statement) on rule + file + line.
|
|
605
|
+
_apply_ignores(result, findings, spans, ignores)
|
|
344
606
|
results.append(result)
|
|
345
607
|
results.sort(key=lambda r: r.rel)
|
|
346
608
|
return results
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Extractors: SQL written inside other kinds of files."""
|