truequery 0.1.1__tar.gz → 0.1.3__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.
Files changed (256) hide show
  1. {truequery-0.1.1 → truequery-0.1.3}/PKG-INFO +1 -1
  2. {truequery-0.1.1 → truequery-0.1.3}/pyproject.toml +1 -1
  3. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/__init__.py +1 -1
  4. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/analyzers/project_checks.py +7 -143
  5. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/analyzers/sql.py +161 -0
  6. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/checks/sql.py +113 -4
  7. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/cli.py +23 -4
  8. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/engine.py +263 -24
  9. truequery-0.1.3/src/truequery/extractors/__init__.py +1 -0
  10. truequery-0.1.3/src/truequery/extractors/python_sql.py +1051 -0
  11. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/hook.py +40 -6
  12. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/project.py +2 -2
  13. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/report.py +58 -12
  14. {truequery-0.1.1 → truequery-0.1.3}/.gitignore +0 -0
  15. {truequery-0.1.1 → truequery-0.1.3}/LICENSE +0 -0
  16. {truequery-0.1.1 → truequery-0.1.3}/NOTICE +0 -0
  17. {truequery-0.1.1 → truequery-0.1.3}/README.md +0 -0
  18. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/analyzers/__init__.py +0 -0
  19. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/checks/__init__.py +0 -0
  20. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/keylookup.py +0 -0
  21. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/models.py +0 -0
  22. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/registry_impl.json +0 -0
  23. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/schema.py +0 -0
  24. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/settings.py +0 -0
  25. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/README.md +0 -0
  26. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/adhoc-limit-required.yaml +0 -0
  27. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/aggregate-before-export.yaml +0 -0
  28. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/consumer-cost-guard.yaml +0 -0
  29. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/consumer-reads-marts.yaml +0 -0
  30. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/dashboard-query-budget.yaml +0 -0
  31. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/dashboard-refresh-schedule.yaml +0 -0
  32. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/deterministic-export-order.yaml +0 -0
  33. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/explicit-timezone-consumers.yaml +0 -0
  34. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/explore-answer-carries-reproducible-query.yaml +0 -0
  35. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/explore-caveats-and-unchecked-stated.yaml +0 -0
  36. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/explore-day-boundaries-and-partial-periods.yaml +0 -0
  37. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/explore-experiment-readout-follows-plan.yaml +0 -0
  38. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/explore-freshness-and-coverage-checked.yaml +0 -0
  39. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/explore-inspect-distributions-and-examples.yaml +0 -0
  40. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/explore-join-row-count-checks.yaml +0 -0
  41. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/explore-null-aware-negative-filters.yaml +0 -0
  42. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/explore-question-metric-grain-stated.yaml +0 -0
  43. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/explore-rates-not-counts-across-segments.yaml +0 -0
  44. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/explore-reconcile-to-known-total.yaml +0 -0
  45. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/explore-reuse-governed-metric.yaml +0 -0
  46. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/export-row-cap.yaml +0 -0
  47. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/freshness-displayed.yaml +0 -0
  48. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/no-deep-offset.yaml +0 -0
  49. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/parameterized-dashboard-filters.yaml +0 -0
  50. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/reverse-etl-idempotent-keys.yaml +0 -0
  51. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/reverse-etl-pii-consent.yaml +0 -0
  52. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/consume/reverse-etl-schema-contract.yaml +0 -0
  53. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/dq/README.md +0 -0
  54. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/dq/accuracy-proxy-or-unmeasurable.yaml +0 -0
  55. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/dq/audits-blocking-every-run.yaml +0 -0
  56. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/dq/checks-versioned-with-code.yaml +0 -0
  57. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/dq/completeness-declare-missing-sentinels.yaml +0 -0
  58. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/dq/completeness-fill-rate-thresholds.yaml +0 -0
  59. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/dq/completeness-not-null-required-columns.yaml +0 -0
  60. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/dq/completeness-table-not-empty.yaml +0 -0
  61. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/dq/consistency-cross-column-row-rules.yaml +0 -0
  62. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/dq/consistency-no-orphan-keys.yaml +0 -0
  63. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/dq/consistency-paired-aggregate-reconciliation.yaml +0 -0
  64. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/dq/schema-conformance-checked-on-read.yaml +0 -0
  65. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/dq/unenforced-constraints-are-tested.yaml +0 -0
  66. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/dq/uniqueness-composite-grain.yaml +0 -0
  67. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/dq/uniqueness-key-no-duplicates.yaml +0 -0
  68. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/dq/unit-tests-with-fixtures.yaml +0 -0
  69. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/dq/validity-allowed-value-sets.yaml +0 -0
  70. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/dq/validity-enforce-model-contracts.yaml +0 -0
  71. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/dq/validity-range-format-type-rules.yaml +0 -0
  72. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/gov/README.md +0 -0
  73. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/gov/audit-columns-or-snapshots.yaml +0 -0
  74. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/gov/column-grants-for-pii.yaml +0 -0
  75. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/gov/declared-model-owner.yaml +0 -0
  76. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/gov/description-coverage-for-shared-models.yaml +0 -0
  77. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/gov/erasure-path-documented.yaml +0 -0
  78. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/gov/exposures-registered.yaml +0 -0
  79. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/gov/group-private-access.yaml +0 -0
  80. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/gov/least-privilege-grants.yaml +0 -0
  81. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/gov/lineage-from-declared-sources.yaml +0 -0
  82. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/gov/mesh-public-contracts-only.yaml +0 -0
  83. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/gov/no-bypassrls-roles.yaml +0 -0
  84. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/gov/no-public-privileges.yaml +0 -0
  85. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/gov/no-raw-pii-in-seeds.yaml +0 -0
  86. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/gov/pii-classification-declared.yaml +0 -0
  87. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/gov/production-pii-not-in-dev.yaml +0 -0
  88. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/gov/redacting-views-for-pii.yaml +0 -0
  89. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/gov/retention-declared.yaml +0 -0
  90. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/gov/row-policy-for-sensitive-tables.yaml +0 -0
  91. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/README.md +0 -0
  92. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/cap-intake-cost-and-volume.yaml +0 -0
  93. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/cdc-replica-identity-required.yaml +0 -0
  94. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/checkpoint-streaming-intake.yaml +0 -0
  95. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/choose-batch-vs-streaming-deliberately.yaml +0 -0
  96. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/declare-source-freshness.yaml +0 -0
  97. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/dedupe-on-natural-key-before-append.yaml +0 -0
  98. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/handle-schema-drift-explicitly.yaml +0 -0
  99. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/idempotent-batch-loads.yaml +0 -0
  100. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/isolate-source-failures.yaml +0 -0
  101. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/landing-rebuildable-from-source.yaml +0 -0
  102. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/monitor-cdc-lag-and-slots.yaml +0 -0
  103. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/pin-connector-and-schema-versions.yaml +0 -0
  104. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/pin-file-format-options.yaml +0 -0
  105. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/propagate-deletes-explicitly.yaml +0 -0
  106. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/quarantine-invalid-rows-at-intake.yaml +0 -0
  107. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/raw-landing-append-only.yaml +0 -0
  108. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/reconcile-row-counts-per-load.yaml +0 -0
  109. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/record-file-lineage-at-intake.yaml +0 -0
  110. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/reference-sources-not-raw-tables.yaml +0 -0
  111. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/require-completeness-marker.yaml +0 -0
  112. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/scan-pii-at-landing.yaml +0 -0
  113. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/seeds-small-static-only.yaml +0 -0
  114. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/test-intake-against-fixtures.yaml +0 -0
  115. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ingest/watermark-and-late-data-policy.yaml +0 -0
  116. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/model/README.md +0 -0
  117. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/model/dbt-contract-enforced.yaml +0 -0
  118. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/model/delete-handling-incremental.yaml +0 -0
  119. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/model/explicit-column-lists.yaml +0 -0
  120. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/model/full-refresh-parity.yaml +0 -0
  121. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/model/grain-preserved-joins.yaml +0 -0
  122. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/model/idempotent-reexec.yaml +0 -0
  123. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/model/incremental-lookback-window.yaml +0 -0
  124. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/model/incremental-watermark-filter.yaml +0 -0
  125. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/model/jinja-macro-determinism.yaml +0 -0
  126. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/model/jinja-no-nested-curlies.yaml +0 -0
  127. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/model/materialization-choice.yaml +0 -0
  128. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/model/merge-source-deduped.yaml +0 -0
  129. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/model/microbatch-event-time.yaml +0 -0
  130. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/model/null-join-keys-excluded.yaml +0 -0
  131. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/model/snapshot-scd2-validity.yaml +0 -0
  132. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/model/snapshot-strategy-choice.yaml +0 -0
  133. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/model/staging-no-business-logic.yaml +0 -0
  134. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/model/surrogate-keys-stable.yaml +0 -0
  135. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/model/unique-key-merge-key.yaml +0 -0
  136. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ops/README.md +0 -0
  137. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ops/breaking-change-categorization.yaml +0 -0
  138. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ops/ci-pr-checks-required.yaml +0 -0
  139. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ops/ci-slim-builds-only-changed.yaml +0 -0
  140. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ops/cost-estimate-before-run.yaml +0 -0
  141. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ops/cost-guardrail-confidence-levels.yaml +0 -0
  142. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ops/dev-environment-expiry.yaml +0 -0
  143. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ops/disposable-dev-environments.yaml +0 -0
  144. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ops/drift-detection-history-first.yaml +0 -0
  145. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ops/full-refresh-approval.yaml +0 -0
  146. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ops/model-versioning-breaking-changes.yaml +0 -0
  147. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ops/plan-preview-before-apply.yaml +0 -0
  148. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ops/post-deploy-data-validation.yaml +0 -0
  149. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ops/pre-destructive-snapshot.yaml +0 -0
  150. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ops/prod-credentials-isolation.yaml +0 -0
  151. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ops/run-artifact-retention.yaml +0 -0
  152. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/ops/staged-upgrades-with-backup.yaml +0 -0
  153. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/orch/README.md +0 -0
  154. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/orch/concurrency-pools-and-limits.yaml +0 -0
  155. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/orch/dag-ci-parse-and-unit-tests.yaml +0 -0
  156. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/orch/data-aware-scheduling-over-polling.yaml +0 -0
  157. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/orch/declared-asset-lineage.yaml +0 -0
  158. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/orch/deferrable-sensors-with-timeout.yaml +0 -0
  159. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/orch/explicit-catchup-policy.yaml +0 -0
  160. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/orch/explicit-schedule-timezone.yaml +0 -0
  161. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/orch/failure-alert-routing.yaml +0 -0
  162. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/orch/idempotent-backfill-windowing.yaml +0 -0
  163. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/orch/idempotent-retries-with-limits.yaml +0 -0
  164. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/orch/light-dag-parse-no-heavy-top-level.yaml +0 -0
  165. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/orch/no-circular-dependencies.yaml +0 -0
  166. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/orch/partitioned-assets-windowing.yaml +0 -0
  167. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/orch/sla-deadline-alerts.yaml +0 -0
  168. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/orch/task-atomicity-no-partial-writes.yaml +0 -0
  169. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/orch/task-timeout-execution-limit.yaml +0 -0
  170. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/py/README.md +0 -0
  171. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/py/airflow-isolate-task-dependencies.yaml +0 -0
  172. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/py/dagster-asset-declared-dependencies.yaml +0 -0
  173. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/py/dagster-io-manager-not-manual-io.yaml +0 -0
  174. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/py/dagster-resources-for-external-clients.yaml +0 -0
  175. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/py/dbt-python-model-contract.yaml +0 -0
  176. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/py/deterministic-model-outputs.yaml +0 -0
  177. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/py/hook-adapter-connection-lifecycle.yaml +0 -0
  178. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/py/idempotent-task-logic.yaml +0 -0
  179. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/py/no-n-plus-one-queries-in-loops.yaml +0 -0
  180. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/py/pandas-filter-before-collect.yaml +0 -0
  181. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/py/pandas-no-chained-assignment.yaml +0 -0
  182. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/py/pandas-no-row-loop-mutations.yaml +0 -0
  183. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/py/pin-pipeline-dependencies.yaml +0 -0
  184. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/py/sqlmesh-audit-python-outputs.yaml +0 -0
  185. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/py/sqlmesh-python-model-execution-context.yaml +0 -0
  186. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/README.md +0 -0
  187. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/aggregation-type-matches-additivity.yaml +0 -0
  188. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/conversion-metrics-window-bounds.yaml +0 -0
  189. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/count-distinct-uses-entity-key.yaml +0 -0
  190. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/cumulative-metrics-time-spine.yaml +0 -0
  191. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/derived-metrics-compose-from-governed.yaml +0 -0
  192. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/description-and-ownership-per-metric.yaml +0 -0
  193. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/dimension-naming-conventions.yaml +0 -0
  194. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/entity-primary-key-declared.yaml +0 -0
  195. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/join-paths-declared-via-entities.yaml +0 -0
  196. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/metric-filters-declared-not-hidden.yaml +0 -0
  197. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/metric-grain-declaration.yaml +0 -0
  198. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/metric-smoke-test-on-change.yaml +0 -0
  199. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/no-fanout-double-counting.yaml +0 -0
  200. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/no-metric-defined-off-staging.yaml +0 -0
  201. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/null-handling-in-aggregations.yaml +0 -0
  202. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/percentile-metrics-use-approximate.yaml +0 -0
  203. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/ratio-metrics-divide-after-aggregation.yaml +0 -0
  204. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/saved-query-canonical-slices.yaml +0 -0
  205. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/semantic-model-validates.yaml +0 -0
  206. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/single-governed-metric-definition.yaml +0 -0
  207. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/time-dimension-standardized.yaml +0 -0
  208. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sem/unit-consistency.yaml +0 -0
  209. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/README.md +0 -0
  210. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/accidental-cross-join.yaml +0 -0
  211. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/average-of-ratios.yaml +0 -0
  212. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/between-date-on-timestamp.yaml +0 -0
  213. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/case-without-else-in-aggregate.yaml +0 -0
  214. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/count-star-after-left-join.yaml +0 -0
  215. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/distinct-dedup-bandaid.yaml +0 -0
  216. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/explore-limit-is-not-a-sample.yaml +0 -0
  217. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/explore-profile-filter-columns.yaml +0 -0
  218. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/fanout-join-pre-aggregation.yaml +0 -0
  219. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/group-by-bare-column.yaml +0 -0
  220. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/insert-explicit-column-list.yaml +0 -0
  221. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/integer-division-truncation.yaml +0 -0
  222. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/keyset-pagination.yaml +0 -0
  223. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/left-join-null-rejecting-where.yaml +0 -0
  224. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/limit-requires-order-by.yaml +0 -0
  225. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/natural-join-explicit-keys.yaml +0 -0
  226. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/negative-filter-drops-nulls.yaml +0 -0
  227. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/nondeterministic-merge-keys.yaml +0 -0
  228. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/not-in-nullable-subquery.yaml +0 -0
  229. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/null-equality-comparison.yaml +0 -0
  230. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/random-sampling-no-sort.yaml +0 -0
  231. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/row-number-dedupe-tiebreaker.yaml +0 -0
  232. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/sargable-filter-bare-column.yaml +0 -0
  233. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/set-operation-column-position.yaml +0 -0
  234. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/unguarded-update-delete.yaml +0 -0
  235. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/sql/union-all-default.yaml +0 -0
  236. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/store/README.md +0 -0
  237. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/store/cluster-on-frequent-filters-joins.yaml +0 -0
  238. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/store/compact-small-files-optimize.yaml +0 -0
  239. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/store/declare-not-null-check-constraints.yaml +0 -0
  240. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/store/declare-sort-order-for-range-queries.yaml +0 -0
  241. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/store/enable-change-feed-for-incremental-consumers.yaml +0 -0
  242. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/store/evolve-partitions-by-metadata-not-rewrite.yaml +0 -0
  243. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/store/explicit-physical-types-no-implicit-casts.yaml +0 -0
  244. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/store/full-refresh-by-replace-not-delete-insert.yaml +0 -0
  245. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/store/incremental-watermark-partition-alignment.yaml +0 -0
  246. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/store/no-high-cardinality-partition-column.yaml +0 -0
  247. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/store/partition-expiration-retention-policy.yaml +0 -0
  248. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/store/partition-on-filter-column.yaml +0 -0
  249. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/store/partition-predicate-required.yaml +0 -0
  250. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/store/prefer-auto-liquid-clustering-over-manual-tune.yaml +0 -0
  251. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/store/rewrite-manifests-and-stats-periodically.yaml +0 -0
  252. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/store/single-open-format-per-medallion-layer.yaml +0 -0
  253. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/store/time-travel-retention-explicit.yaml +0 -0
  254. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/store/use-transient-temporary-for-ephemeral.yaml +0 -0
  255. {truequery-0.1.1 → truequery-0.1.3}/src/truequery/standard/store/vacuum-expire-snapshots-with-retention-floor.yaml +0 -0
  256. {truequery-0.1.1 → truequery-0.1.3}/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.1
