Skip to content

Commit e13fc47

Browse files
sinelineGuillem G.
authored andcommitted
feat: support cloning Iceberg tables on Snowflake by passing table format to the engine adapter.
1 parent 6e69ce6 commit e13fc47

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

sqlmesh/core/engine_adapter/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,10 +1077,11 @@ def clone_table(
10771077
raise NotImplementedError(f"Engine does not support cloning: {type(self)}")
10781078

10791079
kwargs.pop("rendered_physical_properties", None)
1080+
table_kind = kwargs.pop("table_kind", "TABLE")
10801081
self.execute(
10811082
exp.Create(
10821083
this=exp.to_table(target_table_name),
1083-
kind="TABLE",
1084+
kind=table_kind,
10841085
replace=replace,
10851086
exists=exists,
10861087
clone=exp.Clone(

sqlmesh/core/engine_adapter/snowflake.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,12 @@ def clone_table(
675675
if isinstance(table_type, exp.TransientProperty):
676676
kwargs["properties"] = exp.Properties(expressions=[table_type])
677677

678+
# Snowflake requires CREATE ICEBERG TABLE ... CLONE for Iceberg tables
679+
# instead of the regular CREATE TABLE ... CLONE
680+
table_format = kwargs.pop("table_format", None)
681+
if table_format and isinstance(table_format, str) and table_format.upper() == "ICEBERG":
682+
kwargs["table_kind"] = f"{table_format.upper()} TABLE"
683+
678684
super().clone_table(
679685
target_table_name,
680686
source_table_name,

sqlmesh/core/snapshot/evaluator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,7 @@ def _clone_snapshot_in_dev(
10851085
target_table_name,
10861086
snapshot.table_name(),
10871087
rendered_physical_properties=rendered_physical_properties,
1088+
table_format=snapshot.model.table_format,
10881089
)
10891090
self._migrate_target_table(
10901091
target_table_name=target_table_name,

0 commit comments

Comments
 (0)