Skip to content

feat(native): normalise and compare types natively behind the preview engine - #1028

Merged
kvlonge merged 2 commits into
mainfrom
feat/native-type-system
Oct 8, 2026
Merged

kvlonge merged 2 commits into
mainfrom
feat/native-type-system

Conversation

@kvlonge

@kvlonge kvlonge commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Why

Contracts, metadata checks and CTE facts compare types; the native analysis stages need the same answers in Rust. This adds one native type normalization that matches Python byte for byte, behind the preview engine.

Changes

  • sqlbuild-analysis::type_system: a port of Python's normalize_type. It parses with the crate's parse_data_type (same Polyglot commit as the wheel, same complexity guard). It reads the type's SQL and arguments the way the wheel exposes them, then applies Python's family rules, dialect rewrites and text fallback.
  • It defers (per call None, so Python runs) for non-ASCII text, more than 32 [ (Polyglot does not bound [] suffixes), dialects this build of Polyglot does not include or does not know, integers beyond i64, and values Python would hold as objects. It returns the parse error so Python logs the same debug event before its fallback.
  • _native.normalize_type binding, wired into the TYPE_SYSTEM stub. Under native-preview, normalize_type and therefore types_equal use it; python and native are unchanged.

Verification

  • Parity property test against Python: 1,500 generated types (parameterized, nested ARRAY/STRUCT/MAP, quoted, padded, case variants, invalid) × 12 dialect names, comparing results and logged errors. The test requires at least 12,000 native answers, 5,000 parse-error fallbacks and 3,000 deferrals, plus named cases for aliases and defaults.
  • Rust unit tests (including the bracket cap, cap+1 and 100,000 suffixes on a 1 MiB thread), and a DuckDB CLI test where contracts compare type spellings under native-preview (identical report and artifacts, native calls answered).
  • The compiler differential reports no wheel type-normalization calls under preview.
  • Passed: cargo test --workspace --all-features, clippy and fmt (1.99.0), make check-ci, make test, make compiler-differential (CI flags), make compiler-differential-shipped, tests/e2e/scripts/compiler_differential.

@kvlonge
kvlonge force-pushed the feat/native-type-system branch from d0d316d to 42e0974 Compare October 8, 2026 12:46
@kvlonge
kvlonge enabled auto-merge (squash) October 8, 2026 12:46
@kvlonge
kvlonge merged commit 37df06a into main Oct 8, 2026
38 checks passed
@kvlonge
kvlonge deleted the feat/native-type-system branch October 8, 2026 13:14
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