viirya commented on code in PR #60473:
URL: https://github.com/apache/spark/pull/60473#discussion_r4570214505
##########
sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/InvokeProcedures.scala:
##########
@@ -46,6 +46,14 @@ class InvokeProcedures(session: SparkSession) extends
Rule[LogicalPlan] {
session.sessionState.optimizer.execute(c) match {
case Call(ResolvedProcedure(_, _, procedure: BoundProcedure), args, _)
=>
invoke(procedure, args, c)
+ case Call(_, args, _) =>
+ // A rule such as `ExtractPythonUDFs` can add an operator under the
`Call` to evaluate an
+ // argument. Such an argument reads the output of that operator and
does not fold.
+ c.procedure match {
Review Comment:
If #60392 lands after this without a rebase, there is no textual conflict,
but this match throws a `MatchError`: `bound` becomes
`isInstanceOf[ResolvedBoundProcedure]` while this still matches
`ResolvedProcedure`. Taking the procedure from `c` once, before the optimizer
runs, leaves one place to update and merges the two `internalError` branches:
```scala
val procedure = c.procedure match { case ResolvedProcedure(_, _, p:
BoundProcedure) => p }
session.sessionState.optimizer.execute(c) match {
case Call(_: ResolvedProcedure, args, _) => invoke(procedure, args, c)
case optimized =>
optimized match {
case Call(_, args, _) => checkFoldable(procedure, args)
case _ =>
}
throw SparkException.internalError("Unexpected plan for optimized CALL
statement")
}
```
Could the comment also say why it still throws when every argument folds?
##########
sql/core/src/test/scala/org/apache/spark/sql/connector/ProcedureSuite.scala:
##########
@@ -111,6 +111,21 @@ class ProcedureSuite extends SharedSparkSession with
BeforeAndAfter {
"paramType" -> toSQLType("INT")))
}
+ test("SPARK-61669: an argument evaluated by an operator under the CALL") {
Review Comment:
The Python UDF case in the title and the `INTERNAL_ERROR` fallback aren't
covered. Both are cheap to test:
- Python UDF: `assume(shouldTestPythonUDFs)` with `TestPythonUDF`, as in
`JoinSuite`.
- Fallback: an extra optimizer rule
(`spark.experimental.extraOptimizations`) that rewrites `Call(p:
ResolvedProcedure, ...)` to put `Project(p.output, p)` under it, then `CALL
cat.ns.sum(1, 2)`.
Nit: since this is the nested variant of SPARK-61656, it would read better
right after that test.
--
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]