Skip to content

Commit 1517d9d

Browse files
Merge pull request #806 from elementary-data/ele-4224
Ele 4224
2 parents 58a860c + d7254af commit 1517d9d

File tree

56 files changed

+517
-85
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+517
-85
lines changed

.github/workflows/test-all-warehouses.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
databricks_catalog,
4949
athena,
5050
trino,
51+
clickhouse,
5152
]
5253
include:
5354
# If we're not running on a specific dbt version, then always add postgres on 1.7.0

.github/workflows/test-warehouse.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ on:
1616
- spark
1717
- athena
1818
- trino
19+
- clickhouse
1920
elementary-ref:
2021
type: string
2122
required: false
@@ -82,6 +83,11 @@ jobs:
8283
working-directory: ${{ env.TESTS_DIR }}
8384
run: docker compose -f docker-compose-trino.yml up -d
8485

86+
- name: Start Clickhouse
87+
if: inputs.warehouse-type == 'clickhouse'
88+
working-directory: ${{ env.TESTS_DIR }}
89+
run: docker compose up -d clickhouse
90+
8591
- name: Setup Python
8692
uses: actions/setup-python@v4
8793
with:
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
{% macro clear_env() %}
2-
{% do elementary_tests.edr_drop_schema(elementary.target_database(), generate_schema_name()) %}
32
{% set database_name, schema_name = elementary.get_package_database_and_schema('elementary') %}
43
{% do elementary_tests.edr_drop_schema(database_name, schema_name) %}
4+
{% do elementary_tests.edr_drop_schema(elementary.target_database(), generate_schema_name()) %}
55
{% endmacro %}
66

77
{% macro edr_drop_schema(database_name, schema_name) %}
8+
{% do return(adapter.dispatch('edr_drop_schema', 'elementary_tests')(database_name, schema_name)) %}
9+
{% endmacro %}
10+
11+
{% macro default__edr_drop_schema(database_name, schema_name) %}
812
{% set schema_relation = api.Relation.create(database=database_name, schema=schema_name) %}
913
{% do dbt.drop_schema(schema_relation) %}
1014
{% do adapter.commit() %}
1115
{% endmacro %}
16+
17+
{% macro clickhouse__edr_drop_schema(database_name, schema_name) %}
18+
{% do run_query("DROP DATABASE IF EXISTS " ~ schema_name) %}
19+
{% do adapter.commit() %}
20+
{% endmacro %}

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/docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@ services:
1212
volumes:
1313
- postgres:/var/lib/postgresql/data
1414

15+
clickhouse:
16+
image: clickhouse/clickhouse-server:latest
17+
container_name: clickhouse
18+
ports:
19+
- "8123:8123"
20+
- "9000:9000"
21+
volumes:
22+
- ./clickhouse-data:/var/lib/clickhouse
23+
environment:
24+
CLICKHOUSE_DB: default
25+
CLICKHOUSE_USER: default
26+
CLICKHOUSE_PASSWORD: "default"
27+
ulimits:
28+
nofile:
29+
soft: 262144
30+
hard: 262144
31+
1532
pgadmin:
1633
image: dpage/pgadmin4
1734
ports:

integration_tests/tests/dbt_project.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ def test(
151151
) -> Union[Dict[str, Any], List[Dict[str, Any]]]:
152152
if columns and test_column:
153153
raise ValueError("You can't specify both 'columns' and 'test_column'.")
154-
155154
test_vars = test_vars or {}
156155
test_vars["elementary_enabled"] = elementary_enabled
157156

integration_tests/tests/test_all_columns_anomalies.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import datetime, timedelta
22
from typing import Any, Dict, List
33

4+
import pytest
45
from data_generator import DATE_FORMAT, generate_dates
56
from dbt_project import DbtProject
67

@@ -28,6 +29,8 @@ def test_anomalyless_all_columns_anomalies(test_id: str, dbt_project: DbtProject
2829
assert all([res["status"] == "pass" for res in test_results])
2930

3031

32+
# Anomalies currently not supported on ClickHouse
33+
@pytest.mark.skip_targets(["clickhouse"])
3134
def test_anomalous_all_columns_anomalies(test_id: str, dbt_project: DbtProject):
3235
utc_today = datetime.utcnow().date()
3336
test_date, *training_dates = generate_dates(base_date=utc_today - timedelta(1))
@@ -52,6 +55,8 @@ def test_anomalous_all_columns_anomalies(test_id: str, dbt_project: DbtProject):
5255
assert col_to_status == {"superhero": "fail", TIMESTAMP_COLUMN: "pass"}
5356

5457

58+
# Anomalies currently not supported on ClickHouse
59+
@pytest.mark.skip_targets(["clickhouse"])
5560
def test_all_columns_anomalies_with_where_expression(
5661
test_id: str, dbt_project: DbtProject
5762
):

integration_tests/tests/test_anomalies_backfill_logic.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from datetime import datetime, time, timedelta
33

44
import dateutil.parser
5+
import pytest
56
from data_generator import DATE_FORMAT, generate_dates
67
from dbt_project import DbtProject
78

@@ -106,6 +107,8 @@ def test_full_backfill_for_non_incremental_model(dbt_project: DbtProject, test_i
106107
}
107108

108109

110+
# Anomalies currently not supported on ClickHouse
111+
@pytest.mark.skip_targets(["clickhouse"])
109112
def test_partial_backfill_for_incremental_models(dbt_project: DbtProject, test_id: str):
110113
utc_today = datetime.utcnow().date()
111114
data_dates = generate_dates(base_date=utc_today - timedelta(1))
@@ -152,6 +155,8 @@ def test_partial_backfill_for_incremental_models(dbt_project: DbtProject, test_i
152155
}
153156

154157

158+
# Anomalies currently not supported on ClickHouse
159+
@pytest.mark.skip_targets(["clickhouse"])
155160
def test_longer_backfill_in_case_of_a_gap(dbt_project: DbtProject, test_id: str):
156161
date_gap_size = 5
157162
utc_today = datetime.utcnow().date()
@@ -204,6 +209,8 @@ def test_longer_backfill_in_case_of_a_gap(dbt_project: DbtProject, test_id: str)
204209
}
205210

