diff --git a/bigquery/google/cloud/bigquery/client.py b/bigquery/google/cloud/bigquery/client.py index 2c967fa09d7e..47b655ab2345 100644 --- a/bigquery/google/cloud/bigquery/client.py +++ b/bigquery/google/cloud/bigquery/client.py @@ -949,7 +949,7 @@ def load_table_from_file( job_ref = job._JobReference(job_id, project=project, location=location) load_job = job.LoadJob(job_ref, None, destination, self, job_config) - job_resource = load_job._build_resource() + job_resource = load_job.to_api_repr() if rewind: file_obj.seek(0, os.SEEK_SET) diff --git a/bigquery/google/cloud/bigquery/job.py b/bigquery/google/cloud/bigquery/job.py index 7f89efa2d821..c430ddc4285b 100644 --- a/bigquery/google/cloud/bigquery/job.py +++ b/bigquery/google/cloud/bigquery/job.py @@ -519,10 +519,12 @@ def _get_resource_config(cls, resource): '["configuration"]["%s"]' % cls._JOB_TYPE) return job_id, resource['configuration'] - def _build_resource(self): - """Helper: Generate a resource for :meth:`_begin`.""" + def to_api_repr(self): + """Generate a resource for the job.""" raise NotImplementedError("Abstract") + _build_resource = to_api_repr # backward-compatibility alias + def _begin(self, client=None, retry=DEFAULT_RETRY): """API call: begin the job via a POST request @@ -549,7 +551,7 @@ def _begin(self, client=None, retry=DEFAULT_RETRY): # job has an ID. api_response = client._call_api( retry, - method='POST', path=path, data=self._build_resource()) + method='POST', path=path, data=self.to_api_repr()) self._set_properties(api_response) def exists(self, client=None, retry=DEFAULT_RETRY): @@ -1367,7 +1369,7 @@ def output_rows(self): if statistics is not None: return int(statistics['load']['outputRows']) - def _build_resource(self): + def to_api_repr(self): """Generate a resource for :meth:`_begin`.""" configuration = self._configuration.to_api_repr() if self.source_uris is not None: @@ -1543,7 +1545,7 @@ def destination_encryption_configuration(self): """ return self._configuration.destination_encryption_configuration - def _build_resource(self): + def to_api_repr(self): """Generate a resource for :meth:`_begin`.""" source_refs = [{ @@ -1761,7 +1763,7 @@ def destination_uri_file_counts(self): return [int(count) for count in counts] return None - def _build_resource(self): + def to_api_repr(self): """Generate a resource for :meth:`_begin`.""" source_ref = { @@ -2367,7 +2369,7 @@ def schema_update_options(self): """ return self._configuration.schema_update_options - def _build_resource(self): + def to_api_repr(self): """Generate a resource for :meth:`_begin`.""" configuration = self._configuration.to_api_repr() diff --git a/bigquery/tests/unit/test_client.py b/bigquery/tests/unit/test_client.py index 73b14b506244..56f4aabeb651 100644 --- a/bigquery/tests/unit/test_client.py +++ b/bigquery/tests/unit/test_client.py @@ -2214,7 +2214,7 @@ def _initiate_resumable_upload_helper(self, num_retries=None): config = LoadJobConfig() config.source_format = SourceFormat.CSV job = LoadJob(None, None, self.TABLE_REF, client, job_config=config) - metadata = job._build_resource() + metadata = job.to_api_repr() upload, transport = client._initiate_resumable_upload( stream, metadata, num_retries) @@ -2279,7 +2279,7 @@ def _do_multipart_upload_success_helper( config = LoadJobConfig() config.source_format = SourceFormat.CSV job = LoadJob(None, None, self.TABLE_REF, client, job_config=config) - metadata = job._build_resource() + metadata = job.to_api_repr() size = len(data) response = client._do_multipart_upload( stream, metadata, size, num_retries) diff --git a/bigquery/tests/unit/test_job.py b/bigquery/tests/unit/test_job.py index 97c22e211a77..398894839ea7 100644 --- a/bigquery/tests/unit/test_job.py +++ b/bigquery/tests/unit/test_job.py @@ -522,6 +522,12 @@ def test__build_resource(self): with self.assertRaises(NotImplementedError): job._build_resource() + def test_to_api_repr(self): + client = _make_client(project=self.PROJECT) + job = self._make_one(self.JOB_ID, client) + with self.assertRaises(NotImplementedError): + job.to_api_repr() + def test__begin_already(self): job = self._set_properties_job() job._properties['status'] = {'state': 'WHATEVER'} @@ -543,7 +549,7 @@ def test__begin_defaults(self): } } job = self._set_properties_job() - builder = job._build_resource = mock.Mock() + builder = job.to_api_repr = mock.Mock() builder.return_value = resource call_api = job._client._call_api = mock.Mock() call_api.return_value = resource @@ -573,7 +579,7 @@ def test__begin_explicit(self): } } job = self._set_properties_job() - builder = job._build_resource = mock.Mock() + builder = job.to_api_repr = mock.Mock() builder.return_value = resource client = _make_client(project=other_project) call_api = client._call_api = mock.Mock()