Skip to content

Commit

Permalink
[sql lab] extract Hive error messages (#5495)
Browse files Browse the repository at this point in the history
* [sql lab] extract Hive error messages

So pyhive returns an exception object with a stringified thrift error
object. This PR uses a regex to extract the errorMessage portion of that
string.

* Unit test

(cherry picked from commit 41286b7)
  • Loading branch information
mistercrunch committed Aug 12, 2018
1 parent d7485db commit ae26b36
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 4 additions & 4 deletions superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,10 +1071,10 @@ def adjust_database_uri(cls, uri, selected_schema=None):

@classmethod
def extract_error_message(cls, e):
try:
msg = e.message.status.errorMessage
except Exception:
msg = str(e)
msg = str(e)
match = re.search('errorMessage="(.*)", ', msg)
if match:
msg = match.group(1)
return msg

@classmethod
Expand Down
18 changes: 18 additions & 0 deletions tests/db_engine_specs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import unicode_literals

import textwrap
from six import text_type

from superset.db_engine_specs import (
BaseEngineSpec, HiveEngineSpec, MssqlEngineSpec,
Expand Down Expand Up @@ -86,6 +87,23 @@ def test_job_2_launched_stage_2_stages_progress(self):
""".split('\n') # noqa ignore: E501
self.assertEquals(60, HiveEngineSpec.progress(log))

def test_hive_error_msg(self):
msg = (
'{...} errorMessage="Error while compiling statement: FAILED: '
'SemanticException [Error 10001]: Line 4'
':5 Table not found \'fact_ridesfdslakj\'", statusCode=3, '
'sqlState=\'42S02\', errorCode=10001)){...}')
self.assertEquals((
'Error while compiling statement: FAILED: '
'SemanticException [Error 10001]: Line 4:5 '
"Table not found 'fact_ridesfdslakj'"),
HiveEngineSpec.extract_error_message(Exception(msg)))

e = Exception("Some string that doesn't match the regex")
self.assertEquals(
text_type(e),
HiveEngineSpec.extract_error_message(e))

def get_generic_database(self):
return Database(sqlalchemy_uri='mysql://localhost')

Expand Down

0 comments on commit ae26b36

Please sign in to comment.