Repository navigation
fix: apply column codec and ttl to distributed tables - #741
Romano-arist wants to merge 12 commits into
Conversation
…y; ttl stays local-only
…umn-codec-ttl # Conflicts: # CHANGELOG.md
…umn-codec-ttl # Conflicts: # CHANGELOG.md
|
Hi @koletzilla! Could you take a look when you have a moment? |
…/distributed-column-codec-ttl
There was a problem hiding this comment.
🟡 Changes recommended
Adding a TTL-bearing column can fail when its referenced date column has not yet been added, and the sync tests do not cover codec/TTL updates alongside type changes on existing columns.
2 open issues
What changed in this PR
This PR updates the ClickHouse adapter to apply column-level codec and TTL settings to distributed models’ shard-local tables during creation, rebuilds, and incremental schema changes.
Changes:
- Apply column storage clauses during table creation, with or without enforced contracts.
- Include codec and TTL in column additions and modifications, omitting TTL from distributed-table ALTERs.
- Add integration coverage and a user-facing changelog entry.
| File | Description |
|---|---|
tests/integration/adapter/incremental/test_schema_change_ttl.py |
Adds TTL schema-change, rebuild, and creation tests. |
tests/integration/adapter/incremental/test_schema_change_codec.py |
Checks shard-local codecs and adds rebuild and creation tests. |
dbt/include/clickhouse/macros/materializations/table.sql |
Adds a reusable TTL clause macro. |
dbt/include/clickhouse/macros/materializations/incremental/schema_changes.sql |
Applies storage clauses through separate local and distributed ALTER actions. |
dbt/include/clickhouse/macros/materializations/distributed_table.sql |
Renders contract-aware column definitions with codec and TTL settings. |
CHANGELOG.md |
Documents the distributed column-storage fix. |
Review effort: Balanced
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit ddf0187. Configure here.
|
hi @Romano-arist, thank you first of all for the contribution! I'll review this PR today and come back to you with my feedback |
There was a problem hiding this comment.
hi again,
generally I like the changes as it fixes a real gap in the distributed_incremental and distributed_table materializations. I would only like to ask for a narrower scope of these changes. our docs (see https://clickhouse.com/docs/integrations/connectors/data-ingestion/etl-tools/dbt/materializations#column-configuration) currently specify that codec and ttl column configurations require contract enforcement to be enabled. for the moment, we wouldn't want to change this expectation (even though applying codec and ttl independently of contract enforcement might seem logical). we would like to change the behaviour eventually as part of separate work, also aligning any sort inconsistencies and also making sure that syncing of ttl/codec changes are being identified. I would share an issue for this work item soon.
would you be ok with keeping the rule of codec/ttl via enforced contracts for this PR, by gating ttl/codec settings at table creation time, column addition and column modification? I noticed that there is already preexisting breaches of this rule in the clickhouse__add_columns method, but I think that can also be aligned within the scope of this PR.
let me know if you have some other thoughts on this and whether you would like to work on the changes :)
|
@canbekley Thanks for the review! Codec/ttl are now gated on enforced contracts, modify/drop are batched into a single |


Summary
Column-level
codecandttlwere ignored fordistributed_incrementalmodels: they were not applied on table create, and on schema changes onlycodecwas applied (neverttl). This fixes both paths so columncodec/ttlfrom the model contract are applied on create and on add/modify column.Limitations and out of scope for this PR
Checklist
Note
Medium Risk
Touches DDL for distributed tables and incremental ALTER paths; incorrect codec/TTL SQL could break model runs or leave schema drift, though changes are gated on enforced contracts and covered by new integration tests.
Overview
Column-level codec and ttl from the model contract are now applied when building distributed shard-local tables on create/rebuild, and on add/modify column during
on_schema_changefor incremental and distributed materializations. With contract enforced, DDL uses contract rendering (including codec/TTL); without it, schema-change add column no longer applies codec, matching documented behavior. TTL is emitted on the local/shard table only (not on theDistributedwrapper). Schema-change ALTERs are refactored to batch actions and separate local vs distributed DDL where TTL applies only locally.Integration coverage expands for codec (including no-contract cases and distributed table rebuilds) and adds parallel TTL tests.
Reviewed by Cursor Bugbot for commit 624909a. Bugbot is set up for automated code reviews on this repo. Configure here.