Skip to content

Fix!: Allow expressions in scd type 2 models columns, check_cols in dbt#5529

Merged
themisvaltinos merged 3 commits intomainfrom
themis/fix_scd2_dbt_checkcols
Oct 13, 2025
Merged

Fix!: Allow expressions in scd type 2 models columns, check_cols in dbt#5529
themisvaltinos merged 3 commits intomainfrom
themis/fix_scd2_dbt_checkcols

Conversation

@themisvaltinos
Copy link
Contributor

This adds support for expressions in the list of columns in SCD type 2 models in order to support dbt snapshots that have check_cols with casts for example:

{{
    config(
      target_schema='snapshots',
      unique_key='id',
      strategy='check',
      check_cols=['ds::DATE'],
    )
}}

Quite similar to: #2164

@themisvaltinos themisvaltinos requested review from a team and eakmanrq October 10, 2025 16:10
@themisvaltinos themisvaltinos force-pushed the themis/fix_scd2_dbt_checkcols branch from 41ae931 to 864dd0e Compare October 10, 2025 22:43
check_columns = [exp.column(col) for col in unmanaged_columns_to_types]
if check_columns:
# Handle both Star directly and [Star()] (which can happen during serialization/deserialization)
if isinstance(check_columns, exp.Star) or (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be represented more succinctly with the following helpers:

from sqlglot.helper import ensure_list, seq_get

if isinstance(seq_get(ensure_list(check_columns), 0), exp.Star):
 ...

but it's six in one, half a dozen the other

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice that's much cleaner with seq_get thanks

@themisvaltinos themisvaltinos force-pushed the themis/fix_scd2_dbt_checkcols branch from 864dd0e to c248240 Compare October 13, 2025 08:03
@themisvaltinos themisvaltinos force-pushed the themis/fix_scd2_dbt_checkcols branch from c248240 to bbbb3af Compare October 13, 2025 14:11
@themisvaltinos themisvaltinos merged commit 15dac12 into main Oct 13, 2025
36 checks passed
@themisvaltinos themisvaltinos deleted the themis/fix_scd2_dbt_checkcols branch October 13, 2025 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants