Open ernestoongaro opened 6 months ago
It's not expected for tests to create views, and certainly not outside the specified schema. in this case my schema is dbt_eongaro
and it's attempting to create them in dbt_eongaro_tests_schema
Hi @prdpsvs as requested via Slack here's a repro:
1) Create a model my_model.sql
:
with source_data as (
select 'A' as something
union all
select 'B' as something
)
select *
from source_data
2) create a yml file my_example.yml
version: 2
models:
- name: my_model
columns:
- name: id
tests:
- not_null
- accepted_values:
values:
- 'B'
- 'A'
3) run dbt build --select my_model
4) Observe that the test is attempted to be built in EXEC('create view
as tests are ephemral
error
('42000', '[42000] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]The specified schema name "dbt_eongaro_tests_schema" either does not exist or you do not have permission to use it. (2760) (SQLExecDirectW)')
5) Note that the not_null test is perfectly fine as it does not try and build a view
@ernestoongaro , I looked into these errors.
Microsoft Fabric DW does not support nested CTE's. For that reason, the adapter cannot support ephermal tests.
Adapter now will default these tests to dbt_test__audit (generated by dbt) schema to ensure consistency.
I will close this issue for now. Hope this helps.
@prdpsvs I just updated to 1.8.4. The schema dbt_test__audit is not auto generated.
12:11:16 Database Error in test date_is_not_in_future_latest_inventory_movement_latest_inventory_movement (models\marts_marts_models.yml) ('42000', '[42000] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]The specified schema name "dbt_test__audit" either does not exist or you do not have permission to use it. (2760) (SQLExecDirectW)') compiled Code at target\run\msbid\models\marts_marts_models.yml\date_is_not_in_future_latest_i_85e765eeda8d5db57964dc06f11dfe72.sql
The schema dbt_test__audit is not auto generated.
By way of explanation: On every run, dbt-core
will automatically check to see which schemas exist, and create those schemas for DAG nodes that are selected and "relational" (meaning, dbt is going to materialize this node as a database relation).
For some time, we've had conditional logic within dbt-core
to generate schemas for tests if (and only if) "store failures" is enabled, via test config or the --store-failures
flag.
I think there are two mitigation paths forward:
dbt-fabric
should use {{ target.schema }}
instead of {{ node.schema }}
as the location to create these views, under the assumption that the user is likely to be putting other models in their default configured schema, and dbt will create the schema accordingly.dbt-core
so that test nodes' is_relational
property is not conditional on should_store_failures
(here). This is a change we'd want to make carefully, as it could have unrelated consequences.We could change the default schema
config of tests from dbt_test__audit
to None
. Given that it's been the former for many years (since v0.20 in 2021 IIRC), this would be a significant behaviour change and would require a migration plan.
Longer-term, it would be ideal for dbt-fabric
use temp tables (scoped to the session) instead of persistent views (registered in a specific database/schema).
@prdpsvs I recommend reopening this issue in the meantime, while we sort out the appropriate mitigation.
@jtcohen6 , @ernestoongaro , I did not address this completely but dbt-fabric 1.8.6 creates target schema {{ target.schema }}
if it does not exist.
Hello! I have some standard tests in my project, starting with dbt-fabric 1.8 this is what's happening:
with all_values as (
)
select * from all_values where value_field not in ( ''AFRICA'',''MIDDLE EAST'',''ASIA'',''EUROPE'',''AMERICA'' )
;') select
15:12:06 Opening a new connection, currently in state closed 15:12:06 fabric adapter: Using connection string: DRIVER={ODBC Driver 18 for SQL Server};SERVER=5xxoty5si6telax6vdkh6id534-fjebxqqv6kvexcr6vmlnwsjs2e.datawarehouse.pbidedicated.windows.net;Database=sa_demo;Authentication=ActiveDirectoryServicePrincipal;UID={ca9252f9-6361-4d5e-af31-8587eca1a429};PWD=***;encrypt=Yes;TrustServerCertificate=No;APP=dbt-fabric/1.8.2;ConnectRetryCount=1 15:12:08 fabric adapter: Connected to db: sa_demo 15:12:08 fabric adapter: Database error: ('42000', '[42000] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]The specified schema name "dbt_eongaro_tests_schema" either does not exist or you do not have permission to use it. (2760) (SQLExecDirectW)')