You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "zozo123 (via GitHub)" <gi...@apache.org> on 2026/09/16 13:52:31 UTC
[PR] [SPARK-55278][CORE] Make the external UDF worker dispatcher factory configurable [spark]
zozo123 opened a new pull request, #58859:
URL: https://github.com/apache/spark/pull/58859
<!-- Draft: opened for design feedback on how the dispatcher factory should be selected.
Happy to file a dedicated subtask under SPARK-55278 if that is the preferred shape. -->
### What changes were proposed in this pull request?
Resolves the `TODO [SPARK-55278]: Wire in the correct dispatcher factory` in `SparkEnv` by
selecting the `UDFDispatcherFactory` from a new configuration,
`spark.udf.worker.dispatcherFactory`, instead of installing a factory that always throws.
### Why are the changes needed?
`SparkEnv.createUDFDispatcherManager` currently installs a `UDFDispatcherFactory` whose
`createDispatcher` throws unconditionally, so no external UDF worker can be created. I could
not find a subtask under SPARK-55278 covering this slot.
It cannot simply name a concrete dispatcher. `core` depends on `udf-worker-proto` and
`udf-worker-core`; nothing in the reactor depends on `udf-worker-grpc`, which owns
`DirectGrpcDispatcher` -- not `core`, `sql/core`, `assembly`, or the Connect server.
`udf/worker/README.md` states this is deliberate:
> Keeping gRPC here means `proto/`, `core/`, and their consumers (`core`, `catalyst`,
> `sql/core`) carry no gRPC dependency on their classpath.
So there is no module where the wiring code and a concrete dispatcher share a classpath.
Closing the TODO by referencing a dispatcher at compile time would hand the engine back the
gRPC dependency the module layout was built to avoid, and relocating the wiring hits the same
wall. Resolving the factory reflectively preserves that boundary.
It also makes the extensibility the framework already documents reachable without a fork:
`WorkerDispatcher` is described as decoupled from the provisioning model ("direct local spawn,
indirect daemon-provided"), and the README reserves `core/indirect/` for "obtaining workers
from a provisioning service or daemon".
### Does this PR introduce _any_ user-facing change?
No behaviour change by default. When the config is unset the resolved factory still throws,
and still only on first use, so applications that never execute an external UDF are
unaffected. The message now names the config key rather than pointing at the SPIP.
Adds `spark.udf.worker.dispatcherFactory` (optional, no default). Deliberately not documented
in `configuration.md`: the surrounding APIs are `@Experimental` and not yet wired to a
production execution path.
### How was this patch tested?
New `SparkEnvUDFDispatcherSuite` in `core`:
| Case | Expectation |
|---|---|
| config unset | resolution succeeds; `createDispatcher` throws naming the config key |
| no-arg factory | instantiated and returned |
| `(SparkConf, isDriver)` factory | receives the conf and the correct `isDriver` for both values |
| class not implementing `UDFDispatcherFactory` | `SparkException` naming the config key and the class |
| unknown class name | `ClassNotFoundException` |
### Open questions
1. Is configuration-driven selection the intended resolution, or is something else planned
(`ServiceLoader`, or giving a specific module the gRPC dependency)?
2. Config in `core` alongside `Python.scala`, or in the SQL namespace given that external UDFs
are planned at the SQL layer?
3. `Utils.instantiateSerializerOrShuffleManager` does the right thing here but is named for its
original callers -- reuse, or extract a generic helper?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-59822][UDF] Make the external UDF worker dispatcher factory configurable [spark]
Posted by "zozo123 (via GitHub)" <gi...@apache.org>.
zozo123 commented on PR #58859:
URL: https://github.com/apache/spark/pull/58859#issuecomment-5898983692
@haiyangsun-db done. thank you!
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-59822][UDF] Make the external UDF worker dispatcher factory configurable [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #58859:
URL: https://github.com/apache/spark/pull/58859#issuecomment-5900341699
**Merge Summary:**
- merged into master https://github.com/apache/spark/commit/1d9f7989802d644810f95741d66cd3995147531d
- merged into branch-4.x https://github.com/apache/spark/commit/f361570152fc64b8fb8babd5b7ed0afcbd522d1a
*Posted by `merge_spark_pr.py`*
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-59822][CORE] Make the external UDF worker dispatcher factory configurable [spark]
Posted by "haiyangsun-db (via GitHub)" <gi...@apache.org>.
haiyangsun-db commented on PR #58859:
URL: https://github.com/apache/spark/pull/58859#issuecomment-5892321863
@zozo123 one more thing, can you use component [UDF] instead of [CORE] in the PR title?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-55278][CORE] Make the external UDF worker dispatcher factory configurable [spark]
Posted by "haiyangsun-db (via GitHub)" <gi...@apache.org>.
haiyangsun-db commented on code in PR #58859:
URL: https://github.com/apache/spark/pull/58859#discussion_r4122593130
##########
core/src/main/scala/org/apache/spark/SparkEnv.scala:
##########
@@ -225,17 +226,8 @@ class SparkEnv (
@volatile private var udfDispatcherManager: Option[UDFDispatcherManager] = None
private def createUDFDispatcherManager(): UDFDispatcherManager = {
- val factory = new UDFDispatcherFactory {
- override def createDispatcher(
- workerSpec: UDFWorkerSpecification,
- logger: org.apache.spark.udf.worker.core.WorkerLogger
- ): WorkerDispatcher = {
- // TODO [SPARK-55278]: Wire in the correct dispatcher factory
- throw new UnsupportedOperationException(
- "No UDF dispatcher factory configured. " +
- "Set up a concrete factory for SPARK-55278.")
- }
- }
+ val factory = SparkEnv.resolveUDFDispatcherFactory(
Review Comment:
Coordinate lazy manager creation with `SparkEnv.stop()`. Running tasks survive `threadPool.shutdown()`, so stop can miss a manager published afterward and leave its workers unclosed. Use one lifecycle gate, reject creation after `isStopped`, and cover this interleaving.
##########
core/src/main/scala/org/apache/spark/SparkEnv.scala:
##########
@@ -527,6 +519,50 @@ object SparkEnv extends Logging {
private[spark] val driverSystemName = "sparkDriver"
private[spark] val executorSystemName = "sparkExecutor"
+ /**
+ * :: Experimental ::
+ * Resolves the [[UDFDispatcherFactory]] used to create dispatchers for external UDF
+ * workers (SPARK-55278), from `spark.udf.worker.dispatcherFactory`.
+ *
+ * The factory is loaded reflectively rather than named here: `core` depends on
+ * `udf-worker-proto` and `udf-worker-core` only, so that neither it nor its consumers
+ * carry a gRPC dependency. Every concrete dispatcher therefore lives in a module that
+ * core cannot reference at compile time, and the implementation has to be selected by
+ * configuration.
+ *
+ * When the config is unset the returned factory throws on first use rather than at
+ * SparkEnv creation, so applications that never run an external UDF are unaffected.
+ */
+ private[spark] def resolveUDFDispatcherFactory(
+ conf: SparkConf,
+ isDriver: Boolean): UDFDispatcherFactory = {
+ conf.get(UDF.DISPATCHER_FACTORY) match {
+ case Some(className) =>
+ // Validate before constructing so that a misconfigured class is reported against
+ // the config key, rather than as a ClassCastException from the call site.
+ val cls = Utils.classForName[AnyRef](className)
Review Comment:
`classForName` initializes by default, so an incompatible class can run or fail before this check and bypass the targeted config error.
```suggestion
val cls = Utils.classForName[AnyRef](className, initialize = false)
```
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-59822][UDF] Make the external UDF worker dispatcher factory configurable [spark]
Posted by "haiyangsun-db (via GitHub)" <gi...@apache.org>.
haiyangsun-db commented on code in PR #58859:
URL: https://github.com/apache/spark/pull/58859#discussion_r4141899455
##########
core/src/main/scala/org/apache/spark/internal/config/UDF.scala:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+package org.apache.spark.internal.config
+
+private[spark] object UDF {
+
+ val DISPATCHER_FACTORY = ConfigBuilder("spark.udf.worker.dispatcherFactory")
Review Comment:
After thinking this again, this probably should not be the final state. The ideal case is that custom logic should be wired via the worker spec contract while Spark should offer several generic dispatching options.
In most of cases, Spark should be able to offer the generic dispatching logic by default without needing a custom dispatcher (generalizing what pyspark is doing nowadays). And it's also possible to offer several dispatching options in spark. So this config ideally could be replaced with an enum to choose between few built-in dispatching options rather an arbitrary class.
Directly allow arbitrary code here can make the behavior unpredictable for the engine. And imagine that the factory class is also a special kind of "udf", this won't fit into spark applications that are security-sensitive.
I created a new ticket to follow up on this: https://issues.apache.org/jira/browse/SPARK-59886
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-59822][CORE] Make the external UDF worker dispatcher factory configurable [spark]
Posted by "haiyangsun-db (via GitHub)" <gi...@apache.org>.
haiyangsun-db commented on PR #58859:
URL: https://github.com/apache/spark/pull/58859#issuecomment-5892314458
@HyukjinKwon this PR should be good to go, can you please take a look?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-59822][UDF] Make the external UDF worker dispatcher factory configurable [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon closed pull request #58859: [SPARK-59822][UDF] Make the external UDF worker dispatcher factory configurable
URL: https://github.com/apache/spark/pull/58859
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-59822][UDF] Make the external UDF worker dispatcher factory configurable [spark]
Posted by "haiyangsun-db (via GitHub)" <gi...@apache.org>.
haiyangsun-db commented on code in PR #58859:
URL: https://github.com/apache/spark/pull/58859#discussion_r4141899455
##########
core/src/main/scala/org/apache/spark/internal/config/UDF.scala:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+package org.apache.spark.internal.config
+
+private[spark] object UDF {
+
+ val DISPATCHER_FACTORY = ConfigBuilder("spark.udf.worker.dispatcherFactory")
Review Comment:
After thinking this again, this probably should not be the final state. The ideal case is that custom logic should be wired via the worker spec contract.
In most of cases, Spark should be able to offer the generic dispatching logic by default without needing a custom dispatcher (generalizing what pyspark is doing nowadays). And it's also possible to offer several dispatching options in spark. So this config ideally could be replaced with an enum to choose between few built-in dispatching options rather an arbitrary class.
Directly allow arbitrary custom logic here can make the behavior unpredictable for the engine.
I created a new ticket to follow up on this: https://issues.apache.org/jira/browse/SPARK-59886
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-59822][UDF] Make the external UDF worker dispatcher factory configurable [spark]
Posted by "haiyangsun-db (via GitHub)" <gi...@apache.org>.
haiyangsun-db commented on code in PR #58859:
URL: https://github.com/apache/spark/pull/58859#discussion_r4141899455
##########
core/src/main/scala/org/apache/spark/internal/config/UDF.scala:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+package org.apache.spark.internal.config
+
+private[spark] object UDF {
+
+ val DISPATCHER_FACTORY = ConfigBuilder("spark.udf.worker.dispatcherFactory")
Review Comment:
After thinking this again, this probably should not be the final state. The ideal case is that custom logic should be wired via the worker spec contract.
In most of cases, Spark should be able to offer the generic dispatching logic by default without needing a custom dispatcher (generalizing what pyspark is doing nowadays). And it's also possible to offer several dispatching options directly. So this config ideally could be an enum for few built-in dispatching options rather an arbitrary class.
Directly allow arbitrary custom logic here can make the behavior unpredictable for the engine.
I created a new ticket to follow up on this: https://issues.apache.org/jira/browse/SPARK-59886
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-59822][UDF] Make the external UDF worker dispatcher factory configurable [spark]
Posted by "zozo123 (via GitHub)" <gi...@apache.org>.
zozo123 commented on code in PR #58859:
URL: https://github.com/apache/spark/pull/58859#discussion_r4142818148
##########
core/src/main/scala/org/apache/spark/internal/config/UDF.scala:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+package org.apache.spark.internal.config
+
+private[spark] object UDF {
+
+ val DISPATCHER_FACTORY = ConfigBuilder("spark.udf.worker.dispatcherFactory")
Review Comment:
Agreed — I followed up in #59153. The PR removes the arbitrary factory-class setting and keeps dispatch Spark-owned. One refinement is that `UDFWorkerSpecification.worker` already generates a closed `WorkerCase` enum, so Spark routes from that instead of adding a second enum config that could disagree with the specification. `DIRECT` maps only to a hard-coded Spark factory; worker-specific behavior remains in the specification and outside the Spark JVM. I also outlined generic provisioned/indirect workers as a separate follow-up rather than adding backend-specific APIs here. Thank you for reconsidering the boundary.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-55278][CORE] Make the external UDF worker dispatcher factory configurable [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #58859:
URL: https://github.com/apache/spark/pull/58859#issuecomment-5861632749
cc @haiyangsun-db
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org