-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from calogica/add/expect_grouped_row_values_to…
…_have_recent_data Add test "expect_grouped_row_values_to_have_recent_data"
- Loading branch information
Showing
4 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
integration_tests/models/schema_tests/timeseries_data_grouped.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
with dates as ( | ||
{{ dbt_date.get_base_dates(n_dateparts=12, datepart='month') }} | ||
), | ||
groupings as ( | ||
{{ dbt_utils.generate_series(upper_bound=4) }} | ||
), | ||
row_values as ( | ||
{{ dbt_utils.generate_series(upper_bound=10) }} | ||
), | ||
add_row_values as ( | ||
|
||
select | ||
d.date_day, | ||
cast(g.generated_number as {{ dbt_utils.type_int() }}) as group_id, | ||
cast(floor(100 * r.generated_number) as {{ dbt_utils.type_int() }}) as row_value | ||
from | ||
dates d | ||
cross join | ||
groupings g | ||
cross join | ||
row_values r | ||
|
||
), | ||
add_logs as ( | ||
|
||
select | ||
*, | ||
{{ dbt_expectations.log_natural('nullif(row_value, 0)') }} as row_value_log | ||
from | ||
add_row_values | ||
) | ||
select | ||
* | ||
from | ||
add_logs |
24 changes: 24 additions & 0 deletions
24
macros/schema_tests/table_shape/expect_grouped_row_values_to_have_recent_data.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{% macro test_expect_grouped_row_values_to_have_recent_data(model, group_by, timestamp_column, datepart, interval) %} | ||
with latest_grouped_timestamps as ( | ||
|
||
select | ||
{%- for g in group_by %} | ||
{{ g }}, | ||
{%- endfor %} | ||
max({{ timestamp_column }}) as latest_timestamp_column | ||
from | ||
{{ model }} | ||
{{ dbt_utils.group_by(group_by | length )}} | ||
|
||
), | ||
validation_errors as ( | ||
|
||
select * | ||
from | ||
latest_grouped_timestamps | ||
where | ||
latest_timestamp_column < {{ dbt_utils.dateadd(datepart, interval * -1, dbt_date.now()) }} | ||
|
||
) | ||
select count(*) from validation_errors | ||
{% endmacro %} |