data-flow-control 0.2.3__tar.gz → 0.2.4__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 (195) hide show
  1. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/Cargo.lock +3 -3
  2. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/Cargo.toml +1 -1
  3. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/PKG-INFO +1 -1
  4. data_flow_control-0.2.4/passant-core/src/catalog/constraint_subquery.rs +217 -0
  5. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/catalog.rs +10 -1
  6. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/mod.rs +31 -6
  7. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-py/src/bindings/planner.rs +7 -0
  8. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/pyproject.toml +1 -1
  9. data_flow_control-0.2.4/python/data_flow_control/adapters/duckdb_policy_binding.py +263 -0
  10. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/connection.py +35 -3
  11. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/planner.py +4 -0
  12. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/LICENSE +0 -0
  13. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/Cargo.toml +0 -0
  14. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/benches/rewrite_perf.rs +0 -0
  15. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/aggregate_registry.rs +0 -0
  16. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/catalog/dimension.rs +0 -0
  17. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/diagnostics.rs +0 -0
  18. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/explain.rs +0 -0
  19. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/full_push.rs +0 -0
  20. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/identifiers.rs +0 -0
  21. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/intern.rs +0 -0
  22. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/ir.rs +0 -0
  23. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/lib.rs +0 -0
  24. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/optimizer.rs +0 -0
  25. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/parser.rs +0 -0
  26. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/partial_push.rs +0 -0
  27. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/planner.rs +0 -0
  28. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/policy.rs +0 -0
  29. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/policy_compile.rs +0 -0
  30. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/policy_index.rs +0 -0
  31. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/policy_parser.rs +0 -0
  32. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/policy_pgn.pest +0 -0
  33. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/policy_store/branch.rs +0 -0
  34. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/policy_store/compiled.rs +0 -0
  35. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/policy_store/delete.rs +0 -0
  36. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/policy_store/indexes.rs +0 -0
  37. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/policy_store/memory.rs +0 -0
  38. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/policy_store/mod.rs +0 -0
  39. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/query_analysis.rs +0 -0
  40. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/resolution_placement.rs +0 -0
  41. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/resolution_registry.rs +0 -0
  42. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewrite_stats.rs +0 -0
  43. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewrite_strategy.rs +0 -0
  44. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/aggregates.rs +0 -0
  45. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/columns.rs +0 -0
  46. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/constraint_preprocess.rs +0 -0
  47. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/derived_policy.rs +0 -0
  48. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/dimensions.rs +0 -0
  49. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/exists.rs +0 -0
  50. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/expr.rs +0 -0
  51. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/helpers.rs +0 -0
  52. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/insert_output_policy.rs +0 -0
  53. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/joint_lineage/grouped_projection.rs +0 -0
  54. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/joint_lineage/terminal_distinct.rs +0 -0
  55. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/joint_lineage/terminal_except.rs +0 -0
  56. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/joint_lineage/terminal_intersect.rs +0 -0
  57. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/joint_lineage.rs +0 -0
  58. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/limit.rs +0 -0
  59. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/output_scope.rs +0 -0
  60. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/plan/actions.rs +0 -0
  61. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/plan/applicability.rs +0 -0
  62. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/plan/dominance.rs +0 -0
  63. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/plan/mod.rs +0 -0
  64. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/plan/scope_plan.rs +0 -0
  65. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/plan/write_plan.rs +0 -0
  66. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/policy_expr.rs +0 -0
  67. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/projection.rs +0 -0
  68. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/resolution.rs +0 -0
  69. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/scope.rs +0 -0
  70. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/select.rs +0 -0
  71. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/sink_columns.rs +0 -0
  72. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/types.rs +0 -0
  73. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/rewriter/write_path.rs +0 -0
  74. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/semiring.rs +0 -0
  75. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/source_set_index.rs +0 -0
  76. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/source_sets/analysis.rs +0 -0
  77. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/source_sets/annotations.rs +0 -0
  78. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/source_sets/branch.rs +0 -0
  79. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/source_sets/mod.rs +0 -0
  80. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/source_sets/rewrites.rs +0 -0
  81. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/source_sets/split.rs +0 -0
  82. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/sql/ast_stats.rs +0 -0
  83. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/sql/builders.rs +0 -0
  84. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/sql/columns.rs +0 -0
  85. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/sql/dialect.rs +0 -0
  86. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/sql/expr.rs +0 -0
  87. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/sql/expr_key.rs +0 -0
  88. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/sql/mod.rs +0 -0
  89. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/sql/parse.rs +0 -0
  90. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/sql/render.rs +0 -0
  91. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/statement_tables.rs +0 -0
  92. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/src/threshold.rs +0 -0
  93. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/common/duckdb.rs +0 -0
  94. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/common/mod.rs +0 -0
  95. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/completion/conformance.rs +0 -0
  96. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/completion/main.rs +0 -0
  97. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/completion/partial_push.rs +0 -0
  98. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/completion/pgn.rs +0 -0
  99. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/completion/pgn_unique.rs +0 -0
  100. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/completion/policy_storage.rs +0 -0
  101. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/completion/rewrite_api_parity.rs +0 -0
  102. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/completion/semiring.rs +0 -0
  103. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/completion/source_sets.rs +0 -0
  104. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/completion/symmetric_self_join.rs +0 -0
  105. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/completion/threshold.rs +0 -0
  106. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/completion/unique_not_unique.rs +0 -0
  107. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/dialect.rs +0 -0
  108. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/execution/insert.rs +0 -0
  109. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/execution/kill.rs +0 -0
  110. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/execution/main.rs +0 -0
  111. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/execution/oracle.rs +0 -0
  112. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/execution/remove.rs +0 -0
  113. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/execution/update.rs +0 -0
  114. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/expected/duckdb/remove_scan.sql +0 -0
  115. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/expected/postgres/remove_scan.sql +0 -0
  116. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/expected/sqlite/remove_scan.sql +0 -0
  117. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/explain_strategy.rs +0 -0
  118. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/gaps/column_propagation.rs +0 -0
  119. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/gaps/dimensions.rs +0 -0
  120. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/gaps/exists_join.rs +0 -0
  121. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/gaps/having_where.rs +0 -0
  122. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/gaps/identifiers.rs +0 -0
  123. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/gaps/insert_shapes.rs +0 -0
  124. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/gaps/main.rs +0 -0
  125. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/gaps/multi_source.rs +0 -0
  126. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/gaps/operators.rs +0 -0
  127. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/gaps/query_shapes.rs +0 -0
  128. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/gaps/scalar_subquery.rs +0 -0
  129. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/indexed_candidate_differential.rs +0 -0
  130. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/insert_values_body.rs +0 -0
  131. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/kill_null_guard_regression.rs +0 -0
  132. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/paper_examples.rs +0 -0
  133. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/parser.rs +0 -0
  134. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/planner.rs +0 -0
  135. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/policy.rs +0 -0
  136. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/policy_dialect.rs +0 -0
  137. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/policy_store_memory.rs +0 -0
  138. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/rewrite/derived_policy.rs +0 -0
  139. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/rewrite/in_semijoin.rs +0 -0
  140. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/rewrite/insert.rs +0 -0
  141. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/rewrite/joins.rs +0 -0
  142. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/rewrite/main.rs +0 -0
  143. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/rewrite/meal_deduction.rs +0 -0
  144. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/rewrite/output.rs +0 -0
  145. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/rewrite/recursive.rs +0 -0
  146. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/rewrite/scan.rs +0 -0
  147. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/rewrite/update.rs +0 -0
  148. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/rewrite_candidate_regression.rs +0 -0
  149. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/rewrite_fast_paths.rs +0 -0
  150. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/rewrite_large_registry.rs +0 -0
  151. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/rewrite_stats_timings.rs +0 -0
  152. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/scan_ready_expr.rs +0 -0
  153. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/source_set_split_no_parse.rs +0 -0
  154. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/sql_builders.rs +0 -0
  155. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/sql_columns.rs +0 -0
  156. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-core/tests/ui_resolution.rs +0 -0
  157. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-py/Cargo.toml +0 -0
  158. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-py/src/bindings/catalog.rs +0 -0
  159. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-py/src/bindings/errors.rs +0 -0
  160. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-py/src/bindings/mod.rs +0 -0
  161. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-py/src/bindings/policy.rs +0 -0
  162. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-py/src/bindings/stats.rs +0 -0
  163. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/passant-py/src/lib.rs +0 -0
  164. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/__init__.py +0 -0
  165. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/_rust.py +0 -0
  166. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/adapters/__init__.py +0 -0
  167. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/adapters/_retry.py +0 -0
  168. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/adapters/base.py +0 -0
  169. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/adapters/clickhouse.py +0 -0
  170. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/adapters/datafusion.py +0 -0
  171. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/adapters/duckdb.py +0 -0
  172. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/adapters/kill.py +0 -0
  173. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/adapters/pg_catalog.py +0 -0
  174. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/adapters/postgres.py +0 -0
  175. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/adapters/registry.py +0 -0
  176. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/adapters/sqlite.py +0 -0
  177. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/adapters/umbra.py +0 -0
  178. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/aggregate_introspection.py +0 -0
  179. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/catalog.py +0 -0
  180. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/dialect.py +0 -0
  181. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/errors.py +0 -0
  182. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/langchain/__init__.py +0 -0
  183. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/langchain/agent.py +0 -0
  184. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/langchain/call_tool_with_dataflow.py +0 -0
  185. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/langchain/database.py +0 -0
  186. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/langchain/middleware.py +0 -0
  187. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/langchain/schema.py +0 -0
  188. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/langchain/sql_validation.py +0 -0
  189. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/langchain/tool_spec.py +0 -0
  190. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/langchain/wrapper.py +0 -0
  191. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/options.py +0 -0
  192. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/policy.py +0 -0
  193. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/tools/__init__.py +0 -0
  194. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/tools/retry.py +0 -0
  195. {data_flow_control-0.2.3 → data_flow_control-0.2.4}/python/data_flow_control/ui.py +0 -0
