Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#### Improvements
* Starting with this release the `dbt-clickhouse` packages will be published to PyPI using Github Actions as a [Trusted Publisher](https://docs.pypi.org/trusted-publishers/). This will improve both the usability and the security of the release process ([#614](https://github.com/ClickHouse/dbt-clickhouse/pull/614)).

#### Bugs
* Fix `dbt_valid_to_current` snapshot configuration being ignored in the ClickHouse adapter. The snapshot macros for both timestamp and check strategies now correctly read and apply the `dbt_valid_to_current` config value, matching dbt-core's expected behavior. Previously, snapshots configured with `dbt_valid_to_current` would produce duplicate rows on subsequent runs because the adapter always filtered current records with `WHERE dbt_valid_to IS NULL`, missing rows that had the configured sentinel value.


### Release [1.10.0], 2026-02-16

Expand Down
22 changes: 18 additions & 4 deletions dbt/include/clickhouse/macros/materializations/snapshot.sql
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@

{% macro clickhouse__snapshot_staging_table_check_strategy(strategy, source_sql, target_relation) -%}

{% set dbt_valid_to_current = config.get('dbt_valid_to_current') %}

with snapshot_time as (
select {{ strategy.updated_at }} as ts -- Single timestamp
),
Expand All @@ -114,7 +116,12 @@
{{ strategy.unique_key }} as dbt_unique_key

from {{ target_relation }}
where dbt_valid_to is null
where
{% if dbt_valid_to_current %}
( dbt_valid_to = {{ dbt_valid_to_current }} or dbt_valid_to is null )
{% else %}
dbt_valid_to is null
{% endif %}

),

Expand All @@ -125,7 +132,7 @@
{{ strategy.unique_key }} as dbt_unique_key,
snapshot_time.ts as dbt_updated_at,
snapshot_time.ts as dbt_valid_from,
nullif(snapshot_time.ts, snapshot_time.ts) as dbt_valid_to,
coalesce(nullif(snapshot_time.ts, snapshot_time.ts), {{ dbt_valid_to_current or 'null' }}) as dbt_valid_to,
{{ strategy.scd_id }} as dbt_scd_id

from snapshot_query, snapshot_time
Expand Down Expand Up @@ -217,6 +224,8 @@

{% macro clickhouse__snapshot_staging_table_timestamp_strategy(strategy, source_sql, target_relation) -%}

{% set dbt_valid_to_current = config.get('dbt_valid_to_current') %}

with snapshot_query as (

{{ source_sql }}
Expand All @@ -229,7 +238,12 @@
{{ strategy.unique_key }} as dbt_unique_key

from {{ target_relation }}
where dbt_valid_to is null
where
{% if dbt_valid_to_current %}
( dbt_valid_to = {{ dbt_valid_to_current }} or dbt_valid_to is null )
{% else %}
dbt_valid_to is null
{% endif %}

),

Expand All @@ -240,7 +254,7 @@
{{ strategy.unique_key }} as dbt_unique_key,
{{ strategy.updated_at }} as dbt_updated_at,
{{ strategy.updated_at }} as dbt_valid_from,
nullif({{ strategy.updated_at }}, {{ strategy.updated_at }}) as dbt_valid_to,
coalesce(nullif({{ strategy.updated_at }}, {{ strategy.updated_at }}), {{ dbt_valid_to_current or 'null' }}) as dbt_valid_to,
{{ strategy.scd_id }} as dbt_scd_id

from snapshot_query
Expand Down
Loading