Skip to content

Commit

Permalink
feat: add support for map target type in Parquet options (#1919)
Browse files Browse the repository at this point in the history
* Update format_options.py to include the newly added map target type.

The map target type creates a schema without the added key_value repeated field.

* Added tests

* add unit test

* lint

---------

Co-authored-by: Lingqing Gan <lingqing.gan@gmail.com>
  • Loading branch information
sclmn and Linchin committed May 21, 2024
1 parent 32b2c35 commit c3f7b23
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
15 changes: 15 additions & 0 deletions google/cloud/bigquery/format_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,21 @@ def enable_list_inference(self) -> bool:
def enable_list_inference(self, value: bool) -> None:
self._properties["enableListInference"] = value

@property
def map_target_type(self) -> str:
"""Indicates whether to simplify the representation of parquet maps to only show keys and values."""

return self._properties.get("mapTargetType")

@map_target_type.setter
def map_target_type(self, value: str) -> None:
"""Sets the map target type.
Args:
value: The map target type (eg ARRAY_OF_STRUCT).
"""
self._properties["mapTargetType"] = value

@classmethod
def from_api_repr(cls, resource: Dict[str, bool]) -> "ParquetOptions":
"""Factory: construct an instance from a resource dict.
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/test_format_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ def test_from_api_repr(self):
)
assert not config.enum_as_string
assert config.enable_list_inference
assert config.map_target_type is None

def test_to_api_repr(self):
config = self._get_target_class()()
config.enum_as_string = True
config.enable_list_inference = False
config.map_target_type = "ARRAY_OF_STRUCT"

result = config.to_api_repr()
assert result == {"enumAsString": True, "enableListInference": False}
assert result == {
"enumAsString": True,
"enableListInference": False,
"mapTargetType": "ARRAY_OF_STRUCT",
}

0 comments on commit c3f7b23

Please sign in to comment.
  翻译: