microsoft / dbt-fabric

MIT License
79 stars 28 forks source link

Testviews should be created in an expected schema and not dbo #130

Closed dsjoho closed 7 months ago

dsjoho commented 8 months ago

In the macro fabric__get_test_sql in macros/materializations/tests/helpers.sql, the schema for the temporary testview is hardcoded as dbo.testview_{{ range(1300, 19000) | random}}. See https://github.com/microsoft/dbt-fabric/blob/a97aa2fa94cc940fa925162cbd1a976ad776dfb4/dbt/include/fabric/macros/materializations/tests/helpers.sql#L4-L6

This breaks in the situation where dbt does not have access to the dbo schema, or the preferred schema is something else.

I suggest that this should instead utilize the generate_schema_name macro with a custom schema name. Possibly with a custom_name to allow redirecting it, or just letting it fall through to place the testview in the default schema.

Maybe something like

    {% set testview %}
      {{ generate_schema_name('tests_schema' }}.testview_{{ range(1300, 19000) | random }}
    {% endset %}

Or the sensible way of not providing any custom schema name in which case we just get whatever the target profile uses.

prdpsvs commented 8 months ago

@dsjoho , I am going to take your suggestion and replace dbo with generate_schema_name macro.

Can you share the steps to invoke fabric__get_test_sql from dbt project? I will run some tests and support something close to this post - https://stackoverflow.com/questions/73563223/dbt-conditionally-set-schema-config