Skip to content

Commit 0fd7347

Browse files
authored
feat: Support jsonExtension in LoadJobConfig (#1751)
* 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
1 parent a167f9a commit 0fd7347

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

google/cloud/bigquery/job/load.py

+13
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,19 @@ def ignore_unknown_values(self):
327327
def ignore_unknown_values(self, value):
328328
self._set_sub_prop("ignoreUnknownValues", value)
329329

330+
@property
331+
def json_extension(self):
332+
"""Optional[str]: The extension to use for writing JSON data to BigQuery. Only supports GeoJSON currently.
333+
334+
See: https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.json_extension
335+
336+
"""
337+
return self._get_sub_prop("jsonExtension")
338+
339+
@json_extension.setter
340+
def json_extension(self, value):
341+
self._set_sub_prop("jsonExtension", value)
342+
330343
@property
331344
def max_bad_records(self):
332345
"""Optional[int]: Number of invalid rows to ignore.

tests/unit/job/test_load_config.py

+23
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,29 @@ def test_ignore_unknown_values_setter(self):
413413
config.ignore_unknown_values = True
414414
self.assertTrue(config._properties["load"]["ignoreUnknownValues"])
415415

416+
def test_json_extension_missing(self):
417+
config = self._get_target_class()()
418+
self.assertIsNone(config.json_extension)
419+
420+
def test_json_extension_hit(self):
421+
config = self._get_target_class()()
422+
config._properties["load"]["jsonExtension"] = "GEOJSON"
423+
self.assertEqual(config.json_extension, "GEOJSON")
424+
425+
def test_json_extension_setter(self):
426+
config = self._get_target_class()()
427+
self.assertFalse(config.json_extension)
428+
config.json_extension = "GEOJSON"
429+
self.assertTrue(config.json_extension)
430+
self.assertEqual(config._properties["load"]["jsonExtension"], "GEOJSON")
431+
432+
def test_to_api_repr_includes_json_extension(self):
433+
config = self._get_target_class()()
434+
config._properties["load"]["jsonExtension"] = "GEOJSON"
435+
api_repr = config.to_api_repr()
436+
self.assertIn("jsonExtension", api_repr["load"])
437+
self.assertEqual(api_repr["load"]["jsonExtension"], "GEOJSON")
438+
416439
def test_max_bad_records_missing(self):
417440
config = self._get_target_class()()
418441
self.assertIsNone(config.max_bad_records)

0 commit comments

Comments
 (0)