Skip to content

fix: add explicit sqlserver__ dispatch to T-SQL fabric macros (CORE-877)#1013

Merged
elazarlachkar merged 5 commits into
masterfrom
CORE-877/fix-sqlserver-tsql-dispatch
May 26, 2026
Merged

fix: add explicit sqlserver__ dispatch to T-SQL fabric macros (CORE-877)#1013
elazarlachkar merged 5 commits into
masterfrom
CORE-877/fix-sqlserver-tsql-dispatch

Conversation

@elazarlachkar
Copy link
Copy Markdown
Contributor

@elazarlachkar elazarlachkar commented May 26, 2026

Summary

  • Adds explicit sqlserver__* macro delegations to the existing fabric__* T-SQL implementations across ~35 macro files
  • Fixes SQL Server CI failure (Invalid column name 'True') when building dbt_invocations — caused by default__dummy_values() emitting bare True instead of T-SQL-safe 1
  • Colocates each sqlserver__ delegate next to its fabric__ implementation (same pattern as fabricspark__) so SQL Server behavior is discoverable in context
  • Updates outdated comments that assumed dbt-sqlserver still dispatches through dbt-fabric
  • Adds sqlserver__ delegations for integration-test schema utilities

Context

Linear: CORE-877

After dbt-msft/dbt-sqlserver#628 removed the Fabric adapter dependency, the dispatch chain for type: sqlserver is sqlserver__ → default__ — it no longer reaches fabric__ macros. T-SQL-safe logic already lives in fabric__*; this PR wires SQL Server to it explicitly.

Each delegate follows the existing cross-adapter convention:

{% macro sqlserver__some_macro(args) %}
    {{ elementary.fabric__some_macro(args) }}
{% endmacro %}

Dedicated sqlserver__ implementations that differ from Fabric (e.g. get_normalized_data_type, generate_elementary_profile_args, target_database) are left unchanged.

Test plan

  • Re-run test-all-warehouses workflow on dbt-data-reliability with sqlserver matrix job
  • Confirm dbt run --select elementary succeeds on SQL Server (dbt_invocations builds without Invalid column name 'True')
  • Confirm Fabric CI job still passes (unchanged path)

Summary by CodeRabbit

  • New Features
    • Broadened SQL Server adapter coverage: schema and table operations, temp-table workflows, replace/insert behaviors, and relation name limits.
    • Extended data monitoring and schema-change support: numeric/string metrics, freshness and bucket windows, baseline comparisons, and anomaly/test sampling.
    • Added comprehensive SQL Server cross-db utilities: date/time, string, concat, type mappings, casting and timestamp helpers — reusing existing Fabric/T-SQL logic.

Review Change Stack

dbt-sqlserver removed dbt-fabric from its adapter dispatch chain, so
sqlserver targets no longer inherit fabric__ macros. Delegate sqlserver__
to the existing T-SQL implementations to fix CI failures such as
Invalid column name 'True' when building dbt_invocations on SQL Server.

CORE-877

Co-authored-by: Cursor <cursoragent@cursor.com>
@linear
Copy link
Copy Markdown

linear Bot commented May 26, 2026

CORE-877

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

Important

Review skipped

This PR was authored by the user configured for CodeRabbit reviews. CodeRabbit does not review PRs authored by this user. It's recommended to use a dedicated user account to post CodeRabbit review feedback.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 743a5d8d-3d37-498a-a5bd-6c8091c059bf

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • ✅ Review completed - (🔄 Check again to review again)
📝 Walkthrough

Walkthrough

Adds many sqlserver__* adapter macros that delegate to existing elementary.fabric__* implementations across system utilities, date/time, types, table operations, monitoring, tests, and schema discovery to restore explicit SQL Server dispatch to Fabric/T-SQL macros.

Changes

SQL Server Adapter Dispatch for Fabric T-SQL

