Skip to content

Commit 7afcf1b

Browse files
author
Michael Myaskovsky
committed
74 tests pass
1 parent 03b27c9 commit 7afcf1b

File tree

8 files changed

+87
-4
lines changed

8 files changed

+87
-4
lines changed

integration_tests/dbt_project/macros/get_anomaly_config.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{% macro get_anomaly_config(model_config, config) %}
2+
{{ return(adapter.dispatch('get_anomaly_config', 'elementary')(model_config, config)) }}
3+
{% endmacro %}
4+
5+
{% macro default__get_anomaly_config(model_config, config) %}
26
{% set mock_model = {
37
"alias": "mock_model",
48
"config": {
@@ -19,4 +23,27 @@
1923
}
2024
}) %}
2125
{% do return(elementary.get_anomalies_test_configuration(api.Relation.create("db", "schema", "mock_model"), **config)[0]) %}
26+
{% endmacro %}
27+
28+
{% macro clickhouse__get_anomaly_config(model_config, config) %}
29+
{% set mock_model = {
30+
"alias": "mock_model",
31+
"config": {
32+
"elementary": model_config
33+
}
34+
} %}
35+
{# trick elementary into thinking this is the running model #}
36+
{% do context.update({
37+
"model": {
38+
"depends_on": {
39+
"nodes": ["id"]
40+
}
41+
},
42+
"graph": {
43+
"nodes": {
44+
"id": mock_model
45+
}
46+
}
47+
}) %}
48+
{% do return(elementary.get_anomalies_test_configuration(api.Relation.create("schema", "schema", "mock_model"), **config)[0]) %}
2249
{% endmacro %}

integration_tests/tests/test_dbt_artifacts/test_artifacts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def test_source_freshness_results(test_id: str, dbt_project: DbtProject):
9898
"sources": [
9999
{
100100
"name": "test_source",
101-
"database": "{{target.database}}",
101+
"database": "{{target.database if target.type != 'clickhouse' else target.schema}}",
102102
"schema": "{{target.schema}}",
103103
"tables": [
104104
{

macros/edr/data_monitoring/monitors_query/table_monitoring_query.sql

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227
consecutive_updates_freshness as (
228228
select
229229
timestamp_val as update_timestamp,
230-
{{ elementary.timediff('second', 'lag(timestamp_val) over (order by timestamp_val)', 'timestamp_val') }} as freshness
230+
{{ elementary.timediff('second', elementary.lag('timestamp_val') ~ ' over (order by timestamp_val)', 'timestamp_val') }} as freshness
231231
from unique_timestamps
232232
),
233233
time_filtered_consecutive_updates_freshness as (
@@ -300,9 +300,21 @@
300300
{% endmacro %}
301301

302302
{% macro get_no_timestamp_event_freshness_query(metric, metric_properties) %}
303+
{{ return(adapter.dispatch('get_no_timestamp_event_freshness_query', 'elementary')(metric, metric_properties)) }}
304+
{% endmacro %}
305+
306+
{% macro default__get_no_timestamp_event_freshness_query(metric, metric_properties) %}
303307
select
304308
{{ elementary.const_as_string(metric.name) }} as metric_name,
305309
{{ elementary.const_as_string("event_freshness") }} as metric_type,
306310
{{ elementary.timediff('second', elementary.edr_cast_as_timestamp("max({})".format(metric_properties.event_timestamp_column)), elementary.edr_quote(elementary.get_run_started_at())) }} as metric_value
307311
from monitored_table
308312
{% endmacro %}
313+
314+
{% macro clickhouse__get_no_timestamp_event_freshness_query(metric, metric_properties) %}
315+
select
316+
{{ elementary.const_as_string(metric.name) }} as metric_name,
317+
{{ elementary.const_as_string("event_freshness") }} as metric_type,
318+
{{ elementary.timediff('second', elementary.edr_cast_as_timestamp("max(toDateTime64({}, 3))".format(metric_properties.event_timestamp_column)), elementary.edr_quote(elementary.get_run_started_at())) }} as metric_value
319+
from monitored_table
320+
{% endmacro %}

macros/edr/system/system_utils/full_names.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@
3333
{% endmacro %}
3434

3535

36+
{% macro clickhouse__full_name_split(part_name) %}
37+
{%- if part_name == 'database_name' -%}
38+
{%- set part_index = 1 -%}
39+
{%- elif part_name == 'schema_name' -%}
40+
{%- set part_index = 2 -%}
41+
{%- elif part_name == 'table_name' -%}
42+
{%- set part_index = 3 -%}
43+
{%- else -%}
44+
{{ return('') }}
45+
{%- endif -%}
46+
trim(BOTH '"' FROM splitByChar('.', full_table_name)[{{ part_index }}]) AS {{ part_name }}
47+
{% endmacro %}
48+
49+
3650
{% macro bigquery__full_name_split(part_name) %}
3751
{%- if part_name == 'database_name' -%}
3852
{%- set part_index = 0 %}
@@ -88,6 +102,7 @@
88102
{{ return(full_table_name) }}
89103
{% endmacro %}
90104

105+
91106
{% macro model_node_to_full_name(model_node) %}
92107
{% set identifier = model_node.identifier or model_node.alias %}
93108
{%- if model_node.database %}

macros/edr/tests/test_column_anomalies.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
{{ exceptions.raise_compiler_error("Failed to create test configuration dict for test `{}`".format(test_table_name)) }}
4343
{%- endif %}
4444
{{ elementary.debug_log('test configuration - ' ~ test_configuration) }}
45-
4645
{%- set column_obj_and_monitors = elementary.get_column_obj_and_monitors(model_relation, column_name, column_anomalies) -%}
4746
{%- if not column_obj_and_monitors -%}
4847
{{ exceptions.raise_compiler_error("Unable to find column `{}` in `{}`".format(column_name, full_table_name)) }}

macros/edr/tests/test_schema_changes_from_baseline.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
{% if not model_relation %}
66
{{ exceptions.raise_compiler_error("Unsupported model: " ~ model ~ " (this might happen if you override 'ref' or 'source)") }}
77
{% endif %}
8-
98
{%- if elementary.is_ephemeral_model(model_relation) %}
109
{{ exceptions.raise_compiler_error("The test is not supported for ephemeral models, model name: {}".format(model_relation.identifier)) }}
1110
{%- endif %}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{% macro lag(column, offset=1) %}
2+
{{ return(adapter.dispatch('lag', 'elementary')(column, offset)) }}
3+
{% endmacro %}
4+
5+
{% macro default__lag(column, offset=1) %}
6+
lag({{ column }}, {{ offset }})
7+
{% endmacro %}
8+
9+
{% macro clickhouse__lag(column, offset=1) %}
10+
lagInFrame({{ column }}, {{ offset }})
11+
{% endmacro %}

macros/utils/data_types/data_type_list.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,23 @@
131131
{%- endif %}
132132

133133
{% endmacro %}
134+
135+
{% macro clickhouse__data_type_list(data_type) %}
136+
{% set string_list = ['String', 'FixedString', 'LowCardinality(String)'] | list %}
137+
{% set numeric_list = ['Int8', 'Int16', 'Int32', 'Int64', 'UInt8', 'UInt16', 'UInt32', 'UInt64', 'Float32', 'Float64', 'Decimal', 'Decimal32', 'Decimal64', 'Decimal128'] | list %}
138+
{% set timestamp_list = ['DateTime', 'DateTime64', 'Date', 'Date32'] | list %}
139+
{% set boolean_list = ["UInt8","Bool"] | list %}
140+
141+
{%- if data_type == 'string' %}
142+
{{ return(string_list) }}
143+
{%- elif data_type == 'numeric' %}
144+
{{ return(numeric_list) }}
145+
{%- elif data_type == 'timestamp' %}
146+
{{ return(timestamp_list) }}
147+
{%- elif data_type == "boolean" %}
148+
{{ return(boolean_list) }}
149+
{%- else %}
150+
{{ return([]) }}
151+
{%- endif %}
152+
153+
{% endmacro %}

0 commit comments

Comments
 (0)