Skip to content

Commit 7465c74

Browse files
authored
Merge pull request #2428 from toru-takahashi/master
Improve a query failure message for Treasure Data Runner
2 parents a8a9110 + b1567f4 commit 7465c74

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

redash/query_runner/treasuredata.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
try:
1010
import tdclient
11+
from tdclient import errors
1112
enabled = True
1213

1314
except ImportError:
@@ -102,22 +103,24 @@ def run_query(self, query, user):
102103
db=self.configuration.get('db'))
103104

104105
cursor = connection.cursor()
105-
106-
cursor.execute(query)
107-
columns_data = [(row[0], cursor.show_job()['hive_result_schema'][i][1]) for i,row in enumerate(cursor.description)]
108-
109-
columns = [{'name': col[0],
110-
'friendly_name': col[0],
111-
'type': TD_TYPES_MAPPING.get(col[1], None)} for col in columns_data]
112-
113-
if cursor.rowcount == 0:
114-
rows = []
115-
else:
116-
rows = [dict(zip(([c[0] for c in columns_data]), r)) for i, r in enumerate(cursor.fetchall())]
117-
data = {'columns': columns, 'rows': rows}
118-
json_data = json.dumps(data, cls=JSONEncoder)
119-
error = None
120-
106+
try:
107+
cursor.execute(query)
108+
columns_data = [(row[0], cursor.show_job()['hive_result_schema'][i][1]) for i,row in enumerate(cursor.description)]
109+
110+
columns = [{'name': col[0],
111+
'friendly_name': col[0],
112+
'type': TD_TYPES_MAPPING.get(col[1], None)} for col in columns_data]
113+
114+
if cursor.rowcount == 0:
115+
rows = []
116+
else:
117+
rows = [dict(zip(([c[0] for c in columns_data]), r)) for i, r in enumerate(cursor.fetchall())]
118+
data = {'columns': columns, 'rows': rows}
119+
json_data = json.dumps(data, cls=JSONEncoder)
120+
error = None
121+
except errors.InternalError as e:
122+
json_data = None
123+
error = "%s: %s" % (e.message, cursor.show_job().get('debug', {}).get('stderr', 'No stderr message in the response')
121124
return json_data, error
122125

123126
register(TreasureData)

0 commit comments

Comments
 (0)