sqlassert 0.3.1__tar.gz → 0.3.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 (324) hide show
  1. sqlassert-0.3.3/.github/workflows/demo-pages.yml +37 -0
  2. {sqlassert-0.3.1 → sqlassert-0.3.3}/.gitignore +1 -0
  3. sqlassert-0.3.3/AGENTS.md +74 -0
  4. sqlassert-0.3.3/CITATION.cff +9 -0
  5. {sqlassert-0.3.1 → sqlassert-0.3.3}/CONTEXT.md +76 -12
  6. {sqlassert-0.3.1 → sqlassert-0.3.3}/PKG-INFO +121 -39
  7. {sqlassert-0.3.1 → sqlassert-0.3.3}/README.md +119 -37
  8. sqlassert-0.3.3/docs/adr/0006-model-only-current-strict-engines.md +7 -0
  9. sqlassert-0.3.3/docs/assets/fan-trap.sql +9 -0
  10. sqlassert-0.3.3/docs/assets/inner-join.sql +9 -0
  11. sqlassert-0.3.3/docs/assets/redundant-join.sql +6 -0
  12. sqlassert-0.3.3/docs/assets/social-preview.png +0 -0
  13. sqlassert-0.3.3/docs/assets/sqlassert-demo-preview.png +0 -0
  14. sqlassert-0.3.3/docs/assets/sqlassert-demo.html +85 -0
  15. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/calcite-audit.md +37 -30
  16. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/dialect-provenance.json +232 -37
  17. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/dialects.md +105 -48
  18. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/functional-dependencies.md +70 -44
  19. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/implementation-conventions.md +75 -21
  20. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/0011-fuzz-test-analyze-against-a-real-world-sql-corpus.md +5 -0
  21. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/0027-soundness-oracle-against-duckdb.md +9 -3
  22. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/0039-smaller-lowering-gaps.md +2 -1
  23. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/0042-lowering-support-v2.md +13 -4
  24. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/0043-external-integrations.md +4 -1
  25. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/0046-certify-dialect-facts.md +10 -2
  26. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/0049-collation-aware-properties.md +6 -0
  27. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/0051-validate-snowflake-against-a-real-engine.md +4 -1
  28. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/0052-validate-bigquery-against-a-real-engine.md +4 -1
  29. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/0053-validate-databricks-against-a-real-engine.md +5 -2
  30. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/0054-validate-redshift-against-a-real-engine.md +4 -1
  31. sqlassert-0.3.3/docs/issues/0057-dbt-incremental-models.md +59 -0
  32. sqlassert-0.3.3/docs/issues/0058-dbt-source-mapping.md +59 -0
  33. sqlassert-0.3.3/docs/issues/0059-postgres-user-defined-functions.md +89 -0
  34. sqlassert-0.3.3/docs/issues/0060-audit-inference-against-cockroachdb.md +79 -0
  35. sqlassert-0.3.3/docs/issues/0061-symbolic-oracle-with-verieql.md +59 -0
  36. sqlassert-0.3.3/docs/issues/0062-cross-check-suggest-rewrites-with-equivalence-checkers.md +51 -0
  37. sqlassert-0.3.3/docs/issues/0063-generate-random-programs-for-the-oracle.md +51 -0
  38. sqlassert-0.3.3/docs/issues/0064-triage-wetune-rewrite-rules.md +36 -0
  39. sqlassert-0.3.3/docs/issues/0065-triage-sqlcheck-anti-patterns.md +33 -0
  40. sqlassert-0.3.3/docs/issues/0066-check-semantics-against-guagliardo-libkin.md +44 -0
  41. sqlassert-0.3.3/docs/issues/0067-recheck-calcite-funcdepset.md +28 -0
  42. sqlassert-0.3.3/docs/issues/0068-name-suggestion-types-by-severity.md +30 -0
  43. sqlassert-0.3.3/docs/issues/0069-real-world-sql-corpora.md +84 -0
  44. sqlassert-0.3.3/docs/issues/0070-decide-whether-to-warn-on-hidden-join-fanout-by-default.md +48 -0
  45. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/README.md +41 -17
  46. {sqlassert-0.3.1/docs/issues → sqlassert-0.3.3/docs/issues/done}/0015-suggest-provable-properties-for-unannotated-sql.md +56 -52
  47. {sqlassert-0.3.1/docs/issues → sqlassert-0.3.3/docs/issues/done}/0023-close-ir-lowering-gaps.md +16 -12
  48. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0024-functional-dependency-reasoning.md +1 -1
  49. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0026-equality-groups.md +1 -1
  50. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0031-enumerated-domains-through-set-operations.md +1 -1
  51. {sqlassert-0.3.1/docs/issues → sqlassert-0.3.3/docs/issues/done}/0037-close-the-paulley-audit-missing-rules.md +35 -10
  52. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0038-lower-order-by-and-select-list-subqueries.md +2 -2
  53. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0040-audit-inference-against-calcite.md +1 -1
  54. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0041-join-cardinality-markers-and-fan-trap-smell.md +1 -1
  55. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0044-v1-external-integrations.md +1 -1
  56. sqlassert-0.3.3/docs/issues/done/0045-close-the-calcite-audit-missing-proofs.md +123 -0
  57. sqlassert-0.3.3/docs/issues/done/0050-dbt-catalog-json.md +59 -0
  58. sqlassert-0.3.3/docs/issues/done/0055-dbt-suggest-model-files.md +38 -0
  59. sqlassert-0.3.3/docs/issues/done/0056-dbt-live-connection.md +78 -0
  60. sqlassert-0.3.3/docs/issues/done/0070-drop-legacy-and-permissive-dialect-support.md +51 -0
  61. sqlassert-0.3.3/docs/issues/done/0071-rewrites-carry-exact-edits.md +72 -0
  62. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/mvp-scope.md +1 -1
  63. sqlassert-0.3.3/docs/references.md +156 -0
  64. sqlassert-0.3.3/docs/site/index.html +18 -0
  65. sqlassert-0.3.3/integrations/dbt/README.md +234 -0
  66. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/pyproject.toml +2 -1
  67. sqlassert-0.3.3/integrations/dbt/sqlassert_dbt/__init__.py +21 -0
  68. sqlassert-0.3.3/integrations/dbt/sqlassert_dbt/__main__.py +350 -0
  69. sqlassert-0.3.3/integrations/dbt/sqlassert_dbt/connect.py +135 -0
  70. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/sqlassert_dbt/jinja.py +130 -0
  71. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/sqlassert_dbt/manifest.py +56 -2
  72. sqlassert-0.3.3/integrations/dbt/sqlassert_dbt/program.py +1139 -0
  73. sqlassert-0.3.3/integrations/dbt/sqlassert_dbt/project.py +622 -0
  74. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/sqlassert_dbt/report.py +114 -4
  75. sqlassert-0.3.3/integrations/dbt/tests/conftest.py +43 -0
  76. sqlassert-0.3.3/integrations/dbt/tests/test_catalog.py +146 -0
  77. sqlassert-0.3.3/integrations/dbt/tests/test_connect.py +101 -0
  78. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/tests/test_dbt.py +93 -4
  79. sqlassert-0.3.3/integrations/dbt/tests/test_suggest.py +325 -0
  80. {sqlassert-0.3.1 → sqlassert-0.3.3}/poetry.lock +8 -9
  81. {sqlassert-0.3.1 → sqlassert-0.3.3}/pyproject.toml +5 -2
  82. sqlassert-0.3.3/scripts/README.md +14 -0
  83. {sqlassert-0.3.1 → sqlassert-0.3.3}/scripts/certify_dialects.py +101 -46
  84. sqlassert-0.3.3/scripts/render_sqlassert_interactive_demo.py +129 -0
  85. sqlassert-0.3.3/scripts/render_sqlassert_social_preview.py +72 -0
  86. sqlassert-0.3.3/sqlassert/__main__.py +9 -0
  87. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/check.py +10 -3
  88. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/diagnostics.py +19 -6
  89. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/dialects.py +69 -22
  90. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/discovery/duckdb.py +12 -16
  91. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/discovery/fetcher.py +45 -29
  92. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/discovery/information_schema.py +4 -3
  93. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/discovery/postgres.py +6 -7
  94. sqlassert-0.3.3/sqlassert/edits.py +240 -0
  95. sqlassert-0.3.3/sqlassert/hazards.py +574 -0
  96. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/ir/__init__.py +3 -1
  97. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/ir/convert.py +1315 -183
  98. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/ir/model.py +128 -25
  99. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/main.py +3 -9
  100. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/python_engine.py +63 -6
  101. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/reporting.py +3 -0
  102. sqlassert-0.3.3/sqlassert/rewrites.py +1541 -0
  103. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/rules/domain.py +117 -21
  104. sqlassert-0.3.3/sqlassert/rules/equality.py +442 -0
  105. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/rules/exactly_one.py +40 -1
  106. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/rules/foreign_key.py +7 -4
  107. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/rules/join_cardinality.py +33 -11
  108. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/rules/nullability.py +239 -30
  109. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/rules/uniqueness.py +355 -52
  110. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/sql_parse.py +196 -89
  111. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/suggest.py +127 -48
  112. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert.egg-info/PKG-INFO +121 -39
  113. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert.egg-info/SOURCES.txt +56 -13
  114. sqlassert-0.3.3/sqlassert.egg-info/entry_points.txt +2 -0
  115. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert.egg-info/requires.txt +1 -1
  116. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert.egg-info/scm_file_list.json +55 -12
  117. sqlassert-0.3.3/sqlassert.egg-info/scm_version.json +8 -0
  118. sqlassert-0.3.3/sqlassert.egg-info/top_level.txt +2 -0
  119. sqlassert-0.3.1/sqlassert/__main__.py → sqlassert-0.3.3/sqlassert_cli.py +27 -35
  120. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/aggregate_and_distinct.sqltest +44 -0
  121. sqlassert-0.3.3/tests/aggregates_in_expressions.sqltest +99 -0
  122. sqlassert-0.3.3/tests/always_null_columns.sqltest +57 -0
  123. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/calcite_audit_iq.sqltest +50 -14
  124. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/calcite_audit_keys.sqltest +107 -29
  125. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/calcite_audit_nulls.sqltest +305 -56
  126. sqlassert-0.3.3/tests/check_constraints.sqltest +53 -0
  127. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/composite_unique_sets.sqltest +44 -5
  128. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/database_hydration.sqltest +2 -4
  129. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/dialect_duckdb.sqltest +31 -16
  130. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/dialect_mysql.sqltest +21 -16
  131. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/dialect_postgres.sqltest +15 -13
  132. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/dialect_trino.sqltest +14 -1
  133. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/dialect_warehouses.sqltest +55 -7
  134. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/enumerated_domain.sqltest +19 -5
  135. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/enumerated_domain_standalone.sqltest +1 -2
  136. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/exactly_one_join.sqltest +44 -3
  137. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/foreign_keys.sqltest +6 -6
  138. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/functional_dependencies.sqltest +38 -0
  139. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/functional_dependencies_of_functions.sqltest +9 -3
  140. sqlassert-0.3.3/tests/lowering_having_values_subqueries.sqltest +97 -0
  141. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/marker_accounting.sqltest +7 -2
  142. sqlassert-0.3.3/tests/nested_joins.sqltest +113 -0
  143. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/not_null.sqltest +33 -2
  144. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/not_null_rejection.sqltest +31 -4
  145. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/paulley_audit.sqltest +256 -1
  146. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/qualify_by_partition.sqltest +43 -0
  147. sqlassert-0.3.3/tests/review_soundness.sqltest +80 -0
  148. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/root_select_body.sqltest +23 -1
  149. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/scalar_aggregates.sqltest +3 -3
  150. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/scalar_subqueries.sqltest +2 -2
  151. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/schema_amendments.sqltest +8 -2
  152. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/schema_amendments_standalone.sqltest +1 -1
  153. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/set_operations.sqltest +17 -0
  154. sqlassert-0.3.3/tests/set_returning_functions.sqltest +62 -0
  155. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/soundness.sqltest +2 -4
  156. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/soundness_oracle.py +36 -14
  157. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_analyze_aggregate_and_distinct.py +1 -21
  158. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_analyze_cte_and_subquery.py +2 -2
  159. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_analyze_enumerated_domain.py +0 -1
  160. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_analyze_marker_accounting.py +4 -0
  161. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_analyze_scalar_subqueries.py +8 -8
  162. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_check.py +16 -4
  163. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_connection_warnings.py +1 -1
  164. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_dialect_certification.py +22 -1
  165. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_dialects.py +4 -5
  166. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_duckdb_hydration.py +1 -1
  167. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_equality_groups.py +9 -5
  168. sqlassert-0.3.3/tests/test_hazards.py +386 -0
  169. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_ir_model.py +29 -1
  170. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_mysql_catalog.py +3 -3
  171. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_postgres_catalog.py +10 -8
  172. sqlassert-0.3.3/tests/test_review_soundness.py +108 -0
  173. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_sql_parse.py +8 -8
  174. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_sqltest.py +1 -1
  175. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_suggest.py +41 -4
  176. sqlassert-0.3.3/tests/test_suggest_rewrites.py +1424 -0
  177. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/unique_join.sqltest +4 -5
  178. sqlassert-0.3.3/tests/unsupported_constructs.sqltest +93 -0
  179. {sqlassert-0.3.1 → sqlassert-0.3.3}/uv.lock +20 -20
  180. sqlassert-0.3.1/AGENTS.md +0 -33
  181. sqlassert-0.3.1/docs/issues/0045-close-the-calcite-audit-missing-proofs.md +0 -119
  182. sqlassert-0.3.1/docs/issues/0050-dbt-catalog-json.md +0 -32
  183. sqlassert-0.3.1/docs/references.md +0 -67
  184. sqlassert-0.3.1/integrations/dbt/README.md +0 -129
  185. sqlassert-0.3.1/integrations/dbt/sqlassert_dbt/__init__.py +0 -19
  186. sqlassert-0.3.1/integrations/dbt/sqlassert_dbt/__main__.py +0 -115
  187. sqlassert-0.3.1/integrations/dbt/sqlassert_dbt/program.py +0 -686
  188. sqlassert-0.3.1/integrations/dbt/sqlassert_dbt/project.py +0 -340
  189. sqlassert-0.3.1/integrations/dbt/tests/conftest.py +0 -16
  190. sqlassert-0.3.1/sqlassert/improvements.py +0 -528
  191. sqlassert-0.3.1/sqlassert/rules/equality.py +0 -233
  192. sqlassert-0.3.1/sqlassert/smells.py +0 -306
  193. sqlassert-0.3.1/sqlassert.egg-info/entry_points.txt +0 -2
  194. sqlassert-0.3.1/sqlassert.egg-info/scm_version.json +0 -8
  195. sqlassert-0.3.1/sqlassert.egg-info/top_level.txt +0 -1
  196. sqlassert-0.3.1/tests/test_smells.py +0 -170
  197. sqlassert-0.3.1/tests/test_suggest_improvements.py +0 -611
  198. sqlassert-0.3.1/tmp/clingo-rules-rebuild-assessment.md +0 -577
  199. sqlassert-0.3.1/tmp/sqlassert-clingo-grilling-handoff.md +0 -335
  200. sqlassert-0.3.1/tmp/try.py +0 -14
  201. {sqlassert-0.3.1 → sqlassert-0.3.3}/.github/workflows/ci.yml +0 -0
  202. {sqlassert-0.3.1 → sqlassert-0.3.3}/CLAUDE.md +0 -0
  203. {sqlassert-0.3.1 → sqlassert-0.3.3}/LICENSE +0 -0
  204. {sqlassert-0.3.1 → sqlassert-0.3.3}/case.sql +0 -0
  205. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/adr/0001-isolate-clingo-as-the-property-engine.md +0 -0
  206. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/adr/0002-use-a-framework-independent-ir.md +0 -0
  207. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/adr/0003-encode-the-ir-in-clingo.md +0 -0
  208. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/adr/0004-use-python-analysis-functions-for-property-inference.md +0 -0
  209. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/adr/0005-analyze-sql-without-a-connection.md +0 -0
  210. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/calcite-notes.md +0 -0
  211. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0001-spec-rewrite-the-property-engine-around-a-relational-ir-and.md +0 -0
  212. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0002-prove-one-declared-unique-join-through-clingo.md +0 -0
  213. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0003-prove-composite-and-nullable-unique-sets.md +0 -0
  214. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0004-propagate-uniqueness-through-relation-instances-filters-and.md +0 -0
  215. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0005-analyze-cte-and-from-subquery-plans.md +0 -0
  216. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0006-expand-create-views-with-provenance-and-cycle-detection.md +0 -0
  217. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0007-derive-uniqueness-from-aggregate-and-distinct.md +0 -0
  218. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0008-derive-uniqueness-from-qualifybypartition.md +0 -0
  219. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0009-return-conservative-diagnostics-for-the-complete-mvp-boundar.md +0 -0
  220. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0010-cut-over-to-analyze-and-retire-the-legacy-analyzer.md +0 -0
  221. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0012-add-unique-set-assertions-for-select-expressions-unique-prim.md +0 -0
  222. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0013-refactoring.md +0 -0
  223. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0014-hydrate-analysis-from-database-catalogs-with-recursive-view.md +0 -0
  224. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0016-assert-and-declare-string-enum-domains.md +0 -0
  225. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0017-complete-typed-enum-support.md +0 -0
  226. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0018-assert-exhaustive-simple-case-expressions.md +0 -0
  227. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0019-assert-and-declare-direct-foreign-keys.md +0 -0
  228. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0020-propagate-foreign-keys-through-queries.md +0 -0
  229. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0021-assert-simple-exactly-one-joins.md +0 -0
  230. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0022-complete-exactly-one-reasoning.md +0 -0
  231. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0025-check-rule-consistency-invariants.md +0 -0
  232. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0028-analyze-join-markers-inside-cte-bodies.md +0 -0
  233. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0029-enum-string-literals-may-coincide.md +0 -0
  234. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0030-read-enum-types-and-collations-from-the-catalog.md +0 -0
  235. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0032-infer-simple-case-nullability.md +0 -0
  236. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0033-inner-join-suggestion-across-join-chains-and-ctes.md +0 -0
  237. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0034-close-soundness-oracle-blind-spots.md +0 -0
  238. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0035-audit-fd-propagation-against-paulley.md +0 -0
  239. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0036-refactor-tests-for-corpus-and-oracle-scale.md +0 -0
  240. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0047-discovery-base-class.md +0 -0
  241. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/issues/done/0048-dbt-plugin-package.md +0 -0
  242. {sqlassert-0.3.1 → sqlassert-0.3.3}/docs/literature-notes.md +0 -0
  243. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/LICENSE +0 -0
  244. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/sqlassert_dbt/expectations.py +0 -0
  245. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/tests/dbt_project/dbt_project.yml +0 -0
  246. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/tests/dbt_project/models/active_customers.sql +0 -0
  247. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/tests/dbt_project/models/customer_keys.sql +0 -0
  248. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/tests/dbt_project/models/customer_orders.sql +0 -0
  249. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/tests/dbt_project/models/customer_signups.sql +0 -0
  250. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/tests/dbt_project/models/customers.sql +0 -0
  251. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/tests/dbt_project/models/orders_appended.sql +0 -0
  252. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/tests/dbt_project/models/orders_incremental.sql +0 -0
  253. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/tests/dbt_project/models/schema.yml +0 -0
  254. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/tests/dbt_project/models/stg_customers.sql +0 -0
  255. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/tests/dbt_project/models/stg_orders.sql +0 -0
  256. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/tests/dbt_project/profiles.yml +0 -0
  257. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/tests/dbt_project/seeds/raw_payments.csv +0 -0
  258. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/tests/dbt_runs.py +0 -0
  259. {sqlassert-0.3.1 → sqlassert-0.3.3}/integrations/dbt/tests/test_contracts.py +0 -0
  260. {sqlassert-0.3.1 → sqlassert-0.3.3}/join.sql +0 -0
  261. {sqlassert-0.3.1 → sqlassert-0.3.3}/left.sql +0 -0
  262. {sqlassert-0.3.1 → sqlassert-0.3.3}/scripts/publish-pypi.sh +0 -0
  263. {sqlassert-0.3.1 → sqlassert-0.3.3}/setup.cfg +0 -0
  264. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/__init__.py +0 -0
  265. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/discovery/__init__.py +0 -0
  266. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/discovery/bigquery.py +0 -0
  267. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/discovery/databricks.py +0 -0
  268. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/discovery/mysql.py +0 -0
  269. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/discovery/redshift.py +0 -0
  270. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/discovery/snowflake.py +0 -0
  271. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/discovery/trino.py +0 -0
  272. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/properties.py +0 -0
  273. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/provenance.py +0 -0
  274. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/rules/STYLEGUIDE.md +0 -0
  275. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/rules/__init__.py +0 -0
  276. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert/rules/column_set.py +0 -0
  277. {sqlassert-0.3.1 → sqlassert-0.3.3}/sqlassert.egg-info/dependency_links.txt +0 -0
  278. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/calcite_audit.sqltest +0 -0
  279. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/conftest.py +0 -0
  280. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/connection_warnings.sqltest +0 -0
  281. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/cte_and_subquery.sqltest +0 -0
  282. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/duckdb_hydration.sqltest +0 -0
  283. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/exhaustive_case.sqltest +0 -0
  284. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/foreign_keys_standalone.sqltest +0 -0
  285. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/functional_dependencies_standalone.sqltest +0 -0
  286. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/join_cardinality.sqltest +0 -0
  287. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/join_kinds.sqltest +0 -0
  288. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/join_kinds_standalone.sqltest +0 -0
  289. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/joins_in_bodies.sqltest +0 -0
  290. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/limit.sqltest +0 -0
  291. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/not_null_case_expressions.sqltest +0 -0
  292. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/not_null_standalone.sqltest +0 -0
  293. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/not_null_values.sqltest +0 -0
  294. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/propagation.sqltest +0 -0
  295. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/sqltest.py +0 -0
  296. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/subqueries.sqltest +0 -0
  297. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_analyze_exactly_one_join.py +0 -0
  298. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_analyze_exhaustive_case.py +0 -0
  299. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_analyze_join_cardinality.py +0 -0
  300. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_analyze_join_kinds.py +0 -0
  301. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_analyze_joins_in_bodies.py +0 -0
  302. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_analyze_not_null.py +0 -0
  303. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_analyze_qualify_by_partition.py +0 -0
  304. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_analyze_relation_facts.py +0 -0
  305. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_analyze_set_operations.py +0 -0
  306. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_analyze_soundness.py +0 -0
  307. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_analyze_unique_join.py +0 -0
  308. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_analyze_unique_set_assertion.py +0 -0
  309. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_analyze_views.py +0 -0
  310. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_database_hydration.py +0 -0
  311. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_ir_unions.py +0 -0
  312. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_main.py +0 -0
  313. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_module_boundaries.py +0 -0
  314. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_oracle_plugin.py +0 -0
  315. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_property_functions.py +0 -0
  316. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_python_engine.py +0 -0
  317. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_soundness_oracle.py +0 -0
  318. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_trino_catalog.py +0 -0
  319. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/test_warehouse_catalogs.py +0 -0
  320. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/unique_set_assertion.sqltest +0 -0
  321. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/unique_set_declaration.sqltest +0 -0
  322. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/unique_set_declaration_standalone.sqltest +0 -0
  323. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/unsupported_statements.sqltest +0 -0
  324. {sqlassert-0.3.1 → sqlassert-0.3.3}/tests/views.sqltest +0 -0
