Closed matsonj closed 2 months ago
@matsonj
If you want to use CTEs in custom tests, start your code with WITH
. Then it works correctly. Perhaps you have a comment in SQL format /*.... */
or --....
, then change it to the Jinja format {#.... #}
.
The custom test appropriately uses as CTE. The problem is in 1.4 (previous version), the test was first added as a view and then executed. In 1.7, the test is tested directly with a subquery, which means you cannot use CTEs inside of custom tests.
@pl-pr I will provide more notes here shortly. Thanks for the feedback
@matsonj unfortunately it's because of the dependency to dbt-fabric. This, like many other errors, is fixed in the version 1.8.0
https://github.com/microsoft/dbt-fabric/commit/57f2aa60ef9f60f5bf2a065fd508c5c3335b6ea1
Well, there is another error related to the version 1.8.0
https://github.com/microsoft/dbt-fabric/issues/168
And also I found that if you have comments at the beginning of the sql it won't work since it checks if the sql starts with 'with'
main_sql.strip().lower().startswith('with')
I've pushed a changed to swap it to using a regex search instead of the with
statement. If you'd like to test on your models please feel free.
https://github.com/dbt-msft/dbt-sqlserver/pull/518
Should be closed by https://github.com/dbt-msft/dbt-sqlserver/pull/518
When invoking custom tests in the previous version, the generated SQL looks like this:
however, in 1.7.2rc2, it generates SQL like this:
Since it is dropping the raw SQL query into the executed SQL query, this breaks any custom tests that use CTEs.
Workaround: Don't use CTEs in custom tests.