Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for map target type in Parquet options #1919

Merged
merged 7 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
}