Navigation Menu

Skip to content

Commit

Permalink
TreasureData: improve error handling and upgrade client.
Browse files Browse the repository at this point in the history
  • Loading branch information
arikfr committed May 15, 2017
1 parent 931c322 commit 4a06123
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
30 changes: 13 additions & 17 deletions redash/query_runner/treasuredata.py
@@ -1,9 +1,9 @@
import json
import logging

from redash.utils import JSONEncoder
from redash.query_runner import *
from redash.utils import JSONEncoder

import logging
logger = logging.getLogger(__name__)

try:
Expand Down Expand Up @@ -103,21 +103,17 @@ def run_query(self, query, user):

cursor = connection.cursor()

try:
cursor.execute(query)
columns_data = [(row[0], cursor.show_job()['hive_result_schema'][i][1]) for i,row in enumerate(cursor.description)]

columns = [{'name': col[0],
'friendly_name': col[0],
'type': TD_TYPES_MAPPING.get(col[1], None)} for col in columns_data]

rows = [dict(zip(([c[0] for c in columns_data]), r)) for i, r in enumerate(cursor.fetchall())]
data = {'columns': columns, 'rows': rows}
json_data = json.dumps(data, cls=JSONEncoder)
error = None
except Exception, ex:
json_data = None
error = ex.message
cursor.execute(query)
columns_data = [(row[0], cursor.show_job()['hive_result_schema'][i][1]) for i,row in enumerate(cursor.description)]

columns = [{'name': col[0],
'friendly_name': col[0],
'type': TD_TYPES_MAPPING.get(col[1], None)} for col in columns_data]

rows = [dict(zip(([c[0] for c in columns_data]), r)) for i, r in enumerate(cursor.fetchall())]
data = {'columns': columns, 'rows': rows}
json_data = json.dumps(data, cls=JSONEncoder)
error = None

return json_data, error

Expand Down
2 changes: 1 addition & 1 deletion requirements_all_ds.txt
Expand Up @@ -8,7 +8,7 @@ pyhive==0.3.0
pymongo==3.2.1
pyOpenSSL==0.14
vertica-python==0.5.1
td-client==0.4.1
td-client==0.8.0
pymssql==2.1.3
dql==0.5.16
dynamo3==0.4.7
Expand Down

0 comments on commit 4a06123

Please sign in to comment.