-
When I have: version: 2
models:
- name: table_1
columns:
- name: col_a
tests:
- unique:
name: table_1.col_a is not unique then
From this failure message, I understood "54 values are somehow duplicated" but I could not get the information of "what values are duplicated". I know Is there a good way to output "what values are invalid" as a failure message? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
@gecko655 This is a quite-old issue, and so the implementation steps I played around with a few years ago would need some updating, but this is theoretically possible to do what you're describing: I don't think it would scale well to showing all 54 results in the console, but perhaps:
|
Beta Was this translation helpful? Give feedback.
-
I noticed that I could use the doc: https://docs.getdbt.com/reference/commands/show So, my CI script is going to look like this: # prerequisite: jq
# Delete previous log if exists
rm -f logs/dbt.log
# Execute the test and show human readable output while output json log file
dbt --log-format-file json test --store-failures -t dev
# Extract the failed test node names
# note: Z022 is 'RunResultFailure' log ( https://github.com/dbt-labs/dbt-core/blob/5814928e3836467ffa90297e871d8a99f8c8b855/core/dbt/events/types.py#L2121-L2128 )
failed_test_names="$(cat logs/dbt.log | jq -r 'select(.info.code == "Z022") | .data.node_name')"
# Show failed values for each failed tests
for failed_test_name in $(echo $failed_test_names); do
echo '-----'
echo "Failed values for test '$failed_test_name':"
dbt show -t dev -s "$failed_test_name"
done This script outputs like:
It contains some verbose output, but this is good enough for me to use as a CI report. |
Beta Was this translation helpful? Give feedback.
I noticed that I could use the
dbt show
command (added in dbt 1.5) to show test results saved by store_failure.This seems to meet my requirements.
doc: https://docs.getdbt.com/reference/commands/show
So, my CI script is going to look like this: