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
equality test can now compare columns with different names
The compare_columns now optionally accepts a list of two column names.
This allows the column names to be different between base model and
other model when comparing two columns.
The body of the macro is also refactored to make it more DRY, and reduce
convoluting the different steps and capabilities.
1. First, we gather a set of numeric column names that we need to
round. This is referenced later.
2. Next, we build two lists of column names that we want to compare:
one list per model. If compare_columns was given, we build the
lists from that. Otherwise, read column names from the first model,
filter the excluded column names, and use the result for both
models, as we did before this commit.
3. Now that we have lists of column names, we can build comma-separated
lists for each model. At this point, we do the number rounding
expression if the column name is found in the set from step 1.
Note this refactoring also cleans up some weird inconsistencies that
resulted from duplication of logic. For example, suppose a model's
column name was uppercase, and your database is case-sensitive. If you
did not specify a "precision" argument, then you need to provide an
upper-case "compare_columns" argument. However, if you _did_ specify a
"precision" argument, then the "compare-columns" argument was _NOT_
case-sensitive. It's pretty unexpected to have the case sensitivity of
one argument be dependent on a seemingly-unrelated argument.
Copy file name to clipboardExpand all lines: macros/generic_tests/equality.sql
+81-49Lines changed: 81 additions & 49 deletions
Original file line number
Diff line number
Diff line change
@@ -63,42 +63,15 @@
63
63
{%- endif -%}
64
64
65
65
{% if compare_columns_set != compare_model_columns_set %}
66
-
{{ exceptions.raise_compiler_error(compare_model ~" has less columns than " ~ model ~ ", please ensure they have the same columns or use the `compare_columns` or `exclude_columns` arguments to subset them.") }}
66
+
{{ exceptions.raise_compiler_error(compare_model ~" has different columns than " ~ model ~ ", please ensure they have the same columns or use the `compare_columns` or `exclude_columns` arguments to subset them.") }}
67
67
{% endif %}
68
68
69
69
70
70
{% endif %}
71
71
72
-
{%- if not precision -%}
73
-
{%- if not compare_columns -%}
74
-
{#
75
-
You cannot get the columns in an ephemeral model (due to not existing in the information schema),
76
-
so if the user does not provide an explicit list of columns we must error in the case it is ephemeral
77
-
#}
78
-
{%- do dbt_utils._is_ephemeral(model, 'test_equality') -%}
0 commit comments