max-muoto commented on code in PR #750:
URL: https://github.com/apache/datafusion-python/pull/750#discussion_r1670758586


##########
python/datafusion/udf.py:
##########
@@ -0,0 +1,62 @@
+# 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.
+
+from __future__ import annotations
+
+import datafusion._internal as df_internal
+from datafusion.expr import Expr
+from typing import Callable, TYPE_CHECKING
+
+if TYPE_CHECKING:
+    import pyarrow
+
+
+class ScalarUDF:
+    def __init__(
+        self,
+        name: str | None,
+        func: Callable,
+        input_types: list[pyarrow.DataType],
+        return_type: pyarrow.DataType,
+        volatility: str,
+    ) -> None:
+        self.udf = df_internal.ScalarUDF(
+            name, func, input_types, return_type, volatility
+        )
+
+    def __call__(self, *args: Expr) -> Expr:
+        args = [arg.expr for arg in args]
+        return Expr(self.udf.__call__(*args))
+
+
+class AggregateUDF:
+    def __init__(
+        self,
+        name: str | None,
+        accumulator: Callable,

Review Comment:
   It would be good to provide to be specific with the generics here and above:
   
   ```python
   accumulator: Callable[..., Any]
   ```
   
   I think we could could use generics here though:
   
   
   ```python
   _R = TypeVar("_R", bound=pyarrow.DataType)
   
   class AggregateUDF:
       def __init__(
           self,
           name: str | None,
           accumulator: Callable[..., _R],
           input_types: list[pyarrow.DataType],
           return_type: _R,
           state_type: list[pyarrow.DataType],
           volatility: str,
       ) -> None:
           self.udf = df_internal.AggregateUDF(
               name, accumulator, input_types, return_type, state_type, 
volatility
           )
   
       def __call__(self, *args: Expr) -> Expr:
           args = [arg.expr for arg in args]
           return Expr(self.udf.__call__(*args))
   ```
   



##########
python/datafusion/substrait.py:
##########
@@ -15,9 +15,156 @@
 # specific language governing permissions and limitations
 # under the License.
 
+from __future__ import annotations
 
-from ._internal import substrait
+from ._internal import substrait as substrait_internal
 
+from typing import TYPE_CHECKING
 
-def __getattr__(name):
-    return getattr(substrait, name)
+if TYPE_CHECKING:
+    from datafusion.context import SessionContext
+    from datafusion._internal import LogicalPlan
+
+
+class plan:
+    def __init__(self, plan: substrait_internal.plan) -> None:
+        self.plan_internal = plan
+
+    def encode(self) -> bytes:
+        """Encode the plan to bytes.
+
+        Returns
+        -------
+        bytes
+            Encoded plan.
+        """
+        return self.plan_internal.encode()
+
+
+class serde:
+    @staticmethod
+    def serialize(sql: str, ctx: SessionContext, path: str) -> None:

Review Comment:
   Would this work on `pathlib.Path`?



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to