mirror of
https://github.com/apache/superset.git
synced 2026-04-21 09:04:38 +00:00
chore(bigquery): Add extra logging for BigQuery exceptions so we can have better insight on exceptions (#22024)
This commit is contained in:
committed by
GitHub
parent
736b53418a
commit
95b4c7b7fe
@@ -430,6 +430,15 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
|||||||
"""
|
"""
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def parse_error_exception(cls, exception: Exception) -> Exception:
|
||||||
|
"""
|
||||||
|
Each engine can implement and converge its own specific parser method
|
||||||
|
|
||||||
|
:return: An Exception with a parsed string off the original exception
|
||||||
|
"""
|
||||||
|
return exception
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_dbapi_mapped_exception(cls, exception: Exception) -> Exception:
|
def get_dbapi_mapped_exception(cls, exception: Exception) -> Exception:
|
||||||
"""
|
"""
|
||||||
@@ -443,7 +452,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
|||||||
"""
|
"""
|
||||||
new_exception = cls.get_dbapi_exception_mapping().get(type(exception))
|
new_exception = cls.get_dbapi_exception_mapping().get(type(exception))
|
||||||
if not new_exception:
|
if not new_exception:
|
||||||
return exception
|
return cls.parse_error_exception(exception)
|
||||||
return new_exception(str(exception))
|
return new_exception(str(exception))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
@@ -578,3 +578,12 @@ class BigQueryEngineSpec(BaseEngineSpec):
|
|||||||
"author__name" and "author__email", respectively.
|
"author__name" and "author__email", respectively.
|
||||||
"""
|
"""
|
||||||
return [column(c["name"]).label(c["name"].replace(".", "__")) for c in cols]
|
return [column(c["name"]).label(c["name"].replace(".", "__")) for c in cols]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def parse_error_exception(cls, exception: Exception) -> Exception:
|
||||||
|
try:
|
||||||
|
return Exception(str(exception).splitlines()[0].rsplit(":")[1].strip())
|
||||||
|
except Exception: # pylint: disable=broad-except
|
||||||
|
# If for some reason we get an exception, for example, no new line
|
||||||
|
# We will return the original exception
|
||||||
|
return exception
|
||||||
|
|||||||
@@ -244,3 +244,44 @@ def test_mask_encrypted_extra_when_empty() -> None:
|
|||||||
from superset.db_engine_specs.bigquery import BigQueryEngineSpec
|
from superset.db_engine_specs.bigquery import BigQueryEngineSpec
|
||||||
|
|
||||||
assert BigQueryEngineSpec.mask_encrypted_extra(None) is None
|
assert BigQueryEngineSpec.mask_encrypted_extra(None) is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_error_message() -> None:
|
||||||
|
"""
|
||||||
|
Test that we parse a received message and just extract the useful information.
|
||||||
|
|
||||||
|
Example errors:
|
||||||
|
bigquery error: 400 Table \"case_detail_all_suites\" must be qualified with a dataset (e.g. dataset.table).
|
||||||
|
|
||||||
|
(job ID: ddf30b05-44e8-4fbf-aa29-40bfccaed886)
|
||||||
|
-----Query Job SQL Follows-----
|
||||||
|
| . | . | . |\n 1:select * from case_detail_all_suites\n 2:LIMIT 1001\n | . | . | . |
|
||||||
|
"""
|
||||||
|
from superset.db_engine_specs.bigquery import BigQueryEngineSpec
|
||||||
|
|
||||||
|
message = 'bigquery error: 400 Table "case_detail_all_suites" must be qualified with a dataset (e.g. dataset.table).\n\n(job ID: ddf30b05-44e8-4fbf-aa29-40bfccaed886)\n\n -----Query Job SQL Follows----- \n\n | . | . | . |\n 1:select * from case_detail_all_suites\n 2:LIMIT 1001\n | . | . | . |'
|
||||||
|
expected_result = '400 Table "case_detail_all_suites" must be qualified with a dataset (e.g. dataset.table).'
|
||||||
|
assert (
|
||||||
|
str(BigQueryEngineSpec.parse_error_exception(Exception(message)))
|
||||||
|
== expected_result
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_error_raises_exception() -> None:
|
||||||
|
"""
|
||||||
|
Test that we handle any exception we might get from calling the parse_error_exception method.
|
||||||
|
|
||||||
|
Example errors:
|
||||||
|
400 Syntax error: Expected "(" or keyword UNNEST but got "@" at [4:80]
|
||||||
|
bigquery error: 400 Table \"case_detail_all_suites\" must be qualified with a dataset (e.g. dataset.table).
|
||||||
|
"""
|
||||||
|
from superset.db_engine_specs.bigquery import BigQueryEngineSpec
|
||||||
|
|
||||||
|
message = 'bigquery error: 400 Table "case_detail_all_suites" must be qualified with a dataset (e.g. dataset.table).'
|
||||||
|
message_2 = "6"
|
||||||
|
expected_result = '400 Table "case_detail_all_suites" must be qualified with a dataset (e.g. dataset.table).'
|
||||||
|
assert (
|
||||||
|
str(BigQueryEngineSpec.parse_error_exception(Exception(message)))
|
||||||
|
== expected_result
|
||||||
|
)
|
||||||
|
assert str(BigQueryEngineSpec.parse_error_exception(Exception(message_2))) == "6"
|
||||||
|
|||||||
Reference in New Issue
Block a user