Skip to content

Commit

Permalink
Backport close cursor code to 1.7 (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
benc-db authored Jul 25, 2024
1 parent a59e537 commit 2399002
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## dbt-databricks 1.7.17 (July 25, 2024)

### Fixes

- Backport warning prevention from 1.9

## dbt-databricks 1.7.16 (May 21, 2024)

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion dbt/adapters/databricks/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version: str = "1.7.16"
version: str = "1.7.17"
5 changes: 5 additions & 0 deletions dbt/adapters/databricks/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class DatabricksColumn(SparkColumn):
def translate_type(cls, dtype: str) -> str:
return super(SparkColumn, cls).translate_type(dtype).lower()

@classmethod
def create(cls, name: str, label_or_dtype: str) -> "DatabricksColumn":
column_type = cls.translate_type(label_or_dtype)
return cls(name, column_type)

@property
def data_type(self) -> str:
return self.translate_type(self.dtype)
Expand Down
16 changes: 16 additions & 0 deletions dbt/adapters/databricks/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,22 @@ def _type_from_names(
else:
return DatabricksRelationType.Unknown

@available.parse(lambda *a, **k: [])
def get_column_schema_from_query(self, sql: str) -> List[DatabricksColumn]:
"""Get a list of the Columns with names and data types from the given sql."""
_, cursor = self.connections.add_select_query(sql)
try:
columns: List[DatabricksColumn] = [
self.Column.create(
column_name, self.connections.data_type_code_to_name(column_type_code)
)
# https://peps.python.org/pep-0249/#description
for column_name, column_type_code, *_ in cursor.description
]
finally:
cursor.close()
return columns

def get_relation(
self,
database: Optional[str],
Expand Down

0 comments on commit 2399002

Please sign in to comment.