superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [incubator-superset] branch master updated: [sql lab] extract Hive error messages (#5495)
Date Thu, 26 Jul 2018 22:18:01 GMT
This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 41286b7  [sql lab] extract Hive error messages (#5495)
41286b7 is described below

commit 41286b7545f8fc6a4a8c9782b169afd62a73e9c1
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Thu Jul 26 15:17:55 2018 -0700

    [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
---
 superset/db_engine_specs.py   |  8 ++++----
 tests/db_engine_specs_test.py | 19 +++++++++++++++++++
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py
index cc1345e..5e5a304 100644
--- a/superset/db_engine_specs.py
+++ b/superset/db_engine_specs.py
@@ -1051,10 +1051,10 @@ class HiveEngineSpec(PrestoEngineSpec):
 
     @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 c85e23a..287114c 100644
--- a/tests/db_engine_specs_test.py
+++ b/tests/db_engine_specs_test.py
@@ -4,6 +4,8 @@ from __future__ import division
 from __future__ import print_function
 from __future__ import unicode_literals
 
+from six import text_type
+
 from superset.db_engine_specs import (
     BaseEngineSpec, HiveEngineSpec, MssqlEngineSpec,
     MySQLEngineSpec, PrestoEngineSpec,
@@ -84,6 +86,23 @@ class DbEngineSpecsTestCase(SupersetTestCase):
         """.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')
 


Mime
View raw message