Skip to content

Commit 3f3cc73

Browse files
committed
Strip boilerplate: use custom properties from PR #1075.
1 parent 2a9ad94 commit 3f3cc73

File tree

2 files changed

+32
-337
lines changed

2 files changed

+32
-337
lines changed

gcloud/bigquery/job.py

Lines changed: 32 additions & 221 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,6 @@ def cancel(self, client=None):
395395
self._set_properties(api_response)
396396

397397

398-
399-
400398
class _LoadConfiguration(object):
401399
"""User-settable configuration options for load jobs."""
402400
# None -> use server default.
@@ -817,232 +815,45 @@ def __init__(self, name, query, client):
817815
self.query = query
818816
self._configuration = _QueryConfiguration()
819817

820-
@property
821-
def allow_large_results(self):
822-
"""Allow query to return arbitraily large result sets.
823-
824-
See:
825-
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.query.allowLargeResults
826-
827-
:rtype: boolean, or ``NoneType``
828-
:returns: The value as set by the user, or None (the default).
829-
"""
830-
return self._configuration._allow_large_results
831-
832-
@allow_large_results.setter
833-
def allow_large_results(self, value):
834-
"""Update allow_large_results.
835-
836-
:type value: boolean
837-
:param value: new allow_large_results
838-
839-
:raises: ValueError for invalid value types.
840-
"""
841-
if not isinstance(value, bool):
842-
raise ValueError("Pass a boolean")
843-
self._configuration._allow_large_results = value
844-
845-
@allow_large_results.deleter
846-
def allow_large_results(self):
847-
"""Delete allow_large_results."""
848-
del self._configuration._allow_large_results
849-
850-
@property
851-
def create_disposition(self):
852-
"""Handling for missing destination table.
853-
854-
See:
855-
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.copy.createDisposition
856-
857-
:rtype: string, or ``NoneType``
858-
:returns: The value as set by the user, or None (the default).
859-
"""
860-
return self._configuration._create_disposition
861-
862-
@create_disposition.setter
863-
def create_disposition(self, value):
864-
"""Update create_disposition.
865-
866-
:type value: string
867-
:param value: allowed values for :class:`CreateDisposition`
868-
"""
869-
CreateDisposition.validate(value) # raises ValueError if invalid
870-
self._configuration._create_disposition = value
871-
872-
@create_disposition.deleter
873-
def create_disposition(self):
874-
"""Delete create_disposition."""
875-
del self._configuration._create_disposition
876-
877-
@property
878-
def default_dataset(self):
879-
"""Default dataset for unprefixed table names in query.
880-
881-
See:
882-
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.query.defaultDataset
883-
884-
:rtype: :class:`gcloud.bigquery.dataset.Dataset`
885-
:returns: The value as set by the user, or None (the default).
886-
"""
887-
return self._configuration._default_dataset
888-
889-
@default_dataset.setter
890-
def default_dataset(self, value):
891-
"""Update default_dataset.
892-
893-
:type value: :class:`gcloud.bigquery.dataset.Dataset`
894-
:param value: new default dataset.
895-
"""
896-
if not isinstance(value, Dataset):
897-
raise ValueError('Pass a Dataset instance')
898-
self._configuration._default_dataset = value
899-
900-
@default_dataset.deleter
901-
def default_dataset(self):
902-
"""Delete default_dataset."""
903-
del self._configuration._default_dataset
904-
905-
@property
906-
def destination_table(self):
907-
"""Table into which query results are writen.
908-
909-
See:
910-
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.query.destinationTable
911-
912-
:rtype: :class:`gcloud.bigquery.table.Table`
913-
:returns: The value as set by the user, or None (the default).
914-
"""
915-
return self._configuration._destination_table
916-
917-
@destination_table.setter
918-
def destination_table(self, value):
919-
"""Update destination_table.
920-
921-
:type value: :class:`gcloud.bigquery.table.Table`
922-
:param value: new default dataset.
923-
"""
924-
if not isinstance(value, Table):
925-
raise ValueError('Pass a Table instance')
926-
self._configuration._destination_table = value
927-
928-
@destination_table.deleter
929-
def destination_table(self):
930-
"""Delete destination_table."""
931-
del self._configuration._destination_table
932-
933-
@property
934-
def flatten_results(self):
935-
"""Flatten nested/repeated fields in results.
936-
937-
See:
938-
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.query.flattenResults
939-
940-
:rtype: boolean, or ``NoneType``
941-
:returns: The value as set by the user, or None (the default).
942-
"""
943-
return self._configuration._flatten_results
944-
945-
@flatten_results.setter
946-
def flatten_results(self, value):
947-
"""Update flatten_results.
948-
949-
:type value: boolean
950-
:param value: new flatten_results
951-
952-
:raises: ValueError for invalid value types.
953-
"""
954-
if not isinstance(value, bool):
955-
raise ValueError("Pass a boolean")
956-
self._configuration._flatten_results = value
957-
958-
@flatten_results.deleter
959-
def flatten_results(self):
960-
"""Delete flatten_results."""
961-
del self._configuration._flatten_results
962-
963-
@property
964-
def priority(self):
965-
"""Handling for missing destination table.
966-
967-
See:
968-
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.copy.createDisposition
969-
970-
:rtype: string, or ``NoneType``
971-
:returns: The value as set by the user, or None (the default).
972-
"""
973-
return self._configuration._priority
974-
975-
@priority.setter
976-
def priority(self, value):
977-
"""Update priority.
978-
979-
:type value: string
980-
:param value: allowed values for :class:`QueryPriority`
981-
"""
982-
QueryPriority.validate(value) # raises ValueError if invalid
983-
self._configuration._priority = value
984-
985-
@priority.deleter
986-
def priority(self):
987-
"""Delete priority."""
988-
del self._configuration._priority
989-
990-
@property
991-
def use_query_cache(self):
992-
"""Set whether the query will be loaded from cache, if available.
993-
994-
See:
995-
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.query.useQueryCache
996-
997-
:rtype: boolean, or ``NoneType``
998-
:returns: The value as set by the user, or None (the default).
999-
"""
1000-
return self._configuration._use_query_cache
1001-
1002-
@use_query_cache.setter
1003-
def use_query_cache(self, value):
1004-
"""Update use_query_cache.
1005-
1006-
:type value: boolean
1007-
:param value: new use_query_cache
1008-
1009-
:raises: ValueError for invalid value types.
1010-
"""
1011-
if not isinstance(value, bool):
1012-
raise ValueError("Pass a boolean")
1013-
self._configuration._use_query_cache = value
818+
allow_large_results = _TypedProperty('allow_large_results', bool)
819+
"""See:
820+
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.query.allowLargeResults
821+
"""
1014822

