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

[CT-655] [where] Macro support for get_where_subquery #5259

Closed
1 task done
cccs-jc opened this issue May 17, 2022 · 1 comment
Closed
1 task done

[CT-655] [where] Macro support for get_where_subquery #5259

cccs-jc opened this issue May 17, 2022 · 1 comment
Labels
dbt tests Issues related to built-in dbt testing functionality enhancement New feature or request

Comments

@cccs-jc
Copy link

cccs-jc commented May 17, 2022

Is this your first time opening an issue?

Describe the Feature

the get_where_subquery macro allows you to place conditions in a where configuration

version: 2

models:
  - name: large_table
    columns:
      - name: my_column
        tests:
          - accepted_values:
              values: ["a", "b", "c"]
              config:
                where: "date_column = current_date"

However it's not possible to make use of macro in the where. It is treated as a string a place as is in the subquery.

We have period filter macro what we would like to use inside the where

version: 2

models:
  - name: large_table
    columns:
      - name: my_column
        tests:
          - accepted_values:
              values: ["a", "b", "c"]
              config:
                where: " {{ period_filter_sql(date_column) }} "

Describe alternatives you've considered

We worked around this limitation by writing our own version of the get_where_subquery macro.

Our version of the macro is specific to our use case of using period_filter_sql.

tests:
  model1:
    +meta:
      period_filter: date_column

This works but makes it hard to cover other uses cases since our get_where_subquery macro does one thing only.

Who will this benefit?

Having the ability to use the power of dbt within the where configuration would enable uses to leverage macros when applying conditions to the tests.

Are you interested in contributing this feature?

I'm interested in contributing.

Anything else?

No response

@cccs-jc cccs-jc added enhancement New feature or request triage labels May 17, 2022
@github-actions github-actions bot changed the title [where] Macro support for get_where_subquery [CT-655] [where] Macro support for get_where_subquery May 17, 2022
@jtcohen6 jtcohen6 added dbt tests Issues related to built-in dbt testing functionality Team:Language labels May 17, 2022
@emmyoop
Copy link
Member

emmyoop commented May 17, 2022

@cccs-jc this makes sense and I can see where you're coming from. Thanks for writing up the request with such clear details. This is actually a duplicate of [Feature] Support ref + custom macros in test config rendering context. Unfortunately the workaround you are currently employing is what we suggest to handle the desired behavior.

Closing this issue as a duplicate to keep the conversation centralized on one issue. Feel free to comment over on #4103 if you have anything to add!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dbt tests Issues related to built-in dbt testing functionality enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants