You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
dbt specifies that you can add where: to a test to filter the results that you are testing on. I wanted to do this with your cool mock tool so I gave it a go.
You get an error
Compilation Error in test dbt_datamocktool_xxxxx (models/gold/gold.yml)
12:12:58 'str object' has no attribute 'name'
12:12:58
12:12:58 > in macro get_unit_test_sql (macros/dmt_get_test_sql.sql)
12:12:58 > called by macro test_unit_test (macros/dmt_unit_test.sql)
12:12:58 > called by test dbt_datamocktool_unit_test_scorecard_results_orb
I've tracked this down to when you call model.name within get_unit_test_sql. This is because dbt replaces the "model" parameter with a string with the where clause applied, like so: (select * from <Table> where <where_clause>) dbt_subquery
It no longer has a name attribute.
Describe alternatives you've considered
It could be possible to override this functionality to take a where_clause parameter instead and handle it differently within the code (so where: would still not work)
Would then need to modify the code to call audit_helper's compare_queries instead in this case, with the compare_model being SELECT <cols> from <mocked_table> WHERE <where_clause>.
I can't think of an alternative that wouldn't involve a PR.
Additional context
Is this feature database-specific? Which database(s) is/are relevant? Please include any other relevant context here.
I doubt it's DB specific, I am using Snowflake
Who will this benefit?
Anyone else who wants to only test certain results are present in the table we are mocking
Are you interested in contributing this feature?
Yes I could give this a go.
The text was updated successfully, but these errors were encountered:
Good suggestion. I don't think it should be too hard, we just have to find the <Table> (model) in (select * from <Table> where <where_clause>) dbt_subquery, send that to get_unit_test_sql() and put it back in.
I'm curious, what's the use-case for adding a where clause in a unit test?
My experience with the native where-clause has sometimes been bad - especially when comparing two tables. It is impossible to access the where statement in the test macro! A common pattern is to use a parameter specifying the condition and implementing it yourself.
I am also curious of the use case for this since I myself has not felt the need for it in unit testing.
Describe the feature
dbt specifies that you can add
where:
to a test to filter the results that you are testing on. I wanted to do this with your cool mock tool so I gave it a go.You get an error
I've tracked this down to when you call
model.name
withinget_unit_test_sql
. This is because dbt replaces the "model" parameter with a string with the where clause applied, like so:(select * from <Table> where <where_clause>) dbt_subquery
It no longer has a
name
attribute.Describe alternatives you've considered
It could be possible to override this functionality to take a
where_clause
parameter instead and handle it differently within the code (sowhere:
would still not work)Would then need to modify the code to call
audit_helper
'scompare_queries
instead in this case, with thecompare_model
beingSELECT <cols> from <mocked_table> WHERE <where_clause>
.I can't think of an alternative that wouldn't involve a PR.
Additional context
Is this feature database-specific? Which database(s) is/are relevant? Please include any other relevant context here.
I doubt it's DB specific, I am using Snowflake
Who will this benefit?
Anyone else who wants to only test certain results are present in the table we are mocking
Are you interested in contributing this feature?
Yes I could give this a go.
The text was updated successfully, but these errors were encountered: