Skip to content

Commit

Permalink
manual backport/modifcation of #520 to mergable to 1.0.latest
Browse files Browse the repository at this point in the history
  • Loading branch information
ueshin authored and McKnight-42 committed Nov 29, 2022
1 parent 52dacf9 commit e91e70d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Fixes-20221116-234601.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Fixes
body: Support new error messages in the future Spark.
time: 2022-11-16T23:46:01.899921861Z
custom:
Author: ueshin
Issue: "515"
PR: "520"
36 changes: 26 additions & 10 deletions dbt/adapters/spark/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@

logger = AdapterLogger("Spark")

GET_COLUMNS_IN_RELATION_MACRO_NAME = 'get_columns_in_relation'
LIST_SCHEMAS_MACRO_NAME = 'list_schemas'
LIST_RELATIONS_MACRO_NAME = 'list_relations_without_caching'
DROP_RELATION_MACRO_NAME = 'drop_relation'
FETCH_TBL_PROPERTIES_MACRO_NAME = 'fetch_tbl_properties'

KEY_TABLE_OWNER = 'Owner'
KEY_TABLE_STATISTICS = 'Statistics'
GET_COLUMNS_IN_RELATION_MACRO_NAME = "get_columns_in_relation"
LIST_SCHEMAS_MACRO_NAME = "list_schemas"
LIST_RELATIONS_MACRO_NAME = "list_relations_without_caching"
DROP_RELATION_MACRO_NAME = "drop_relation"
FETCH_TBL_PROPERTIES_MACRO_NAME = "fetch_tbl_properties"

KEY_TABLE_OWNER = "Owner"
KEY_TABLE_STATISTICS = "Statistics"

TABLE_OR_VIEW_NOT_FOUND_MESSAGES = (
"[TABLE_OR_VIEW_NOT_FOUND]",
"Table or view not found",
"NoSuchTableException",
)


@dataclass
Expand Down Expand Up @@ -231,8 +237,18 @@ def get_columns_in_relation(self, relation: Relation) -> List[SparkColumn]:
# return relation's schema. if columns are empty from cache,
# use get_columns_in_relation spark macro
# which would execute 'describe extended tablename' query
rows: List[agate.Row] = super().get_columns_in_relation(relation)
columns = self.parse_describe_extended(relation, rows)
try:
rows: List[agate.Row] = super().get_columns_in_relation(relation)
columns = self.parse_describe_extended(relation, rows)
except dbt.exceptions.RuntimeException as e:
# spark would throw error when table doesn't exist, where other
# CDW would just return and empty list, normalizing the behavior here
errmsg = getattr(e, "msg", "")
found_msgs = (msg in errmsg for msg in TABLE_OR_VIEW_NOT_FOUND_MESSAGES)
if any(found_msgs):
pass
else:
raise e

# strip hudi metadata columns.
columns = [x for x in columns
Expand Down

0 comments on commit e91e70d

Please sign in to comment.