3
+ Version: 0.1.3
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.1"
10
+ version = "0.1.3"
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"
@@ -1,3 +1,3 @@
1
1
  """TrueQuery: one standard for data work, enforced on every edit."""
2
2
 
3
- __version__ = "0.1.1"
3
+ __version__ = "0.1.3"
@@ -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
- SQL_KEYWORDS = ("SELECT", "WITH", "INSERT", "UPDATE", "DELETE", "MERGE",
219
- "CREATE", "REPLACE", "DROP")
220
-
221
- # Call sites where a string literal is plausibly SQL. Matched by function
222
- # name only (pd.read_sql, conn.execute, spark.sql, sqlalchemy text, ...);
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):
@@ -8,9 +8,12 @@ attaches no node positions, so each rule searches its statement text
8
8
  for its own anchor (documented approximation, good to the statement
9
9
  and usually the line).
10
10
  """
11
+ import contextlib
12
+ import logging
11
13
  import re
12
14
 
13
15
  import sqlglot
16
+ from sqlglot import exp as _exp
14
17
 
15
18
  from truequery import std_registry
16
19
  from truequery.checks import sql as checks
@@ -329,6 +332,9 @@ class Locator:
329
332
  nth = self.used.get((rule, None), 0)
330
333
  off = self._locate_anchor(rule, nth)
331
334
  self.used[(rule, None)] = nth + 1
335
+ # Offset inside the statement text, for callers that map
336
+ # positions back to another file (SQL inside Python).
337
+ self.last_offset = off
332
338
  pre = self.text[:off]
333
339
  return (self.start_line + pre.count("\n"),
334
340
  off - (pre.rfind("\n") + 1) + 1)
@@ -398,6 +404,145 @@ class Locator:
398
404
  _ANSI = re.compile(r"\x1b\[[0-9;]*m")
399
405
 
400
406
 
407
+ # -- statements sqlglot reads only as a Command ------------------------------
408
+ # For syntax it doesn't support, sqlglot doesn't raise: it keeps the text
409
+ # as an opaque exp.Command, and no check can see inside one. Whether that
410
+ # leaves something unchecked depends on what the statement is, judged on
411
+ # its leading keywords. The lists below are the whole policy.
412
+ #
413
+ # Statements that hold a query or a data change: every check is about
414
+ # these, so reading one only as a Command skipped them. That is a parse
415
+ # failure (the file is not checked; in Python the fragment is unparsed).
416
+ _DATA_HEADS = frozenset({
417
+ "SELECT", "WITH", "VALUES", "TABLE", "FROM", # queries (TABLE t, FROM-first)
418
+ "INSERT", "UPDATE", "DELETE", "MERGE", "REPLACE", "UPSERT", "COPY",
419
+ "EXPLAIN", # wraps a query; EXPLAIN ANALYZE also runs it
420
+ "PREPARE", # PREPARE p AS <query>
421
+ "DECLARE", # DECLARE c CURSOR FOR <query>
422
+ "DO", # an anonymous block of statements
423
+ "CACHE", # Spark CACHE TABLE t AS <query>
424
+ })
425
+ # CREATE / ALTER of these objects can hold a query: CREATE TABLE … AS,
426
+ # a view's query, a function, procedure, rule, trigger or macro body, a
427
+ # scheduled task's statement. A plain CREATE TABLE is here too: the
428
+ # Command's text can't show that no AS <query> follows.
429
+ _DATA_OBJECTS = frozenset({"TABLE", "VIEW", "FUNCTION", "PROCEDURE",
430
+ "ROUTINE", "RULE", "TRIGGER", "MACRO", "TASK"})
431
+ _ALTER_DATA_OBJECTS = frozenset({"VIEW"}) # ALTER VIEW v AS <query>
432
+
433
+ # Statements no check applies to: session and transaction control,
434
+ # permissions, maintenance, and schema objects that hold no query. A
435
+ # Command here skipped nothing, so it is no diagnostic.
436
+ _NO_CHECK_HEADS = frozenset({
437
+ "SET", "RESET", "SHOW", "USE", "PRAGMA", # session
438
+ "BEGIN", "START", "COMMIT", "END", "ROLLBACK", "ABORT", # transactions
439
+ "SAVEPOINT", "RELEASE",
440
+ "GRANT", "REVOKE", "DENY", "REASSIGN", # permissions
441
+ "VACUUM", "ANALYZE", "OPTIMIZE", "REINDEX", "CLUSTER", # maintenance
442
+ "CHECKPOINT", "DISCARD", "LOCK", "UNLOCK", "REFRESH", "MSCK", "KILL",
443
+ "SYSTEM",
444
+ "COMMENT", "SECURITY", # COMMENT ON, SECURITY LABEL
445
+ "LISTEN", "NOTIFY", "UNLISTEN", "LOAD", "ATTACH", "DETACH",
446
+ "DESCRIBE", "DESC",
447
+ # Run something already defined, or move a cursor: no query text here.
448
+ "CALL", "EXECUTE", "EXEC", "DEALLOCATE", "FETCH", "MOVE", "CLOSE",
449
+ "DROP", # removes an object; never holds a query
450
+ "TRUNCATE", # removes every row on purpose; no check is about it
451
+ })
452
+ _NO_CHECK_OBJECTS = frozenset({
453
+ "INDEX", "STATISTICS", "EXTENSION", "SCHEMA", "DATABASE", "SEQUENCE",
454
+ "TYPE", "DOMAIN", "COLLATION", "CAST", "OPERATOR", "AGGREGATE", "TEXT",
455
+ "ROLE", "USER", "GROUP", "POLICY", "PUBLICATION", "SUBSCRIPTION",
456
+ "SERVER", "FOREIGN", "EVENT", "ACCESS", "CONVERSION", "LANGUAGE",
457
+ "TABLESPACE", "TRANSFORM", "SECRET", "STAGE",
458
+ "VIRTUAL", # SQLite VIRTUAL TABLE … USING module(...)
459
+ "KEYSPACE", "CUSTOM", "AUTHORIZATION", "MAPPING", # Cassandra, Teradata, Hazelcast
460
+ })
461
+ # Words between CREATE / ALTER and the object they name.
462
+ _OBJECT_MODIFIERS = frozenset({
463
+ "OR", "REPLACE", "ALTER", "IF", "NOT", "EXISTS", "TEMP", "TEMPORARY",
464
+ "UNLOGGED", "GLOBAL", "LOCAL", "MATERIALIZED", "RECURSIVE", "TRANSIENT",
465
+ "SECURE", "VOLATILE", "EXTERNAL", "DYNAMIC", "ICEBERG", "HYBRID",
466
+ "MULTISET", "UNIQUE", "CONCURRENTLY", "CONSTRAINT", "DEFAULT",
467
+ "TRUSTED", "PROCEDURAL",
468
+ })
469
+ # Anything not named on either side is treated as holding a query: an
470
+ # unknown statement is not checked, never silently clean. (ClickHouse
471
+ # CREATE DICTIONARY is left unknown on purpose: its SOURCE can be a query.)
472
+
473
+ _WORD = re.compile(r"[A-Za-z_][A-Za-z_0-9]*")
474
+
475
+
476
+ def _command_words(stmt):
477
+ rest = stmt.expression
478
+ if isinstance(rest, _exp.Literal):
479
+ rest = rest.name
480
+ elif isinstance(rest, _exp.Expression):
481
+ rest = rest.sql()
482
+ return [w.upper() for w in _WORD.findall(f"{stmt.this or ''} {rest or ''}")]
483
+
484
+
485
+ def command_holds_query(stmt) -> bool:
486
+ """True when a Command statement is one a check would have looked at
487
+ (see the lists above)."""
488
+ words = _command_words(stmt)
489
+ if not words:
490
+ return False
491
+ head = words[0]
492
+ if head in ("CREATE", "ALTER"):
493
+ obj = next((w for w in words[1:] if w not in _OBJECT_MODIFIERS), "")
494
+ if head == "ALTER":
495
+ return obj in _ALTER_DATA_OBJECTS
496
+ if obj in _DATA_OBJECTS:
497
+ return True
498
+ return obj not in _NO_CHECK_OBJECTS
499
+ if head in _DATA_HEADS:
500
+ return True
501
+ return head not in _NO_CHECK_HEADS
502
+
503
+
504
+ def unread_detail(stmt):
505
+ """Why a statement wasn't checked, or None when it was: a query or
506
+ data change that parsed only as an opaque Command."""
507
+ if not isinstance(stmt, _exp.Command) or not command_holds_query(stmt):
508
+ return None
509
+ words = _command_words(stmt)
510
+ what = " ".join(words[:2]) if words[0] in ("CREATE", "ALTER") \
511
+ else words[0]
512
+ return (f"unsupported syntax: this {what} statement could be read "
513
+ "only as an opaque command, so no check looked inside it")
514
+
515
+
516
+ def _command_line(chunk, stmt, start_line, after):
517
+ """(line, end) of a Command statement in its chunk, searching from
518
+ `after`: its first words, any spacing. The chunk's first line when
519
+ they can't be found."""
520
+ words = _command_words(stmt)[:3]
521
+ pattern = r"\b" + r"\W+".join(map(re.escape, words)) + r"\b"
522
+ hit = re.compile(pattern, re.IGNORECASE).search(chunk, after)
523
+ if hit is None:
524
+ rows = chunk.split("\n")
525
+ first = next((i for i, row in enumerate(rows) if row.strip()), 0)
526
+ return start_line + first, after
527
+ return start_line + chunk.count("\n", 0, hit.start()), hit.end()
528
+
529
+
530
+ @contextlib.contextmanager
531
+ def quiet_sqlglot():
532
+ """Hold sqlglot's logger at ERROR while checking. It warns 'contains
533
+ unsupported syntax' on stderr for every Command fallback, and the
534
+ checker's output must be only TrueQuery's. The level is restored
535
+ afterwards, so a host application's logging is left as it was."""
536
+ logger = logging.getLogger("sqlglot")
537
+ before = logger.level
538
+ if logger.getEffectiveLevel() < logging.ERROR:
539
+ logger.setLevel(logging.ERROR)
540
+ try:
541
+ yield
542
+ finally:
543
+ logger.setLevel(before)
544
+
545
+
401
546
  def _parse_diagnostic(start_line, chunk, exc):
