Skip to content

Commit 04999ed

Browse files
committed
parse column from cast expression
1 parent 858f432 commit 04999ed

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

sqlmesh/dbt/model.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,17 @@ def _validate_check_cols(cls, v: t.Union[str, t.List[str]]) -> t.Union[str, t.Li
172172
return "*"
173173
return ensure_list(v)
174174

175+
@field_validator("updated_at", mode="before")
176+
@classmethod
177+
def _validate_updated_at(cls, v: t.Optional[str]) -> t.Optional[str]:
178+
if v is None:
179+
return None
180+
parsed = d.parse_one(v)
181+
if isinstance(parsed, exp.Cast) and isinstance(parsed.this, exp.Column):
182+
return parsed.this.name
183+
184+
return v
185+
175186
@field_validator("sql", mode="before")
176187
@classmethod
177188
def _validate_sql(cls, v: t.Union[str, SqlStr]) -> SqlStr:

tests/dbt/test_transformation.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,23 @@ def test_model_kind():
652652
== ManagedKind()
653653
)
654654

655+
assert ModelConfig(
656+
materialized=Materialization.SNAPSHOT,
657+
unique_key=["id"],
658+
updated_at="updated_at::timestamp",
659+
strategy="timestamp",
660+
dialect="redshift",
661+
).model_kind(context) == SCDType2ByTimeKind(
662+
unique_key=["id"],
663+
valid_from_name="dbt_valid_from",
664+
valid_to_name="dbt_valid_to",
665+
updated_at_as_valid_from=True,
666+
updated_at_name="updated_at",
667+
dialect="redshift",
668+
on_destructive_change=OnDestructiveChange.IGNORE,
669+
on_additive_change=OnAdditiveChange.ALLOW,
670+
)
671+
655672

656673
def test_model_kind_snapshot_bigquery():
657674
context = DbtContext()

0 commit comments

Comments
 (0)