From 10e1e40e582339879cfd8b75be92f726b56af062 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Thu, 26 Jul 2018 15:17:55 -0700 Subject: [PATCH] [sql lab] extract Hive error messages (#5495) * [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 41286b7545f8fc6a4a8c9782b169afd62a73e9c1) (cherry picked from commit 214f5a94c3118e8b4f8bee7c53fe4e9ab6c96859) --- superset/db_engine_specs.py | 8 ++++---- tests/db_engine_specs_test.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py index 4181c49d67f5b..4a1401a706fdc 100644 --- a/superset/db_engine_specs.py +++ b/superset/db_engine_specs.py @@ -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 diff --git a/tests/db_engine_specs_test.py b/tests/db_engine_specs_test.py index 447914ed5f840..e1fc0c1564a37 100644 --- a/tests/db_engine_specs_test.py +++ b/tests/db_engine_specs_test.py @@ -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, @@ -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')