dbt-msft / tsql-utils

dbt-utils for the dbt-msft family of packages
MIT License
25 stars 24 forks source link

dbt_utils expression_is_true does not work without `--store-failures` #102

Open jlkravitz opened 5 months ago

jlkravitz commented 5 months ago

I have dbt_utils and tsql_utils installed.

On one of my model's columns, I have the following test:

- name: MyColumn
  tests:
    - not_null
    - accepted_values:
        values: ["Opt1", "Opt2", "Opt3", "Opt4"]
    - dbt_utils.expression_is_true:
        expression: "!= 'Opt1'"
        config:
          where: "OtherColumn is null or OtherColumn = 0"

When I run dbt test, I get the following error: ('42000', '[42000] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Create View or Function failed because no column name was specified for column 1. (4511) (SQLMoreResults)')

The compiled SQL is

select
    1
from (select * from MyTable where OtherColumn is null or OtherColumn = 0) dbt_subquery

where not(MyColumn != 'Opt1')

which, when run, is created as a view. SQL Server does not support unnamed columns in views, so this fails.

For reference, the following dispatch configuration is in my dbt_project.yml

dispatch:
  - macro_namespace: dbt_utils
    search_order: ["tsql_utils", "dbt_utils"]

Is this a bug, or am I doing something wrong? It seems there is no expression_is_true macro in tsql-utils for dbt_utils, but I may be understanding the dispatch flow incorrectly. Thanks!