Skip to content
Open
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
5 changes: 1 addition & 4 deletions dbt/adapters/databricks/events/credential_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,5 @@ def __init__(self, exception: Exception):


class CredentialShardEvent:
def __init__(self, password_len: int):
self.password_len = password_len

def __str__(self) -> str:
return f"Password is {self.password_len} characters, sharding it"
return "Sharding credentials"
4 changes: 3 additions & 1 deletion dbt/adapters/databricks/relation_configs/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class QueryProcessor(DatabricksComponentProcessor[QueryConfig]):
@classmethod
def from_relation_results(cls, result: RelationResults) -> QueryConfig:
view_definition = result["information_schema.views"]["view_definition"].strip()
if view_definition[0] == "(" and view_definition[-1] == ")":
if view_definition.startswith("(") and view_definition.endswith(")"):
view_definition = view_definition[1:-1]
return QueryConfig(query=SqlUtils.clean_sql(view_definition))

Expand All @@ -49,4 +49,6 @@ class DescribeQueryProcessor(QueryProcessor):
def from_relation_results(cls, result: RelationResults) -> QueryConfig:
table = result["describe_extended"]
row = next(x for x in table if x[0] == "View Text")
if len(row) < 2:
raise DbtRuntimeError("Unexpected result from DESCRIBE EXTENDED: missing View Text value")
return QueryConfig(query=SqlUtils.clean_sql(row[1]))
23 changes: 22 additions & 1 deletion tests/unit/relation_configs/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
from agate import Row
from dbt.exceptions import DbtRuntimeError

from dbt.adapters.databricks.relation_configs.query import QueryConfig, QueryProcessor
from dbt.adapters.databricks.relation_configs.query import (
DescribeQueryProcessor,
QueryConfig,
QueryProcessor,
)

sql = "select * from foo"

Expand All @@ -31,6 +35,13 @@ def test_from_model_node__without_query(self):
):
_ = QueryProcessor.from_relation_config(model)

def test_from_relation_results__empty_view_definition(self):
results = {
"information_schema.views": Row(["", "other"], ["view_definition", "comment"])
}
spec = QueryProcessor.from_relation_results(results)
assert spec == QueryConfig(query="")

def test_get_diff__similar_query(self):
model = QueryConfig(query="select * from foo")
results = {
Expand All @@ -50,3 +61,13 @@ def test_get_diff__different_query(self):
}
other = QueryProcessor.from_relation_results(results)
assert model.get_diff(other) is model


class TestDescribeQueryProcessor:
def test_from_relation_results__malformed_view_text_row(self):
results = {"describe_extended": [("View Text",)]}
with pytest.raises(
DbtRuntimeError,
match="Unexpected result from DESCRIBE EXTENDED: missing View Text value",
):
DescribeQueryProcessor.from_relation_results(results)
Loading