Skip to content

Commit f192cb6

Browse files
alixhamitswast
authored andcommitted
BigQuery: removes LoadJob error for autodetect + schema (googleapis#4213)
1 parent 6dae47f commit f192cb6

File tree

3 files changed

+11
-35
lines changed

3 files changed

+11
-35
lines changed

bigquery/google/cloud/bigquery/job.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,6 @@ class AutoDetectSchema(_TypedApiResourceProperty):
143143
"""
144144
def __set__(self, instance, value):
145145
self._validate(value)
146-
if instance.schema:
147-
raise ValueError('A schema should not be already defined '
148-
'when using schema auto-detection')
149146
instance._properties[self.resource_name] = value
150147

151148

@@ -638,9 +635,6 @@ def schema(self):
638635
def schema(self, value):
639636
if not all(isinstance(field, SchemaField) for field in value):
640637
raise ValueError('Schema items must be fields')
641-
if self.autodetect:
642-
raise ValueError(
643-
'Schema can not be set if `autodetect` property is True')
644638
self._schema = tuple(value)
645639

646640
def to_api_repr(self):

bigquery/tests/system.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,9 @@ def test_load_table_from_storage_then_dump_table(self):
466466
self.assertEqual(sorted(row_tuples, key=by_age),
467467
sorted(ROWS, key=by_age))
468468

469-
def test_load_table_from_storage_w_autodetect_schema(self):
469+
def test_load_table_from_storage_w_autodetect_schema_then_get_job(self):
470470
from google.cloud.bigquery import SchemaField
471+
from google.cloud.bigquery.job import LoadJob
471472

472473
rows = ROWS * 100
473474
# BigQuery internally uses the first 100 rows to detect schema
@@ -477,11 +478,12 @@ def test_load_table_from_storage_w_autodetect_schema(self):
477478
HEADER_ROW, rows)
478479
dataset = self.temp_dataset(_make_dataset_id('load_gcs_then_dump'))
479480
table_ref = dataset.table('test_table')
481+
JOB_ID = 'load_table_w_autodetect_{}'.format(str(uuid.uuid4()))
480482

481483
config = bigquery.LoadJobConfig()
482484
config.autodetect = True
483-
job = Config.CLIENT.load_table_from_storage(gs_url, table_ref,
484-
job_config=config)
485+
job = Config.CLIENT.load_table_from_storage(
486+
gs_url, table_ref, job_config=config, job_id=JOB_ID)
485487

486488
# Allow for 90 seconds of "warm up" before rows visible. See
487489
# https://cloud.google.com/bigquery/streaming-data-into-bigquery#dataavailability
@@ -502,6 +504,12 @@ def test_load_table_from_storage_w_autodetect_schema(self):
502504
self.assertEqual(
503505
sorted(actual_row_tuples, key=by_age), sorted(rows, key=by_age))
504506

507+
fetched_job = Config.CLIENT.get_job(JOB_ID)
508+
509+
self.assertIsInstance(fetched_job, LoadJob)
510+
self.assertEqual(fetched_job.job_id, JOB_ID)
511+
self.assertEqual(fetched_job.autodetect, True)
512+
505513
def _write_csv_to_storage(self, bucket_name, blob_name, header_row,
506514
data_rows):
507515
from google.cloud._testing import _NamedTemporaryFile

bigquery/tests/unit/test_job.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -426,32 +426,6 @@ def test_schema_setter(self):
426426
config.schema = [full_name, age]
427427
self.assertEqual(config.schema, [full_name, age])
428428

429-
def test_schema_setter_w_autodetect(self):
430-
from google.cloud.bigquery.schema import SchemaField
431-
432-
config = LoadJobConfig()
433-
schema = [SchemaField('full_name', 'STRING')]
434-
config.autodetect = False
435-
config.schema = schema
436-
self.assertEqual(config.schema, schema)
437-
438-
config.schema = []
439-
config.autodetect = True
440-
with self.assertRaises(ValueError):
441-
config.schema = schema
442-
443-
def test_autodetect_setter_w_schema(self):
444-
from google.cloud.bigquery.schema import SchemaField
445-
446-
config = LoadJobConfig()
447-
448-
config.autodetect = False
449-
config.schema = [SchemaField('full_name', 'STRING')]
450-
self.assertEqual(config.autodetect, False)
451-
452-
with self.assertRaises(ValueError):
453-
config.autodetect = True
454-
455429
def test_props_set_by_server(self):
456430
import datetime
457431
from google.cloud._helpers import UTC

0 commit comments

Comments
 (0)