@@ -0,0 +1,37 @@
1
+ name: Publish interactive demo
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ paths:
7
+ - docs/assets/sqlassert-demo.html
8
+ - docs/site/index.html
9
+ - .github/workflows/demo-pages.yml
10
+ workflow_dispatch:
11
+
12
+ concurrency:
13
+ group: demo-pages
14
+
15
+ jobs:
16
+ deploy:
17
+ runs-on: ubuntu-latest
18
+ permissions:
19
+ contents: read
20
+ pages: write
21
+ id-token: write
22
+ environment:
23
+ name: github-pages
24
+ url: ${{ steps.deployment.outputs.page_url }}
25
+ steps:
26
+ - uses: actions/checkout@v6
27
+ - uses: actions/configure-pages@v5
28
+ - name: Prepare demo
29
+ run: |
30
+ mkdir _site
31
+ cp docs/site/index.html _site/index.html
32
+ cp docs/assets/sqlassert-demo.html _site/demo.html
33
+ - uses: actions/upload-pages-artifact@v4
34
+ with:
35
+ path: _site
36
+ - uses: actions/deploy-pages@v4
37
+ id: deployment
@@ -7,3 +7,4 @@ papers/
7
7
  vendor/
8
8
  __pycache__/
9
9
  docs/issues/mkt/