1015-
@use_query_cache.deleter
1016-
def use_query_cache(self):
1017-
"""Delete use_query_cache."""
1018-
del self._configuration._use_query_cache
823+
create_disposition = CreateDisposition('create_disposition')
824+
"""See:
825+
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.query.createDisposition
826+
"""
1019827

1020-
@property
1021-
def write_disposition(self):
1022-
"""Allow rows with missing trailing commas for optional fields.
828+
default_dataset = _TypedProperty('default_dataset', Dataset)
829+
"""See:
830+
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.query.default_dataset
831+
"""
1023832

1024-
See:
1025-
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.copy.writeDisposition
833+
destination_table = _TypedProperty('destination_table', Table)
834+
"""See:
835+
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.query.destinationTable
836+
"""
1026837

1027-
:rtype: string, or ``NoneType``
1028-
:returns: The value as set by the user, or None (the default).
1029-
"""
1030-
return self._configuration._write_disposition
838+
flatten_results = _TypedProperty('flatten_results', bool)
839+
"""See:
840+
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.query.flattenResults
841+
"""
1031842

1032-
@write_disposition.setter
1033-
def write_disposition(self, value):
1034-
"""Update write_disposition.
843+
priority = QueryPriority('priority')
844+
"""See:
845+
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.query.priority
846+
"""
1035847

1036-
:type value: string
1037-
:param value: allowed values for :class:`WriteDisposition`.
1038-
"""
1039-
WriteDisposition.validate(value) # raises ValueError if invalid
1040-
self._configuration._write_disposition = value
848+
use_query_cache = _TypedProperty('use_query_cache', bool)
849+
"""See:
850+
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.query.useQueryCache
851+
"""
1041852

1042-
@write_disposition.deleter
1043-
def write_disposition(self):
1044-
"""Delete write_disposition."""
1045-
del self._configuration._write_disposition
853+
write_disposition = WriteDisposition('write_disposition')
854+
"""See:
855+
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.query.writeDisposition
856+
"""
1046857

1047858
def _destination_table_resource(self):
1048859
if self.destination_table is not None:

gcloud/bigquery/test_job.py

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,122 +1175,6 @@ def test_ctor(self):
11751175
self.assertTrue(job.use_query_cache is None)
11761176
self.assertTrue(job.write_disposition is None)
11771177

1178-
def test_allow_large_results_setter_bad_value(self):
1179-
client = _Client(self.PROJECT)
1180-
job = self._makeOne(self.JOB_NAME, self.QUERY, client)
1181-
with self.assertRaises(ValueError):
1182-
job.allow_large_results = object()
1183-
1184-
def test_allow_large_results_setter_deleter(self):
1185-
client = _Client(self.PROJECT)
1186-
job = self._makeOne(self.JOB_NAME, self.QUERY, client)
1187-
job.allow_large_results = True
1188-
self.assertTrue(job.allow_large_results)
1189-
del job.allow_large_results
1190-
self.assertTrue(job.allow_large_results is None)
1191-
1192-
def test_create_disposition_setter_bad_value(self):
1193-
client = _Client(self.PROJECT)
1194-
job = self._makeOne(self.JOB_NAME, self.QUERY, client)
1195-
with self.assertRaises(ValueError):
1196-
job.create_disposition = 'BOGUS'
1197-
1198-
def test_create_disposition_setter_deleter(self):
1199-
client = _Client(self.PROJECT)
1200-
job = self._makeOne(self.JOB_NAME, self.QUERY, client)
1201-
job.create_disposition = 'CREATE_IF_NEEDED'
1202-
self.assertEqual(job.create_disposition, 'CREATE_IF_NEEDED')
1203-
del job.create_disposition
1204-
self.assertTrue(job.create_disposition is None)
1205-
1206-
def test_default_dataset_setter_bad_value(self):
1207-
client = _Client(self.PROJECT)
1208-
job = self._makeOne(self.JOB_NAME, self.QUERY, client)
1209-
with self.assertRaises(ValueError):
1210-
job.default_dataset = object()
1211-
1212-
def test_default_dataset_setter_deleter(self):
1213-
from gcloud.bigquery.dataset import Dataset
1214-
client = _Client(self.PROJECT)
1215-
dataset = Dataset('DATASET', client)
1216-
job = self._makeOne(self.JOB_NAME, self.QUERY, client)
1217-
job.default_dataset = dataset
1218-
self.assertTrue(job.default_dataset is dataset)
1219-
del job.default_dataset
1220-
self.assertTrue(job.default_dataset is None)
1221-
1222-
def test_destination_table_setter_bad_value(self):
1223-
client = _Client(self.PROJECT)
1224-
job = self._makeOne(self.JOB_NAME, self.QUERY, client)
1225-
with self.assertRaises(ValueError):
1226-
job.destination_table = object()
1227-
1228-
def test_destination_table_setter_deleter(self):
1229-
from gcloud.bigquery.dataset import Table
1230-
client = _Client(self.PROJECT)
1231-
table = Table('TABLE', object())
1232-
job = self._makeOne(self.JOB_NAME, self.QUERY, client)
1233-
job.destination_table = table
1234-
self.assertTrue(job.destination_table is table)
1235-
del job.destination_table
1236-
self.assertTrue(job.destination_table is None)
1237-
1238-
def test_flatten_results_setter_bad_value(self):
1239-
client = _Client(self.PROJECT)
1240-
job = self._makeOne(self.JOB_NAME, self.QUERY, client)
1241-
with self.assertRaises(ValueError):
1242-
job.flatten_results = object()
1243-
1244-
def test_flatten_results_setter_deleter(self):
1245-
client = _Client(self.PROJECT)
1246-
job = self._makeOne(self.JOB_NAME, self.QUERY, client)
1247-
job.flatten_results = True
1248-
self.assertTrue(job.flatten_results)
1249-
del job.flatten_results
1250-
self.assertTrue(job.flatten_results is None)
1251-
1252-
def test_priority_setter_bad_value(self):
1253-
client = _Client(self.PROJECT)
1254-
job = self._makeOne(self.JOB_NAME, self.QUERY, client)
1255-
with self.assertRaises(ValueError):
1256-
job.priority = 'BOGUS'
1257-
1258-
def test_priority_setter_deleter(self):
1259-
client = _Client(self.PROJECT)
1260-
job = self._makeOne(self.JOB_NAME, self.QUERY, client)
1261-
job.priority = 'INTERACTIVE'
1262-
self.assertEqual(job.priority, 'INTERACTIVE')
1263-
del job.priority
1264-
self.assertTrue(job.priority is None)
1265-
1266-
def test_use_query_cache_setter_bad_value(self):
1267-
client = _Client(self.PROJECT)
1268-
job = self._makeOne(self.JOB_NAME, self.QUERY, client)
1269-
with self.assertRaises(ValueError):
1270-
job.use_query_cache = object()
1271-
1272-
def test_use_query_cache_setter_deleter(self):
1273-
client = _Client(self.PROJECT)
1274-
job = self._makeOne(self.JOB_NAME, self.QUERY, client)
1275-
job.use_query_cache = True
1276-
self.assertTrue(job.use_query_cache)
1277-
del job.use_query_cache
1278-
self.assertTrue(job.use_query_cache is None)
1279-
1280-
def test_write_disposition_setter_bad_value(self):
1281-
client = _Client(self.PROJECT)
1282-
job = self._makeOne(self.JOB_NAME, self.QUERY, client)
1283-
with self.assertRaises(ValueError):
1284-
job.write_disposition = 'BOGUS'
1285-
1286-
def test_write_disposition_setter_deleter(self):
1287-
client = _Client(self.PROJECT)
1288-
job = self._makeOne(self.JOB_NAME, self.QUERY, client)
1289-
job.write_disposition = 'WRITE_TRUNCATE'
1290-
self.assertEqual(job.write_disposition, 'WRITE_TRUNCATE')
1291-
del job.write_disposition
1292-
self.assertTrue(job.write_disposition is None)
1293-
12941178
def test_begin_w_bound_client(self):
12951179
PATH = 'projects/%s/jobs' % self.PROJECT
12961180
RESOURCE = self._makeResource()

0 commit comments

Comments
 (0)