-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
tests/integration/adapter/clickhouse/test_clickhouse_table_ttl.py
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,54 @@ | ||
import pytest | ||
from dbt.tests.util import run_dbt | ||
from dbt.tests.adapter.basic.test_base import BaseSimpleMaterializations | ||
from dbt.tests.adapter.basic.files import model_base, schema_base_yml | ||
from dbt.tests.util import ( | ||
relation_from_name, | ||
run_dbt, | ||
) | ||
import time | ||
|
||
class TestTableTTL(BaseSimpleMaterializations): | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
config_materialized_table = """ | ||
{{ config( | ||
order_by='(some_date, id, name)', | ||
engine='MergeTree()', | ||
materialized='table', | ||
settings={'allow_nullable_key': 1}, | ||
ttl='some_date + INTERVAL 5 SECONDS' | ||
query_settings={'allow_nondeterministic_mutations': 1}) | ||
}} | ||
""" | ||
base_table_sql = config_materialized_table + model_base | ||
return { | ||
"table_model.sql": base_table_sql, | ||
"schema.yml": schema_base_yml, | ||
} | ||
|
||
def test_base(self, project): | ||
# seed command | ||
results = run_dbt(["seed"]) | ||
# seed result length | ||
assert len(results) == 1 | ||
|
||
# run command | ||
results = run_dbt() | ||
# run result length | ||
assert len(results) == 1 | ||
|
||
# base table rowcount | ||
relation = relation_from_name(project.adapter, "table_model") | ||
result = project.run_sql(f"select count(*) as num_rows from {relation}", fetch="one") | ||
assert result[0] == 10 | ||
|
||
# wait for TTL to expire | ||
time.sleep(6) | ||
|
||
# optimize table | ||
final = project.run_sql(f"OPTIMIZE TABLE {relation} FINAL") | ||
|
||
# make sure is empty | ||
result = project.run_sql(f"select count(*) as num_rows from {relation}", fetch="one") | ||
assert result[0] == 0 |