-
Notifications
You must be signed in to change notification settings - Fork 125
/
Copy pathquery.py
25 lines (18 loc) · 963 Bytes
/
query.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import pkg_resources
from google.cloud import bigquery
# Version with query config breaking change.
BIGQUERY_CONFIG_VERSION = pkg_resources.parse_version('0.32.0.dev1')
def query_config_old_version(resource):
# Verify that we got a query resource. In newer versions of
# google-cloud-bigquery enough of the configuration is passed on to the
# backend that we can expect a backend validation error instead.
if len(resource) != 1:
raise ValueError("Only one job type must be specified, but "
"given {}".format(','.join(resource.keys())))
if 'query' not in resource:
raise ValueError("Only 'query' job type is supported")
return bigquery.QueryJobConfig.from_api_repr(resource['query'])
def query_config(resource, installed_version):
if installed_version < BIGQUERY_CONFIG_VERSION:
return query_config_old_version(resource)
return bigquery.QueryJobConfig.from_api_repr(resource)