Skip to content

Commit 6e07b8d

Browse files
committed
Fix: Include column types in Databricks materialized views with comments
Databricks requires column types to be specified when adding column comments in CREATE MATERIALIZED VIEW statements. Without the column types, the comments are silently ignored. This change adds a Databricks-specific override of _build_column_defs that forces column types to be included when creating views with column descriptions.
1 parent a99bfaa commit 6e07b8d

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

sqlmesh/core/engine_adapter/databricks.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,3 +394,19 @@ def _build_table_properties_exp(
394394
expressions.append(clustered_by_exp)
395395
properties = exp.Properties(expressions=expressions)
396396
return properties
397+
398+
def _build_column_defs(
399+
self,
400+
target_columns_to_types: t.Dict[str, exp.DataType],
401+
column_descriptions: t.Optional[t.Dict[str, str]] = None,
402+
is_view: bool = False,
403+
) -> t.List[exp.ColumnDef]:
404+
# Databricks requires column types to be specified when adding column comments
405+
# in CREATE MATERIALIZED VIEW statements. Override is_view to False to force
406+
# column types to be included when comments are present.
407+
if is_view and column_descriptions:
408+
engine_supports_schema_comments = self.COMMENT_CREATION_VIEW.supports_schema_def
409+
if engine_supports_schema_comments and self.comments_enabled:
410+
is_view = False
411+
412+
return super()._build_column_defs(target_columns_to_types, column_descriptions, is_view)

0 commit comments

Comments
 (0)