@@ -1593,7 +1593,7 @@ dependencies = [
1593
1593
 
1594
1594
  [[package]]
1595
1595
  name = "passant-cli"
1596
- version = "0.2.3"
1596
+ version = "0.2.4"
1597
1597
  dependencies = [
1598
1598
  "anyhow",
1599
1599
  "assert_cmd",
@@ -1605,7 +1605,7 @@ dependencies = [
1605
1605
 
1606
1606
  [[package]]
1607
1607
  name = "passant-core"
1608
- version = "0.2.3"
1608
+ version = "0.2.4"
1609
1609
  dependencies = [
1610
1610
  "anyhow",
1611
1611
  "criterion",
@@ -1623,7 +1623,7 @@ dependencies = [
1623
1623
 
1624
1624
  [[package]]
1625
1625
  name = "passant-py"
1626
- version = "0.2.3"
1626
+ version = "0.2.4"
1627
1627
  dependencies = [
1628
1628
  "passant-core",
1629
1629
  "pyo3",
@@ -3,7 +3,7 @@ members = ["passant-core", "passant-py"]
3
3
  resolver = "2"
4
4
 
5
5
  [workspace.package]
6
- version = "0.2.3"
6
+ version = "0.2.4"
7
7
  edition = "2024"
8
8
  license = "MIT"
9
9
  authors = ["Charlie Summers"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: data-flow-control
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Requires-Dist: duckdb>=1.3.0
5
5
  Requires-Dist: numpy>=1.24.4
6
6
  Requires-Dist: sqlglot==28.3.0
@@ -0,0 +1,217 @@
1
+ //! Registration-time physical relation checks for SQL subqueries in CONSTRAINT.
2
+
3
+ use std::{collections::HashSet, ops::ControlFlow, ptr};
4
+
5
+ use sqlparser::ast::{Expr, ObjectName, Query, TableFactor, Visit, Visitor};
6
+
7
+ use super::TableCatalog;
8
+ use crate::{
9
+ diagnostics::{ErrorKind, RewriteError},
10
+ identifiers::TableKey,
11
+ };
12
+
13
+ #[derive(Default)]
14
+ struct QueryScope {
15
+ visible_ctes: HashSet<TableKey>,
16
+ // A nonrecursive WITH item enters scope only after its defining query.
17
+ pending_ctes: Vec<(*const Query, TableKey)>,
18
+ }
19
+
20
+ pub(super) fn validate(
21
+ catalog: &TableCatalog,
22
+ expr: &Expr,
23
+ constraint: &str,
24
+ ) -> Result<(), RewriteError> {
25
+ struct Relations<'a> {
26
+ catalog: &'a TableCatalog,
27
+ constraint: &'a str,
28
+ queries: Vec<QueryScope>,
29
+ }
30
+
31
+ impl Visitor for Relations<'_> {
32
+ type Break = RewriteError;
33
+
34
+ fn pre_visit_query(&mut self, query: &Query) -> ControlFlow<Self::Break> {
35
+ let mut scope = QueryScope::default();
36
+ if let Some(with) = &query.with {
37
+ for cte in &with.cte_tables {
38
+ let name = TableKey::new(&cte.alias.name.to_string());
39
+ if with.recursive {
40
+ scope.visible_ctes.insert(name);
41
+ } else {
42
+ scope
43
+ .pending_ctes
44
+ .push((ptr::from_ref(cte.query.as_ref()), name));
45
+ }
46
+ }
47
+ }
48
+ self.queries.push(scope);
49
+ ControlFlow::Continue(())
50
+ }
51
+
52
+ fn post_visit_query(&mut self, query: &Query) -> ControlFlow<Self::Break> {
53
+ self.queries.pop();
54
+ if let Some(parent) = self.queries.last_mut()
55
+ && let Some((_, name)) = parent
56
+ .pending_ctes
57
+ .iter()
58
+ .find(|(definition, _)| ptr::eq(*definition, query))
59
+ {
60
+ parent.visible_ctes.insert(name.clone());
61
+ }
62
+ ControlFlow::Continue(())
63
+ }
64
+
65
+ fn pre_visit_table_factor(&mut self, factor: &TableFactor) -> ControlFlow<Self::Break> {
66
+ // Derived tables, aliases and table functions are not physical
67
+ // catalog entries. The visitor still traverses their children.
68
+ let TableFactor::Table {
69
+ name, args: None, ..
70
+ } = factor
71
+ else {
72
+ return ControlFlow::Continue(());
73
+ };
74
+ let name_str = name.to_string();
75
+ let key = TableKey::new(&name_str);
76
+ let is_cte = name.0.len() == 1
77
+ && self
78
+ .queries
79
+ .iter()
80
+ .rev()
81
+ .any(|scope| scope.visible_ctes.contains(&key));
82
+ if self.queries.is_empty() || is_cte || table_exists(self.catalog, name, &name_str) {
83
+ return ControlFlow::Continue(());
84
+ }
85
+ ControlFlow::Break(RewriteError::catalog_with_context(
86
+ ErrorKind::UnknownTable,
87
+ format!(
88
+ "CONSTRAINT subquery table '{name_str}' does not exist in the explicit catalog"
89
+ ),
90
+ Some(name_str),
91
+ None,
92
+ Some(self.constraint.to_string()),
93
+ Some("catalog_validation"),
94
+ ))
95
+ }
96
+ }
97
+
98
+ match expr.visit(&mut Relations {
99
+ catalog,
100
+ constraint,
101
+ queries: Vec::new(),
102
+ }) {
103
+ ControlFlow::Continue(()) => Ok(()),
104
+ ControlFlow::Break(err) => Err(err),
105
+ }
106
+ }
107
+
108
+ // The catalog may store default-schema tables without their schema prefix.
109
+ fn table_exists(catalog: &TableCatalog, name: &ObjectName, display: &str) -> bool {
110
+ if catalog.table_exists(display) {
111
+ return true;
112
+ }
113
+ match name.0.as_slice() {
114
+ [_] => catalog
115
+ .search_path
116
+ .iter()
117
+ .any(|schema| catalog.table_exists(&format!("{schema}.{display}"))),
118
+ [schema, table] => {
119
+ let schema = TableKey::new(&schema.to_string());
120
+ catalog.default_schema.as_ref() == Some(&schema)
121
+ && catalog.table_exists(&table.to_string())
122
+ }
123
+ _ => false,
124
+ }
125
+ }
126
+
127
+ #[cfg(test)]
128
+ mod tests {
129
+ use super::*;
130
+ use crate::{catalog::CatalogSnapshot, rewriter::PassantRewriter};
131
+
132
+ fn register(constraint: &str) -> Result<(), RewriteError> {
133
+ let mut catalog = TableCatalog::from_snapshot(CatalogSnapshot {
134
+ default_schema: Some("main".into()),
135
+ search_path: vec!["tenant".into(), "main".into()],
136
+ ..CatalogSnapshot::default()
137
+ });
138
+ catalog.register_table("target", vec!["id".into()]);
139
+ catalog.register_table("lookup_correct", vec!["id".into()]);
140
+ catalog.register_table("extra_lookup", vec!["id".into()]);
141
+ catalog.register_table("tenant.path_lookup", vec!["id".into()]);
142
+ let mut rewriter = PassantRewriter::with_catalog(catalog);
143
+ rewriter.register_policy_text(&format!(
144
+ "SINK target AS t DIMENSION lookup_correct AS d CONSTRAINT {constraint} ON FAIL RETRY('blocked')"
145
+ ))
146
+ }
147
+
148
+ #[test]
149
+ fn rejects_missing_subquery_relations_with_a_valid_dimension() {
150
+ let cases = [
151
+ (
152
+ "EXISTS (SELECT 1 FROM lookup_typo AS d WHERE d.id = t.id)",
153
+ "lookup_typo",
154
+ ),
155
+ (
156
+ "(SELECT MAX(x.id) FROM lookup_typo AS x) > 0",
157
+ "lookup_typo",
158
+ ),
159
+ ("t.id IN (SELECT x.id FROM lookup_typo AS x)", "lookup_typo"),
160
+ (
161
+ "EXISTS (SELECT 1 FROM lookup_correct AS x WHERE EXISTS (SELECT 1 FROM lookup_typo AS x))",
162
+ "lookup_typo",
163
+ ),
164
+ (
165
+ "EXISTS (WITH x AS (SELECT id FROM lookup_typo) SELECT 1 FROM x)",
166
+ "lookup_typo",
167
+ ),
168
+ (
169
+ "EXISTS (WITH x AS (SELECT id FROM later), later AS (SELECT 1 AS id) SELECT 1 FROM x)",
170
+ "later",
171
+ ),
172
+ (
173
+ "EXISTS (WITH x AS (SELECT 1) SELECT 1 FROM missing_schema.x)",
174
+ "missing_schema.x",
175
+ ),
176
+ (
177
+ "EXISTS (SELECT 1 FROM missing_schema.lookup_correct)",
178
+ "missing_schema.lookup_correct",
179
+ ),
180
+ (
181
+ "EXISTS (SELECT 1 FROM (WITH x AS (SELECT 1) SELECT 1 FROM x) AS q JOIN x ON TRUE)",
182
+ "x",
183
+ ),
184
+ ];
185
+ for (constraint, table) in cases {
186
+ let error = register(constraint).expect_err(constraint);
187
+ assert_eq!(error.kind(), ErrorKind::UnknownTable, "{constraint}");
188
+ let RewriteError::Catalog(details) = error else {
189
+ panic!("expected catalog diagnostic");
190
+ };
191
+ assert_eq!(details.table.as_deref(), Some(table), "{constraint}");
192
+ assert_eq!(details.constraint.as_deref(), Some(constraint));
193
+ assert_eq!(
194
+ details.validation_phase.as_deref(),
195
+ Some("catalog_validation")
196
+ );
197
+ }
198
+ }
199
+
200
+ #[test]
201
+ fn accepts_physical_relations_ctes_and_correlated_aliases() {
202
+ let cases = [
203
+ "EXISTS (SELECT 1 FROM lookup_correct AS d WHERE d.id = t.id)",
204
+ "EXISTS (SELECT 1 FROM extra_lookup AS t WHERE t.id = 9)",
205
+ "EXISTS (SELECT 1 FROM main.lookup_correct AS d WHERE d.id = t.id)",
206
+ "EXISTS (SELECT 1 FROM path_lookup AS p WHERE p.id = t.id)",
207
+ "EXISTS (SELECT 1 FROM unnest([t.id]) AS t(id) WHERE t.id = 1)",
208
+ "EXISTS (SELECT 1 FROM (SELECT t.id AS id) AS t WHERE t.id = 1)",
209
+ "EXISTS (WITH x AS (SELECT id FROM lookup_correct), y AS (SELECT id FROM x) SELECT 1 FROM y WHERE EXISTS (SELECT 1 FROM x WHERE x.id = t.id))",
210
+ "EXISTS (WITH RECURSIVE x(id) AS (SELECT 1 UNION ALL SELECT x.id + 1 FROM x WHERE x.id < 2) SELECT 1 FROM x)",
211
+ "(SELECT t.id) > 0",
212
+ ];
213
+ for constraint in cases {
214
+ register(constraint).unwrap_or_else(|error| panic!("{constraint}: {error}"));
215
+ }
216
+ }
217
+ }
@@ -16,6 +16,7 @@ use crate::policy::{PolicyIr, Resolution};
16
16
  use crate::policy_compile::{
17
17
  ParsedPolicyConstraint, parse_policy_constraint, parse_policy_constraint_with_registry,
18
18
  };
19
+ mod constraint_subquery;
19
20
  mod dimension;
20
21
 
21
22
  /// Catalog facts supplied at policy registration time (from any adapter snapshot).
@@ -25,6 +26,8 @@ pub struct TableCatalog {
25
26
  column_types: HashMap<(TableKey, String), String>,
26
27
  unique_columns: HashSet<(TableKey, String)>,
27
28
  table_row_counts: HashMap<TableKey, u64>,
29
+ default_schema: Option<TableKey>,
30
+ search_path: Vec<String>,
28
31
  loaded: bool,
29
32
  }
30
33
 
@@ -70,7 +73,11 @@ impl TableCatalog {
70
73
  }
71
74
 
72
75
  pub fn from_snapshot(snapshot: CatalogSnapshot) -> Self {
73
- let mut catalog = Self::new();
76
+ let mut catalog = Self {
77
+ default_schema: snapshot.default_schema.as_deref().map(TableKey::new),
78
+ search_path: snapshot.search_path,
79
+ ..Self::default()
80
+ };
74
81
  for (table, info) in snapshot.tables {
75
82
  catalog.register_table(table.clone(), info.columns.clone());
76
83
  for (column, sql_type) in info.types {
@@ -401,6 +408,8 @@ fn validate_pgn_policy_parsed(
401
408
  dimension_columns.insert(TableKey::new(alias), columns);
402
409
  }
403
410
 
411
+ constraint_subquery::validate(catalog, expr, &constraint)?;
412
+
404
413
  let source_names = sources
405
414
  .iter()
406
415
  .map(|source| TableKey::new(source))
@@ -150,16 +150,41 @@ impl PassantRewriter {
150
150
  self.register_policy(policy)
151
151
  }
152
152
 
153
+ fn validate_registration(
154
+ &self,
155
+ policy: &PolicyIr,
156
+ ) -> Result<crate::policy_compile::ParsedPolicyConstraint, RewriteError> {
157
+ let parsed = crate::policy_compile::parse_policy_constraint_with_registry(
158
+ policy.constraint(),
159
+ &self.aggregate_registry,
160
+ )?;
161
+ self.catalog
162
+ .validate_pgn_policy_parsed(policy, &parsed, &self.aggregate_registry)?;
163
+ Ok(parsed)
164
+ }
165
+
166
+ /// Check a batch without adding policies; return constraint SQL and top-level aggregate flags.
167
+ pub fn registration_binding_inputs(
168
+ &self,
169
+ policies: &[PolicyIr],
170
+ ) -> Result<Vec<(String, bool)>, RewriteError> {
171
+ policies
172
+ .iter()
173
+ .map(|policy| {
174
+ let parsed = self.validate_registration(policy)?;
175
+ let aggregate = self
176
+ .aggregate_registry
177
+ .expr_contains_aggregate(&parsed.expr);
178
+ Ok((parsed.sql, aggregate))
179
+ })
180
+ .collect()
181
+ }
182
+
153
183
  /// Validate the entire batch before allocating stable policy identities.
154
184
  pub fn register_policies(&mut self, policies: Vec<PolicyIr>) -> Result<(), RewriteError> {
155
185
  let mut validated = Vec::with_capacity(policies.len());
156
186
  for policy in policies {
157
- let parsed = crate::policy_compile::parse_policy_constraint_with_registry(
158
- policy.constraint(),
159
- &self.aggregate_registry,
160
- )?;
161
- self.catalog
162
- .validate_pgn_policy_parsed(&policy, &parsed, &self.aggregate_registry)?;
187
+ let parsed = self.validate_registration(&policy)?;
163
188
  validated.push((policy, parsed));
164
189
  }
165
190
  let registry = self.aggregate_registry.clone();
@@ -58,6 +58,13 @@ impl PyPlanner {
58
58
  .map_err(map_rewrite_error)
59
59
  }
60
60
 
61
+ fn registration_binding_inputs(&self, policies_json: String) -> PyResult<Vec<(String, bool)>> {
62
+ let policies = parse_policy_specs(&policies_json)?;
63
+ self.rewriter
64
+ .registration_binding_inputs(&policies)
65
+ .map_err(map_rewrite_error)
66
+ }
67
+
61
68
  fn sync_catalog(&mut self, catalog_json: String) -> PyResult<()> {
62
69
  let snapshot = super::catalog::deserialize_catalog_snapshot(&catalog_json)?;
63
70
  self.rewriter.apply_catalog_snapshot(snapshot);
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "data-flow-control"
3
- version = "0.2.3"
3
+ version = "0.2.4"
4
4
  description = "Rust-backed Data Flow Control rewrite engine"
5
5
  license = "MIT"
6
6
  license-files = ["LICENSE"]
@@ -0,0 +1,263 @@
1
+ """Registration binding on a data-free DuckDB connection, not on the live database."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import duckdb
6
+ import sqlglot
7
+ from sqlglot import exp
8
+
9
+ from .._passant import PassantRewriteError
10
+
11
+
12
+ class _Deferred(Exception):
13
+ """An expression has no faithful, safe registration-time context."""
14
+
15
+
16
+ def _quote(name):
17
+ return '"' + name.replace('"', '""') + '"'
18
+
19
+
20
+ def _parts(name):
21
+ node = sqlglot.parse_one(name, into=exp.Table, read="duckdb")
22
+ if not node.parts or not all(isinstance(part, exp.Identifier) for part in node.parts):
23
+ raise _Deferred("relation identifier is not a plain catalog name")
24
+ return tuple(part.name for part in node.parts)
25
+
26
+
27
+ def _parse(sql):
28
+ try:
29
+ return sqlglot.parse_one(sql, read="duckdb")
30
+ except sqlglot.errors.SqlglotError as error:
31
+ raise _Deferred("cannot inspect this SQL form safely") from error
32
+
33
+
34
+ def _read_only(sql, conn):
35
+ # Never send a policy-supplied string to execute(). A second parser makes
36
+ # statement shape independent of sqlglot's inspection.
37
+ statements = conn.extract_statements(sql)
38
+ if len(statements) != 1 or statements[0].type != duckdb.StatementType.SELECT:
39
+ raise _Deferred("expected a single SELECT")
40
+ return conn.sql(sql)
41
+
42
+
43
+ def _native_error(label, error, sql):
44
+ exc = PassantRewriteError(f"{label} failed DuckDB registration binding: {error}\nSQL: {sql}")
45
+ exc.kind = "backend_binding"
46
+ return exc
47
+
48
+
49
+ def _function_names(conn):
50
+ return {
51
+ name.lower()
52
+ for (name,) in conn.execute(
53
+ "SELECT DISTINCT function_name FROM system.main.duckdb_functions()"
54
+ ).fetchall()
55
+ }
56
+
57
+
58
+ class _Binder:
59
+ def __init__(self, sandbox, source_conn, catalog):
60
+ self.sandbox = sandbox
61
+ self.source_conn = source_conn
62
+ self.catalog = catalog
63
+ self.tables = {name.lower(): (name, entry) for name, entry in catalog["tables"].items()}
64
+ self.cloned = set()
65
+ self.live_only_functions = None
66
+
67
+ def _check(self, node):
68
+ if any(isinstance(expr, (exp.DDL, exp.DML, exp.Command)) for expr in node.walk()):
69
+ raise _Deferred("query includes a non-read-only operation")
70
+ if any(not isinstance(table.this, exp.Identifier) for table in node.find_all(exp.Table)):
71
+ # DuckDB can invoke user callbacks or infer a file's schema while
72
+ # binding a table function. Never bind arbitrary table functions.
73
+ raise _Deferred("table function outside the safe binding subset")
74
+ names = {function.name.lower() for function in node.find_all(exp.Anonymous)}
75
+ if names and self.live_only_functions is None:
76
+ declared = {
77
+ entry["name"].lower() for entry in self.catalog.get("aggregate_functions", [])
78
+ }
79
+ self.live_only_functions = (
80
+ _function_names(self.source_conn) | declared
81
+ ) - _function_names(self.sandbox)
82
+ if names & (self.live_only_functions or set()):
83
+ raise _Deferred("requires functions defined only on the live connection")
84
+
85
+ def _lookup(self, parts):
86
+ name = ".".join(parts).lower()
87
+ candidates = [name]
88
+ if len(parts) == 1:
89
+ candidates.extend(
90
+ f"{schema.lower()}.{name}" for schema in self.catalog.get("search_path", [])
91
+ )
92
+ elif len(parts) == 2 and parts[0].lower() == self.catalog.get("default_schema", "").lower():
93
+ candidates.append(parts[1].lower())
94
+ return next((self.tables[key] for key in candidates if key in self.tables), None)
95
+
96
+ def _clone(self, table):
97
+ name, entry = table
98
+ columns = entry["columns"]
99
+ if name in self.cloned:
100
+ return columns
101
+ parts = name.split(".")
102
+ if len(parts) > 2:
103
+ raise _Deferred("catalog relation without a reproducible schema")
104
+ if len(parts) == 2:
105
+ self.sandbox.execute(f"CREATE SCHEMA IF NOT EXISTS {_quote(parts[0])}")
106
+ qualified = ".".join(map(_quote, parts))
107
+ try:
108
+ types = [
109
+ # Metadata only. Parse types separately and interpolate the
110
+ # backend's canonical type rendering, not a policy string.
111
+ str(self.sandbox.sqltype(entry["types"][column]))
112
+ for column in columns
113
+ ]
114
+ except (KeyError, duckdb.Error) as error:
115
+ raise _Deferred("type not reproducible in the isolated catalog") from error
116
+ declarations = ", ".join(
117
+ f"{_quote(column)} {column_type}"
118
+ for column, column_type in zip(columns, types, strict=True)
119
+ )
120
+ statement = f"CREATE TABLE {qualified} ({declarations})"
121
+ parsed = self.sandbox.extract_statements(statement)
122
+ if len(parsed) != 1 or parsed[0].type != duckdb.StatementType.CREATE:
123
+ raise _Deferred("catalog type rendering does not form a single CREATE TABLE")
124
+ self.sandbox.execute(statement)
125
+ self.cloned.add(name)
126
+ return columns
127
+
128
+ def _clone_referenced(self, node):
129
+ for table in node.find_all(exp.Table):
130
+ if table.this.quoted and any(separator in table.name for separator in ("/", "\\")):
131
+ raise _Deferred("possible external relation")
132
+ metadata = self._lookup(tuple(part.name for part in table.parts))
133
+ if metadata is not None:
134
+ self._clone(metadata)
135
+ # CTE names need not exist in the catalog. If it is a missing real
136
+ # table, the native static check or DuckDB itself will reject it.
137
+
138
+ def dimensions(self, policy):
139
+ results, columns = {}, {}
140
+ for alias, sql in (policy.dimension_queries or {}).items():
141
+ try:
142
+ node = _parse(sql)
143
+ self._check(node)
144
+ self._clone_referenced(node)
145
+ columns[alias] = _read_only(sql, self.sandbox).columns
146
+ results[alias] = "duckdb bound"
147
+ except _Deferred as error:
148
+ results[alias] = f"static only: {error}"
149
+ except duckdb.Error as error:
150
+ raise _native_error(f"DIMENSION {alias!r}", error, sql) from error
151
+ return results, columns
152
+
153
+ def constraint(self, policy, sql, aggregate, dimension_columns):
154
+ node = _parse(sql)
155
+ self._check(node)
156
+ self._clone_referenced(node)
157
+ qualifiers = {
158
+ tuple(part.name.lower() for part in column.parts[:-1])
159
+ for column in node.find_all(exp.Column)
160
+ if len(column.parts) > 1
161
+ }
162
+ if ("_output_",) in qualifiers and policy.sink is None:
163
+ raise _Deferred("_OUTPUT_ columns depend on a future query")
164
+ from_items, group_items, used = [], [], set()
165
+
166
+ def add_relation(sql, qualifier, columns):
167
+ normalized = tuple(part.lower() for part in qualifier)
168
+ if normalized in used:
169
+ return
170
+ used.add(normalized)
171
+ from_items.append(sql)
172
+ prefix = ".".join(map(_quote, qualifier))
173
+ group_items.extend(f"{prefix}.{_quote(column)}" for column in columns)
174
+
175
+ def add_table(table, alias=None, *, force=False, allow_short=True):
176
+ parts = _parts(table)
177
+ prefix = (_parts(alias)[-1],) if alias else parts
178
+ normalized = tuple(part.lower() for part in prefix)
179
+ if not force and normalized not in qualifiers and (
180
+ alias or not allow_short or normalized[-1:] not in qualifiers
181
+ ):
182
+ return
183
+ # The native static layer checked direct relation declarations.
184
+ metadata = self._lookup(parts)
185
+ if metadata is None:
186
+ raise _Deferred("catalog relation cannot be reproduced")
187
+ columns = self._clone(metadata)
188
+ table_sql = ".".join(map(_quote, parts))
189
+ add_relation(
190
+ f"{table_sql} AS {_quote(prefix[0])}" if alias else table_sql, prefix, columns
191
+ )
192
+
193
+ for source in policy.sources:
194
+ source_parts = tuple(part.lower() for part in _parts(source))
195
+ aliased = any(
196
+ tuple(part.lower() for part in _parts(base)) == source_parts
197
+ for base in (policy.source_aliases or {}).values()
198
+ )
199
+ add_table(source, force=not aliased, allow_short=not aliased)
200
+ for alias, source in (policy.source_aliases or {}).items():
201
+ add_table(source, alias)
202
+ if policy.sink:
203
+ add_table(policy.sink, policy.sink_alias)
204
+ if policy.sink_alias:
205
+ add_table(policy.sink, allow_short=False)
206
+ add_table(policy.sink, "_OUTPUT_")
207
+ for dimension in policy.dimensions or []:
208
+ dimension_parts = tuple(part.lower() for part in _parts(dimension))
209
+ aliased = any(
210
+ tuple(part.lower() for part in _parts(base)) == dimension_parts
211
+ for alias, base in (policy.dimension_aliases or {}).items()
212
+ if alias not in (policy.dimension_queries or {})
213
+ )
214
+ add_table(dimension, allow_short=not aliased)
215
+ for alias, dimension in (policy.dimension_aliases or {}).items():
216
+ if alias not in (policy.dimension_queries or {}):
217
+ add_table(dimension, alias)
218
+ for alias, query in (policy.dimension_queries or {}).items():
219
+ alias_name = _parts(alias)[-1]
220
+ if (alias_name.lower(),) in qualifiers:
221
+ if alias not in dimension_columns:
222
+ raise _Deferred(f"requires an unbound DIMENSION {alias!r}")
223
+ # An outer derived-table alias provides column bindings only;
224
+ # do not expose it as a CTE or a physical FROM target.
225
+ add_relation(
226
+ f"({query}) AS {_quote(alias_name)}", (alias_name,), dimension_columns[alias]
227
+ )
228
+
229
+ query = f'SELECT ({sql}) AS "__passant_registration_constraint"'
230
+ if from_items:
231
+ query += " FROM " + ", ".join(from_items)
232
+ if aggregate and group_items:
233
+ # The witness need not reproduce multiplicity; it must permit the
234
+ # same typed references beside top-level policy aggregates.
235
+ query += " GROUP BY " + ", ".join(dict.fromkeys(group_items))
236
+ result = _read_only(query, self.sandbox)
237
+ datatype = str(result.types[0])
238
+ if datatype not in {"BOOLEAN", '"NULL"', "NULL"}:
239
+ raise _native_error("CONSTRAINT", f"expected boolean, got {datatype}", sql)
240
+ return "duckdb bound"
241
+
242
+
243
+ def validate_policy_bindings(source_conn, catalog, policies, inputs):
244
+ """Run the binder, never evaluate policy results or expose live data/functions."""
245
+ config = {
246
+ "enable_external_access": False,
247
+ "autoload_known_extensions": False,
248
+ "autoinstall_known_extensions": False,
249
+ "python_enable_replacements": False,
250
+ }
251
+ with duckdb.connect(":memory:", config=config) as sandbox:
252
+ binder = _Binder(sandbox, source_conn, catalog)
253
+ reports = []
254
+ for policy, (sql, aggregate) in zip(policies, inputs, strict=True):
255
+ dimensions, columns = binder.dimensions(policy)
256
+ try:
257
+ constraint = binder.constraint(policy, sql, aggregate, columns)
258
+ except _Deferred as error:
259
+ constraint = f"static only: {error}"
260
+ except duckdb.Error as error:
261
+ raise _native_error("CONSTRAINT", error, sql) from error
262
+ reports.append({"constraint": constraint, "dimensions": dimensions})
263
+ return reports