|
19 | 19 | ) |
20 | 20 | from ..abcs import Compilable |
21 | 21 | from ..queries import this, table, SKIP, code |
22 | | -from .base import BaseDialect, Database, import_helper, parse_table_name, ConnectError, apply_query |
| 22 | +from .base import BaseDialect, Database, import_helper, parse_table_name, ConnectError, apply_query, QueryResult |
23 | 23 | from .base import TIMESTAMP_PRECISION_POS, ThreadLocalInterpreter, Mixin_RandomSample |
24 | 24 |
|
25 | 25 |
|
@@ -161,16 +161,18 @@ def _query_atom(self, sql_code: str): |
161 | 161 | from google.cloud import bigquery |
162 | 162 |
|
163 | 163 | try: |
164 | | - res = list(self._client.query(sql_code)) |
| 164 | + result = self._client.query(sql_code).result() |
| 165 | + columns = [c.name for c in result.schema] |
| 166 | + rows = list(result) |
165 | 167 | except Exception as e: |
166 | 168 | msg = "Exception when trying to execute SQL code:\n %s\n\nGot error: %s" |
167 | 169 | raise ConnectError(msg % (sql_code, e)) |
168 | 170 |
|
169 | | - if res and isinstance(res[0], bigquery.table.Row): |
170 | | - res = [tuple(self._normalize_returned_value(v) for v in row.values()) for row in res] |
171 | | - return res |
| 171 | + if rows and isinstance(rows[0], bigquery.table.Row): |
| 172 | + rows = [tuple(self._normalize_returned_value(v) for v in row.values()) for row in rows] |
| 173 | + return QueryResult(rows, columns) |
172 | 174 |
|
173 | | - def _query(self, sql_code: Union[str, ThreadLocalInterpreter]): |
| 175 | + def _query(self, sql_code: Union[str, ThreadLocalInterpreter]) -> QueryResult: |
174 | 176 | return apply_query(self._query_atom, sql_code) |
175 | 177 |
|
176 | 178 | def close(self): |
|
0 commit comments