10
+ docs/issues/pvt/
@@ -0,0 +1,74 @@
1
+ # Agent Guidelines
2
+
3
+ ## No backwards compatibility while in alpha
4
+
5
+ sqlassert is alpha. Code simplicity wins over compatibility:
6
+
7
+ - Replace mechanisms outright; do not keep old and new side by side.
8
+ - No feature flags, shims, deprecation paths, or fallback branches for old
9
+ behavior. They are an anchor on every later change.
10
+ - Delete superseded code, tests, and docs in the same change.
11
+
12
+ The one contract to keep stable is the user-facing one: the Property Markers
13
+ (`/**ASSERT ...**/`, `/**DECLARE ...**/`) and the Properties they introduce.
14
+ Internal representation (IR, analysis functions, rules) may change freely.
15
+
16
+ ## Analysis works without a connection
17
+
18
+ `analyze(sql)` must work from the SQL alone ([ADR 0005](docs/adr/0005-analyze-sql-without-a-connection.md)).
19
+ Whenever a connection would have helped (a table with no `CREATE`, an unknown
20
+ column type, an ambiguous column), emit a warning Diagnostic saying what is
21
+ missing and how to supply it, and treat the affected facts as unknown; never
22
+ guess. With a connection (`analyze_database`), resolve it from the catalog. A
23
+ connection may only add proofs, never change what the SQL alone proves.
24
+
25
+ ## Current, strict engines only
26
+
27
+ Model each engine's latest release under its default settings, strict modes
28
+ on ([ADR 0006](docs/adr/0006-model-only-current-strict-engines.md)). No
29
+ older versions, no permissive settings (non-strict `sql_mode`, Spark ANSI
30
+ off), and no meaning for SQL the standard rejects but a flavor tolerates
31
+ (a column neither grouped nor aggregated): make it opaque and warn
32
+ `unsupported-construct`. Simpler code beats supporting outdated SQL.
33
+
34
+ ## Where things are
35
+
36
+ - Domain language: `CONTEXT.md`. Use its terms; it lists terms to avoid.
37
+ - Implementation conventions: `docs/implementation-conventions.md`.
38
+ - Rule style: `sqlassert/rules/STYLEGUIDE.md`.
39
+ - Test style: SQL cases in `tests/*.sqltest` (format in `tests/sqltest.py`;
40
+ see "Tests" in `docs/implementation-conventions.md`).
41
+ - Open work: `docs/issues/` (index in `docs/issues/README.md`). Marketing
42
+ work is in `docs/issues/mkt/`, client work in `docs/issues/pvt/`; both are
43
+ gitignored and never committed.
44
+ - Architecture decisions: `docs/adr/`.
45
+
46
+ ## Testing workflow
47
+
48
+ - **On each commit:** run only the focused tests for what changed (the
49
+ `.sqltest` files and test modules it touches) and `ty check sqlassert
50
+ tests`. No full suite, no oracle.
51
+ - **At push time:** whoever pushes runs the full suite and
52
+ `pytest --soundness-oracle` on everything not yet pushed
53
+ (`git log @{upstream}..HEAD`), fixes any failure with that context,
54
+ commits the fix, runs the checks below, pushes, then updates the local
55
+ issue tracker (`tmp/issue_tracker.yaml`, rebuilt with
56
+ `tmp/build_issue_tracker.py`).
57
+
58
+ ## Before pushing
59
+
60
+ The repository is public. Before every push, check that nothing private
61
+ leaves:
62
+
63
+ - Client work (paths, project and model names, env vars, commands run on a
64
+ client project) goes only in gitignored places: `docs/issues/pvt/`,
65
+ `docs/issues/mkt/`, `tmp/`. A public issue that comes from client work is
66
+ phrased without client details.
67
+ - No outgoing file is under those directories:
68
+ `git diff --name-only @{upstream}..HEAD`.
69
+ - No added line or commit message matches a term in
70
+ `docs/issues/pvt/denylist.txt`:
71
+ `git log -p @{upstream}..HEAD | grep -iEf <(grep -v '^#' docs/issues/pvt/denylist.txt)`
72
+ must print nothing. Add a term there whenever a new client name shows up.
73
+
74
+ On any hit, stop and ask; do not push.
@@ -0,0 +1,9 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use sqlassert in published research, please cite the version you used."
3
+ title: sqlassert
4
+ type: software
5
+ authors:
6
+ - given-names: Fred
7
+ family-names: Israel
8
+ repository-code: "https://github.com/polvoazul/sqlassert"
9
+ license: MIT
@@ -30,17 +30,29 @@ A SEMI or ANTI join has no Join Cardinality: it outputs no right rows.
30
30
  _Avoid_: Unique join marker, duplicate check, 1:N
31
31
 
32
32
  **Fan Trap**, **Chasm Trap**:
33
- An aggregate whose argument's rows a join may repeat (a Smell). A Fan Trap
33
+ An aggregate whose argument's rows a join may repeat (a Hazard). A Fan Trap
34
34
  is through a join that is not proved to be a Unique Join; a Chasm Trap through
35
35
  a One To Many (or Many To One) Join whose argument is on the side with one row
36
36
  per key.
37
37
 
38
+ **Float Equality**:
39
+ An equality comparison (`=`, `<>`, `IS [NOT] DISTINCT FROM`, an IN list or
40
+ subquery) with an operand of a known floating type, REAL, FLOAT or DOUBLE
41
+ in any spelling (a Hazard): floats round, so comparing one for exact
42
+ equality is wrong, against another float, an integer, a decimal or a
43
+ literal (`x = 0.1`). Which values a float holds exactly, and how each
44
+ dialect converts the other side, are no rule to rely on. An ordering
45
+ (`<`, `>`) is none, and so is an operand whose type is unknown.
46
+ _Avoid_: Lossy comparison, float comparison (an ordering is fine), precision
47
+ loss, rounding comparison, implicit cast (that Hazard is text)
48
+
38
49
  **Exactly One Join Assertion**:
39
50
  An assertion that every row of a join's left-hand input matches exactly one
40
51
  right-hand row, so the join neither multiplies nor removes left rows and a left
41
52
  join null-extends none of them. It combines a Many To One Join (at most one match)
42
- with guaranteed matching (at least one): an ON made only of equalities between
43
- left and right columns, non-null left columns, and Referential Coverage of the
53
+ with guaranteed matching (at least one): an ON made only of equalities (`=`,
54
+ or `IS NOT DISTINCT FROM`, which is `=` once the left columns are non-null)
55
+ between left and right columns, non-null left columns, and Referential Coverage of the
44
56
  left columns, as one tuple, onto the right columns they are paired with.
45
57
  _Avoid_: Lookup join, mandatory join, 1:1 join
46
58
 
@@ -111,7 +123,7 @@ An explicit report that part of a SQL program could not be analyzed, such as an
111
123
  _Avoid_: Error, warning, validation failure, unknown
112
124
 
113
125
  **Connection Warning**:
114
- A Diagnostic reported apart, in `Report.warnings`, when the SQL alone lacks a fact a database connection would supply: a table with no `CREATE`, or an unqualified column more than one undeclared source may own. The affected facts are unknown; the warning names the fix. It never fails a Report, and `analyze_database` emits none ([ADR 0005](docs/adr/0005-analyze-sql-without-a-connection.md)). `Report.warnings` also carries the other facts the SQL leaves open: a key or foreign key the dialect does not enforce (`unenforced-constraint`; `RELY` or `trust_unenforced_keys`, on by default, makes it a Property Declaration, never Knowledge, and then no warning is reported), an operator whose meaning a setting decides (`ambiguous-operator`: MySQL's `||`), a comparison of a `CAST` of a timestamp that keeps its zone (`zoned-timestamp-cast`: Trino's), and a comparison of a composite column or `CAST` whose elements may be NULL (`composite-comparison`). The last three are about the SQL itself, so `analyze_database` keeps them.
126
+ A Diagnostic reported apart, in `Report.warnings`, when the SQL alone lacks a fact a database connection would supply: a table with no `CREATE`, or an unqualified column more than one undeclared source may own. The affected facts are unknown; the warning names the fix. It never fails a Report, and `analyze_database` emits none ([ADR 0005](docs/adr/0005-analyze-sql-without-a-connection.md)). `Report.warnings` also carries the other facts the SQL leaves open: a key or foreign key the dialect does not enforce (`unenforced-constraint`; `RELY` or `trust_unenforced_keys`, on by default, makes it a Property Declaration, never Knowledge, and then no warning is reported), a CHECK constraint whose shape states no Enumerated Domain (`ignored-check-constraint`), a comparison of a `CAST` of a timestamp that keeps its zone (`zoned-timestamp-cast`: Trino's), a comparison of a composite column or `CAST` whose elements may be NULL (`composite-comparison`), and a proved Property that holds trivially because a column it names is always NULL (`always-null-column`, once per column: an empty Enumerated Domain satisfies every ENUM and EXHAUSTIVE, and NULL exempts a row from a Unique Set, a dependency's determinant, Referential Coverage and Non-Null Elements). The last four are about the SQL itself, so `analyze_database` keeps them.
115
127
 
116
128
  **Non-Null Elements**:
117
129
  A Property of composite columns (ARRAY, ROW, MAP): no element of a listed
@@ -215,11 +227,11 @@ database enum type, though a catalog's enum type could supply it as Knowledge.
215
227
  _Avoid_: Enum type, value set, check constraint
216
228
 
217
229
  **Equality Group**:
