-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Show unexpected values when accepted_values test fails #3265
Comments
@brylie What a cool idea! I think that the requisite pieces may just be falling into place, so that we could make this happen. Back in #2593, I made a detailed proposal for how tests could store their (failing) results in database tables. To date, each schema test query has returned a single numeric value— All of which is to say, if we're doing all that and can save those results in a database table, in addition to grabbing the total failure count/value, we could also print a few of those results to stdout using good old Failure in test accepted_values__orders__order_status (models/resources.yml)
Found 7 unacceptable values of orders.order_status, erroring because >0.
| VALUE_FIELD | COUNT |
| ----------- | ---------- |
| blue | 17,452,443 |
| red | 6,105,277 |
| green | 1,111,547 |
For full results:
--------------------------------------------------------------------------------
select * from dev_jcohen__dbt_test_results.accepted_values__orders__order_status
--------------------------------------------------------------------------------
compiled SQL at target/compiled/models/resources.yml/schema_test/not_null__orders__order_status.sql I think we'd put in limitations like:
Let me know what you think about the above, and let's see if we can sneak in this (or something like it) alongside the other test functionality coming in v0.20.0 :) |
Yeah, that seems like a good idea. How does the error message "Got N results, expected 0." get the row count? Would it be possible to run a |
I think this imagines us rewriting the default with all_values as (
select
{{ column_name }} as value_field,
count(*) as count
from {{ model }}
group by 1
),
validation_errors as (
select
value_field,
count
from all_values
where value_field not in (
{% for value in values -%}
{% if quote_values -%}
'{{ value }}'
{%- else -%}
{{ value }}
{%- endif -%}
{%- if not loop.last -%},{%- endif %}
{%- endfor %}
)
)
select * from validation_errors |
I was able to get this working (sorta) with some janky code that leverages the existing functionality around Steps:
All of that for:
|
This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please remove the stale label or comment on the issue, or it will be closed in 7 days. |
When an
accepted_values
test fails, print the unexpected values.I am currently writing a test against a column with many possible values, where we want to know if any new values appear in the column that might affect our analytics.
When the
accepted_values
test fails, it shows a message like:However, it doesn't display information about the unexpected results
Showing the unexpected results would make it easier to investigate and modify the test.
I can help contribute to this feature.
The text was updated successfully, but these errors were encountered: