Skip to content

feat(native): recover CTE facts natively behind the preview engine - #1062

Closed
kvlonge wants to merge 3 commits into
mainfrom
feat/native-cte-facts
Closed

kvlonge wants to merge 3 commits into
mainfrom
feat/native-cte-facts

Conversation

@kvlonge

@kvlonge kvlonge commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Why

Native enrichment sent CTE fact recovery for contract models back to Python. Under preview those deferrals are now 0.

Changes

  • Native port of _polyglot_cte_passthrough_facts and filtered non-null outputs (cte_facts.rs); adapter nullability rules passed to native.
  • Defers: non-ASCII text, unknown dialect, types the normaliser defers, unshipped rules, unusual CASE/star/join/CTE shapes, panics. No Python deleted: the default engine still uses it.
  • Test-only binding _oracle_cte_fact_recovery (existing _oracle_* pattern).
  • Out of scope: 12 legacy_analysis, 1 input_enrichment deferrals (same on main).

Test expectation changes

  • Model-analysis parity: "≥20 CTE recoveries" counted Python's reference run, so it is now python_cte_recoveries ≥40, a corpus floor (deterministic 40). Native proof: 0 input_enrichment deferrals (max 120 -> 0) and no mismatches. Native-model minimum also subtracts enrichment deferrals.
  • New test_native_cte_fact_recovery.py: native vs Python recovery over 5,000 seeded queries, adapter profiles (duckdb, snowflake, bigquery, databricks, postgres, tsql, generic, None). The end-to-end test misses most differences (enrichment output only fills untyped columns), and no file compares the functions. Deterministic floors: 4,319 compared, recovered types 1,243, nullability 417, direct 859, non-null 38; 681 non-ASCII deferrals.
  • The wheel parses IF/IFF as if_func, whose arguments Python never collects, so adapters' IF/IFF rules are unknown on both sides. A synthetic kind-keyed profile reaches conditional_result/first_arg.

Verification

  • Sabotage (temporary, reverted): conditional_result and first_arg each fail the differential (2 and 3 mismatches). Forcing native recovery to defer fails the parity gate (68 <= 0).
  • cargo test -p sqlbuild-analysis, clippy/fmt 1.99.0, parity files, make check-ci, make test, hygiene. Earlier: differential (319 identical), seam/differential E2E.

…tion

A seeded differential compares native CTE fact recovery with Python's over 5,000 queries and adapter profiles through a test-only oracle binding. The model-analysis CTE recovery count is relabelled as a corpus floor over Python's reference run.
@kvlonge
kvlonge added this pull request to the merge queue Oct 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 9, 2026
@kvlonge
kvlonge added this pull request to the merge queue Oct 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 9, 2026
@kvlonge
kvlonge added this pull request to the merge queue Oct 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Oct 9, 2026
@kvlonge
kvlonge added this pull request to the merge queue Oct 9, 2026
@kvlonge
kvlonge removed this pull request from the merge queue due to a manual request Oct 9, 2026
@kvlonge

kvlonge commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Landed together in #1075 to cut merge-queue CI runs; review history stays here.

@kvlonge kvlonge closed this Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant