From 2d146f511a15e7a5b2b9fbf70e9ad4c759f25466 Mon Sep 17 00:00:00 2001
From: Kevin Longe <273747162+kvlonge@users.noreply.github.com>
Date: Sun, 8 Nov 2026 07:22:56 +0000
Subject: [PATCH 1/2] feat(types): normalize adapter types without Polyglot
Read each type with SQLQuack's parser for the dialect, or SQLBuild's own
type reader where a dialect has none, and spell it the way the
Polyglot-based normalization did so the same aliases stay equal.
normalize_type now raises only ValueError, for an unknown dialect.
---
Cargo.lock | 1 +
crates/sqlbuild-analysis/Cargo.toml | 1 +
.../main/classify_cursor_sql_type.rs | 6 +-
.../src/type_system/_helpers/mod.rs | 3 +-
.../src/type_system/_helpers/parsed.rs | 234 +-
.../src/type_system/_helpers/shallow_args.rs | 442 --
.../src/type_system/_helpers/spelling.rs | 510 ++
.../src/type_system/_helpers/type_reader.rs | 440 ++
.../src/type_system/constants.rs | 42 +-
.../src/type_system/errors.rs | 7 +-
.../src/type_system/main/mod.rs | 2 +-
.../src/type_system/main/normalize_type.rs | 40 +-
.../type_system/main/polyglot_type_args.rs | 17 -
.../src/type_system/main/type_args.rs | 13 +
.../src/type_system/models.rs | 2 +-
.../src/type_system/tests/alias_groups.json | 327 ++
.../src/type_system/tests/helpers.rs | 10 +-
.../type_system/tests/test_normalize_type.rs | 12 +-
.../src/type_system/tests/test_same_type.rs | 59 +-
.../src/type_system/tests/test_types.rs | 7 +
.../src/warehouse_types/_helpers/mod.rs | 1 +
.../warehouse_types/_helpers/type_trees.rs | 67 +
.../src/warehouse_types/main/mod.rs | 1 +
.../main/parse_warehouse_type.rs | 57 +-
.../src/warehouse_types/main/type_tree.rs | 15 +
.../src/warehouse_types/mod.rs | 2 +
.../src/warehouse_types/models.rs | 14 +
.../_helpers/contracts/model_contracts.rs | 2 +-
.../_helpers/semantic_checks/completion.rs | 2 +-
.../_helpers/semantic_checks/failures.rs | 6 +-
.../_helpers/semantic_checks/metadata.rs | 2 +-
.../_helpers/semantic_checks/type_recovery.rs | 2 +-
.../bindings/_helpers/type_system/equality.rs | 5 +-
.../_helpers/type_system/normalization.rs | 21 +-
fensu.toml | 4 +-
src/sqlbuild/adapter/type_system/constants.py | 2 +-
.../main/_native_normalize_type.py | 2 +-
...ped_nullability_and_dynamic_contracts.json | 4 +-
...rized_nested_padded_and_invalid_types.json | 4228 ++++++++---------
.../adapter/type_system/_test_types.py | 2 +-
.../sqlbuild/adapter/type_system/helpers.py | 2 +-
.../test_native_type_normalization.py | 2 +-
42 files changed, 3806 insertions(+), 2812 deletions(-)
delete mode 100644 crates/sqlbuild-analysis/src/type_system/_helpers/shallow_args.rs
create mode 100644 crates/sqlbuild-analysis/src/type_system/_helpers/spelling.rs
create mode 100644 crates/sqlbuild-analysis/src/type_system/_helpers/type_reader.rs
delete mode 100644 crates/sqlbuild-analysis/src/type_system/main/polyglot_type_args.rs
create mode 100644 crates/sqlbuild-analysis/src/type_system/main/type_args.rs
create mode 100644 crates/sqlbuild-analysis/src/type_system/tests/alias_groups.json
create mode 100644 crates/sqlbuild-analysis/src/warehouse_types/_helpers/mod.rs
create mode 100644 crates/sqlbuild-analysis/src/warehouse_types/_helpers/type_trees.rs
create mode 100644 crates/sqlbuild-analysis/src/warehouse_types/main/type_tree.rs
create mode 100644 crates/sqlbuild-analysis/src/warehouse_types/models.rs
diff --git a/Cargo.lock b/Cargo.lock
index 4d81a5009e..fdfb5d93bb 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4145,6 +4145,7 @@ dependencies = [
"sqlquack-syntax",
"sqlquack-syntax-bigquery",
"sqlquack-syntax-postgres",
+ "stacker",
]
[[package]]
diff --git a/crates/sqlbuild-analysis/Cargo.toml b/crates/sqlbuild-analysis/Cargo.toml
index 9a7d4b5a89..3bae24f07f 100644
--- a/crates/sqlbuild-analysis/Cargo.toml
+++ b/crates/sqlbuild-analysis/Cargo.toml
@@ -29,6 +29,7 @@ sqlclean.workspace = true
sqlquack-syntax.workspace = true
sqlquack-syntax-bigquery.workspace = true
sqlquack-syntax-postgres.workspace = true
+stacker.workspace = true
[lints]
workspace = true
diff --git a/crates/sqlbuild-analysis/src/planner_strategy/main/classify_cursor_sql_type.rs b/crates/sqlbuild-analysis/src/planner_strategy/main/classify_cursor_sql_type.rs
index 22dedf16bd..1636707d0d 100644
--- a/crates/sqlbuild-analysis/src/planner_strategy/main/classify_cursor_sql_type.rs
+++ b/crates/sqlbuild-analysis/src/planner_strategy/main/classify_cursor_sql_type.rs
@@ -7,9 +7,9 @@ use crate::planner_strategy::_helpers::type_names::{argument, named_type};
use crate::planner_strategy::constants::{GENERIC_DIALECT, POLYGLOT_CUSTOM_TYPE_NAME};
use crate::planner_strategy::errors::TypeParseFailure;
use crate::planner_strategy::models::CursorType;
-use crate::type_system::main::polyglot_type_args::polyglot_type_args;
+use crate::type_system::main::type_args::type_args;
-/// Timestamp or integer for supported cross-adapter types; `Err` when Polyglot cannot parse an unknown type.
+/// Timestamp or integer for supported cross-adapter types; `Err` when an unknown type does not parse.
pub fn classify_cursor_sql_type(sql_type: &str) -> Result