Skip to content

Commit db769fb

Browse files
sinelineStuffbyYuki
authored andcommitted
fix(snowflake): preserve dynamic Iceberg column comments
1 parent 52bfbfa commit db769fb

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
@@ -669,6 +669,31 @@ def test_create_managed_table(make_mocked_engine_adapter: t.Callable, mocker: Mo
669669
]
670670

671671

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

0 commit comments

Comments
 (0)