206211

212+
# Anomalies currently not supported on ClickHouse
213+
@pytest.mark.skip_targets(["clickhouse"])
207214
def test_full_backfill_if_metric_not_updated_for_a_long_time(
208215
dbt_project: DbtProject, test_id: str
209216
):
@@ -263,6 +270,8 @@ def test_full_backfill_if_metric_not_updated_for_a_long_time(
263270
}
264271

265272

273+
# Anomalies currently not supported on ClickHouse
274+
@pytest.mark.skip_targets(["clickhouse"])
266275
def test_backfill_when_metric_doesnt_exist_back_enough(
267276
dbt_project: DbtProject, test_id: str
268277
):
@@ -307,6 +316,8 @@ def test_backfill_when_metric_doesnt_exist_back_enough(
307316
}
308317

309318

319+
# Anomalies currently not supported on ClickHouse
320+
@pytest.mark.skip_targets(["clickhouse"])
310321
def test_backfill_with_middle_buckets_gap(dbt_project: DbtProject, test_id: str):
311322
utc_today = datetime.utcnow().date()
312323
data_start = utc_today - timedelta(21)
@@ -375,6 +386,8 @@ def test_backfill_with_middle_buckets_gap(dbt_project: DbtProject, test_id: str)
375386
}
376387

377388

389+
# Anomalies currently not supported on ClickHouse
390+
@pytest.mark.skip_targets(["clickhouse"])
378391
def test_bucket_size_not_aligned_with_days(dbt_project: DbtProject, test_id: str):
379392
"""
380393
In this test we choose a bucket size that is not aligned with one day - specifically 7 hours.

integration_tests/tests/test_anomalies_ranges.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from datetime import datetime, timedelta
33
from typing import Any, Dict, List
44

5+
import pytest
56
from data_generator import DATE_FORMAT, generate_dates
67
from dbt_project import DbtProject
78

@@ -33,6 +34,8 @@ def get_latest_anomaly_test_points(dbt_project: DbtProject, test_id: str):
3334
return [json.loads(result["result_row"]) for result in results]
3435

3536

37+
# Anomalies currently not supported on ClickHouse
38+
@pytest.mark.skip_targets(["clickhouse"])
3639
def test_anomaly_ranges_are_valid(test_id: str, dbt_project: DbtProject):
3740
utc_today = datetime.utcnow().date()
3841
test_date, *training_dates = generate_dates(base_date=utc_today - timedelta(1))
@@ -66,6 +69,8 @@ def test_anomaly_ranges_are_valid(test_id: str, dbt_project: DbtProject):
6669
assert all([row["min_value"] == row["max_value"] for row in anomaly_test_points])
6770

6871

72+
# Anomalies currently not supported on ClickHouse
73+
@pytest.mark.skip_targets(["clickhouse"])
6974
def test_anomaly_ranges_are_valid_with_seasonality(
7075
test_id: str, dbt_project: DbtProject
7176
):

integration_tests/tests/test_anomaly_exclude_metrics.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import datetime, timedelta
22
from typing import Any, Dict, List
33

4+
import pytest
45
from data_generator import DATE_FORMAT, generate_dates
56
from dbt_project import DbtProject
67
from parametrization import Parametrization
@@ -24,6 +25,8 @@
2425
time_bucket={"period": "hour", "count": 6},
2526
dates_step=timedelta(hours=6),
2627
)
28+
# Anomalies currently not supported on ClickHouse
29+
@pytest.mark.skip_targets(["clickhouse"])
2730
def test_exclude_specific_dates(
2831
test_id: str, dbt_project: DbtProject, time_bucket: dict, dates_step: timedelta
2932
):
@@ -123,6 +126,8 @@ def test_exclude_specific_timestamps(test_id: str, dbt_project: DbtProject):
123126
assert test_result["status"] == "fail"
124127

125128

129+
# Anomalies currently not supported on ClickHouse
130+
@pytest.mark.skip_targets(["clickhouse"])
126131
def test_exclude_date_range(test_id: str, dbt_project: DbtProject):
127132
utc_today = datetime.utcnow().date()
128133
test_date, *training_dates = generate_dates(base_date=utc_today - timedelta(1))
@@ -158,6 +163,8 @@ def test_exclude_date_range(test_id: str, dbt_project: DbtProject):
158163
assert test_result["status"] == "fail"
159164

160165

166+
# Anomalies currently not supported on ClickHouse
167+
@pytest.mark.skip_targets(["clickhouse"])
161168
def test_exclude_by_metric_value(test_id: str, dbt_project: DbtProject):
162169
utc_today = datetime.utcnow().date()
163170
test_date, *training_dates = generate_dates(base_date=utc_today - timedelta(1))

0 commit comments

Comments
 (0)