[SPARK-53273][CONNECT][SQL] Make RegisterUserDefinedFunction in SparkConnectPlanner side effect free #52026
+147
−26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
This PR refactors the
RegisterUserDefinedFunction
handling inSparkConnectPlanner
to make it side effect free by converting it from a direct execution approach to a logical plan transformation approach. The key changes include:Created new command classes for UDF registration:
RegisterJavaUDAFCommand
- for Java UDAF registrationRegisterJavaUDFCommand
- for Java UDF registrationRegisterPythonUDFCommand
- for Python UDF registrationRegisterScalaUDFCommand
- for Scala UDF registrationRefactored
SparkConnectPlanner
:transformCommand()
to handleREGISTER_FUNCTION
case and return a logical plan transformerhandleRegisterUserDefinedFunction()
withtransformRegisterUserDefinedFunction()
that returnsLogicalPlan
instead of executing side effectsWhy are the changes needed?
The current implementation of
RegisterUserDefinedFunction
inSparkConnectPlanner
directly executes side effects during the planning phase, which violates the principle that planners should be side effect free. This makes the code harder to test, reason about, and maintain.Does this PR introduce any user-facing change?
No - This is an internal refactoring that maintains the same external behavior. Users will not see any changes in how UDF registration works from their perspective.
How was this patch tested?
build/sbt "connect-client-jvm/testOnly *ClientE2ETestSuite"
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Cursor 1.4.3