lisancao commented on code in PR #59778:
URL: https://github.com/apache/spark/pull/59778#discussion_r4516982638
##########
sql/connect/server/src/main/scala/org/apache/spark/sql/connect/planner/SparkConnectPlanner.scala:
##########
@@ -2346,12 +2346,68 @@ class SparkConnectPlanner(
name = fun.getFunctionName,
func = function,
dataType = transformDataType(udf.getOutputType),
- pythonEvalType = udf.getEvalType,
+ pythonEvalType = correctPythonEvalType(udf.getEvalType, function),
udfDeterministic = fun.getDeterministic,
// Set only for incremental Python aggregators (see PythonAggregate).
bufferType = if (udf.hasBufferType) transformDataType(udf.getBufferType)
else null)
}
+ /**
+ * Falls back to a regular Python UDF when the Python that runs an
Arrow-optimized one cannot
+ * run it, as a Python client does before it creates the UDF, see
`_create_py_udf` in
+ * `pyspark.sql.udf`. A Spark Connect client checks its own Python rather
than the one that runs
+ * the UDF, so the server checks again. It checks once per session for each
Python executable,
+ * environment and pandas requirement, and keeps the UDF Arrow-optimized if
the check cannot
+ * run.
+ */
+ private def correctPythonEvalType(evalType: Int, function:
SimplePythonFunction): Int = {
+ if (evalType == PythonEvalType.SQL_ARROW_BATCHED_UDF) {
Review Comment:
Thanks, this is a real gap. A default `@udtf` still fails with
`[PACKAGE_NOT_INSTALLED]` on a server built from this branch (reproduced on the
4.2.0 image), so the two Arrow-by-default function kinds do behave differently
there for now.
I'd like to keep this PR to Python UDFs so it stays reviewable, and handle
UDTFs separately: I filed SPARK-60828 for the UDTF fallback
(`SQL_ARROW_TABLE_UDF` to `SQL_TABLE_UDF`, with pandas required only under
`spark.sql.legacy.execution.pythonUDTF.pandas.conversion.enabled`), and I'll
open the fix for it once this one lands. It will make the decision at the same
point this PR ends up making it, so if the UDF fallback moves to the executors
(the other P2 here), the UDTF change follows it rather than adding a second set
of semantics.
--
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]