gaogaotiantian commented on code in PR #58729:
URL: https://github.com/apache/spark/pull/58729#discussion_r4020537209


##########
python/pyspark/sql/eval_handlers/_base.py:
##########
@@ -0,0 +1,129 @@
+#
+# 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.
+#
+
+"""Base classes and registry for the eval type handlers.
+
+Kept in a leaf module (importing only ``_typing`` and serializers) so both the
+package ``__init__`` and the concrete-handler submodules can import it without 
a
+circular import.
+"""
+
+from abc import ABCMeta, abstractmethod
+from collections.abc import Iterator
+from typing import TYPE_CHECKING, Any, ClassVar, Generic, Optional, cast
+
+from pyspark.serializers import Serializer
+from pyspark.sql.eval_handlers._typing import (
+    CoGroupedBatch,
+    GroupedBatch,
+    InputBatch,
+    OutputBatch,
+)
+from pyspark.sql.pandas.serializers import (
+    ArrowStreamCoGroupSerializer,
+    ArrowStreamGroupSerializer,
+    ArrowStreamSerializer,
+)
+
+if TYPE_CHECKING:
+    import pyarrow as pa  # noqa: F401  # only in the batch category's 
forward-ref subscript
+
+    from pyspark.worker_util import EvalConf, RunnerConf
+
+# eval type -> handler class, populated by _EvalTypeHandlerMeta at class 
definition.
+EVAL_TYPE_HANDLERS: "dict[int, type[EvalTypeHandler]]" = {}
+
+
+class _EvalTypeHandlerMeta(ABCMeta):
+    """Registers a concrete handler under its ``eval_type`` at definition time.
+
+    Runs after ``ABCMeta`` sets ``__abstractmethods__``, so a class that 
declares
+    an ``eval_type`` while leaving ``run``/``serializer`` abstract is rejected 
here
+    instead of failing when ``read_udfs`` instantiates it.
+    """
+
+    def __new__(mcs, name: str, bases: tuple, namespace: dict, **kwargs: Any) 
-> type:
+        cls = cast("type[EvalTypeHandler]", super().__new__(mcs, name, bases, 
namespace, **kwargs))

Review Comment:
   We can probably do a runtime check here like `assert issubclass(cls, 
EvalTypeHandler)` then mypy should be happy.



##########
python/pyspark/sql/eval_handlers/_base.py:
##########
@@ -0,0 +1,129 @@
+#
+# 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.
+#
+
+"""Base classes and registry for the eval type handlers.
+
+Kept in a leaf module (importing only ``_typing`` and serializers) so both the
+package ``__init__`` and the concrete-handler submodules can import it without 
a
+circular import.
+"""
+
+from abc import ABCMeta, abstractmethod
+from collections.abc import Iterator
+from typing import TYPE_CHECKING, Any, ClassVar, Generic, Optional, cast
+
+from pyspark.serializers import Serializer
+from pyspark.sql.eval_handlers._typing import (
+    CoGroupedBatch,
+    GroupedBatch,
+    InputBatch,
+    OutputBatch,
+)
+from pyspark.sql.pandas.serializers import (
+    ArrowStreamCoGroupSerializer,
+    ArrowStreamGroupSerializer,
+    ArrowStreamSerializer,
+)
+
+if TYPE_CHECKING:
+    import pyarrow as pa  # noqa: F401  # only in the batch category's 
forward-ref subscript
+
+    from pyspark.worker_util import EvalConf, RunnerConf
+
+# eval type -> handler class, populated by _EvalTypeHandlerMeta at class 
definition.
+EVAL_TYPE_HANDLERS: "dict[int, type[EvalTypeHandler]]" = {}

Review Comment:
   All cap normally means "constant" in Python. This should be 
`_eval_type_handlers`. Let's expose a function in this module to get the 
handler, instead of directly using this variable.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to