From 2e1b52f9ef2abf0809dc8cb5cae96145e8898730 Mon Sep 17 00:00:00 2001 From: Layla Bristol Date: Mon, 15 Apr 2019 11:25:32 -0700 Subject: [PATCH 1/4] Added new properties to LoadJob that are in LoadJobConfig. --- bigquery/google/cloud/bigquery/job.py | 18 ++++++++++++++++++ bigquery/tests/unit/test_job.py | 20 ++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/bigquery/google/cloud/bigquery/job.py b/bigquery/google/cloud/bigquery/job.py index 94a2290cc29e..4057d68feff8 100644 --- a/bigquery/google/cloud/bigquery/job.py +++ b/bigquery/google/cloud/bigquery/job.py @@ -1371,6 +1371,24 @@ def destination_encryption_configuration(self): """ return self._configuration.destination_encryption_configuration + @property + def destination_table_description(self): + """Union[str, None] name given to destination table. + + See: + https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.load.destinationTableProperties.description + """ + return self._configuration.destination_table_description + + @property + def destination_table_friendly_name(self): + """Union[str, None] name given to destination table. + + See: + https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.load.destinationTableProperties.friendlyName + """ + return self._configuration.destination_table_friendly_name + @property def time_partitioning(self): """See diff --git a/bigquery/tests/unit/test_job.py b/bigquery/tests/unit/test_job.py index a42d9ffc311c..2bdb60ecda9a 100644 --- a/bigquery/tests/unit/test_job.py +++ b/bigquery/tests/unit/test_job.py @@ -1753,6 +1753,24 @@ def _verifyResourceProperties(self, job, resource): else: self.assertIsNone(job.destination_encryption_configuration) + if "destinationTableDescription" in config: + self.assertIsNotNone(job.destination_table_description) + self.assertEqual( + job.destination_table_description.description, + config["destinationTableDescription"]["description"], + ) + else: + self.assertIsNone(job.destination_table_description) + + if "destinationTableFriendlyName" in config: + self.assertIsNotNone(job.destination_table_friendly_name) + self.assertEqual( + job.destination_table_friendly_name.friendly_name, + config["destinationTableFriendlyName"]["friendlyName"], + ) + else: + self.assertIsNone(job.destination_table_description) + def test_ctor(self): client = _make_client(project=self.PROJECT) job = self._make_one(self.JOB_ID, [self.SOURCE1], self.TABLE_REF, client) @@ -1786,6 +1804,8 @@ def test_ctor(self): self.assertIsNone(job.source_format) self.assertIsNone(job.write_disposition) self.assertIsNone(job.destination_encryption_configuration) + self.assertIsNone(job.destination_table_description) + self.assertIsNone(job.destination_table_friendly_name) self.assertIsNone(job.time_partitioning) self.assertIsNone(job.use_avro_logical_types) self.assertIsNone(job.clustering_fields) From 26b8a2026f1c6ff68c6cdb978c40885016827515 Mon Sep 17 00:00:00 2001 From: Layla Bristol Date: Mon, 15 Apr 2019 14:38:22 -0700 Subject: [PATCH 2/4] Added destination property and updated tests per feedback. --- bigquery/google/cloud/bigquery/job.py | 9 +++++++- bigquery/tests/unit/test_job.py | 31 +++++++++++---------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/bigquery/google/cloud/bigquery/job.py b/bigquery/google/cloud/bigquery/job.py index 4057d68feff8..664d6872fb34 100644 --- a/bigquery/google/cloud/bigquery/job.py +++ b/bigquery/google/cloud/bigquery/job.py @@ -1257,9 +1257,16 @@ def __init__(self, job_id, source_uris, destination, client, job_config=None): job_config = LoadJobConfig() self.source_uris = source_uris - self.destination = destination + self._destination = destination self._configuration = job_config + @property + def destination(self): + """See + :attr:`google.cloud.bigquery.job.LoadJobConfig.destination`. + """ + return self._destination + @property def allow_jagged_rows(self): """See diff --git a/bigquery/tests/unit/test_job.py b/bigquery/tests/unit/test_job.py index 2bdb60ecda9a..c6379f78913a 100644 --- a/bigquery/tests/unit/test_job.py +++ b/bigquery/tests/unit/test_job.py @@ -1753,24 +1753,6 @@ def _verifyResourceProperties(self, job, resource): else: self.assertIsNone(job.destination_encryption_configuration) - if "destinationTableDescription" in config: - self.assertIsNotNone(job.destination_table_description) - self.assertEqual( - job.destination_table_description.description, - config["destinationTableDescription"]["description"], - ) - else: - self.assertIsNone(job.destination_table_description) - - if "destinationTableFriendlyName" in config: - self.assertIsNotNone(job.destination_table_friendly_name) - self.assertEqual( - job.destination_table_friendly_name.friendly_name, - config["destinationTableFriendlyName"]["friendlyName"], - ) - else: - self.assertIsNone(job.destination_table_description) - def test_ctor(self): client = _make_client(project=self.PROJECT) job = self._make_one(self.JOB_ID, [self.SOURCE1], self.TABLE_REF, client) @@ -1814,6 +1796,7 @@ def test_ctor(self): def test_ctor_w_config(self): from google.cloud.bigquery.schema import SchemaField from google.cloud.bigquery.job import LoadJobConfig + from google.cloud.bigquery.job import LoadJob client = _make_client(project=self.PROJECT) full_name = SchemaField("full_name", "STRING", mode="REQUIRED") @@ -1825,6 +1808,18 @@ def test_ctor_w_config(self): ) self.assertEqual(job.schema, [full_name, age]) + config.destination_table_description = "Description" + expected = {"description": "Description"} + self.assertEqual( + config._properties["load"]["destinationTableProperties"], expected + ) + + friendly_name = "Friendly Name" + config._properties["load"]["destinationTableProperties"] = { + "friendlyName": friendly_name + } + self.assertEqual(config.destination_table_friendly_name, friendly_name) + def test_ctor_w_job_reference(self): from google.cloud.bigquery import job From 5df6ccdb4817e90dd04c85f464996acd195237d8 Mon Sep 17 00:00:00 2001 From: Layla Bristol Date: Mon, 15 Apr 2019 14:45:18 -0700 Subject: [PATCH 3/4] Updated docstring for destination property --- bigquery/google/cloud/bigquery/job.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bigquery/google/cloud/bigquery/job.py b/bigquery/google/cloud/bigquery/job.py index 664d6872fb34..1aa99e699db3 100644 --- a/bigquery/google/cloud/bigquery/job.py +++ b/bigquery/google/cloud/bigquery/job.py @@ -1262,8 +1262,10 @@ def __init__(self, job_id, source_uris, destination, client, job_config=None): @property def destination(self): - """See - :attr:`google.cloud.bigquery.job.LoadJobConfig.destination`. + """google.cloud.bigquery.table.TableReference: table where loaded rows are written + + See: + https://g.co/cloud/bigquery/docs/reference/rest/v2/jobs#configuration.load.destinationTable """ return self._destination From a202773d0815f711de718739d04d4de7d1892a7e Mon Sep 17 00:00:00 2001 From: Layla Bristol Date: Mon, 15 Apr 2019 14:47:14 -0700 Subject: [PATCH 4/4] Removed unnecessary line --- bigquery/tests/unit/test_job.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/bigquery/tests/unit/test_job.py b/bigquery/tests/unit/test_job.py index c6379f78913a..bbb2c54d852f 100644 --- a/bigquery/tests/unit/test_job.py +++ b/bigquery/tests/unit/test_job.py @@ -1796,7 +1796,6 @@ def test_ctor(self): def test_ctor_w_config(self): from google.cloud.bigquery.schema import SchemaField from google.cloud.bigquery.job import LoadJobConfig - from google.cloud.bigquery.job import LoadJob client = _make_client(project=self.PROJECT) full_name = SchemaField("full_name", "STRING", mode="REQUIRED") @@ -1807,13 +1806,11 @@ def test_ctor_w_config(self): self.JOB_ID, [self.SOURCE1], self.TABLE_REF, client, config ) self.assertEqual(job.schema, [full_name, age]) - config.destination_table_description = "Description" expected = {"description": "Description"} self.assertEqual( config._properties["load"]["destinationTableProperties"], expected ) - friendly_name = "Friendly Name" config._properties["load"]["destinationTableProperties"] = { "friendlyName": friendly_name