Skip to content

Commit b7d3b2d

Browse files
committed
Fix!: use sql() instead of gen() for time data type data hash computation
1 parent 3d368c8 commit b7d3b2d

3 files changed

Lines changed: 46 additions & 1 deletion

File tree

sqlmesh/core/model/kind.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ def data_hash_values(self) -> t.List[t.Optional[str]]:
711711
gen(self.valid_from_name),
712712
gen(self.valid_to_name),
713713
str(self.invalidate_hard_deletes),
714-
gen(self.time_data_type),
714+
self.time_data_type.sql(self.dialect),
715715
gen(self.batch_size) if self.batch_size is not None else None,
716716
]
717717

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""Use sql(...) instead of gen when computing the data hash of the time data type."""
2+
3+
4+
def migrate(state_sync, **kwargs): # type: ignore
5+
pass

tests/core/test_model.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9587,3 +9587,43 @@ def test_semicolon_is_not_included_in_model_state(tmp_path, assert_exp_eq):
95879587
plan = ctx.plan(no_prompts=True, auto_apply=True)
95889588

95899589
assert not plan.context_diff.modified_snapshots
9590+
9591+
9592+
def test_scd_time_data_type_does_not_cause_diff_after_deserialization() -> None:
9593+
for dialect in (
9594+
"athena",
9595+
"bigquery",
9596+
"clickhouse",
9597+
"databricks",
9598+
"duckdb",
9599+
"dune",
9600+
"hive",
9601+
"mysql",
9602+
"postgres",
9603+
"presto",
9604+
"redshift",
9605+
"snowflake",
9606+
"spark",
9607+
"trino",
9608+
"tsql",
9609+
):
9610+
sql = f"""
9611+
MODEL (
9612+
name test_schema.test_model,
9613+
kind SCD_TYPE_2_BY_COLUMN (
9614+
unique_key ARRAY(col),
9615+
columns ARRAY(col),
9616+
invalidate_hard_deletes TRUE,
9617+
on_destructive_change error
9618+
),
9619+
dialect {dialect}
9620+
);
9621+
9622+
SELECT
9623+
1 AS col
9624+
"""
9625+
9626+
model = load_sql_based_model(d.parse(sql))
9627+
deserialized_model = SqlModel.parse_raw(model.json())
9628+
9629+
assert model.data_hash == deserialized_model.data_hash

0 commit comments

Comments
 (0)