Skip to content

Commit

Permalink
test: add test for TTL
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Mar 22, 2024
1 parent 48ead30 commit 484abeb
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/integration/adapter/clickhouse/test_clickhouse_table_ttl.py
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

0 comments on commit 484abeb

Please sign in to comment.