Performs a query and returns an array of dicts.
(self,
query,
timeout=QUERY_TIMEOUT,
max_results=QUERY_MAX_RESULTS,
offset=0,
limit=None)
| 237 | time.sleep(1) |
| 238 | |
| 239 | def query(self, |
| 240 | query, |
| 241 | timeout=QUERY_TIMEOUT, |
| 242 | max_results=QUERY_MAX_RESULTS, |
| 243 | offset=0, |
| 244 | limit=None): |
| 245 | """Performs a query and returns an array of dicts.""" |
| 246 | rows = [] |
| 247 | start_time = time.time() |
| 248 | |
| 249 | result = self.raw_query(query, max_results=0) |
| 250 | |
| 251 | result = self.wait_for_completion( |
| 252 | job_id=result['jobReference']['jobId'], |
| 253 | offset=offset, |
| 254 | max_results=_get_max_results(max_results, limit, 0), |
| 255 | start_time=start_time, |
| 256 | timeout=timeout) |
| 257 | |
| 258 | # totalRows is only present after the job completed successfully. |
| 259 | total_count = int(result['totalRows']) |
| 260 | |
| 261 | while limit is None or len(rows) < limit: |
| 262 | rows += convert(result) |
| 263 | |
| 264 | if result['jobComplete'] and 'pageToken' not in result: |
| 265 | total_count = int(result['totalRows']) |
| 266 | break |
| 267 | |
| 268 | result = self.get_query_results( |
| 269 | job_id=result['jobReference']['jobId'], |
| 270 | page_token=result.get('pageToken'), |
| 271 | start_index=0, |
| 272 | max_results=_get_max_results(max_results, limit, len(rows))) |
| 273 | |
| 274 | return QueryResult(rows=rows, total_count=total_count) |
| 275 | |
| 276 | @retry.wrap( |
| 277 | retries=QUERY_RETRY_COUNT, |