Database Reference
In-Depth Information
u'rows': [{u'f': [{u'v': u'17'}]}],
u'totalRows': u'1'}
Using Jobs.insert() you got the same result: “17,” but with two more
API calls. You might also notice that the results of Jobs.query()
contained the schema of the result table but the TableData.list()
response did not. Sometimes you might already know the resulting schema.
If you wrote the query yourself, you may know exactly what the schema
should look like. Most of the time, however, you likely won't know the result
schema in advance. To get the table schema requires another API call, this
time to the Tables.get() API.
>>> schema =
service.tables().get(**table_ref).execute()['schema']
>>> pprint.pprint(schema)
{u'fields': [{u'mode': u'NULLABLE', u'name': u'f0_',
u'type': u'INTEGER'}]}
Jobs.query() RPC
As previously mentioned, Jobs.query() is the simpler query API. It lacks
some of the configuration options controlling how to run your query that
Jobs.insert() has but is usually the easiest way to run a query and get
the results.
Running Jobs.query() is equivalent to calling Jobs.insert() to start
the job, Jobs.get() to poll for job completion, and TableData.list()
to get the first page of results. Query results get stored in a temporary table
that lives for 24 hours. If you need your query results to stick around longer,
you can copy them to a permanent table with a copy job, or you can use the
more fully featured Jobs.insert() method to run your query and specify
a destination table.
The most important parameter (other than the query string, of course)
is timeoutMs , which controls how long the query request waits before
returning. The default timeout is 10 seconds; it is set so short because
many contexts where you may be issuing the query (such as AppEngine)
automatically cancel any HTTP request that takes too long. The maximum
timeoutMs is 200 seconds; you can set it to something larger, but BigQuery
treats it as if you set it to the maximum value.
Search WWH ::




Custom Search