Database Reference
In-Depth Information
if query_complete:
fields = response.get('schema',
{}).get('fields', [])
rows = response.get('rows', [])
response_handler(fields, rows)
if page_token is None:
# The query is done and there are no more
results
# to read.
break
response = self.service.jobs().getQueryResults(
projectId = self.project_id,
jobId = job_ref['jobId'],
timeoutMs = timeout_ms,
pageToken = page_token,
maxResults = max_results).execute()
def main(argv):
if len(argv) == 0:
print 'Usage: query.py <project_id> [query]'
return
service = auth.build_bq_client()
project_id = argv[0]
query = QueryRpc(service, project_id)
if len(argv) < 2:
query_text = 'SELECT 17'
else:
# The entire rest of the command line is the query.
query_text = ' '.join(argv[1:])
query.run(query_text)
if __name__ == "__main__":
main(sys.argv[1:])
Querying via Jobs.insert()
As previously mentioned, Jobs.insert() is the most flexible way to run a
query job. To indicate that the job is a query, you need to fill out the query
subsection of the job configuration. When using Jobs.insert() , you can
run your query at a lower priority, abort the query if the result isn't already
cached, append results to a destination table, or specify your own job ID.
Search WWH ::




Custom Search