Skip to content

Commit cc2e1f1

Browse files
authored
Fix: Redundant creation of view models during the first evaluation (#5337)
1 parent fdf2f89 commit cc2e1f1

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

sqlmesh/core/snapshot/evaluator.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
CustomKind,
5151
)
5252
from sqlmesh.core.model.kind import _Incremental
53-
from sqlmesh.utils import CompletionStatus
53+
from sqlmesh.utils import CompletionStatus, columns_to_types_all_known
5454
from sqlmesh.core.schema_diff import (
5555
has_drop_alteration,
5656
TableAlterOperation,
@@ -747,6 +747,11 @@ def _evaluate_snapshot(
747747
adapter.execute(model.render_pre_statements(**render_statements_kwargs))
748748

749749
if not target_table_exists or (model.is_seed and not snapshot.intervals):
750+
columns_to_types_provided = (
751+
model.kind.is_materialized
752+
and model.columns_to_types_
753+
and columns_to_types_all_known(model.columns_to_types_)
754+
)
750755
if self._can_clone(snapshot, deployability_index):
751756
self._clone_snapshot_in_dev(
752757
snapshot=snapshot,
@@ -759,7 +764,7 @@ def _evaluate_snapshot(
759764
)
760765
runtime_stage = RuntimeStage.EVALUATING
761766
target_table_exists = True
762-
elif model.annotated or model.is_seed or model.kind.is_scd_type_2:
767+
elif columns_to_types_provided or model.is_seed or model.kind.is_scd_type_2:
763768
self._execute_create(
764769
snapshot=snapshot,
765770
table_name=target_table_name,

tests/core/test_snapshot_evaluator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ def test_evaluate_materialized_view(
646646
)
647647

648648
# Ensure that the materialized view is recreated even if it exists
649-
assert adapter_mock.create_view.assert_called
649+
assert adapter_mock.create_view.call_count == 1
650650

651651

652652
def test_evaluate_materialized_view_with_partitioned_by_cluster_by(

0 commit comments

Comments
 (0)