-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ele 700 add default values to time bucket (#346)
* added default to time_bucket * default time_bucket and validation * default time_bucket and validation * fix * fix * added e2e * added e2e * remove debug * format * PR fixes
- Loading branch information
Showing
18 changed files
with
196 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{% test config_levels(model, expected_config, time_bucket) %} | ||
{%- if execute and flags.WHICH in ['test', 'build'] %} | ||
{%- set unexpected_config = [] %} | ||
{%- set model_relation = dbt.load_relation(model) %} | ||
{% set model_graph_node = elementary.get_model_graph_node(model_relation) %} | ||
|
||
{%- set time_bucket = elementary.get_time_bucket(time_bucket, model_graph_node) %} | ||
{%- if time_bucket != expected_config.get('time_bucket') %} | ||
{%- set unexpected_message = ('got config: {0}, expected config: {1}').format(time_bucket, expected_config.get('time_bucket') ) %} | ||
{%- do unexpected_config.append(unexpected_message) -%} | ||
{%- endif %} | ||
|
||
{%- if unexpected_config | length > 0 %} | ||
{%- do exceptions.raise_compiler_error('Failure config_levels: ' ~ unexpected_config) -%} | ||
{%- else %} | ||
{#- test must run an sql query -#} | ||
{{ elementary.no_results_query() }} | ||
{%- endif %} | ||
{%- endif %} | ||
{%- endtest %} |
18 changes: 18 additions & 0 deletions
18
integration_tests/macros/e2e_tests/validate_config_levels.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,18 @@ | ||
{% macro validate_config_levels() %} | ||
{% set alerts_relation = ref('test_alerts_union') %} | ||
|
||
{% set config_levels_validation_query %} | ||
with error_tests as ( | ||
select | ||
table_name, alert_description, | ||
{{ elementary.contains('tags', 'config_levels') }} as is_config_levels_tag | ||
from {{ alerts_relation }} | ||
where status = 'error' | ||
) | ||
select table_name, alert_description | ||
from error_tests | ||
where is_config_levels_tag = true | ||
{% endset %} | ||
{% set results = elementary.agate_to_dicts(run_query(config_levels_validation_query)) | unique | list %} | ||
{{ assert_lists_contain_same_items(results, []) }} | ||
{% endmacro %} |
24 changes: 24 additions & 0 deletions
24
integration_tests/macros/unit_tests/test_get_time_bucket.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_get_time_bucket() %} | ||
|
||
{%- set default_config = elementary.get_default_time_bucket() %} | ||
|
||
{%- set config = {'period': 'day', 'count': 5} %} | ||
{%- set result = elementary.get_time_bucket(config) %} | ||
{{ assert_value(result.period, "day") }} | ||
{{ assert_value(result.count, 5) }} | ||
|
||
{%- set config = {'period': 'week'} %} | ||
{%- set result = elementary.get_time_bucket(config) %} | ||
{{ assert_value(result.period, "week") }} | ||
{{ assert_value(result.count, default_config.count) }} | ||
|
||
{%- set config = {'count': 3} %} | ||
{%- set result = elementary.get_time_bucket(config) %} | ||
{{ assert_value(result.count, 3) }} | ||
{{ assert_value(result.period, default_config.period) }} | ||
|
||
{%- set result = elementary.get_time_bucket() %} | ||
{{ assert_value(result.count, default_config.count) }} | ||
{{ assert_value(result.period, default_config.period) }} | ||
|
||
{% endmacro %} |
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 @@ | ||
select 1 as one |
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 @@ | ||
select 1 as one |
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
7 changes: 0 additions & 7 deletions
7
macros/edr/data_monitoring/data_monitors_configuration/time_bucket.sql
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,7 +1,18 @@ | ||
{% macro get_test_argument(argument_name, value=none) %} | ||
{% macro get_test_argument(argument_name, value, model_graph_node) %} | ||
{% if value %} | ||
{{ return(value) }} | ||
{% else %} | ||
{%- endif %} | ||
{%- if model_graph_node %} | ||
{% set elementary_config = elementary.get_elementary_config_from_node(model_graph_node) %} | ||
{% if elementary_config and elementary_config is mapping %} | ||
{%- set model_config_value = elementary_config.get(argument_name) %} | ||
{%- if model_config_value %} | ||
{{ return(model_config_value) }} | ||
{%- endif %} | ||
{% endif %} | ||
{% endif %} | ||
{%- if elementary.get_config_var(argument_name) %} | ||
{{ return(elementary.get_config_var(argument_name)) }} | ||
{% endif %} | ||
{% endmacro %} | ||
{{ return(none) }} | ||
{% endmacro %} |
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
File renamed without changes.
File renamed without changes.
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,66 @@ | ||
{% macro get_daily_time_bucket() %} | ||
{% do return({"period": "day", "count": 1}) %} | ||
{% endmacro %} | ||
|
||
{% macro get_default_time_bucket() %} | ||
{% do return(elementary.get_daily_time_bucket()) %} | ||
{% endmacro %} | ||
|
||
{% macro get_time_bucket(time_bucket, model_graph_node) %} | ||
{%- set configured_time_bucket = elementary.get_test_argument('time_bucket', time_bucket, model_graph_node) %} | ||
{%- do elementary.validate_time_bucket(configured_time_bucket) %} | ||
{%- set default_time_bucket = elementary.get_default_time_bucket() %} | ||
|
||
{%- if not configured_time_bucket %} | ||
{{ return(default_time_bucket) }} | ||
{%- else %} | ||
{%- set time_bucket = default_time_bucket.copy() %} | ||
{%- do time_bucket.update(configured_time_bucket) %} | ||
{{ return(time_bucket) }} | ||
{%- endif %} | ||
{% endmacro %} | ||
|
||
|
||
{% macro validate_time_bucket(time_bucket) %} | ||
{% if time_bucket %} | ||
{%- if time_bucket is not mapping %} | ||
{% do exceptions.raise_compiler_error( | ||
" | ||
Invalid time_bucket format. Expected format: | ||
time_bucket: | ||
count: int | ||
period: string | ||
") %} | ||
{%- endif %} | ||
{%- if time_bucket is mapping %} | ||
{%- set invalid_keys = [] %} | ||
{%- set valid_keys = ['period', 'count'] %} | ||
{%- for key, value in time_bucket.items() %} | ||
{%- if key not in valid_keys %} | ||
{%- do invalid_keys.append(key) -%} | ||
{%- endif %} | ||
{%- endfor %} | ||
{%- if invalid_keys | length > 0 %} | ||
{% do exceptions.raise_compiler_error( | ||
(" | ||
Found invalid keys in time_bucket: {0}. | ||
Supported keys: {1}. | ||
Expected format: | ||
time_bucket: | ||
count: int | ||
period: string | ||
").format(invalid_keys, valid_keys)) %} | ||
{%- endif %} | ||
{%- endif %} | ||
|
||
{% if time_bucket.count and time_bucket.count is not integer %} | ||
{% do exceptions.raise_compiler_error("time_bucket.count expects valid integer, got: {} (If it's an integer, try to remove quotes)".format(time_bucket.count)) %} | ||
{% endif %} | ||
{% set supported_periods = ['hour','day','week','month'] %} | ||
{% if time_bucket.period and time_bucket.period not in supported_periods %} | ||
{% do exceptions.raise_compiler_error("time_bucket.period value should be one of {0}, got: {1}".format(supported_periods, time_bucket.period)) %} | ||
{% endif %} | ||
{% endif %} | ||
{% endmacro %} |
File renamed without changes.
File renamed without changes.
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