Skip to content

feat(sqlserver): Part 6 — SQL type mapping and column builder - #16

Merged
axellpadilla merged 1 commit into
sqlserver-v2-portfrom
part-6-sqlserver-types
Aug 3, 2026
Merged

feat(sqlserver): Part 6 — SQL type mapping and column builder#16
axellpadilla merged 1 commit into
sqlserver-v2-portfrom
part-6-sqlserver-types

Conversation

@axellpadilla

Copy link
Copy Markdown
Collaborator

Part 6 of the SQL Server Fusion adapter series. Part of dbt-labs#15714.

Stacked on #15 (Part 5). Base is part-5-sqlserver-catalog, so this diff shows only Part 6's two files. Merge #11#12#13#14#15 first; this retargets automatically as each lands.

sql_types.rs and column_builder.rs — the two files rg '\bFabric\b' flags as Part 6's work list. Adds SqlServer everywhere Fabric already has an arm, matching Fabric's value where SQL Server's T-SQL surface agrees and diverging where it measurably doesn't.

Where it diverges from Fabric

  • STRING → VARCHAR(MAX), not Fabric's VARCHAR(8000). Fabric Warehouse tracks its own byte cap in FABRIC_MAX_VARCHAR_TYPE; on-prem/Azure SQL Database has no equivalent limit tracked here. VARCHAR(MAX) is v1's current native mapping (dbt_sqlserver_use_native_string_types, default True as of 1.12) — the legacy VARCHAR(8000) path is deprecated in v1 and isn't what this ports.
  • Decimal → "float"/"int" by scale, not Fabric's unconditional "float". v1's convert_number_type is "float" if decimals else "int"; the new SqlServer arms in the scale-keyed match reproduce that threshold instead of Fabric's flat mapping.
  • Boolean ("bit"), timestamp ("datetime2(6)"), and time ("time(6)") match both v1 and Fabric — no divergence, just added.

Column builder

build_fabric, not build_postgres_like, is the right model here — confirmed by reading rather than assumed: build_postgres_like hardcodes Column::new(AdapterType::Postgres, ...) (would mislabel every SQL Server column) and special-cases Timestamp/Time64 to a bare "datetime" literal regardless of adapter (would lose the datetime2(6) precision v1 relies on). build_sqlserver mirrors build_fabric's shape instead, backed by the new sqlserver::try_format_type module.

Left alone

  • get_field_sql_type_metadata_key gets todo!() for SqlServer, matching the other adapters that already work and are already todo!() there (Databricks, Postgres, Salesforce, Spark, DuckDB, Alt). The function is unused outside its own Bigquery-only unit test; the metadata key that's actually live is dbt_adapter_sql::types::SQLSERVER_KEYS.
  • adapter_impl.rs's remaining SqlServer E0004s are Part 7's scope, not this file pair's — a full cargo check -p dbt-adapter still fails until feat(sqlserver): Part 7 — adapter_impl.rs match arms #7 lands, same as it did before this PR.

Verification

cargo check -p dbt-adapter --tests reports zero errors in sql_types.rs or column_builder.rs (all remaining errors are in adapter_impl.rs, Part 7's file). Full cargo test can't run yet — the crate doesn't build until Part 7 closes the gap — so the new unit tests (sqlserver_try_format_type_formats_native_types, sqlserver_try_format_type_rejects_unsupported_arrow_types, plus SqlServer assertions added to the existing convert_*_type tests) are type-checked but not yet executed.

PRs against sqlserver-v2-port in this repo, use Closes #<this issue>.

Closes #6

Adds SqlServer arms to sql_types.rs (format_arrow_type_as_sql dispatch,
the convert_*_type consolidation match, field_comment, build_sdf_schema,
max_varchar_size/max_varbinary_size) and column_builder.rs (build,
build_from_parts), mirroring the Fabric arms where SQL Server's T-SQL
surface agrees and diverging where it measurably doesn't.

Values are checked against dbt/adapters/sqlserver/sqlserver_adapter.py
and sqlserver_column.py (v1's actual behavior, not its deprecated
legacy path — dbt_sqlserver_use_native_string_types defaults True as
of 1.12): convert_number_type's "float" if decimals else "int" rule,
convert_boolean_type's "bit", convert_datetime_type's "datetime2(6)",
convert_time_type's "time(6)".

STRING maps to VARCHAR(MAX), not Fabric's VARCHAR(8000): Fabric
Warehouse tracks its own byte cap here, and on-prem/Azure SQL Database
has no equivalent one — VARCHAR(MAX) is v1's native mapping.

A new sqlserver module (mirroring the fabric one) backs the
format_arrow_type_as_sql dispatch and build_sqlserver's
type_ops.format_arrow_type_as_sql call.

get_field_sql_type_metadata_key gets `todo!()`, matching its other
untouched arms (Databricks, Postgres, Salesforce, Spark, DuckDB, Alt):
the function is dead outside its own Bigquery-only test, and the
answer that matters lives in dbt_adapter_sql::types::SQLSERVER_KEYS.

Leaves Part 7's scope (adapter_impl.rs's SqlServer arms) untouched;
those E0004s are unrelated to this file pair and still block a full
crate build.

Closes #6
@axellpadilla
axellpadilla changed the base branch from part-5-sqlserver-catalog to sqlserver-v2-port August 3, 2026 01:18
@axellpadilla
axellpadilla merged commit df3ba4c into sqlserver-v2-port Aug 3, 2026
@axellpadilla axellpadilla linked an issue Aug 3, 2026 that may be closed by this pull request
4 tasks
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.

feat(sqlserver): Part 6 — SQL type mapping and column builder

1 participant