DhanushPillay commented on code in PR #41737:
URL: https://github.com/apache/beam/pull/41737#discussion_r4726819751
##########
sdks/python/apache_beam/typehints/arrow_type_compatibility.py:
##########
@@ -295,13 +298,75 @@ def _arrow_type_from_beam_fieldtype(
return output_arrow_type
+def _to_arrow_value_fn(
+ arrow_type: pa.DataType) -> Optional[Callable[[Any], Any]]:
+ """Build a converter; pa.array rejects row objects for struct fields."""
+ if isinstance(arrow_type, pa.StructType):
+ fields = [(arrow_type[i].name, _to_arrow_value_fn(arrow_type[i].type))
+ for i in range(len(arrow_type))]
+ return _row_to_dict_fn(fields)
+
+ if isinstance(arrow_type, (pa.ListType, pa.LargeListType)):
+ convert_element = _to_arrow_value_fn(arrow_type.value_type)
+ if convert_element is None:
+ return None
+ return lambda value: None if value is None else [
+ convert_element(element) for element in value
+ ]
+
+ if isinstance(arrow_type, pa.MapType):
+ convert_item = _to_arrow_value_fn(arrow_type.item_type)
+ if convert_item is None:
+ return None
+
+ def convert_map(value):
+ if value is None:
+ return None
+ return {key: convert_item(item) for key, item in value.items()}
Review Comment:
Applied this. convert_map now accepts both mappings and sequences of
key/value pairs, with a regression test that passes map values as a list of
tuples. Commits e0f2f7f and 2e44621. Tests: 104 passed, 1 skipped.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]