diff --git a/dbt/adapters/clickhouse/impl.py b/dbt/adapters/clickhouse/impl.py index 38bfee91..03b45fa4 100644 --- a/dbt/adapters/clickhouse/impl.py +++ b/dbt/adapters/clickhouse/impl.py @@ -41,6 +41,7 @@ class ClickHouseConfig(AdapterConfig): order_by: Optional[Union[List[str], str]] = 'tuple()' partition_by: Optional[Union[List[str], str]] = None sharding_key: Optional[Union[List[str], str]] = 'rand()' + ttl: Optional[Union[List[str], str]] = None class ClickHouseAdapter(SQLAdapter): diff --git a/dbt/include/clickhouse/macros/materializations/table.sql b/dbt/include/clickhouse/macros/materializations/table.sql index 72cc72c8..d9b4c49b 100644 --- a/dbt/include/clickhouse/macros/materializations/table.sql +++ b/dbt/include/clickhouse/macros/materializations/table.sql @@ -121,6 +121,12 @@ {%- endif %} {%- endmacro -%} +{% macro ttl_config(label) %} + {%- if config.get("ttl")%} + {{ label }} {{ config.get("ttl") }} + {%- endif %} +{%- endmacro -%} + {% macro on_cluster_clause(relation, force_sync) %} {% set active_cluster = adapter.get_clickhouse_cluster_name() %} {%- if active_cluster is not none and relation.should_on_cluster %} @@ -170,6 +176,7 @@ {{ order_cols(label="order by") }} {{ primary_key_clause(label="primary key") }} {{ partition_cols(label="partition by") }} + {{ ttl_config(label="ttl")}} {{ adapter.get_model_settings(model) }} {%- if not has_contract %}