Skip to content

Commit 1e84ba5

Browse files
authored
Fix: pass model dialect to sqlglot.diff to avoid possible generation issues (#3877)
1 parent 31bea82 commit 1e84ba5

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

sqlmesh/core/model/definition.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,7 @@ def is_breaking_change(self, previous: Model) -> t.Optional[bool]:
14141414
matchings=[(previous_query, this_query)],
14151415
delta_only=True,
14161416
copy=False,
1417+
dialect=self.dialect if self.dialect == previous.dialect else None,
14171418
)
14181419
inserted_expressions = {e.expression for e in edits if isinstance(e, Insert)}
14191420

tests/core/engine_adapter/integration/test_integration_clickhouse.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from tests.core.engine_adapter.integration import TestContext
44
import pandas as pd
55
from sqlglot import exp, parse_one
6+
from sqlmesh.core.snapshot import SnapshotChangeCategory
67

78

89
@pytest.fixture(
@@ -545,3 +546,27 @@ def test_inc_by_time_auto_partition_string(ctx: TestContext):
545546
# The automatic time partitioning creates one partition per week. The 4 input data points
546547
# are located in three distinct weeks, which should have one partition each.
547548
assert len(partitions) == 3
549+
550+
551+
def test_diff_requires_dialect(ctx: TestContext):
552+
sql = """
553+
MODEL (
554+
name test_schema.some_view,
555+
kind VIEW,
556+
dialect clickhouse
557+
);
558+
559+
SELECT
560+
maxIf('2020-01-01'::Date, 1={rhs})::Nullable(Date) as col
561+
"""
562+
563+
sqlmesh_context, model = ctx.upsert_sql_model(sql.format(rhs="1"))
564+
sqlmesh_context.plan(no_prompts=True, auto_apply=True)
565+
566+
_, model = ctx.upsert_sql_model(sql.format(rhs="2"))
567+
sqlmesh_context.upsert_model(model)
568+
569+
plan = sqlmesh_context.plan(no_prompts=True, auto_apply=True, no_diff=True)
570+
571+
new_snapshot = plan.context_diff.modified_snapshots['"test_schema"."some_view"'][0]
572+
assert new_snapshot.change_category == SnapshotChangeCategory.BREAKING

0 commit comments

Comments
 (0)