Skip to content

Commit 83c28fb

Browse files
committed
fix(snowflake): preserve dynamic Iceberg column comments
1 parent b0ed0ca commit 83c28fb

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎sqlmesh/core/engine_adapter/base.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,9 @@ def _create_table_from_source_queries(
993993
self._create_table_comment(table_name, table_description)
994994
if column_descriptions and schema is None and self.comments_enabled:
995995
self._create_column_comments(
996-
table_name, column_descriptions, table_format=kwargs.get("table_format")
996+
table_name,
997+
column_descriptions,
998+
table_format=None if table_kind else kwargs.get("table_format"),
997999
)
9981000

9991001
def _create_table(

‎tests/core/engine_adapter/test_snowflake.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,31 @@ def test_create_managed_table(make_mocked_engine_adapter: t.Callable, mocker: Mo
663663
]
664664

665665

666+
@pytest.mark.parametrize("table_format", [None, "iceberg"])
667+
def test_create_managed_table_column_comments(
668+
make_mocked_engine_adapter: t.Callable, table_format: t.Optional[str]
669+
):
670+
adapter = make_mocked_engine_adapter(SnowflakeEngineAdapter)
671+
672+
# Unknown column types require a post-creation comment command.
673+
adapter.create_managed_table(
674+
table_name="test_table",
675+
query=parse_one("SELECT a, b FROM source_table"),
676+
table_format=table_format,
677+
table_properties={
678+
"target_lag": exp.Literal.string("20 minutes"),
679+
"warehouse": exp.to_identifier("test_warehouse"),
680+
},
681+
column_descriptions={"a": "a column description", "b": "b column description"},
682+
)
683+
684+
table_kind = "DYNAMIC ICEBERG TABLE" if table_format else "DYNAMIC TABLE"
685+
assert to_sql_calls(adapter) == [
686+
f'CREATE OR REPLACE {table_kind} "test_table" TARGET_LAG=\'20 minutes\' WAREHOUSE="test_warehouse" AS SELECT "a", "b" FROM "source_table"',
687+
"""ALTER TABLE "test_table" ALTER COLUMN "a" COMMENT 'a column description', COLUMN "b" COMMENT 'b column description'""",
688+
]
689+
690+
666691
def test_drop_managed_table(make_mocked_engine_adapter: t.Callable, mocker: MockerFixture):
667692
adapter = make_mocked_engine_adapter(SnowflakeEngineAdapter)
668693

0 commit comments

Comments
 (0)