|
8 | 8 |
|
9 | 9 | try: |
10 | 10 | import tdclient |
| 11 | + from tdclient import errors |
11 | 12 | enabled = True |
12 | 13 |
|
13 | 14 | except ImportError: |
@@ -102,22 +103,24 @@ def run_query(self, query, user): |
102 | 103 | db=self.configuration.get('db')) |
103 | 104 |
|
104 | 105 | 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') |
121 | 124 | return json_data, error |
122 | 125 |
|
123 | 126 | register(TreasureData) |
0 commit comments