Layer / File(s) Summary
System utilities and type helpers
macros/edr/system/system_utils/empty_table.sql, macros/edr/system/system_utils/buckets_cte.sql, macros/edr/system/system_utils/full_names.sql, macros/edr/system/system_utils/get_config_var.sql, macros/utils/cross_db_utils/concat.sql
Adds sqlserver__dummy_values, sqlserver__complete_buckets_cte, sqlserver__full_name_split, boolean/T-SQL helpers (sqlserver__edr_boolean_literal, sqlserver__edr_is_true, sqlserver__edr_is_false, sqlserver__is_tsql), and sqlserver__edr_concat, all delegating to elementary.fabric__*.
Date and time arithmetic functions
macros/utils/cross_db_utils/current_timestamp.sql, date_trunc.sql, dateadd.sql, datediff.sql, day_of_week.sql, hour_of_day.sql, hour_of_week.sql, time_trunc.sql, timeadd.sql
Introduces SQL Server temporal wrappers (sqlserver__edr_current_timestamp, sqlserver__edr_current_timestamp_in_utc, sqlserver__edr_date_trunc, sqlserver__edr_dateadd, sqlserver__edr_datediff, sqlserver__edr_day_of_week_expression, sqlserver__edr_hour_of_day_expression, sqlserver__edr_hour_of_week_expression, sqlserver__edr_time_trunc, sqlserver__edr_timeadd) forwarding to Fabric implementations.
Type system and data conversion
macros/utils/data_types/data_type.sql, macros/utils/data_types/data_type_list.sql, macros/utils/data_types/try_cast_column_to_timestamp.sql, macros/utils/cross_db_utils/to_char.sql
Adds type mapping and conversion adapters (sqlserver__edr_type_bool, sqlserver__edr_type_string, sqlserver__edr_type_long_string, sqlserver__edr_type_timestamp, sqlserver__data_type_list, sqlserver__try_cast_column_to_timestamp, sqlserver__edr_to_char) delegating to Fabric.
Table operation dispatch
macros/utils/table_operations/create_temp_table.sql, replace_table_data.sql, get_relation_max_length.sql, insert_as_select.sql, insert_rows.sql, make_temp_relation.sql, macros/utils/cross_db_utils/multi_value_in.sql
Adds table operation wrappers (sqlserver__create_temp_table, sqlserver__replace_table_data, sqlserver__get_relation_max_name_length, sqlserver__insert_as_select, sqlserver__escape_special_chars, sqlserver__edr_make_temp_relation, sqlserver__edr_multi_value_in) and updates comments about adapter dispatch.
Column monitoring and statistics
macros/edr/data_monitoring/monitors/column_numeric_monitors.sql, macros/edr/data_monitoring/monitors/column_string_monitors.sql
Adds sqlserver__standard_deviation, sqlserver__variance, sqlserver__max_length, sqlserver__min_length, and sqlserver__average_length that forward to Fabric monitor macros.
Data freshness and schema change monitoring
macros/edr/data_monitoring/monitors_query/get_latest_full_refresh.sql, macros/edr/data_monitoring/monitors_query/table_monitoring_query.sql, macros/edr/data_monitoring/schema_changes/get_columns_changes_query.sql
Introduces sqlserver__get_latest_full_refresh, sqlserver___bucket_end_freshness_expr, sqlserver__freshness_metric_query, and sqlserver__get_column_changes_from_baseline_cur delegating to Fabric monitoring logic.
Test materialization and anomaly detection
macros/edr/materializations/test/test.sql, macros/edr/materializations/test/failed_row_count.sql, macros/edr/tests/test_utils/get_anomaly_query.sql
Adds sqlserver__query_test_result_rows, sqlserver__get_failed_row_count_calc_query, sqlserver__get_anomaly_query, and sqlserver__get_anomaly_query_for_dimension_anomalies delegating to Fabric test/anomaly implementations.
Incremental strategy and schema discovery
macros/utils/cross_db_utils/incremental_strategy.sql, integration_tests/dbt_project/macros/schema_utils/list_schemas.sql, integration_tests/dbt_project/macros/schema_utils/schema_exists.sql
Adds sqlserver__get_default_incremental_strategy, sqlserver__edr_list_schemas, and sqlserver__edr_schema_exists as thin wrappers calling Fabric equivalents.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • haritamar

Poem