402
547
  """One clean agent-facing line + full detail for --json/--verbose.
403
548
 
@@ -471,6 +616,7 @@ def _active_checks(registry, settings, tiers, include_disabled):
471
616
  INTDIV = "sql/integer-division-truncation"
472
617
 
473
618
 
619
+ @quiet_sqlglot()
474
620
  def check_text(text, dialect=None, path="<input>", mode="build", registry=None,
475
621
  include_disabled=False, tiers=None, settings=None):
476
622
  """Run enabled file-level checks. Returns {path, findings,
@@ -489,7 +635,9 @@ def check_text(text, dialect=None, path="<input>", mode="build", registry=None,
489
635
  active = _active_checks(registry, settings, tiers, include_disabled)
490
636
  ctx = checks.CheckContext(dialect=dialect, path=path, mode=mode,
491
637
  keys=keylookup.declared_keys_for(path))
638
+ base = 0 # offset of the chunk in the cleaned text (chunks are contiguous)
492
639
  for chunk, start_line in chunks:
640
+ chunk_base, base = base, base + len(chunk)
493
641
  try:
494
642
  stmts = sqlglot.parse(chunk, read=dialect or None)
495
643
  except Exception as exc:
@@ -511,9 +659,21 @@ def check_text(text, dialect=None, path="<input>", mode="build", registry=None,
511
659
  diagnostics.append(_parse_diagnostic(start_line + first, chunk,
512
660
  exc))
513
661
  continue
662
+ searched = 0
514
663
  for stmt in stmts:
515
664
  if stmt is None:
516
665
  continue
666
+ detail = unread_detail(stmt)
667
+ if detail is not None:
668
+ # A query read only as an opaque Command: not checked,
669
+ # like any parse failure. The chunk's other statements
670
+ # still are.
671
+ line, searched = _command_line(chunk, stmt, start_line,
672
+ searched)
673
+ diagnostics.append({
674
+ "message": f"line {line}: could not parse (not checked)",
675
+ "detail": detail})
676
+ continue
517
677
  loc = Locator(chunk, start_line)
518
678
  for slug, check, record, setting in active:
519
679
  for node, why, fix in check(stmt, loc, ctx):
@@ -521,6 +681,7 @@ def check_text(text, dialect=None, path="<input>", mode="build", registry=None,
521
681
  findings.append(_finding(
522
682
  slug, _severity(record, setting, mode), mode, path,
523
683
  chunk, start_line, line, col, why, fix))
684
+ findings[-1]["offset"] = chunk_base + loc.last_offset
524
685
  for suppressed in loc.suppressed:
525
686
  if suppressed not in key_lookups:
526
687
  key_lookups.append(suppressed)
@@ -377,7 +377,7 @@ def accidental_cross_join(stmt, loc, ctx):
377
377
  if join.args.get("using"):
378
378
  continue # JOIN ... USING names explicit keys
379
379
  right_alias = _alias_key(join.this)
380
- sel = _owning_select(join)
380
+ sel = _join_scope(join)
381
381
  others = _from_keys(sel, join, right_alias) if sel is not None else set()
382
382
  if _is_correlated(join.this, others, ctx.dialect):
383
383
  continue # LATERAL / function over earlier columns: linked
@@ -445,8 +445,48 @@ def _qualifiers(node):
445
445
  return {_ident_key(c.args.get("table")) for c in node.find_all(exp.Column)}
446
446
 
447
447
 
448
+ def _join_scope(join):
449
+ """The query level a join belongs to: its SELECT, or the UPDATE /
450
+ DELETE whose FROM / USING holds it. sqlglot hangs Postgres
451
+ `UPDATE t ... FROM a JOIN b` and `DELETE FROM t USING a JOIN b`
452
+ joins on the FROM / USING table, with no SELECT around them."""
453
+ node = getattr(join, "parent", None)
454
+ while node is not None:
455
+ if isinstance(node, exp.Select):
456
+ return node
457
+ if isinstance(node, (exp.Update, exp.Delete)):
458
+ return node
459
+ node = getattr(node, "parent", None)
460
+ return None
461
+
462
+
463
+ def _dml_from_keys(dml, join, this_alias):
464
+ """Alias keys an UPDATE / DELETE join can link to: the target, the
465
+ FROM / USING items and their other joins."""
466
+ items = [dml.this]
467
+ sources = dml.args.get("from_") if isinstance(dml, exp.Update) else None
468
+ if sources is not None:
469
+ items.append(sources.this)
470
+ items.extend(sources.expressions or [])
471
+ items.extend(dml.args.get("using") or [])
472
+ others = set()
473
+ for item in items:
474
+ if item is None:
475
+ continue
476
+ name = _alias_key(item)
477
+ if name and name != this_alias:
478
+ others.add(name)
479
+ for other in item.args.get("joins") or []:
480
+ name = _alias_key(other.this) if other is not join else ""
481
+ if name and name != this_alias:
482
+ others.add(name)
483
+ return others
484
+
485
+
448
486
  def _from_keys(sel, join, this_alias):
449
487
  """Alias keys of every top-level FROM item except this one."""
488
+ if isinstance(sel, (exp.Update, exp.Delete)):
489
+ return _dml_from_keys(sel, join, this_alias)
450
490
  others = set()
451
491
  frm = sel.args.get("from_")
452
492
  if frm is not None and frm.this is not None:
@@ -465,7 +505,7 @@ def _from_keys(sel, join, this_alias):
465
505
  def _joined_on_ast(join, this_alias):
466
506
  """True when some predicate links this table to another FROM table,
467
507
  judged on column qualifiers — never on text substrings."""
468
- sel = _owning_select(join)
508
+ sel = _join_scope(join)
469
509
  if sel is None:
470
510
  return False
471
511
  others = _from_keys(sel, join, this_alias)
@@ -524,7 +564,7 @@ def _on_links_both_sides(join, right_alias):
524
564
  (`ON key = t.key` can only resolve against the remaining FROM scope),
525
565
  so requiring both qualifiers misfires on ordinary joins. `ON a.flag
526
566
  = 1` still crosses: it never references the joined table at all."""
527
- sel = _owning_select(join)
567
+ sel = _join_scope(join)
528
568
  if sel is None or not right_alias:
529
569
  return False
530
570
  others = _from_keys(sel, join, right_alias)
@@ -984,6 +1024,8 @@ def distinct_dedup_bandaid(stmt, loc, ctx):
984
1024
  def insert_explicit_column_list(stmt, loc, ctx):
985
1025
  out = []
986
1026
  for insert in stmt.find_all(exp.Insert):
1027
+ if insert.args.get("default"):
1028
+ continue # INSERT INTO t DEFAULT VALUES: no values, no order
987
1029
  if isinstance(insert.this, exp.Table):
988
1030
  out.append((insert,
989
1031
  "INSERT without a column list breaks silently when columns are added or reordered",
@@ -1147,6 +1189,72 @@ def _qualify_filters(qualify):
1147
1189
  for node in qualify.find_all(exp.EQ, exp.LT, exp.LTE))
1148
1190
 
1149
1191
 
1192
+ _ORDINALITY = "U:ordinality" # the column's name when none is declared
1193
+
1194
+
1195
+ def _ordinality_names(item, stmt, depth=0):
1196
+ """{(name, qualifier)} of WITH ORDINALITY numbers a FROM item exposes,
1197
+ unique per row of it. Declared name (`AS u(v, n)`, the last column)
1198
+ or the default `ordinality`. A CTE or subquery passes the column
1199
+ through when it reads that one source alone (no join to repeat it)
1200
+ and selects it by name."""
1201
+ if depth > 4 or item is None:
1202
+ return set()
1203
+ qual = _alias_key(item)
1204
+ inner = item.this if isinstance(item, exp.Lateral) else item
1205
+ if isinstance(inner, exp.Unnest):
1206
+ offset = inner.args.get("offset")
1207
+ if isinstance(offset, exp.Identifier):
1208
+ return {(_ident_key(offset), qual)}
1209
+ return {(_ORDINALITY, qual)} if offset is True else set()
1210
+ if item.args.get("ordinality"):
1211
+ alias = item.args.get("alias")
1212
+ cols = alias.args.get("columns") if alias is not None else None
1213
+ name = _ident_key(cols[-1]) if cols else _ORDINALITY
1214
+ return {(name, qual)}
1215
+ sel = None
1216
+ if isinstance(item, exp.Subquery):
1217
+ sel = item.this
1218
+ elif isinstance(item, exp.Table) and not item.args.get("db"):
1219
+ sel = _cte_select(stmt, _ident_key(item.this))
1220
+ if not isinstance(sel, exp.Select) or sel.args.get("joins"):
1221
+ return set()
1222
+ frm = sel.args.get("from_")
1223
+ source = _ordinality_names(frm.this if frm is not None else None, stmt,
1224
+ depth + 1)
1225
+ names = {name for name, _ in source}
1226
+ out = set()
1227
+ for proj in sel.expressions:
1228
+ col = proj.this if isinstance(proj, exp.Alias) else proj
1229
+ if isinstance(col, exp.Column) and _ident_key(col.this) in names:
1230
+ out.add((_ident_key(proj.args.get("alias"))
1231
+ if isinstance(proj, exp.Alias) else _ident_key(col.this),
1232
+ qual))
1233
+ return out
1234
+
1235
+
1236
+ def _cte_select(stmt, name):
1237
+ for cte in stmt.find_all(exp.CTE):
1238
+ if _ident_key(cte.args.get("alias").this) == name:
1239
+ return cte.this
1240
+ return None
1241
+
1242
+
1243
+ def _orders_by_ordinality(window, key):
1244
+ """The single ORDER BY key is a WITH ORDINALITY number of the one
1245
+ source the window's SELECT reads: unique, so no ties to break."""
1246
+ col = key.this if isinstance(key, exp.Ordered) else key
1247
+ sel = _owning_select(window)
1248
+ if not isinstance(col, exp.Column) or sel is None or sel.args.get("joins"):
1249
+ return False
1250
+ frm = sel.args.get("from_")
1251
+ stmt = sel.root()
1252
+ names = _ordinality_names(frm.this if frm is not None else None, stmt)
1253
+ name = _ident_key(col.this)
1254
+ qual = _ident_key(col.args.get("table"))
1255
+ return any(name == n and (not qual or qual == q) for n, q in names)
1256
+
1257
+
1150
1258
  def row_number_dedupe_tiebreaker(stmt, loc, ctx):
1151
1259
  out = []
1152
1260
  for window in stmt.find_all(exp.Window):
@@ -1162,7 +1270,8 @@ def row_number_dedupe_tiebreaker(stmt, loc, ctx):
1162
1270
  "a unique tiebreaker"))
1163
1271
  continue
1164
1272
  keys = order.expressions if hasattr(order, "expressions") else []
1165
- if len(keys) == 1 and _picks_one_row(stmt, window):
1273
+ if (len(keys) == 1 and _picks_one_row(stmt, window)
1274
+ and not _orders_by_ordinality(window, keys[0])):
1166
1275
  out.append((window,
1167
1276
  "ROW_NUMBER with a single ORDER BY key picks an arbitrary "
1168
1277
  "winner on ties (uniqueness can't be verified from the file)",
@@ -15,6 +15,7 @@ from truequery import report as RP
15
15
  from truequery import schema
16
16
  from truequery import settings as S
17
17
  from truequery import std_registry
18
+ from truequery.analyzers import sql as analyzer
18
19
  from truequery.engine import ENGINE_VERSION, active_overrides, run
19
20
 
20
21
  EXIT_CLEAN = 0
@@ -208,8 +209,18 @@ def cmd_detect(args: argparse.Namespace) -> int:
208
209
  def _review_tables(results, dialect) -> list[str]:
209
210
  # Only files the checker read: a skipped file (over the size limit,
210
211
  # unparseable) is never opened again for the receipt.
211
- return P.tables_in_files([r.path for r in results
212
- if r.kind == "sql" and r.verified], dialect)
212
+ tables = P.tables_in_files([r.path for r in results
213
+ if r.kind == "sql" and r.verified], dialect)
214
+ seen = {t.lower() for t in tables}
215
+ for result in results: # the SQL checked inside Python files
216
+ for frag in result.fragments:
217
+ if not frag.checked:
218
+ continue
219
+ for table in P.referenced_tables(frag.sql, dialect):
220
+ if table.lower() not in seen:
221
+ seen.add(table.lower())
222
+ tables.append(table)
223
+ return tables
213
224
 
214
225
 
215
226
  def cmd_review(args: argparse.Namespace) -> int:
@@ -538,9 +549,12 @@ def cmd_ignore_add(args: argparse.Namespace) -> int:
538
549
  except OSError:
539
550
  print(f"truequery: no such file: {raw_path}", file=sys.stderr)
540
551
  return EXIT_ERROR
541
- spans = E._chunk_hashes(text, (config or {}).get("dialect"))
552
+ spans = E.statement_spans(path, text, (config or {}).get("dialect"))
542
553
  digest = E.stmt_hash_at(spans, line)
543
- if digest is None:
554
+ # Outside any SQL statement, only an Airflow DAG has findings a line
555
+ # ignore can cover (the DAG check).
556
+ if digest is None and not (path.endswith(".py") and
557
+ E.project_checks.applies_to_file(path, text)):
544
558
  print(f"truequery: line {line} is not inside a SQL statement",
545
559
  file=sys.stderr)
546
560
  return EXIT_ERROR
@@ -558,6 +572,10 @@ def cmd_ignore_add(args: argparse.Namespace) -> int:
558
572
  entry = {"rule": args.rule, "path": path, "line": line,
559
573
  "stmt": digest, "offset": E.stmt_offset(spans, line),
560
574
  "reason": args.reason.strip()}
575
+ if digest is None:
576
+ # A Python line outside its SQL (an Airflow DAG finding): that
577
+ # one line, matched by rule + file + line.
578
+ del entry["stmt"], entry["offset"]
561
579
  if entry not in entries:
562
580
  entries.append(entry)
563
581
  with open(ignores_path, "w", encoding="utf-8") as handle:
@@ -695,6 +713,7 @@ def build_parser() -> argparse.ArgumentParser:
695
713
  return parser
696
714
 
697
715
 
716
+ @analyzer.quiet_sqlglot()
698
717
  def main(argv: list[str] | None = None) -> int:
699
718
  parser = build_parser()
700
719
  args = parser.parse_args(argv)