Skip to content

Commit c1ec990

Browse files
committed
Test: Add test for Databricks materialized views with column comments
Verifies that column types are included in CREATE MATERIALIZED VIEW statements when column comments are present, as required by Databricks.
1 parent 6e07b8d commit c1ec990

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/core/engine_adapter/test_databricks.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,36 @@ def test_materialized_view_properties(mocker: MockFixture, make_mocked_engine_ad
376376
]
377377

378378

379+
def test_materialized_view_with_column_comments(
380+
mocker: MockFixture, make_mocked_engine_adapter: t.Callable
381+
):
382+
mocker.patch(
383+
"sqlmesh.core.engine_adapter.databricks.DatabricksEngineAdapter.set_current_catalog"
384+
)
385+
adapter = make_mocked_engine_adapter(DatabricksEngineAdapter, default_catalog="test_catalog")
386+
mocker.patch.object(adapter, "get_current_catalog", return_value="test_catalog")
387+
388+
adapter.create_view(
389+
"test_view",
390+
parse_one("SELECT a, b FROM source_table"),
391+
target_columns_to_types={
392+
"a": exp.DataType.build("INT"),
393+
"b": exp.DataType.build("STRING"),
394+
},
395+
materialized=True,
396+
column_descriptions={
397+
"a": "column a description",
398+
"b": "column b description",
399+
},
400+
)
401+
402+
sql_calls = to_sql_calls(adapter)
403+
# Databricks requires column types when column comments are present in materialized views
404+
assert sql_calls == [
405+
"CREATE OR REPLACE MATERIALIZED VIEW `test_view` (`a` INT COMMENT 'column a description', `b` STRING COMMENT 'column b description') AS SELECT `a`, `b` FROM `source_table`",
406+
]
407+
408+
379409
def test_create_table_clustered_by(mocker: MockFixture, make_mocked_engine_adapter: t.Callable):
380410
mocker.patch(
381411
"sqlmesh.core.engine_adapter.databricks.DatabricksEngineAdapter.set_current_catalog"

0 commit comments

Comments
 (0)