Skip to content

Commit a57a2b3

Browse files
Adding configuration properties for maximum billing tier and maximum bytes billed
1 parent 1137e6a commit a57a2b3

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

google/cloud/bigquery/job.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,8 @@ class _AsyncQueryConfiguration(object):
933933
_use_query_cache = None
934934
_use_legacy_sql = None
935935
_write_disposition = None
936+
_maximum_billing_tier = None
937+
_maximum_bytes_billed = None
936938

937939

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

1015+
maximum_billing_tier = _TypedProperty('maximum_billing_tier', int)
1016+
"""See:
1017+
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.query.maximumBillingTier
1018+
"""
1019+
1020+
maximum_bytes_billed = _TypedProperty('maximum_bytes_billed', int)
1021+
"""See:
1022+
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.query.maximumBytesBilled
1023+
"""
1024+
10131025
def _destination_table_resource(self):
10141026
"""Create a JSON resource for the destination table.
10151027
@@ -1047,6 +1059,10 @@ def _populate_config_resource(self, configuration):
10471059
configuration['useLegacySql'] = self.use_legacy_sql
10481060
if self.write_disposition is not None:
10491061
configuration['writeDisposition'] = self.write_disposition
1062+
if self.maximum_billing_tier is not None:
1063+
configuration['maximumBillingTier'] = self.maximum_billing_tier
1064+
if self.maximum_bytes_billed is not None:
1065+
configuration['maximumBytesBilled'] = self.maximum_bytes_billed
10501066
if len(self._udf_resources) > 0:
10511067
configuration[self._UDF_KEY] = _build_udf_resources(
10521068
self._udf_resources)

unit_tests/bigquery/test_job.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,11 +1324,24 @@ def _verifyBooleanResourceProperties(self, job, config):
13241324
else:
13251325
self.assertTrue(job.use_legacy_sql is None)
13261326

1327+
def _verifyIntegerResourceProperties(self, job, config):
1328+
if 'maximumBillingTier' in config:
1329+
self.assertEqual(job.maximum_billing_tier,
1330+
config['maximumBillingTier'])
1331+
else:
1332+
self.assertTrue(job.maximum_billing_tier is None)
1333+
if 'maximumBytesBilled' in config:
1334+
self.assertEqual(job.maximum_bytes_billed,
1335+
config['maximumBytesBilled'])
1336+
else:
1337+
self.assertTrue(job.maximum_bytes_billed is None)
1338+
13271339
def _verifyResourceProperties(self, job, resource):
13281340
self._verifyReadonlyResourceProperties(job, resource)
13291341

13301342
config = resource.get('configuration', {}).get('query')
13311343
self._verifyBooleanResourceProperties(job, config)
1344+
self._verifyIntegerResourceProperties(job, config)
13321345

13331346
if 'createDisposition' in config:
13341347
self.assertEqual(job.create_disposition,
@@ -1387,6 +1400,8 @@ def test_ctor(self):
13871400
self.assertTrue(job.use_query_cache is None)
13881401
self.assertTrue(job.use_legacy_sql is None)
13891402
self.assertTrue(job.write_disposition is None)
1403+
self.assertTrue(job.maximum_billing_tier is None)
1404+
self.assertTrue(job.maximum_bytes_billed is None)
13901405

13911406
def test_from_api_repr_missing_identity(self):
13921407
self._setUpConstants()
@@ -1498,6 +1513,8 @@ def test_begin_w_alternate_client(self):
14981513
'useQueryCache': True,
14991514
'useLegacySql': True,
15001515
'writeDisposition': 'WRITE_TRUNCATE',
1516+
'maximumBillingTier': 4,
1517+
'maximumBytesBilled': 123456
15011518
}
15021519
RESOURCE['configuration']['query'] = QUERY_CONFIGURATION
15031520
conn1 = _Connection()
@@ -1518,6 +1535,8 @@ def test_begin_w_alternate_client(self):
15181535
job.use_query_cache = True
15191536
job.use_legacy_sql = True
15201537
job.write_disposition = 'WRITE_TRUNCATE'
1538+
job.maximum_billing_tier = 4
1539+
job.maximum_bytes_billed = 123456
15211540

15221541
job.begin(client=client2)
15231542

0 commit comments

Comments
 (0)