A rabbit hops through SQL Server's gate,
Forty wrappers send calls straight,
To Fabric's halls the macros flee,
Delegating neatly, one-two-three,
A tidy bridge for T-SQL fate. 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding explicit sqlserver__ macro delegations to fabric__ T-SQL implementations across multiple files to fix SQL Server dispatch behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@macros/utils/cross_db_utils/sqlserver_tsql_dispatch.sql`:
- Around line 81-87: The wrapper macro sqlserver__create_temp_table currently
calls the delegated macro elementary.fabric__create_temp_table with {% do ... %}
which discards its return value; change the call to return the delegated result
(e.g., replace {% do elementary.fabric__create_temp_table(...) %} with {{
return(elementary.fabric__create_temp_table(...)) }} or simply {{
elementary.fabric__create_temp_table(...) }} depending on your macro
conventions) so the relation/SQL is propagated to callers; apply the same change
to the other wrapper(s) that delegate to elementary.fabric__create_temp_table
(the similar block around the other occurrence).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d33a9e59-dc7c-4261-9ebf-340db82eb584

📥 Commits

Reviewing files that changed from the base of the PR and between b47af33 and 77c03be.

📒 Files selected for processing (6)
  • integration_tests/dbt_project/macros/schema_utils/list_schemas.sql
  • integration_tests/dbt_project/macros/schema_utils/schema_exists.sql
  • macros/edr/system/system_utils/empty_table.sql
  • macros/utils/cross_db_utils/sqlserver_tsql_dispatch.sql
  • macros/utils/table_operations/create_temp_table.sql
  • macros/utils/table_operations/replace_table_data.sql

Comment thread macros/utils/cross_db_utils/sqlserver_tsql_dispatch.sql Outdated
Remove the central sqlserver_tsql_dispatch.sql file and add sqlserver__
delegates beside each fabric__ implementation so future developers can
see SQL Server behavior in context.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
macros/utils/data_types/data_type.sql (1)

174-176: ⚡ Quick win

Inconsistent return pattern with other sqlserver delegates in this file.

Lines 15-17, 59-61, and 100-102 use {% do return(elementary.fabric__...) %}, but this macro uses {{ elementary.fabric__... }} without an explicit return statement. While both patterns work, consistency within the same batch of additions improves maintainability.

Align with the return pattern used by other sqlserver delegates in this file
 {% macro sqlserver__edr_type_timestamp() %}
-    {{ elementary.fabric__edr_type_timestamp() }}
+    {% do return(elementary.fabric__edr_type_timestamp()) %}
 {% endmacro %}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@macros/utils/data_types/data_type.sql` around lines 174 - 176, The macro
