Skip to content

Commit

Permalink
Avoid describe extended on hive_metastore (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
benc-db authored Sep 12, 2023
2 parents e9809db + 32d3abc commit 74c3ac7
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Fixes

- Fixed an issue with AWS OAuth M2M flow ([#445](https://github.com/databricks/dbt-databricks/pull/445))
- Fixed an issue where every table in hive_metastore would get described ([#446](https://github.com/databricks/dbt-databricks/pull/446))

## dbt-databricks 1.6.3 (September 8, 2023)

Expand Down
2 changes: 2 additions & 0 deletions dbt/adapters/databricks/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ def typeFromNames(
if view_names[name]
else DatabricksRelationType.View
)
elif database is None or database == "hive_metastore":
return DatabricksRelationType.Table
else:
# not a view so it might be a streaming table
# get extended information to determine
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{ config(
materialized = 'table'
) }}

select cast(1 as bigint) as id, 'hello' as msg
union all
select cast(2 as bigint) as id, 'goodbye' as msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
id,msg
1,hello
2,goodbye
2,yo
3,anyway
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from tests.integration.base import DBTIntegrationTest, use_profile


class TestAvoidDescribeExtended(DBTIntegrationTest):
"""Tests in this class exist to ensure we don't call describe extended unnecessarily.
This became a problem due to needing to discern tables from streaming tables, which is not
relevant on hive, but users on hive were having all of their tables describe extended-ed.
We only need to call describe extended if we are using a UC catalog and we can't determine the
type of the materialization."""

@property
def schema(self):
return "schema"

@property
def models(self):
return "models"

def _test_avoid_describe_extended(self):
# Add some existing data to ensure we don't try to 'describe extended' it.
self.run_dbt(["seed"])
_, log_output = self.run_dbt_and_capture(["run"])
self.assertNotIn("describe extended", log_output)

@use_profile("databricks_cluster")
def test_avoid_describe_extended_databricks_cluster(self):
"""When UC is not enabled, we can assumed that all tables are regular tables"""
self._test_avoid_describe_extended()

@use_profile("databricks_uc_sql_endpoint")
def test_avoid_describe_extended_databricks_uc_sql_endpoint(self):
"""When UC is enabled, regular tables are marked as such"""
self._test_avoid_describe_extended()

0 comments on commit 74c3ac7

Please sign in to comment.