truequery 0.1.1__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.1 → truequery-0.1.2}/PKG-INFO +1 -1
- {truequery-0.1.1 → truequery-0.1.2}/pyproject.toml +1 -1
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/__init__.py +1 -1
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/analyzers/project_checks.py +7 -143
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/analyzers/sql.py +6 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/cli.py +21 -4
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/engine.py +259 -24
- 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.1 → truequery-0.1.2}/src/truequery/hook.py +39 -6
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/project.py +2 -2
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/report.py +58 -12
- {truequery-0.1.1 → truequery-0.1.2}/.gitignore +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/LICENSE +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/NOTICE +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/README.md +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/analyzers/__init__.py +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/checks/__init__.py +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/checks/sql.py +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/keylookup.py +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/models.py +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/registry_impl.json +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/schema.py +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/settings.py +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/README.md +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/adhoc-limit-required.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/aggregate-before-export.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/consumer-cost-guard.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/consumer-reads-marts.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/dashboard-query-budget.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/dashboard-refresh-schedule.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/deterministic-export-order.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/explicit-timezone-consumers.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/explore-answer-carries-reproducible-query.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/explore-caveats-and-unchecked-stated.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/explore-day-boundaries-and-partial-periods.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/explore-experiment-readout-follows-plan.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/explore-freshness-and-coverage-checked.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/explore-inspect-distributions-and-examples.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/explore-join-row-count-checks.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/explore-null-aware-negative-filters.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/explore-question-metric-grain-stated.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/explore-rates-not-counts-across-segments.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/explore-reconcile-to-known-total.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/explore-reuse-governed-metric.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/export-row-cap.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/freshness-displayed.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/no-deep-offset.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/parameterized-dashboard-filters.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/reverse-etl-idempotent-keys.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/reverse-etl-pii-consent.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/consume/reverse-etl-schema-contract.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/dq/README.md +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/dq/accuracy-proxy-or-unmeasurable.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/dq/audits-blocking-every-run.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/dq/checks-versioned-with-code.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/dq/completeness-declare-missing-sentinels.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/dq/completeness-fill-rate-thresholds.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/dq/completeness-not-null-required-columns.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/dq/completeness-table-not-empty.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/dq/consistency-cross-column-row-rules.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/dq/consistency-no-orphan-keys.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/dq/consistency-paired-aggregate-reconciliation.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/dq/schema-conformance-checked-on-read.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/dq/unenforced-constraints-are-tested.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/dq/uniqueness-composite-grain.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/dq/uniqueness-key-no-duplicates.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/dq/unit-tests-with-fixtures.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/dq/validity-allowed-value-sets.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/dq/validity-enforce-model-contracts.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/dq/validity-range-format-type-rules.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/gov/README.md +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/gov/audit-columns-or-snapshots.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/gov/column-grants-for-pii.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/gov/declared-model-owner.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/gov/description-coverage-for-shared-models.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/gov/erasure-path-documented.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/gov/exposures-registered.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/gov/group-private-access.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/gov/least-privilege-grants.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/gov/lineage-from-declared-sources.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/gov/mesh-public-contracts-only.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/gov/no-bypassrls-roles.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/gov/no-public-privileges.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/gov/no-raw-pii-in-seeds.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/gov/pii-classification-declared.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/gov/production-pii-not-in-dev.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/gov/redacting-views-for-pii.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/gov/retention-declared.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/gov/row-policy-for-sensitive-tables.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/README.md +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/cap-intake-cost-and-volume.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/cdc-replica-identity-required.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/checkpoint-streaming-intake.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/choose-batch-vs-streaming-deliberately.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/declare-source-freshness.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/dedupe-on-natural-key-before-append.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/handle-schema-drift-explicitly.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/idempotent-batch-loads.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/isolate-source-failures.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/landing-rebuildable-from-source.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/monitor-cdc-lag-and-slots.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/pin-connector-and-schema-versions.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/pin-file-format-options.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/propagate-deletes-explicitly.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/quarantine-invalid-rows-at-intake.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/raw-landing-append-only.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/reconcile-row-counts-per-load.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/record-file-lineage-at-intake.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/reference-sources-not-raw-tables.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/require-completeness-marker.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/scan-pii-at-landing.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/seeds-small-static-only.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/test-intake-against-fixtures.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ingest/watermark-and-late-data-policy.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/model/README.md +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/model/dbt-contract-enforced.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/model/delete-handling-incremental.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/model/explicit-column-lists.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/model/full-refresh-parity.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/model/grain-preserved-joins.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/model/idempotent-reexec.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/model/incremental-lookback-window.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/model/incremental-watermark-filter.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/model/jinja-macro-determinism.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/model/jinja-no-nested-curlies.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/model/materialization-choice.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/model/merge-source-deduped.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/model/microbatch-event-time.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/model/null-join-keys-excluded.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/model/snapshot-scd2-validity.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/model/snapshot-strategy-choice.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/model/staging-no-business-logic.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/model/surrogate-keys-stable.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/model/unique-key-merge-key.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ops/README.md +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ops/breaking-change-categorization.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ops/ci-pr-checks-required.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ops/ci-slim-builds-only-changed.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ops/cost-estimate-before-run.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ops/cost-guardrail-confidence-levels.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ops/dev-environment-expiry.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ops/disposable-dev-environments.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ops/drift-detection-history-first.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ops/full-refresh-approval.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ops/model-versioning-breaking-changes.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ops/plan-preview-before-apply.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ops/post-deploy-data-validation.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ops/pre-destructive-snapshot.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ops/prod-credentials-isolation.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ops/run-artifact-retention.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/ops/staged-upgrades-with-backup.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/orch/README.md +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/orch/concurrency-pools-and-limits.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/orch/dag-ci-parse-and-unit-tests.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/orch/data-aware-scheduling-over-polling.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/orch/declared-asset-lineage.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/orch/deferrable-sensors-with-timeout.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/orch/explicit-catchup-policy.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/orch/explicit-schedule-timezone.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/orch/failure-alert-routing.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/orch/idempotent-backfill-windowing.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/orch/idempotent-retries-with-limits.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/orch/light-dag-parse-no-heavy-top-level.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/orch/no-circular-dependencies.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/orch/partitioned-assets-windowing.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/orch/sla-deadline-alerts.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/orch/task-atomicity-no-partial-writes.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/orch/task-timeout-execution-limit.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/py/README.md +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/py/airflow-isolate-task-dependencies.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/py/dagster-asset-declared-dependencies.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/py/dagster-io-manager-not-manual-io.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/py/dagster-resources-for-external-clients.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/py/dbt-python-model-contract.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/py/deterministic-model-outputs.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/py/hook-adapter-connection-lifecycle.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/py/idempotent-task-logic.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/py/no-n-plus-one-queries-in-loops.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/py/pandas-filter-before-collect.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/py/pandas-no-chained-assignment.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/py/pandas-no-row-loop-mutations.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/py/pin-pipeline-dependencies.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/py/sqlmesh-audit-python-outputs.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/py/sqlmesh-python-model-execution-context.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/README.md +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/aggregation-type-matches-additivity.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/conversion-metrics-window-bounds.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/count-distinct-uses-entity-key.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/cumulative-metrics-time-spine.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/derived-metrics-compose-from-governed.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/description-and-ownership-per-metric.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/dimension-naming-conventions.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/entity-primary-key-declared.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/join-paths-declared-via-entities.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/metric-filters-declared-not-hidden.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/metric-grain-declaration.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/metric-smoke-test-on-change.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/no-fanout-double-counting.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/no-metric-defined-off-staging.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/null-handling-in-aggregations.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/percentile-metrics-use-approximate.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/ratio-metrics-divide-after-aggregation.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/saved-query-canonical-slices.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/semantic-model-validates.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/single-governed-metric-definition.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/time-dimension-standardized.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sem/unit-consistency.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/README.md +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/accidental-cross-join.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/average-of-ratios.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/between-date-on-timestamp.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/case-without-else-in-aggregate.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/count-star-after-left-join.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/distinct-dedup-bandaid.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/explore-limit-is-not-a-sample.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/explore-profile-filter-columns.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/fanout-join-pre-aggregation.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/group-by-bare-column.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/insert-explicit-column-list.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/integer-division-truncation.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/keyset-pagination.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/left-join-null-rejecting-where.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/limit-requires-order-by.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/natural-join-explicit-keys.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/negative-filter-drops-nulls.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/nondeterministic-merge-keys.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/not-in-nullable-subquery.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/null-equality-comparison.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/random-sampling-no-sort.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/row-number-dedupe-tiebreaker.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/sargable-filter-bare-column.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/set-operation-column-position.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/unguarded-update-delete.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/sql/union-all-default.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/store/README.md +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/store/cluster-on-frequent-filters-joins.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/store/compact-small-files-optimize.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/store/declare-not-null-check-constraints.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/store/declare-sort-order-for-range-queries.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/store/enable-change-feed-for-incremental-consumers.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/store/evolve-partitions-by-metadata-not-rewrite.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/store/explicit-physical-types-no-implicit-casts.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/store/full-refresh-by-replace-not-delete-insert.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/store/incremental-watermark-partition-alignment.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/store/no-high-cardinality-partition-column.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/store/partition-expiration-retention-policy.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/store/partition-on-filter-column.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/store/partition-predicate-required.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/store/prefer-auto-liquid-clustering-over-manual-tune.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/store/rewrite-manifests-and-stats-periodically.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/store/single-open-format-per-medallion-layer.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/store/time-travel-retention-explicit.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/store/use-transient-temporary-for-ephemeral.yaml +0 -0
- {truequery-0.1.1 → truequery-0.1.2}/src/truequery/standard/store/vacuum-expire-snapshots-with-retention-floor.yaml +0 -0
- {truequery-0.1.1 → 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
|
|
|
@@ -215,149 +217,11 @@ def applies_to_file(path, text):
|
|
|
215
217
|
return False
|
|
216
218
|
|
|
217
219
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
# the string content decides, so a non-SQL use never matches.
|
|
224
|
-
SQL_CALL_NAMES = frozenset({
|
|
225
|
-
"execute", "executemany", "executescript", "exec_driver_sql",
|
|
226
|
-
"read_sql", "read_sql_query", "read_sql_table", "text", "sql",
|
|
227
|
-
})
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
def _strip_leading_sql_comments(s):
|
|
231
|
-
i, n = 0, len(s)
|
|
232
|
-
while True:
|
|
233
|
-
while i < n and s[i].isspace():
|
|
234
|
-
i += 1
|
|
235
|
-
if s.startswith("--", i):
|
|
236
|
-
j = s.find("\n", i)
|
|
237
|
-
i = n if j == -1 else j + 1
|
|
238
|
-
continue
|
|
239
|
-
if s.startswith("/*", i):
|
|
240
|
-
j = s.find("*/", i + 2)
|
|
241
|
-
if j == -1:
|
|
242
|
-
return ""
|
|
243
|
-
i = j + 2
|
|
244
|
-
continue
|
|
245
|
-
if i < n and s[i] == "#":
|
|
246
|
-
j = s.find("\n", i)
|
|
247
|
-
i = n if j == -1 else j + 1
|
|
248
|
-
continue
|
|
249
|
-
break
|
|
250
|
-
return s[i:]
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
def _starts_with_sql_keyword(s):
|
|
254
|
-
rest = _strip_leading_sql_comments(s)
|
|
255
|
-
upper = rest.upper()
|
|
256
|
-
for kw in SQL_KEYWORDS:
|
|
257
|
-
if upper.startswith(kw):
|
|
258
|
-
after = rest[len(kw):len(kw) + 1]
|
|
259
|
-
if not after or not (after.isalnum() or after == "_"):
|
|
260
|
-
return True
|
|
261
|
-
return False
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
def _lead_text(node):
|
|
265
|
-
"""Static leading text of a string expression, or None.
|
|
266
|
-
|
|
267
|
-
Constants give their value; f-strings give the literal prefix before
|
|
268
|
-
the first placeholder; `+` concatenation gives the left prefix (or the
|
|
269
|
-
right when the left has none). Anything dynamic yields None.
|
|
270
|
-
"""
|
|
271
|
-
if isinstance(node, ast.Constant) and isinstance(node.value, str):
|
|
272
|
-
return node.value
|
|
273
|
-
if isinstance(node, ast.JoinedStr):
|
|
274
|
-
parts = []
|
|
275
|
-
for value in node.values:
|
|
276
|
-
if isinstance(value, ast.Constant) and isinstance(
|
|
277
|
-
value.value, str):
|
|
278
|
-
parts.append(value.value)
|
|
279
|
-
else:
|
|
280
|
-
break
|
|
281
|
-
return "".join(parts) if parts else ""
|
|
282
|
-
if isinstance(node, ast.BinOp) and isinstance(node.op, ast.Add):
|
|
283
|
-
left = _lead_text(node.left)
|
|
284
|
-
if left:
|
|
285
|
-
return left
|
|
286
|
-
return _lead_text(node.right)
|
|
287
|
-
return None
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
def _node_is_sql_string(node):
|
|
291
|
-
lead = _lead_text(node)
|
|
292
|
-
return bool(lead) and _starts_with_sql_keyword(lead)
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
def _assigned_values(tree):
|
|
296
|
-
"""Name -> value nodes assigned to it in this file.
|
|
297
|
-
|
|
298
|
-
Only plain `name = value` and `name: type = value` with a single
|
|
299
|
-
`Name` target: same-file, by-name lookup. No data flow, no imports.
|
|
300
|
-
"""
|
|
301
|
-
out: dict[str, list] = {}
|
|
302
|
-
for node in ast.walk(tree):
|
|
303
|
-
if isinstance(node, ast.Assign) and len(node.targets) == 1:
|
|
304
|
-
target = node.targets[0]
|
|
305
|
-
if isinstance(target, ast.Name):
|
|
306
|
-
out.setdefault(target.id, []).append(node.value)
|
|
307
|
-
elif (isinstance(node, ast.AnnAssign)
|
|
308
|
-
and isinstance(node.target, ast.Name)
|
|
309
|
-
and node.value is not None):
|
|
310
|
-
out.setdefault(node.target.id, []).append(node.value)
|
|
311
|
-
return out
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
def _resolves_to_sql(node, assigned, seen=frozenset()):
|
|
315
|
-
"""True when a call-site argument is (or names) a SQL string.
|
|
316
|
-
|
|
317
|
-
A bare `Name` resolves to the string assigned to it in the same
|
|
318
|
-
file, then gets the same keyword test. Anything else (including a
|
|
319
|
-
docstring, which is never assigned or passed) never matches.
|
|
320
|
-
"""
|
|
321
|
-
if isinstance(node, ast.Name):
|
|
322
|
-
if node.id in seen:
|
|
323
|
-
return False
|
|
324
|
-
return any(_resolves_to_sql(value, assigned, seen | {node.id})
|
|
325
|
-
for value in assigned.get(node.id, []))
|
|
326
|
-
return _node_is_sql_string(node)
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
def has_embedded_sql(text):
|
|
330
|
-
"""True when a .py file holds SQL strings at known call sites.
|
|
331
|
-
|
|
332
|
-
Detection only: a string counts as SQL when it starts (after
|
|
333
|
-
whitespace and SQL comments) with a SQL keyword. A bare name at a
|
|
334
|
-
call site resolves to the string assigned to it in the same file.
|
|
335
|
-
The SQL inside is never parsed or checked here; callers list such
|
|
336
|
-
files as not checked.
|
|
337
|
-
"""
|
|
338
|
-
try:
|
|
339
|
-
tree = ast.parse(text)
|
|
340
|
-
except SyntaxError:
|
|
341
|
-
return False
|
|
342
|
-
assigned = _assigned_values(tree)
|
|
343
|
-
for node in ast.walk(tree):
|
|
344
|
-
if not isinstance(node, ast.Call):
|
|
345
|
-
continue
|
|
346
|
-
func = node.func
|
|
347
|
-
name = (func.id if isinstance(func, ast.Name)
|
|
348
|
-
else func.attr if isinstance(func, ast.Attribute) else "")
|
|
349
|
-
args = list(node.args)
|
|
350
|
-
for kw in node.keywords:
|
|
351
|
-
if kw.arg == "sql":
|
|
352
|
-
args.append(kw.value)
|
|
353
|
-
if not args:
|
|
354
|
-
continue
|
|
355
|
-
if name in SQL_CALL_NAMES or any(
|
|
356
|
-
kw.arg == "sql" for kw in node.keywords):
|
|
357
|
-
for arg in args:
|
|
358
|
-
if _resolves_to_sql(arg, assigned):
|
|
359
|
-
return True
|
|
360
|
-
return False
|
|
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
|
|
361
225
|
|
|
362
226
|
|
|
363
227
|
def check_python(text, path, mode="build", registry=None, settings=None):
|
|
@@ -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)
|
|
@@ -208,8 +208,18 @@ def cmd_detect(args: argparse.Namespace) -> int:
|
|
|
208
208
|
def _review_tables(results, dialect) -> list[str]:
|
|
209
209
|
# Only files the checker read: a skipped file (over the size limit,
|
|
210
210
|
# unparseable) is never opened again for the receipt.
|
|
211
|
-
|
|
212
|
-
|
|
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
|
|
213
223
|
|
|
214
224
|
|
|
215
225
|
def cmd_review(args: argparse.Namespace) -> int:
|
|
@@ -538,9 +548,12 @@ def cmd_ignore_add(args: argparse.Namespace) -> int:
|
|
|
538
548
|
except OSError:
|
|
539
549
|
print(f"truequery: no such file: {raw_path}", file=sys.stderr)
|
|
540
550
|
return EXIT_ERROR
|
|
541
|
-
spans = E.
|
|
551
|
+
spans = E.statement_spans(path, text, (config or {}).get("dialect"))
|
|
542
552
|
digest = E.stmt_hash_at(spans, line)
|
|
543
|
-
|
|
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)):
|
|
544
557
|
print(f"truequery: line {line} is not inside a SQL statement",
|
|
545
558
|
file=sys.stderr)
|
|
546
559
|
return EXIT_ERROR
|
|
@@ -558,6 +571,10 @@ def cmd_ignore_add(args: argparse.Namespace) -> int:
|
|
|
558
571
|
entry = {"rule": args.rule, "path": path, "line": line,
|
|
559
572
|
"stmt": digest, "offset": E.stmt_offset(spans, line),
|
|
560
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"]
|
|
561
578
|
if entry not in entries:
|
|
562
579
|
entries.append(entry)
|
|
563
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__
|
|
@@ -52,13 +54,17 @@ class FileResult:
|
|
|
52
54
|
suppressed: list = field(default_factory=list)
|
|
53
55
|
key_lookups: list = field(default_factory=list)
|
|
54
56
|
# "sql"; "project" for DAG/schema .py/.yml/.yaml files; "macro"
|
|
55
|
-
# for a file of dbt macro definitions; "
|
|
56
|
-
#
|
|
57
|
-
#
|
|
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.
|
|
58
61
|
kind: str = "sql"
|
|
59
|
-
# True when a
|
|
60
|
-
#
|
|
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.
|
|
61
65
|
embedded_sql: bool = False
|
|
66
|
+
# SQL fragments of a .py file (python_sql.Fragment), by position.
|
|
67
|
+
fragments: list = field(default_factory=list)
|
|
62
68
|
|
|
63
69
|
@property
|
|
64
70
|
def verified(self) -> bool:
|
|
@@ -75,6 +81,22 @@ def is_embedded(result: "FileResult") -> bool:
|
|
|
75
81
|
return result.kind == "embedded" or result.embedded_sql
|
|
76
82
|
|
|
77
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
|
+
|
|
78
100
|
def load_ignores(root: str) -> list[dict]:
|
|
79
101
|
"""Entries from .truequery/ignores.json: {rule, path, line?, reason?}.
|
|
80
102
|
|
|
@@ -213,6 +235,213 @@ def _aux_findings(text, path, mode, tiers, settings):
|
|
|
213
235
|
return kept
|
|
214
236
|
|
|
215
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
|
+
|
|
216
445
|
def check_file(path: str, dialect: str | None = None,
|
|
217
446
|
mode: str = "build", tiers=None,
|
|
218
447
|
settings=None, text: str | None = None
|
|
@@ -279,7 +508,8 @@ def _apply_ignores(result: FileResult, findings: list, spans, ignores) -> None:
|
|
|
279
508
|
suppressed by .truequery/ignores.json."""
|
|
280
509
|
for finding in findings:
|
|
281
510
|
finding.file = result.rel
|
|
282
|
-
finding
|
|
511
|
+
if getattr(finding, "_stmt", None) is None:
|
|
512
|
+
finding._stmt = stmt_hash_at(spans, finding.line)
|
|
283
513
|
entry = _suppressed_by(finding, result.rel, ignores, spans)
|
|
284
514
|
if entry is None:
|
|
285
515
|
result.findings.append(finding)
|
|
@@ -350,24 +580,29 @@ def run(paths: list[str], root: str, dialect: str | None = None,
|
|
|
350
580
|
continue
|
|
351
581
|
rel = P._rel(path, root)
|
|
352
582
|
file_mode = P.resolve_mode(rel, config, mode)
|
|
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)
|
|
353
588
|
if project_checks.applies_to_file(path, text):
|
|
354
|
-
# A DAG
|
|
355
|
-
#
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
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)
|
|
606
|
+
results.append(result)
|
|
372
607
|
results.sort(key=lambda r: r.rel)
|
|
373
608
|
return results
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Extractors: SQL written inside other kinds of files."""
|