derrickaw commented on code in PR #38236:
URL: https://github.com/apache/beam/pull/38236#discussion_r3169880503
##########
sdks/python/apache_beam/yaml/yaml_mapping.py:
##########
@@ -205,85 +193,137 @@ def py_value_to_js_dict(py_value):
return py_value
-# TODO(yaml) Consider adding optional language version parameter to support
-# ECMAScript 5 and 6
-def _expand_javascript_mapping_func(
- original_fields, expression=None, callable=None, path=None, name=None):
+def js_to_py(obj):
+ """Converts mini-racer mapped objects to standard Python types.
+
+ This is needed because ctx.eval returns objects that implement Mapping
+ and Iterable but are not picklable (like JSMappedObjectImpl and JSArrayImpl),
+ which would fail when Beam tries to serialize rows containing them.
+ We also preserve datetime objects which are correctly produced by ctx.eval
+ for JS Date objects.
+ """
+ if isinstance(obj, datetime.datetime):
+ return obj
+ elif isinstance(obj, Mapping):
+ return {k: js_to_py(v) for k, v in obj.items()}
+ elif not isinstance(obj, (str, bytes)) and isinstance(obj, Iterable):
Review Comment:
updated imports
--
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]