Skip to content

Commit a54884b

Browse files
Updated databricks adapter to use information_schema to get data-types for columns
Signed-off-by: Bjarke Enkelund <47357343+MisterWheatley@users.noreply.github.com>
1 parent 3be5bba commit a54884b

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

sqlmesh/core/engine_adapter/databricks.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,3 +411,27 @@ def _build_column_defs(
411411
return super()._build_column_defs(
412412
target_columns_to_types, column_descriptions, is_view, materialized
413413
)
414+
415+
def columns(
416+
self, table_name: TableName, include_pseudo_columns: bool = False
417+
) -> t.Dict[str, exp.DataType]:
418+
table = exp.to_table(table_name)
419+
query = (
420+
exp.select("columns.column_name", "columns.full_data_type")
421+
.from_("system.information_schema.columns")
422+
.where(
423+
exp.and_(
424+
exp.column("table_catalog").eq(table.catalog),
425+
exp.column("table_schema").eq(table.db),
426+
exp.column("table_name").eq(table.name),
427+
)
428+
)
429+
.order_by("ordinal_position ASC")
430+
)
431+
432+
result = self.cursor.fetchall(query)
433+
434+
return {
435+
row.column_name: exp.DataType.build(row.full_data_type, dialect=self.dialect)
436+
for row in result
437+
}

0 commit comments

Comments
 (0)