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>
Closes #1110
Summary
Fabric does not allow a database prefix on
CREATE VIEW/DROP VIEW, so the helper views of the testmaterialization 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-partCREATE TABLE … AS <sql>. Fabric supports CTAS with CTEs andcross-warehouse targets (dbt-fabric uses the same statement for models).
sqlserver__create_temp_table: keeps the existing view +SELECT INTOimplementation, as SQL Server has no CTAS.fabric__query_test_result_rows: reads samples from(<sql>) as edr_test_results, sincesqlis already aflat 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:
CREATE TABLE [db].[s].[t] AS WITH c AS (…) SELECT …CREATE VIEW [s].[v] AS …CREATE VIEW [db].[s].[v] AS …End to end (dbt-fabric 1.10.0post2, same fixture as #1111): on
mastertheuniquetest withstore_failures_as: viewerrors with 2760; with this PR all six tests run, samples are stored (including theCTE-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