zkaoudi commented on code in PR #870:
URL: https://github.com/apache/wayang/pull/870#discussion_r4552549180


##########
python/src/pywy/tests/test_load_collection.py:
##########
@@ -0,0 +1,112 @@
+#
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#  contributor license agreements.  See the NOTICE file distributed with
+#  this work for additional information regarding copyright ownership.
+#  The ASF licenses this file to You under the Apache License, Version 2.0
+#  (the "License"); you may not use this file except in compliance with
+#  the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#
+
+import base64
+import json
+from unittest.mock import patch
+
+import cloudpickle
+import pytest
+
+from pywy.dataquanta import DataQuanta, WayangContext
+from pywy.operators import CollectionSource, SourceUnaryOperator
+from pywy.platforms.java import JavaPlugin
+
+
[email protected]("values", [
+    [1, -2, 0, -(2 ** 63), 2 ** 63 - 1],
+    [1.5, -0.0, 1e-300, 1e300],
+    ['quotes " and \\', "line\nfeed\ttab", "雪 😀", "", '${System.exit(1)}'],
+    [],
+    [True, False],
+    [[1, 2], [], [3, ["nested", False]]],
+    [1, "two", 3.5, True],
+])
+def test_collection_plan(values):
+    context = WayangContext().register({JavaPlugin})
+    data = context.load_collection(values)
+    assert isinstance(data, DataQuanta)
+    assert data.context is context
+    assert isinstance(data.operator, SourceUnaryOperator)
+    assert data.operator.inputs == 0
+    assert data.operator.outputs == 1
+
+    with patch("pywy.core.core.requests.post") as post:

Review Comment:
   What is this patch doing?



##########
python/README.md:
##########
@@ -119,6 +119,51 @@ configuration.set_property("wayang.api.python.port", 
"8080")
 The same values can be supplied through environment variables:
 `WAYANG_API_URL`, or `WAYANG_API_HOST` and `WAYANG_API_PORT`.
 
+## In-memory collections
+
+`load_collection()` snapshots a Python list or tuple and returns a 
`DataQuanta`:
+
+```python
+from pywy.dataquanta import WayangContext
+from pywy.platforms.java import JavaPlugin
+
+ctx = WayangContext().register({JavaPlugin})
+ctx.load_collection([1, 2, 3]).store_textfile("file:///tmp/numbers.txt")
+```
+
+Supported values are built-in strings, booleans, signed 64-bit integers, finite
+floats, and nested lists or tuples. Tuples become lists. Empty and mixed
+collections are supported. Input order and nested structure are preserved by
+the source; subsequent operators/platforms determine result ordering. `None`,
+mappings, sets, generators, custom objects, cyclic containers, out-of-range
+integers, and non-finite floats are rejected before submission.
+
+The current Python worker passes records to UDFs as strings, including records
+from collection sources. Convert numeric inputs explicitly:
+
+```python
+(ctx.load_collection([1, 2, 3])
+ .filter(lambda value: int(value) > 1, str)
+ .map(lambda value: int(value) * 2, str, int)
+ .store_textfile("file:///tmp/doubled.txt"))
+```
+
+This example uses the existing fusion of adjacent Python transformations into

Review Comment:
   for example, this has to do with your implementation and should not be part 
of README



##########
python/README.md:
##########
@@ -119,6 +119,51 @@ configuration.set_property("wayang.api.python.port", 
"8080")
 The same values can be supplied through environment variables:
 `WAYANG_API_URL`, or `WAYANG_API_HOST` and `WAYANG_API_PORT`.
 
+## In-memory collections
+

Review Comment:
   That's a very long README addition for just a load collection operator. 



##########
python/src/pywy/operators/source.py:
##########
@@ -44,6 +45,40 @@ def __repr__(self):
         return super().__repr__()
 
 
+class CollectionSource(SourceUnaryOperator):
+    def __init__(self, collection):
+        # Empty and heterogeneous collections use the backend's generic type.
+        super().__init__('Collection', output_type=None)
+        self.json_name = "inputCollection"
+        if type(collection) not in (list, tuple):
+            raise TypeError("load_collection expects a list or tuple")
+        self.values = self._snapshot(collection, set(), "collection")
+
+    @staticmethod
+    def _snapshot(value, ancestors, path):

Review Comment:
   can you add support to handle NumPy values?



-- 
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]

Reply via email to