218
- An analysis-only set of one relation's output columns that carry the same value on every row: merged by strict equalities (`WHERE` and inner-join `ON` `a = b`) between known matching comparison types, never by an outer join's `ON`. Implicit casts and collations do not establish value identity. Stronger than a pair of Functional Dependencies, which an injective `a = f(b)` also satisfies. Value facts such as Enumerated Domains and Foreign Keys read it; uniqueness does not.
230
+ An analysis-only set of one relation's output columns that carry the same value on every row: merged by strict equalities (`WHERE`, inner-join and semi-join `ON` `a = b`, or `a IS NOT DISTINCT FROM b`, NULL then being a shared value; a semi join's through the matched right row's columns) between known matching comparison types, never by an outer join's `ON`. Implicit casts and case-insensitive default collations (MySQL's) do not establish value identity; a `COLLATE` is unsupported. Stronger than a pair of Functional Dependencies, which an injective `a = f(b)` also satisfies. Value facts such as Enumerated Domains and Foreign Keys read it; uniqueness does not.
219
231
  _Avoid_: Equivalence class, alias set
220
232
 
221
233
  **Null Source**:
222
- A reason an output column may be NULL: organically (a nullable source column, an expression whose nullability is not modelled, a NULL literal) or because an outer join padded its row. A column is non-null when it has no Null Source; a null-rejecting condition on a padded column proves its join matched and removes that padding from every column it padded.
234
+ A reason an output column may be NULL: organically (a nullable source column, an expression whose nullability is not modelled, a NULL literal) or because an outer join padded its row. A column is non-null when it has no Null Source; a condition never TRUE on the rows a join pads (null-rejecting on a padded column, or on every part of an OR over them) proves that join matched and removes that padding from every column it padded.
223
235
  _Avoid_: Nullable flag, null-extension
224
236
 
225
237
  **Row Identity**:
@@ -232,18 +244,70 @@ _Avoid_: Select-like expression, query, statement
232
244
 
233
245
  **Attachment Site**:
234
246
  A place in the SQL text where a Property Marker can be written: right before a
235
- JOIN, right after the last token of a Select Expression, or right before a
236
- simple `CASE`. Every marker attaches at one; `suggest` names each site by its
247
+ JOIN, right after the last token of a Select Expression (of the whole query,
248
+ for a set operation: its last operand ends there too, so it has none), or
249
+ right before a simple `CASE`. Every marker attaches at one; `suggest` names each site by its
237
250
  line and what it marks.
238
251
  _Avoid_: Marker position, anchor
239
252
 
240
- **Improvement**:
253
+ **Rewrite**:
241
254
  A rewrite of the SQL itself, at one Attachment Site, that a Proof shows leaves
242
255
  the program's result unchanged as a multiset: an outer join that cannot keep a
243
256
  padded row written as an inner join, a join that is redundant or only filters,
244
- a redundant `DISTINCT` or grouping column, an unused CTE. `suggest` ranks
245
- Improvements (High level) before markers to paste (Mid level).
246
- _Avoid_: Optimization, lint, hint
257
+ a redundant `DISTINCT` or grouping column, an unused CTE. It guarantees the
258
+ same rows; a column's type or precision may change, or its arithmetic
259
+ overflow, which makes it a Rewrite with Caveat.
260
+ Otherwise (same rows, same column types, no new error) it is a plain
261
+ Rewrite, suggestion type `rewrite`. `suggest` ranks Rewrites before Rewrites
262
+ with Caveat, those before markers to paste, and those before Hazards. Every
263
+ Rewrite is made by its Rewrite Edits, and is offered only with them.
264
+ _Avoid_: Improvement, optimization, lint, hint
265
+
266
+ **Rewrite Edit**:
267
+ One exact text change a Rewrite makes to the SQL it was found in: replace
268
+ the text between two source offsets with a replacement, placed from the
269
+ SQL's tokens. An edit never deletes a comment or Property Marker in the text
270
+ it replaces: it keeps them. What `suggest` shows of a Rewrite (the rewritten
271
+ SQL, its diff, the dbt diff against the compiled SQL) is derived from its
272
+ edits, and the equivalence tests run exactly the SQL they make.
273
+ _Avoid_: Patch, fix, rewritten query (for the edits themselves)
274
+
275
+ **Rewrite with Caveat**:
276
+ A Rewrite that keeps the rows but may change an output column's type,
277
+ precision or overflow, its message naming the column and the risk
278
+ (suggestion type `rewrite with caveat`): a `GROUP BY` whose groups are
279
+ single rows, written as a projection, replaces `sum(x)` by `x` (DuckDB's
280
+ HUGEINT sum becomes x's INTEGER, and `sum(x) + 1` as `x + 1` may overflow)
281
+ and `avg(b)` of a BIGINT by `b` (exact, where avg's DOUBLE may round).
282
+ sqlassert has no result-type model per dialect, so precision and type
283
+ differences are always a caveat, never a refusal. A replacement whose value
284
+ differs otherwise (`sum` of a BOOLEAN counts it) or whose type is unknown is
285
+ no Rewrite.
286
+ _Avoid_: Unsafe rewrite, approximate rewrite, lossy rewrite (the rows are
287
+ the same)
288
+
289
+ **Implied Condition**:
290
+ A conjunct of a WHERE or ON that the other conjuncts and the input's facts
291
+ make TRUE on every row whose columns it reads are non-null: an equality two
292
+ others chain, two sides pinned to one value, a self-join's copies of one
293
+ column, a list holding the column's whole Enumerated Domain. Its Rewrite
294
+ deletes it, or, where a column may be NULL, weakens it to `IS NOT NULL`.
295
+ Calcite's term (`RexSimplify`: terms "implied by predicates" are removed or
296
+ weakened); Paulley's subsumed predicate.
297
+ _Avoid_: Redundant condition (the literature's redundant predicates are the
298
+ ones an optimizer adds), subsumed predicate, tautology
299
+
300
+ **Hazard**:
301
+ A place whose result the SQL leaves unspecified or likely wrong, with the
302
+ failed Proof that would have pinned it: a Fan Trap or Chasm Trap, an unmarked
303
+ join that may be many to many, a `LIMIT`
304
+ that picks arbitrary rows among ties, a scalar subquery that may return more
305
+ than one row, a join equality that casts, an exact equality of a float
306
+ (a Float Equality), a query that never returns a row.
307
+ The SQL may be what its author meant. `suggest` lists Hazards last; the
308
+ suggestion's type (`SuggestType`) is rewrite, rewrite with caveat, marker or
309
+ hazard.
310
+ _Avoid_: Smell, code smell, lint, warning; "level" for the suggestion's type
247
311
 
248
312
  **Create Statement**:
249
313
  A top-level SQL declaration that introduces a Named Relation or related schema Knowledge into the analyzed program.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlassert
3
- Version: 0.3.1
3
+ Version: 0.3.3
4
4
  Summary: Asserts and static proofs for your SQL, without touching your data.
5
5
  Author: Fred Israel
6
6
  License-Expression: MIT
@@ -25,13 +25,22 @@ Requires-Dist: hypothesis; extra == "test"
25
25
  Requires-Dist: pytest; extra == "test"
26
26
  Requires-Dist: pytest-xdist; extra == "test"
27
27
  Provides-Extra: dev
28
- Requires-Dist: ty; extra == "dev"
28
+ Requires-Dist: ty>=0.0.104; extra == "dev"
29
29
  Dynamic: license-file
30
30
 
31
31
  # sqlassert
32
32
 
33
+ [![PyPI version](https://img.shields.io/pypi/v/sqlassert)](https://pypi.org/project/sqlassert/)
34
+ [![CI](https://github.com/polvoazul/sqlassert/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/polvoazul/sqlassert/actions/workflows/ci.yml)
35
+ [![MIT license](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
36
+ [![Python 3.13+](https://img.shields.io/badge/python-3.13%2B-blue)](https://pypi.org/project/sqlassert/)
37
+
33
38
  **sqlassert adds asserts and static proofs to your SQL, without touching your data, to catch common mistakes before they ship.**
34
39
 
40
+ [![Open the interactive demo showing highlighted SQL and a Fan Trap finding](docs/assets/sqlassert-demo-preview.png)](https://polvoazul.github.io/sqlassert/demo.html)
41
+
42
+ [Open the interactive demo](https://polvoazul.github.io/sqlassert/demo.html)
43
+
35
44
  Mark what a query must guarantee (this join never multiplies rows, this column is a key, this `CASE` covers every status) and sqlassert proves it from the SQL and schema alone. A proof holds for *any* data, not just the rows in the table today, and it runs in milliseconds in your test suite or CI, with no warehouse and no connection.
36
45
 
37
46
  ```bash
@@ -99,14 +108,32 @@ limit 10;
99
108
 
100
109
  ```console
101
110
  $ sqlassert suggest orders.sql
102
- high line 7 LEFT JOIN users AS u INNER JOIN every left row matches exactly one right row, so the LEFT JOIN pads nothing: write JOIN
103
- high line 8 LEFT JOIN coupons AS c Redundant Join at most one match per row and no column of coupons AS c is used outside its ON: delete the join
104
- mid line 7 LEFT JOIN users AS u Exactly One Join /**ASSERT EXACTLY ONE**/
111
+ rewrite line 7 LEFT JOIN users AS u INNER JOIN every left row matches exactly one right row, so the LEFT JOIN pads nothing: write JOIN
112
+ --- orders.sql
113
+ +++ orders.sql (rewritten)
114
+ @@ -5,5 +5,5 @@
115
+ select o.id, u.name
116
+ from orders o
117
+ -left join users u on u.id = o.user_id -- user_id is NOT NULL REFERENCES users(id)
118
+ +join users u on u.id = o.user_id -- user_id is NOT NULL REFERENCES users(id)
119
+ left join coupons c on c.id = o.coupon_id -- nothing from coupons is used
120
+ order by u.name
121
+ rewrite line 8 LEFT JOIN coupons AS c Redundant Join at most one match per row and no column of coupons AS c is used outside its ON: delete the join
122
+ --- orders.sql
123
+ +++ orders.sql (rewritten)
124
+ @@ -6,5 +6,5 @@
125
+ from orders o
126
+ left join users u on u.id = o.user_id -- user_id is NOT NULL REFERENCES users(id)
127
+ -left join coupons c on c.id = o.coupon_id -- nothing from coupons is used
128
+ +-- nothing from coupons is used
129
+ order by u.name
130
+ limit 10;
131
+ marker line 7 LEFT JOIN users AS u Exactly One Join /**ASSERT EXACTLY ONE**/
105
132
  ...
106
- low line 10 Root Select Arbitrary LIMIT the ORDER BY does not determine (id), so rows tied on it come in an arbitrary order and LIMIT may keep different rows on each run: order by a key as well
133
+ hazard line 10 Root Select Arbitrary LIMIT the ORDER BY does not determine ('id'), so rows tied on it come in an arbitrary order and LIMIT may keep different rows on each run: order by a key as well
107
134
  ```
108
135
 
109
- Every `high` rewrite is backed by a proof that it leaves the result unchanged, row for row. `--annotate` pastes the suggested markers into the file.
136
+ Every rewrite is backed by a proof that it leaves the result unchanged, row for row, and comes with the exact diff that makes it; comments and markers in the text it replaces are kept. `--annotate` pastes the suggested markers into the file.
110
137
 
111
138
  ### A CASE that forgets the new status
112
139
 
@@ -161,7 +188,7 @@ Every marker is a SQL comment (`/**ASSERT ...**/`), so annotated SQL still runs
161
188
  | [`analyze(sql)`](#usage) | Python API: prove a SQL Program's markers from its `CREATE` statements, in your test suite. |
162
189
  | [`analyze_database`](#usage) | The same, with tables, keys and views read from a live catalog (metadata only, never rows). |
163
190
  | [`sqlassert check`](#checking-in-ci) | CLI for CI: text, JSON, SARIF and GitHub annotation output, `pyproject.toml` config. |
164
- | [`sqlassert suggest`](#suggesting-markers) | Lists provable markers, proved rewrites, and smells (fan traps, chasm traps, arbitrary LIMIT, ...). |
191
+ | [`sqlassert suggest`](#suggesting-markers) | Lists provable markers, proved rewrites, and hazards (fan traps, chasm traps, arbitrary LIMIT, ...). |
165
192
  | [`sqlassert-dbt`](https://github.com/polvoazul/sqlassert/tree/main/integrations/dbt#readme) | Checks a dbt project from its manifest and skips the tests the SQL proves. |
166
193
 
167
194
  | Dialect | Key constraints | Catalog fetcher | Dialect facts certified on a real engine |
@@ -222,7 +249,7 @@ where id > 0
222
249
  select * from active_users;
223
250
  ```
224
251
 
225
- The trailing marker applies to the relation produced by that Select Expression. `/**ASSERT NOT NULL UNIQUE(id)**/` asserts that `(id)` is a specific non-null Unique Set of `active_users`; `/**ASSERT UNIQUE(email)**/` would assert nullable-tolerant uniqueness instead. The assertion is proved from the SQL Program, not trusted as a declaration. If it cannot be proved, its outcome is `UNKNOWN`.
252
+ The trailing marker applies to the relation produced by that Select Expression. After the last token of a query with `UNION`, `INTERSECT` or `EXCEPT` (its `ORDER BY` and `LIMIT` included), it applies to the whole query; to mark its last operand alone, put that operand in parentheses. A marker between two operands applies to the one before it. `/**ASSERT NOT NULL UNIQUE(id)**/` asserts that `(id)` is a specific non-null Unique Set of `active_users`; `/**ASSERT UNIQUE(email)**/` would assert nullable-tolerant uniqueness instead. The assertion is proved from the SQL Program, not trusted as a declaration. If it cannot be proved, its outcome is `UNKNOWN`.
226
253
 
227
254
  Unique Set Assertions can be attached to a Root Select, view, CTE, or FROM subquery. A proved assertion on a named relation is also available to later statements in the same SQL Program.
228
255
 
@@ -246,9 +273,9 @@ with tagged as (select id, tags, old_tags from posts /**DECLARE NOT NULL ELEMENT
246
273
  select id, tags <> old_tags as retagged from tagged /**ASSERT NOT NULL(retagged)**/
247
274
  ```
248
275
 
249
- A column of unknown type is taken to be a scalar, not a composite. A
250
- constructor (`ARRAY[...]`, `ROW(...)`) is not modelled, so a comparison with
251
- one is never proved non-null.
276
+ If an operand's type is unknown, a comparison may require evidence that
277
+ its elements are non-null. Declare the source type or supply a catalog
278
+ connection to resolve it.
252
279
 
253
280
  ### Foreign Key
254
281
 
@@ -274,7 +301,7 @@ Nulls follow SQL's `MATCH SIMPLE`: a row with a null in any referencing column i
274
301
 
275
302
  `LIMIT` preserves facts about the rows it retains, including outgoing Foreign Keys, uniqueness, non-nullness, and Enumerated Domains. It may remove a required referenced row, so coverage onto its input does not establish coverage onto its result. The same boundary applies to `OFFSET`. A hard limit of at most one row also proves uniqueness without an input key.
276
303
 
277
- Equality Groups merge columns only when their declared comparison types are known and match, without collation. Mixed or unknown types leave value propagation unproved, even when SQL would compare them using implicit casts.
304
+ Equality Groups merge columns only when their declared comparison types are known and match. Mixed or unknown types leave value propagation unproved, even when SQL would compare them using implicit casts.
278
305
 
279
306
  `/**DECLARE FOREIGN KEY(...) REFERENCES relation(...)**/` states the coverage as trusted evidence (`Declared ReferentialCoverage` in explanations); it never vouches for the referenced Unique Set, which is still proved separately. A marker naming a column the referenced relation does not have is reported as `unknown-referenced-column`.
280
307
 
@@ -321,7 +348,7 @@ Dependencies come from keys, equalities and constants in `WHERE` and `ON`, group
321
348
 
322
349
  ### Enum
323
350
 
324
- `/**ASSERT ENUM(status IN ('new', 'paid'))**/` proves that every non-null value of `status` is one of the listed values. NULL is never in the set: `NOT NULL` governs it separately. One marker names one column, and lists distinct, non-null string, numeric, and boolean literals, which may be mixed: `/**ASSERT ENUM(priority IN (1, 2, 3))**/`, `/**DECLARE ENUM(active IN (TRUE))**/`. Anything else -- `NULL`, an empty list, a repeated value, `DATE '2020-01-01'`, a column, an expression -- is reported as a malformed marker.
351
+ `/**ASSERT ENUM(status IN ('new', 'paid'))**/` proves that every non-null value of `status` is one of the listed values. NULL is never in the set: `NOT NULL` governs it separately. So a column that is always NULL, like `CAST(NULL AS INTEGER) + 1`, satisfies every ENUM; the proof then warns `always-null-column`, as does any proved `UNIQUE`, `DETERMINES` determinant, `FOREIGN KEY`, `NOT NULL ELEMENTS` or `EXHAUSTIVE` operand that holds only because a column it names is always NULL. One marker names one column, and lists distinct, non-null string, numeric, and boolean literals, which may be mixed: `/**ASSERT ENUM(priority IN (1, 2, 3))**/`, `/**DECLARE ENUM(active IN (TRUE))**/`. Anything else -- `NULL`, an empty list, a repeated value, `DATE '2020-01-01'`, a column, an expression -- is reported as a malformed marker.
325
352
 
326
353
  ```sql
327
354
  with o as (
@@ -334,7 +361,7 @@ select status from o where status <> 'void' and status in ('new', 'paid')
334
361
 
335
362
  Domains come from `DECLARE ENUM` and external Knowledge, literals, `coalesce` of enumerated arguments, and simple `CASE` expressions (see below), and follow pass-through and renamed columns through filters, joins, aliases, grouping keys, `DISTINCT`, views, CTEs, and subqueries. A `WHERE` or inner-join `ON` conjunct `status = 'paid'` or `status IN ('new', 'paid')` narrows it, as does an outer join's `ON` on the side it pads. A domain crosses equalities: after `WHERE a = b` (or an inner-join `ON a = b`), `b`'s domain is `a`'s intersected with its own. An asserted set larger than the known domain is proved; an `UNKNOWN` explanation lists each possible value the assertion does not cover, such as "status may be 'void', which the assertion does not cover". A declaration does not claim that every listed value occurs. `UNION` columns, aggregates other than grouping keys, and other computed expressions are not enumerated.
336
363
 
337
- A value keeps its SQL type: numeric `1`, string `'1'`, and `TRUE` are three values, and none covers another. A number is identified by how it is written, because that is its SQL type: `007` is `7`, but `1.0` (a decimal) and `1e0` (a double) are not `1`, so asserting `ENUM(n IN (1))` of a column known to be `1.0` is `UNKNOWN`. Narrowing is more careful than identity: SQL compares a column with a literal after implicit casts, so one value can equal two different literals -- a `FLOAT` equals both `0.1` and `0.100000001`, a `VARCHAR` `'1.4'` equals both `1` and `1.4`, and an `INTEGER` equals both `1` and `'1'`. Domains therefore never lose a value that might equal one on the other side. Distinct strings, too, can equal one value -- an `INTEGER` equals `'01'` and `'1'`, a `VARCHAR COLLATE NOCASE` equals `'a'` and `'A'` -- so they narrow each other only on a column declared `VARCHAR` or `TEXT` compared by identity: with no `COLLATE`, in DuckDB or PostgreSQL (whose default collation is binary). A column of unknown type is not narrowed that way. A MySQL `ENUM` column's domain is its members without trailing spaces, as MySQL stores them (under its default strict `sql_mode`).
364
+ A value keeps its SQL type: numeric `1`, string `'1'`, and `TRUE` are three values, and none covers another. A number is identified by how it is written, because that is its SQL type: `007` is `7`, but `1.0` (a decimal) and `1e0` (a double) are not `1`, so asserting `ENUM(n IN (1))` of a column known to be `1.0` is `UNKNOWN`. Narrowing is more careful than identity: SQL compares a column with a literal after implicit casts, so one value can equal two different literals -- a `FLOAT` equals both `0.1` and `0.100000001`, a `VARCHAR` `'1.4'` equals both `1` and `1.4`, and an `INTEGER` equals both `1` and `'1'`. Domains therefore never lose a value that might equal one on the other side. Distinct strings, too, can equal one value -- an `INTEGER` equals `'01'` and `'1'`, a MySQL `VARCHAR` equals `'a'` and `'A'` -- so they narrow each other only on a column declared `VARCHAR` or `TEXT` compared by identity: in DuckDB, PostgreSQL or Trino (whose default collation is binary). A column of unknown type is not narrowed that way. A MySQL `ENUM` column's domain is its members without trailing spaces, as MySQL stores them (under its default strict `sql_mode`).
338
365
 
339
366
  ### Exhaustive CASE
340
367
 
@@ -477,27 +504,36 @@ Pass `dialect=` (a SQLGlot dialect name) to `analyze`, `analyze_database` and
477
504
  declared `NOT ENFORCED` or `DEFERRABLE`, a MySQL column-level `REFERENCES`
478
505
  (ignored before MySQL 9.0), a foreign key of a MySQL table whose `ENGINE`
479
506
  does not enforce them, and SQLite foreign keys.
480
- - **Text.** `VARCHAR` and `TEXT` with no `COLLATE` are taken to compare by
481
- identity in DuckDB, PostgreSQL and Trino, whose shipped default collation is
482
- binary (Trino has no collations); a setting that changes it (DuckDB's
507
+ - **CHECK constraints.** `CHECK (col IN ('a', 'b'))` and `CHECK (col = v)`,
508
+ over literals and joined by AND, state col's Enumerated Domain, as ENUM
509
+ does (NULL passes a CHECK, and is outside every domain). They are trusted
510
+ like keys: Knowledge where the database checks them, a Property
511
+ Declaration under `trust_unenforced_keys` in Snowflake, BigQuery,
512
+ Redshift, Trino, Hive and Databricks / Spark. Any other CHECK is ignored
513
+ with an `ignored-check-constraint` warning.
514
+ - **Text.** `VARCHAR` and `TEXT` are taken to compare by identity in
515
+ DuckDB, PostgreSQL and Trino, whose shipped default collation is binary
516
+ (Trino has no collations); a setting that changes it (DuckDB's
483
517
  `SET default_collation`) is out of scope. MySQL's default collations ignore case, and the warehouses are
484
- not yet certified, so their text is not. Text with any `COLLATE` is never
485
- taken to compare by identity.
518
+ not yet certified, so their text is not. sqlassert supports each dialect's
519
+ default collation only: a `COLLATE` is opaque and warns
520
+ `unsupported-construct`, and a column declared with one is untyped.
486
521
  - **Zoned timestamps.** A TIMESTAMP WITH TIME ZONE compares by identity where
487
522
  it holds an instant only (DuckDB, PostgreSQL, MySQL, BigQuery, Spark,
488
523
  Redshift). Trino and Snowflake keep the zone it was given, so equal instants
489
524
  cast to different text: there it does not, and comparing a `CAST` of one
490
525
  warns (`zoned-timestamp-cast`).
491
526
  - **NULL.** Arithmetic and CAST are taken never to return NULL for non-null
492
- operands only where they raise instead (DuckDB, PostgreSQL, Snowflake,
493
- BigQuery, Redshift, Trino); division likewise, except in DuckDB. Spark
494
- (outside ANSI mode) may return NULL even from a comparison. MySQL is modelled
527
+ operands only where they raise instead (DuckDB, PostgreSQL, BigQuery,
528
+ Redshift, Trino, and Spark and Databricks under ANSI mode, their default);
529
+ division likewise in PostgreSQL, Snowflake, BigQuery, Redshift, Trino and
530
+ Databricks. Spark and Hive may return NULL even from a comparison (a failed
531
+ implicit cast). Each engine is modelled at its latest release under its
532
+ default settings (ADR 0006). MySQL is modelled
495
533
  under its default strict `sql_mode`, in 8.4 and later: a comparison of
496
534
  non-null operands is non-null, arithmetic is not taken as checked. A CAST from JSON may be NULL everywhere (JSON `null`). `||` and
497
535
  `concat()` follow each dialect's NULL handling.
498
- - **MySQL `||`** is OR, or concatenation under `sql_mode` `PIPES_AS_CONCAT`,
499
- which also groups its operands differently, so it is an unknown function of
500
- its operands, with an `ambiguous-operator` warning: write `OR` or `CONCAT()`.
536
+ - **MySQL `||`** is OR, as under the default `sql_mode` (no `PIPES_AS_CONCAT`).
501
537
 
502
538
  ### Checking in CI
503
539
 
@@ -563,48 +599,81 @@ A column marker goes at the end of the Select Expression on that line; a join ma
563
599
 
564
600
  From Python, `suggest(sql)` returns the same suggestions, each with its `site`, `property`, `marker`, and `evidence`; `report.annotated()` returns the SQL with every marker pasted in. Only proved properties are suggested, each Unique Set in its strongest form (`NOT NULL UNIQUE` over `UNIQUE`) and minimal (no superset of another suggestion), and each join in its most specific proved form: `EXACTLY ONE`, then `ONE TO ONE`, then `MANY TO ONE` or `ONE TO MANY`. Unique Sets are searched exhaustively up to `max_size` columns (default 3); a wider one is still found when no smaller one exists. Properties the SQL already asserts or declares are not suggested again.
565
601
 
566
- #### Improvements
602
+ #### Rewrites
567
603
 
568
- Before any marker, `suggest` lists improvements to the SQL itself (level `high`; markers are `mid`). Each is a rewrite a proof shows leaves the result unchanged, row for row:
604
+ Before any marker, `suggest` lists rewrites to the SQL itself (type `rewrite`; markers are `marker`). Each is a rewrite a proof shows leaves the result unchanged, row for row, printed as the reason and a unified diff of the exact edits that make it. The edits are placed from the SQL's tokens and change only what the rewrite needs: the rest of the text, comments and markers included, stays as written. One that may change an output column's type or precision, or overflow where the original did not, is a `rewrite with caveat`, listed after the others: its message ends with a `Caveat:` naming the column and the risk (sqlassert has no result-type model per dialect, so precision and type differences are caveated, never refused). A plain `rewrite` never turns a query that runs into one that fails.
605
+
606
+ ```sql
607
+ create table users (id integer primary key, name varchar);
608
+ create table coupons (id integer primary key, code varchar);
609
+ create table orders (id integer primary key, user_id integer not null references users (id), coupon_id integer);
610
+ with big as (select * from orders where user_id > 100)
611
+ select o.id, u.name, u.id as user_id
612
+ from orders o
613
+ left join users u on u.id = o.user_id
614
+ left join coupons c on c.id = o.coupon_id
615
+ group by o.id, u.name, u.id;
616
+ ```
569
617
 
570
618
  ```bash
571
619
  $ sqlassert suggest orders.sql
572
- high line 4 CTE big Unused CTE CTE big is never referenced, so it never runs and its markers go unchecked: delete it
573
- high line 7 LEFT JOIN users AS u INNER JOIN every left row matches exactly one right row, so the LEFT JOIN pads nothing: write JOIN
574
- high line 8 LEFT JOIN coupons AS c Redundant Join at most one match per row and no column of coupons AS c is used outside its ON: delete the join
575
- high line 9 Root Select Redundant GROUP BY (o.id, u.name) determine u.id, NULL equal to NULL: drop u.id from GROUP BY and select any_value(u.id) AS user_id
576
- mid line 7 LEFT JOIN users AS u Exactly One Join /**ASSERT EXACTLY ONE**/
620
+ rewrite line 4 CTE big Unused CTE CTE big is never referenced, so it never runs and its markers go unchecked: delete it
621
+ --- orders.sql
622
+ +++ orders.sql (rewritten)
623
+ @@ -2,5 +2,4 @@
624
+ create table coupons (id integer primary key, code varchar);
625
+ create table orders (id integer primary key, user_id integer not null references users (id), coupon_id integer);
626
+ -with big as (select * from orders where user_id > 100)
627
+ select o.id, u.name, u.id as user_id
628
+ from orders o
629
+ rewrite line 7 LEFT JOIN users AS u INNER JOIN every left row matches exactly one right row, so the LEFT JOIN pads nothing: write JOIN
630
+ ...
631
+ rewrite line 9 Root Select GROUP BY of one row per group no two rows agree on ('o.id', 'u.name', 'u.id'), NULL equal to NULL, so every group is one row: drop GROUP BY and write each aggregate as its value over that row
632
+ --- orders.sql
633
+ +++ orders.sql (rewritten)
634
+ @@ -6,4 +6,3 @@
635
+ from orders o
636
+ left join users u on u.id = o.user_id
637
+ -left join coupons c on c.id = o.coupon_id
638
+ -group by o.id, u.name, u.id;
639
+ +left join coupons c on c.id = o.coupon_id;
640
+ marker line 7 LEFT JOIN users AS u Exactly One Join /**ASSERT EXACTLY ONE**/
577
641
  ...
578
642
  ```
579
643
 
580
- | Improvement | When |
644
+ Each diff is of that rewrite alone, against the original SQL.
645
+
646
+ | Rewrite | When |
581
647
  |---|---|
582
648
  | `INNER JOIN` | A LEFT (or RIGHT) JOIN that never keeps a padded row: it matches exactly one row, or a later inner join's ON, a `WHERE EXISTS`/`IN` subquery, or the WHERE clause of the same Select rejects NULL in a column it pads, directly or through a later LEFT JOIN whose ON rejects that column (so it pads the same rows). |
583
649
  | Redundant Join | No column of the joined relation is used outside its own ON, and the join keeps every left row once: a LEFT JOIN with at most one match, or an Exactly One inner JOIN. |
584
- | Filter-Only Join | The same for an inner JOIN with at most one match: it only filters, so it can be a `WHERE EXISTS`. Not suggested when a RIGHT or FULL JOIN follows it. |
650
+ | Filter-Only Join | The same for an inner JOIN with at most one match: it only filters, so it moves into the WHERE as `EXISTS (SELECT 1 FROM <relation> WHERE <its ON>)`. Not suggested when a RIGHT or FULL JOIN follows it. |
585
651
  | Redundant DISTINCT | No two rows agree on the selected columns, NULL equal to NULL. |
586
652
  | Redundant ORDER BY key | The ORDER BY keys before it determine it, NULL equal to NULL: it never breaks a tie. Silent when a key is an expression or a name sqlassert cannot map to one column. |
587
653
  | Redundant GROUP BY | The remaining grouping columns determine this one, NULL equal to NULL. One grouping column always stays. |
654
+ | GROUP BY of one row per group | No two input rows agree on the grouping columns, NULL equal to NULL: every group is one row, so `GROUP BY` goes and each aggregate is its value over that row (`count(*)` is 1, `count(x)` a `CASE`, `sum`, `avg`, `min`, `max`, `any_value`, `bool_and`, `bool_or` of x are x), in the select list and in `HAVING`, whose condition then moves into `WHERE` (`HAVING count(*) > 1` becomes `WHERE 1 > 1`). A rewrite with caveat when a type or precision changes: `sum(x)` of an INTEGER is a HUGEINT in DuckDB, `x` an INTEGER; `sum(x) + 1` may overflow as `x + 1`; `avg(x)` of a BIGINT, HUGEINT, UBIGINT or DECIMAL is `x`, its exact value, where avg's DOUBLE may round it. None where the value may differ otherwise (`sum` of a BOOLEAN, `avg` of an integer inside an expression, which may divide as an integer) or the argument's type is unknown, nor beside a call SQLGlot does not know (DuckDB's `mean` or `arbitrary`), which may be an aggregate the analysis does not model. Every spelling of a call it models is rewritten: with `ALL` or `DISTINCT`, IGNORE or RESPECT NULLS, BigQuery's `HAVING MAX`, or as an ODBC `{fn ...}` escape. |
588
655
  | Redundant EXISTS | A `WHERE EXISTS`, `IN` subquery or SEMI JOIN every row passes: each row matches exactly one row of it (a non-null Foreign Key onto a key, and an ON of column equalities only). |
589
656
  | Unused CTE | Nothing in its WITH reaches it, directly or through another CTE. Its markers are never checked either. |
590
657
 
591
- `report.improvements` holds them, each with its `site`, `rewrite`, `message`, and `evidence`; `--explain` prints the proofs. Padding is only followed within the join's own Select Expression: past it, a LIMIT, window, or aggregate may see the padded rows before a filter removes them.
658
+ `report.rewrites` holds them, each with its `site`, `kind`, `message`, `edits` (each an `Edit(start, end, replacement)` on the original SQL's offsets), `evidence`, and `suggest_type` (`SuggestType.REWRITE` or `SuggestType.REWRITE_WITH_CAVEAT`); `rewrite.rewritten(report.sql)` is the rewritten SQL and `rewrite.diff(report.sql)` its diff. `--explain` prints the proofs. Padding is only followed within the join's own Select Expression: past it, a LIMIT, window, or aggregate may see the padded rows before a filter removes them.
592
659
 
593
- Low-level smells come last: places whose result the SQL leaves unspecified. `report.smells` holds them, each with its `site`, `concern`, `message`, and the failed proof as `evidence`.
660
+ Hazards come last: places whose result the SQL leaves unspecified. `report.hazards` holds them, each with its `site`, `concern`, `message`, and the failed proof as `evidence`.
594
661
 
595
- | Smell | When |
662
+ | Hazard | When |
596
663
  |---|---|
597
664
  | Arbitrary LIMIT | A `LIMIT` or `OFFSET` whose `ORDER BY` (if any) does not determine every selected column, NULL equal to NULL: rows tied on the sort keys may come in any order, so which rows are kept can change between runs. Silent when an `ORDER BY` key is an expression or a name sqlassert cannot map to one column. |
598
665
  | Scalar subquery | A scalar subquery not proved to return at most one row, a runtime error when it returns more: uncorrelated, its body is not proved to have at most one row; correlated, the columns its WHERE binds to the outer row are not proved a Unique Set. |
599
666
  | Implicit Cast | A join equality between a text column and a column of another declared type: the text is cast, so different strings may match one value (`'01'` and `'1'` both equal 1). No cardinality is proved across it either: cast explicitly, and the proof stays `UNKNOWN`, which is correct. |
667
+ | Float equality | An equality (`=`, `<>`, `IS [NOT] DISTINCT FROM`, an `IN` list or subquery) with an operand of a known floating type (REAL, FLOAT, DOUBLE), against another float, an integer, a decimal or a literal: floats round, so `x = 0.1` misses a DOUBLE computed as `0.1 + 0.2 - 0.2`, and `a.id = d.x` of a BIGINT and a DOUBLE matches two ids above 2^53. In a join's ON, a WHERE or HAVING, and an `IN` or `EXISTS` correlation, in every dialect. Silent for an ordering (`<`, `>`) and an operand whose type is unknown. Compare within a tolerance or use an exact type. |
600
668
  | Fan Trap | An aggregate over a join that is not proved to repeat rows of only one input, when its argument (or, for `count(*)`, either input) comes from rows the join may repeat: `sum(p.amount)` over `orders JOIN payments USING (customer_id)`. |
601
669
  | Chasm Trap | An aggregate over a one-to-many join whose argument is on the side with one row per key: `sum(c.credit)` over `customers JOIN orders`. Every aggregate counts, `min` and `max` included. Silent when the repeated input has no known Unique Set, or the argument reads both inputs. |
670
+ | Many-to-many join | A join with no join marker that is not proved to repeat rows of only one input, both inputs having a known Unique Set: `orders JOIN payments USING (customer_id)` repeats each order once per payment and each payment once per order. A many-to-many join is rarely meant. Silent for an explicit `CROSS JOIN`, a semi or anti join, a join in the FROM of a Select whose `DISTINCT` or `GROUP BY` merges the repeats (an aggregate's trap says what they do to it), and a join whose ON equates every column of a known key of one input, when only an unknown column type or an expression keeps the proof from binding it. Write the join marker you expect (`/**ASSERT MANY TO ONE**/`, ...) and `check` proves it or says why not. |
602
671
 
603
672
  `NATURAL JOIN` is unsupported: its presence anywhere in the program produces an `unsupported-natural-join` diagnostic, and `suggest` returns no suggestions. Write explicit `ON` or `USING` conditions instead.
604
673
 
605
674
  ### dbt
606
675
 
607
- The `sqlassert-dbt` plugin, a separate package in this repository (`integrations/dbt/`), checks a compiled dbt project from its `target/manifest.json` (run `dbt compile` or `dbt build` first). It reads only the manifest, so dbt itself is not needed where it runs, and only the latest manifest schema (v12, written by dbt 1.8 through 1.12): compile with a current dbt.
676
+ The `sqlassert-dbt` plugin, a separate package in this repository (`integrations/dbt/`), checks a compiled dbt project from its `target/manifest.json` (run `dbt compile` or `dbt build` first). It reads only the manifest, so dbt itself is not needed where it runs, and only the latest manifest schema (v12, written by dbt 1.8 through 1.12): compile with a current dbt. `target/catalog.json` (written by `dbt docs generate`), read when present, adds the columns and types of sources, seeds and other tables the manifest leaves unknown, except where the project shows the catalog stale; `--catalog PATH` names another.
608
677
 
609
678
  ```bash
610
679
  $ pip install sqlassert-dbt # depends on sqlassert; sqlassert does not depend on it
@@ -633,6 +702,14 @@ $ sqlassert-dbt build . -- --target prod # or: sqlassert-dbt test
633
702
 
634
703
  It runs `dbt compile`, prints the check, then runs `dbt build` (or `dbt test`) with every proved test passed as `--exclude`. dbt runs the upstream tests in that same invocation, so they are trusted, unless the arguments after `--` select nodes (`--select`, `--exclude`, `--selector`, ...), which may leave one out. The exit code is dbt's when dbt fails, else that of the check.
635
704
 
705
+ To see what sqlassert can prove about the models you are editing, as `sqlassert suggest` would on plain SQL:
706
+
707
+ ```bash
708
+ $ sqlassert-dbt suggest models/customers.sql models/stg_orders.sql --explain -- --target dev
709
+ ```
710
+
711
+ It compiles those models and what they read, then lists the rewrites, markers and hazards for each model at its file's lines, with what the model reads declared as `check` declares it. In an incremental model, a rewrite or marker is listed only when both `is_incremental()` branches prove it.
712
+
636
713
  ## Details
637
714
 
638
715
  ### Join Cardinality Syntax
@@ -723,3 +800,8 @@ More compile-time SQL checks can be added under the same model: explicit syntax,
723
800
  ## Roadmap
724
801
 
725
802
  Open work is tracked as one file per issue in [`docs/issues/`](https://github.com/polvoazul/sqlassert/blob/main/docs/issues/README.md).
803
+
804
+ ## Citation
805
+
806
+ If you use sqlassert in published research, please cite the version you used.
807
+ See [CITATION.cff](CITATION.cff) for citation details.