Permalink
Browse files

TreasureData: improve error handling and upgrade client.

  • Loading branch information...
arikfr committed May 15, 2017
1 parent 931c322 commit 4a0612328ea90f9ad571274e3abf685221103c04
Showing with 14 additions and 18 deletions.
  1. +13 −17 redash/query_runner/treasuredata.py
  2. +1 −1 requirements_all_ds.txt
@@ -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:
@@ -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
View
@@ -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

0 comments on commit 4a06123

Please sign in to comment.