From bd1da9aa0a40b02b7d5409a0b094d8380e255c91 Mon Sep 17 00:00:00 2001 From: Mario Torres Jr <105736410+Mattix23@users.noreply.github.com> Date: Tue, 31 Jan 2023 12:06:02 -0600 Subject: [PATCH] feat: add preserveAsciiControlCharacter to LoadJobConfig (#1484) --- google/cloud/bigquery/job/load.py | 13 +++++++++++++ tests/unit/job/test_load_config.py | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/google/cloud/bigquery/job/load.py b/google/cloud/bigquery/job/load.py index 5c7f26841..14a7fa30b 100644 --- a/google/cloud/bigquery/job/load.py +++ b/google/cloud/bigquery/job/load.py @@ -311,6 +311,19 @@ def null_marker(self): def null_marker(self, value): self._set_sub_prop("nullMarker", value) + @property + def preserve_ascii_control_characters(self): + """Optional[bool]: Preserves the embedded ASCII control characters when sourceFormat is set to CSV. + + See: + https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.preserve_ascii_control_characters + """ + return self._get_sub_prop("preserveAsciiControlCharacters") + + @preserve_ascii_control_characters.setter + def preserve_ascii_control_characters(self, value): + self._set_sub_prop("preserveAsciiControlCharacters", bool(value)) + @property def projection_fields(self) -> Optional[List[str]]: """Optional[List[str]]: If diff --git a/tests/unit/job/test_load_config.py b/tests/unit/job/test_load_config.py index 5a0c5a83f..7f77fc085 100644 --- a/tests/unit/job/test_load_config.py +++ b/tests/unit/job/test_load_config.py @@ -424,6 +424,20 @@ def test_null_marker_setter(self): config.null_marker = null_marker self.assertEqual(config._properties["load"]["nullMarker"], null_marker) + def test_preserve_ascii_control_characters_missing(self): + config = self._get_target_class()() + self.assertIsNone(config.preserve_ascii_control_characters) + + def test_preserve_ascii_control_characters_hit(self): + config = self._get_target_class()() + config._properties["load"]["preserveAsciiControlCharacters"] = True + self.assertTrue(config.preserve_ascii_control_characters) + + def test_preserve_ascii_control_characters_setter(self): + config = self._get_target_class()() + config.preserve_ascii_control_characters = True + self.assertTrue(config._properties["load"]["preserveAsciiControlCharacters"]) + def test_projection_fields_miss(self): config = self._get_target_class()() self.assertIsNone(config.projection_fields)