Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bigquery: Adding configuration properties for maximumBillingTier and maximumBytesBilled for QueryJobs #2276

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions google/cloud/bigquery/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,8 @@ class _AsyncQueryConfiguration(object):
_use_query_cache = None
_use_legacy_sql = None
_write_disposition = None
_maximum_billing_tier = None
_maximum_bytes_billed = None


class QueryJob(_AsyncJob):
Expand Down Expand Up @@ -1010,6 +1012,16 @@ def __init__(self, name, query, client, udf_resources=()):
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.query.writeDisposition
"""

maximum_billing_tier = _TypedProperty('maximum_billing_tier', int)
"""See:
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.query.maximumBillingTier
"""

maximum_bytes_billed = _TypedProperty('maximum_bytes_billed', int)
"""See:
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.query.maximumBytesBilled
"""

def _destination_table_resource(self):
"""Create a JSON resource for the destination table.

Expand Down Expand Up @@ -1047,6 +1059,10 @@ def _populate_config_resource(self, configuration):
configuration['useLegacySql'] = self.use_legacy_sql
if self.write_disposition is not None:
configuration['writeDisposition'] = self.write_disposition
if self.maximum_billing_tier is not None:
configuration['maximumBillingTier'] = self.maximum_billing_tier
if self.maximum_bytes_billed is not None:
configuration['maximumBytesBilled'] = self.maximum_bytes_billed
if len(self._udf_resources) > 0:
configuration[self._UDF_KEY] = _build_udf_resources(
self._udf_resources)
Expand Down
19 changes: 19 additions & 0 deletions unit_tests/bigquery/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -1324,11 +1324,24 @@ def _verifyBooleanResourceProperties(self, job, config):
else:
self.assertTrue(job.use_legacy_sql is None)

def _verifyIntegerResourceProperties(self, job, config):
if 'maximumBillingTier' in config:
self.assertEqual(job.maximum_billing_tier,
config['maximumBillingTier'])
else:
self.assertTrue(job.maximum_billing_tier is None)
if 'maximumBytesBilled' in config:
self.assertEqual(job.maximum_bytes_billed,
config['maximumBytesBilled'])
else:
self.assertTrue(job.maximum_bytes_billed is None)

def _verifyResourceProperties(self, job, resource):
self._verifyReadonlyResourceProperties(job, resource)

config = resource.get('configuration', {}).get('query')
self._verifyBooleanResourceProperties(job, config)
self._verifyIntegerResourceProperties(job, config)

if 'createDisposition' in config:
self.assertEqual(job.create_disposition,
Expand Down Expand Up @@ -1387,6 +1400,8 @@ def test_ctor(self):
self.assertTrue(job.use_query_cache is None)
self.assertTrue(job.use_legacy_sql is None)
self.assertTrue(job.write_disposition is None)
self.assertTrue(job.maximum_billing_tier is None)
self.assertTrue(job.maximum_bytes_billed is None)

def test_from_api_repr_missing_identity(self):
self._setUpConstants()
Expand Down Expand Up @@ -1498,6 +1513,8 @@ def test_begin_w_alternate_client(self):
'useQueryCache': True,
'useLegacySql': True,
'writeDisposition': 'WRITE_TRUNCATE',
'maximumBillingTier': 4,
'maximumBytesBilled': 123456
}
RESOURCE['configuration']['query'] = QUERY_CONFIGURATION
conn1 = _Connection()
Expand All @@ -1518,6 +1535,8 @@ def test_begin_w_alternate_client(self):
job.use_query_cache = True
job.use_legacy_sql = True
job.write_disposition = 'WRITE_TRUNCATE'
job.maximum_billing_tier = 4
job.maximum_bytes_billed = 123456

job.begin(client=client2)

Expand Down