Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing macros defined using CTEs #60

Open
dataders opened this issue Sep 20, 2021 · 1 comment
Open

testing macros defined using CTEs #60

dataders opened this issue Sep 20, 2021 · 1 comment

Comments

@dataders
Copy link
Contributor

as I work on #59, I've had to disable ~17 tests in integration_tests/dbt_utils/dbt_project.yml for the same reason. The reason why is because of the pivot to the test block where code to be tested gets injected as a subquery into the result of get_test_sql(). For the ~17 or so macros being tested, they all use CTEs, which aren't allowed as subqueries in TSQL. previously this was only an issue for bespoke tests, where the solution was to tell users that CTEs in bespoke tests were not supported.

However, this issue is a bigger blocker, because now:

  • we don't have the ability to test dbt-utils macros in tsql, without first rewriting them to not use CTEs, and
  • even existing sqlserver__ ports of dbt-utils macros that were working would now need to be refactored to not use CTEs in order to be tested

the above two points are possible, but not ideal. Here's a commit of me doing it once, but I'm not looking forward to how this will look for a macro like get_date_spine.

your input is much appreciated as always @jtcohen6! It's a bummer that I didn't consider this scenario when testing dbt-sqlserver with dbt-core==0.20.0 initially.

@jtcohen6
Copy link
Collaborator

@swanderz I recall discussing (somewhere) that T-SQL adapters might need to override the built-in test materialization, in addition to the get_test_sql macro, to do the following:

  • Create a temp table (instead of a subquery) that contains result of the test query
  • Select from that temp table to get fail_calc, should_warn, should_error`
  • If store_failures is enabled, make it a permanent table instead!

That feels a bit hacky, but it's the best workaround I can think of for the lack of nested-CTE support in T-SQL. I think all parts should be doable with existing dbt-core constructs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants