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

Fix get comparison bounds #104

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- this has no tests, it's just making sure that the introspecive queries for event_time actually run

{{
audit_helper.compare_and_classify_query_results(
a_query="select * from " ~ ref('unit_test_model_a') ~ " where 1=1",
b_query="select * from " ~ ref('unit_test_model_b') ~ " where 1=1",
primary_key_columns=['id'],
columns=['id', 'col1', 'col2'],
event_time='created_at'
)
}}
9 changes: 6 additions & 3 deletions macros/utils/_get_comparison_bounds.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ model_a │ │┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼
┌──► └────────────────────────────┘ ◄────┐
b min_value b max_value
*/
{% macro _get_comparison_bounds(a_relation, b_relation, event_time) %}
{% macro _get_comparison_bounds(a_query, b_query, event_time) %}
{% set min_max_queries %}
with min_maxes as (
select min({{ event_time }}) as min_event_time, max({{ event_time }}) as max_event_time
from {{ a_relation }}
from ({{ a_query }}) a_subq
union all
select min({{ event_time }}) as min_event_time, max({{ event_time }}) as max_event_time
from {{ b_relation }}
from ({{ b_query }}) b_subq
)
select max(min_event_time) as min_event_time, min(max_event_time) as max_event_time
from min_maxes
Expand All @@ -34,6 +34,9 @@ model_a │ │┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼
{% set query_response = dbt_utils.get_query_results_as_dict(min_max_queries) %}

{% set event_time_props = {"event_time": event_time} %}

{# query_response.keys() are only `min_event_time` and `max_event_time`, but they have indeterminate capitalisation #}
{# hence the dynamic approach for what is otherwise just two well-known values #}
{% for k in query_response.keys() %}
{% do event_time_props.update({k | lower: query_response[k][0]}) %}
{% endfor %}
Expand Down