Skip to content

Commit

Permalink
feat: Support jsonExtension in LoadJobConfig (#1751)
Browse files Browse the repository at this point in the history
* feat: support jsonExtension in LoadJobConfig

* reformatted with black

* Updated doc string and added test for the encoding of jsonExtension

* modified setter test to make sure property is set correctly
  • Loading branch information
kiraksi committed Jan 12, 2024
1 parent a167f9a commit 0fd7347
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
13 changes: 13 additions & 0 deletions google/cloud/bigquery/job/load.py
Expand Up @@ -327,6 +327,19 @@ def ignore_unknown_values(self):
def ignore_unknown_values(self, value):
self._set_sub_prop("ignoreUnknownValues", value)

@property
def json_extension(self):
"""Optional[str]: The extension to use for writing JSON data to BigQuery. Only supports GeoJSON currently.
See: https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.json_extension
"""
return self._get_sub_prop("jsonExtension")

@json_extension.setter
def json_extension(self, value):
self._set_sub_prop("jsonExtension", value)

@property
def max_bad_records(self):
"""Optional[int]: Number of invalid rows to ignore.
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/job/test_load_config.py
Expand Up @@ -413,6 +413,29 @@ def test_ignore_unknown_values_setter(self):
config.ignore_unknown_values = True
self.assertTrue(config._properties["load"]["ignoreUnknownValues"])

def test_json_extension_missing(self):
config = self._get_target_class()()
self.assertIsNone(config.json_extension)

def test_json_extension_hit(self):
config = self._get_target_class()()
config._properties["load"]["jsonExtension"] = "GEOJSON"
self.assertEqual(config.json_extension, "GEOJSON")

def test_json_extension_setter(self):
config = self._get_target_class()()
self.assertFalse(config.json_extension)
config.json_extension = "GEOJSON"
self.assertTrue(config.json_extension)
self.assertEqual(config._properties["load"]["jsonExtension"], "GEOJSON")

def test_to_api_repr_includes_json_extension(self):
config = self._get_target_class()()
config._properties["load"]["jsonExtension"] = "GEOJSON"
api_repr = config.to_api_repr()
self.assertIn("jsonExtension", api_repr["load"])
self.assertEqual(api_repr["load"]["jsonExtension"], "GEOJSON")

def test_max_bad_records_missing(self):
config = self._get_target_class()()
self.assertIsNone(config.max_bad_records)
Expand Down

0 comments on commit 0fd7347

Please sign in to comment.