Skip to content

Commit

Permalink
manual backport/modifcation of #520 to mergable to 1.1.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 4fde16a commit bb247f4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 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"
32 changes: 19 additions & 13 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 @@ -232,16 +238,16 @@ def get_columns_in_relation(self, relation: Relation) -> List[SparkColumn]:
# use get_columns_in_relation spark macro
# which would execute 'describe extended tablename' query
try:
rows: List[agate.Row] = super().get_columns_in_relation(relation)
rows: List[agate.Row] = self.execute_macro(
GET_COLUMNS_IN_RELATION_RAW_MACRO_NAME, kwargs={"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", "")
if (
"Table or view not found" in errmsg or
"NoSuchTableException" in errmsg
):
found_msgs = (msg in errmsg for msg in TABLE_OR_VIEW_NOT_FOUND_MESSAGES)
if any(found_msgs):
pass
else:
raise e
Expand Down

0 comments on commit bb247f4

Please sign in to comment.