Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid describe extended on hive_metastore #446

Merged
merged 3 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()