sqlserver__edr_type_timestamp currently renders the delegate function with {{
elementary.fabric__edr_type_timestamp() }}; change it to follow the file's
consistent return pattern by using a Jinja2 explicit return (e.g., {% do
return(elementary.fabric__edr_type_timestamp()) %}) inside the
sqlserver__edr_type_timestamp macro so it matches the other sqlserver delegates
like the ones at lines using {% do return(elementary.fabric__...) %}.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@macros/edr/data_monitoring/schema_changes/get_columns_changes_query.sql`:
- Around line 317-323: The macro sqlserver__get_column_changes_from_baseline_cur
currently calls elementary.fabric__get_column_changes_from_baseline_cur using a
`{% do %}` which discards its return value; change that call to use `{{
elementary.fabric__get_column_changes_from_baseline_cur(...) }}` so the SELECT
SQL returned by the fabric macro is emitted as output (update the call inside
sqlserver__get_column_changes_from_baseline_cur to use `{{ }}` instead of `{% do
%}`).

In `@macros/utils/cross_db_utils/incremental_strategy.sql`:
- Around line 27-29: The sqlserver__get_default_incremental_strategy macro
currently delegates to fabric__get_default_incremental_strategy (which returns
"merge") and thus overrides the adapter default; change the macro
sqlserver__get_default_incremental_strategy to return "none" so SQL Server will
use the adapter-default incremental strategy instead of forcing "merge".

---

Nitpick comments:
In `@macros/utils/data_types/data_type.sql`:
- Around line 174-176: The macro sqlserver__edr_type_timestamp currently renders
the delegate function with {{ elementary.fabric__edr_type_timestamp() }}; change
it to follow the file's consistent return pattern by using a Jinja2 explicit
return (e.g., {% do return(elementary.fabric__edr_type_timestamp()) %}) inside
the sqlserver__edr_type_timestamp macro so it matches the other sqlserver
delegates like the ones at lines using {% do return(elementary.fabric__...) %}.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f60fc786-c5d6-4001-9367-21362790ca33

📥 Commits

Reviewing files that changed from the base of the PR and between 77c03be and 007b5e0.

📒 Files selected for processing (34)
  • macros/edr/data_monitoring/monitors/column_numeric_monitors.sql
  • macros/edr/data_monitoring/monitors/column_string_monitors.sql
  • macros/edr/data_monitoring/monitors_query/get_latest_full_refresh.sql
  • macros/edr/data_monitoring/monitors_query/table_monitoring_query.sql
  • macros/edr/data_monitoring/schema_changes/get_columns_changes_query.sql
  • macros/edr/materializations/test/failed_row_count.sql
  • macros/edr/materializations/test/test.sql
  • macros/edr/system/system_utils/buckets_cte.sql
  • macros/edr/system/system_utils/empty_table.sql
  • macros/edr/system/system_utils/full_names.sql
  • macros/edr/system/system_utils/get_config_var.sql
  • macros/edr/tests/test_utils/get_anomaly_query.sql
  • macros/utils/cross_db_utils/concat.sql
  • macros/utils/cross_db_utils/current_timestamp.sql
  • macros/utils/cross_db_utils/date_trunc.sql
  • macros/utils/cross_db_utils/dateadd.sql
  • macros/utils/cross_db_utils/datediff.sql
  • macros/utils/cross_db_utils/day_of_week.sql
  • macros/utils/cross_db_utils/hour_of_day.sql
  • macros/utils/cross_db_utils/hour_of_week.sql
  • macros/utils/cross_db_utils/incremental_strategy.sql
  • macros/utils/cross_db_utils/multi_value_in.sql
  • macros/utils/cross_db_utils/time_trunc.sql
  • macros/utils/cross_db_utils/timeadd.sql
  • macros/utils/cross_db_utils/to_char.sql
  • macros/utils/data_types/data_type.sql
  • macros/utils/data_types/data_type_list.sql
  • macros/utils/data_types/try_cast_column_to_timestamp.sql
  • macros/utils/table_operations/create_temp_table.sql
  • macros/utils/table_operations/get_relation_max_length.sql
  • macros/utils/table_operations/insert_as_select.sql
  • macros/utils/table_operations/insert_rows.sql
  • macros/utils/table_operations/make_temp_relation.sql
  • macros/utils/table_operations/replace_table_data.sql
✅ Files skipped from review due to trivial changes (1)
  • macros/edr/data_monitoring/monitors_query/get_latest_full_refresh.sql

Comment on lines +27 to +29
{%- macro sqlserver__get_default_incremental_strategy() %}
{% do return(elementary.fabric__get_default_incremental_strategy()) %}
{% endmacro %}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Keep SQL Server on adapter-default incremental strategy.

Line 28 delegates SQL Server to fabric__get_default_incremental_strategy(), which returns "merge". That overrides the generic contract here (non-Athena adapters should return none to use adapter defaults) and can force unexpected merge behavior on SQL Server models.

Suggested fix
 {%- macro sqlserver__get_default_incremental_strategy() %}
-    {% do return(elementary.fabric__get_default_incremental_strategy()) %}
+    {% do return(none) %}
 {% endmacro %}

Based on learnings: In macros/utils/cross_db_utils/incremental_strategy.sql, incremental strategy should return none for all adapters except Athena.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{%- macro sqlserver__get_default_incremental_strategy() %}
{% do return(elementary.fabric__get_default_incremental_strategy()) %}
{% endmacro %}
{%- macro sqlserver__get_default_incremental_strategy() %}
{% do return(none) %}
{% endmacro %}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@macros/utils/cross_db_utils/incremental_strategy.sql` around lines 27 - 29,
The sqlserver__get_default_incremental_strategy macro currently delegates to
fabric__get_default_incremental_strategy (which returns "merge") and thus
overrides the adapter default; change the macro
sqlserver__get_default_incremental_strategy to return "none" so SQL Server will
use the adapter-default incremental strategy instead of forcing "merge".

elazarlachkar and others added 3 commits May 26, 2026 15:56
Fabric implementations use {% do return(...)} but sqlserver wrappers rendered
via {{ }} dropped the return value, causing None to leak as 'None' strings
and empty sampling results.

Co-authored-by: Cursor <cursoragent@cursor.com>
@elazarlachkar elazarlachkar merged commit 8eaaf37 into master May 26, 2026
28 of 30 checks passed
@elazarlachkar elazarlachkar deleted the CORE-877/fix-sqlserver-tsql-dispatch branch May 26, 2026 15:11
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.

2 participants