Skip to content

Commit c45a738

Browse files
tswastplamut
andauthored
feat: add LoadJobConfig.projection_fields to select DATASTORE_BACKUP fields (#736)
* feat: add LoadJobConfig.projection_fields to select DATASTORE_BACKUP fields * add type annotations * annotate setter too Co-authored-by: Peter Lamut <[email protected]>
1 parent 87a09fa commit c45a738

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

google/cloud/bigquery/job/load.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
"""Classes for load jobs."""
1616

17-
from typing import FrozenSet, Iterable, Optional
17+
from typing import FrozenSet, List, Iterable, Optional
1818

1919
from google.cloud.bigquery.encryption_configuration import EncryptionConfiguration
2020
from google.cloud.bigquery.external_config import HivePartitioningOptions
@@ -25,7 +25,6 @@
2525
from google.cloud.bigquery.table import RangePartitioning
2626
from google.cloud.bigquery.table import TableReference
2727
from google.cloud.bigquery.table import TimePartitioning
28-
2928
from google.cloud.bigquery.job.base import _AsyncJob
3029
from google.cloud.bigquery.job.base import _JobConfig
3130
from google.cloud.bigquery.job.base import _JobReference
@@ -300,6 +299,27 @@ def null_marker(self):
300299
def null_marker(self, value):
301300
self._set_sub_prop("nullMarker", value)
302301

302+
@property
303+
def projection_fields(self) -> Optional[List[str]]:
304+
"""Optional[List[str]]: If
305+
:attr:`google.cloud.bigquery.job.LoadJobConfig.source_format` is set to
306+
"DATASTORE_BACKUP", indicates which entity properties to load into
307+
BigQuery from a Cloud Datastore backup.
308+
309+
Property names are case sensitive and must be top-level properties. If
310+
no properties are specified, BigQuery loads all properties. If any
311+
named property isn't found in the Cloud Datastore backup, an invalid
312+
error is returned in the job result.
313+
314+
See:
315+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.projection_fields
316+
"""
317+
return self._get_sub_prop("projectionFields")
318+
319+
@projection_fields.setter
320+
def projection_fields(self, value: Optional[List[str]]):
321+
self._set_sub_prop("projectionFields", value)
322+
303323
@property
304324
def quote_character(self):
305325
"""Optional[str]: Character used to quote data sections (CSV only).

tests/unit/job/test_load_config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,17 @@ def test_null_marker_setter(self):
424424
config.null_marker = null_marker
425425
self.assertEqual(config._properties["load"]["nullMarker"], null_marker)
426426

427+
def test_projection_fields_miss(self):
428+
config = self._get_target_class()()
429+
self.assertIsNone(config.projection_fields)
430+
431+
def test_projection_fields_hit(self):
432+
config = self._get_target_class()()
433+
fields = ["email", "postal_code"]
434+
config.projection_fields = fields
435+
self.assertEqual(config._properties["load"]["projectionFields"], fields)
436+
self.assertEqual(config.projection_fields, fields)
437+
427438
def test_quote_character_missing(self):
428439
config = self._get_target_class()()
429440
self.assertIsNone(config.quote_character)

0 commit comments

Comments
 (0)