Skip to content
Browse files
feat: add LoadJobConfig.projection_fields to select DATASTORE_BACKU…
…P fields (#736)

* feat: add LoadJobConfig.projection_fields to select DATASTORE_BACKUP fields

* add type annotations

* annotate setter too

Co-authored-by: Peter Lamut <>
  • Loading branch information
tswast and plamut committed Jul 15, 2021
1 parent 87a09fa commit c45a738
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
@@ -14,7 +14,7 @@

"""Classes for load jobs."""

from typing import FrozenSet, Iterable, Optional
from typing import FrozenSet, List, Iterable, Optional

from import EncryptionConfiguration
from import HivePartitioningOptions
@@ -25,7 +25,6 @@
from import RangePartitioning
from import TableReference
from import TimePartitioning

from import _AsyncJob
from import _JobConfig
from import _JobReference
@@ -300,6 +299,27 @@ def null_marker(self):
def null_marker(self, value):
self._set_sub_prop("nullMarker", value)

def projection_fields(self) -> Optional[List[str]]:
"""Optional[List[str]]: If
:attr:`` is set to
"DATASTORE_BACKUP", indicates which entity properties to load into
BigQuery from a Cloud Datastore backup.
Property names are case sensitive and must be top-level properties. If
no properties are specified, BigQuery loads all properties. If any
named property isn't found in the Cloud Datastore backup, an invalid
error is returned in the job result.
return self._get_sub_prop("projectionFields")

def projection_fields(self, value: Optional[List[str]]):
self._set_sub_prop("projectionFields", value)

def quote_character(self):
"""Optional[str]: Character used to quote data sections (CSV only).
@@ -424,6 +424,17 @@ def test_null_marker_setter(self):
config.null_marker = null_marker
self.assertEqual(config._properties["load"]["nullMarker"], null_marker)

def test_projection_fields_miss(self):
config = self._get_target_class()()

def test_projection_fields_hit(self):
config = self._get_target_class()()
fields = ["email", "postal_code"]
config.projection_fields = fields
self.assertEqual(config._properties["load"]["projectionFields"], fields)
self.assertEqual(config.projection_fields, fields)

def test_quote_character_missing(self):
config = self._get_target_class()()

0 comments on commit c45a738

Please sign in to comment.