Skip to content

fix(fabric): create test helper relations without views - #1112

Draft
tderk wants to merge 1 commit into
elementary-data:masterfrom
tderk:fix/fabric-test-ddl-without-views
Draft

tderk wants to merge 1 commit into
elementary-data:masterfrom
tderk:fix/fabric-test-ddl-without-views

Conversation

@tderk

@tderk tderk commented Dec 4, 2026 •

Copy link
Copy Markdown

Optional proposal. #1110 describes the problem, its root cause and a reproduction on its own. This PR is one possible fix, verified on a Fabric warehouse but not yet in CI (needs the fork approval). Happy to adapt it or close it if you prefer a different approach.

Closes #1110

Summary

Fabric does not allow a database prefix on CREATE VIEW / DROP VIEW, so the helper views of the test
materialization and of sampling were created in the session's current database. With the elementary schema in
another warehouse this fails with error 2760, and a failing statement in between left the views behind.

  • fabric__create_temp_table: one three-part CREATE TABLE … AS <sql>. Fabric supports CTAS with CTEs and
    cross-warehouse targets (dbt-fabric uses the same statement for models).
  • sqlserver__create_temp_table: keeps the existing view + SELECT INTO implementation, as SQL Server has no CTAS.
  • fabric__query_test_result_rows: reads samples from (<sql>) as edr_test_results, since sql is already a
    flat select from the helper relation. The binary-to-hex select list now describes that query instead of a view.

Verification

Fabric Data Warehouse, session database ≠ elementary warehouse:

Statement Result
CREATE TABLE [db].[s].[t] AS WITH c AS (…) SELECT … ok
CREATE VIEW [s].[v] AS … error 2760
CREATE VIEW [db].[s].[v] AS … error 166

End to end (dbt-fabric 1.10.0post2, same fixture as #1111): on master the unique test with
store_failures_as: view errors with 2760; with this PR all six tests run, samples are stored (including the
CTE-based dbt_utils.unique_combination_of_columns), and no views are left in the elementary schema.

Integration test added in integration_tests/tests/test_tsql_sampling_without_views.py (fabric, sqlserver).
I could not run it locally; it needs the fork approval to run in CI. SQL Server behaviour is unchanged apart from
sampling, which now reads the flat query directly.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved test-result sampling on Fabric so CTE-based tests can return sample rows without creating helper views.
    • Updated temporary-table handling for Fabric and SQL Server, including cleanup of existing tables and intermediate views.

On Fabric the test result helper was built as CREATE VIEW, SELECT INTO,
DROP VIEW, and test samples were read through another temporary view.
CREATE VIEW only accepts two-part names, so it runs in the connection's
database and fails with error 2760 when the elementary schema lives in a
different warehouse. A failing statement in between also left the views
behind.

- Fabric: build the helper with a single three-part CREATE TABLE AS, which
  supports CTEs and cross-warehouse targets
- read samples from the already flat test SQL instead of a temporary view
- SQL Server keeps the view-based helper, as it has no CREATE TABLE AS

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonlevine7

jonlevine7 commented Dec 4, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Fabric test materialization now creates helper tables from queries, while SQL Server retains a view-based workaround. Fabric sampling reads test SQL as a derived table instead of creating a temporary view. Integration tests check sample results and helper relation names.

Changes: T-SQL test materialization and sampling

Layer / File(s) Summary
Backend-specific table creation
macros/utils/table_operations/create_temp_table.sql
Fabric creates a named table from the supplied query. SQL Server uses a view-based workaround. The Snowflake macro retains its temporary-table behavior.
Fabric sampling from test SQL
macros/edr/materializations/test/test.sql
Sampling uses the test SQL as a derived table with TOP when a sample limit is set. Result-set description receives the SQL instead of a view name.
T-SQL sampling integration test
integration_tests/dbt_project/macros/tsql_relation_helpers.sql, integration_tests/tests/test_tsql_sampling_without_views.py
New relation lookup macros find prefix matches and count exact-name relations. The integration test checks the failure status, sample row count, and absence of matching helper relation names.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

Suggested reviewers: guyeshdat, eladbarkay, haritamar

Merge Risk: Minimal · up to 47a45

Fabric test materialization now builds helper tables directly instead of through views, which avoids the cross-warehouse view errors. SQL Server keeps its existing view-based helper. No concrete merge-blocking issue remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(fabric): create test helper relations without views" matches the main change. The PR replaces the Fabric test helper view workflow with a single CREATE TABLE ... AS statement, and sampl…
Linked Issues check Passed [#1110] Fabric helper creation: fabric__create_temp_table in macros/utils/table_operations/create_temp_table.sql at the reviewed head now runs DROP TABLE IF EXISTS and one three-part `CREATE TAB…
Out of Scope Changes check Passed All changed areas map to #1110. The changes are: the Fabric and SQL Server helper macros in create_temp_table.sql, the Fabric sampling path and select-list signature change in test.sql, and the in…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title "fix(fabric): create test helper relations without views" matches the main change. The PR replaces the Fabric test helper view workflow with a single CREATE TABLE ... AS statement, and sampling reads from a derived table instead of a temporary view. The title is specific, short, and states the primary fix. It does not name the SQL Server exception, which is acceptable because the title is not required to cover every detail.

Full details: Linked Issues check

Explanation

[#1110] Fabric helper creation: fabric__create_temp_table in macros/utils/table_operations/create_temp_table.sql at the reviewed head now runs DROP TABLE IF EXISTS and one three-part CREATE TABLE &lt;db&gt;.&lt;schema&gt;.&lt;table&gt; AS &lt;sql_query&gt;. It no longer creates a view, so the Fabric CREATE VIEW database-prefix restriction and the error 2760 path are removed. [#1110] SQL Server: sqlserver__create_temp_table keeps the view-based path (CREATE VIEW without database prefix, SELECT * INTO, DROP VIEW), which matches the issue. [#1110] Sampling: fabric__query_test_result_rows in macros/edr/materializations/test/test.sql reads select [top N] &lt;select list&gt; from (&lt;sql&gt;) as edr_test_results. The sql value is a flat select from the helper relation on T-SQL, because create_test_result_temp_table rewrites it to select * from &lt;relation&gt;. The binary-to-hex select list comes from fabric__get_test_sample_select_list(test_sql), which calls sp_describe_first_result_set on the same query, as the issue requires. The automated integration test in integration_tests/tests/test_tsql_sampling_without_views.py covers the behavior. Its execution is not confirmed by this review. Requirements are met by the code at the reviewed head.

Full details: Out of Scope Changes check

Explanation

All changed areas map to #1110. The changes are: the Fabric and SQL Server helper macros in create_temp_table.sql, the Fabric sampling path and select-list signature change in test.sql, and the integration test helper macros and test file. Those helpers and the test support the required behavior. The summary also reports that snowflake__create_temp_table was relocated. The reviewed code shows its body unchanged in substance, and it is not a functional change outside the issue. No unrelated behavior change was found in the inspected files.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f0a6b084-57e8-42b3-a301-bffc5d90e9a2
Commits

Reviewing files that changed from the base of the PR and between 09516ff and 47a45df.

Files selected for processing: 4

  • integration_tests/dbt_project/macros/tsql_relation_helpers.sql
  • integration_tests/tests/test_tsql_sampling_without_views.py
  • macros/edr/materializations/test/test.sql
  • macros/utils/table_operations/create_temp_table.sql

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@tderk
tderk marked this pull request as draft December 4, 2026 14:51

This branch has not been deployed

No deployments
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.

Fabric: test materialization fails with error 2760 when the elementary schema is in another warehouse

2 participants