anuragmantri commented on code in PR #60392:
URL: https://github.com/apache/spark/pull/60392#discussion_r4566661645
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/v2ResolutionPlans.scala:
##########
@@ -226,6 +226,19 @@ case class ResolvedProcedure(
override def output: Seq[Attribute] = Nil
}
+/**
+ * A procedure that `BindProcedures` has bound to the arguments of a CALL, or
accepted as already
+ * bound, with the arguments rearranged to match its parameters. It is a
separate node from
+ * [[ResolvedProcedure]] because a procedure may implement both
`UnboundProcedure` and
+ * `BoundProcedure`, so its type does not show whether it was bound.
+ */
+case class ResolvedBoundProcedure(
Review Comment:
Agreed, thanks for the correction. Each backport's description will keep the
paragraph for extensions.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2Commands.scala:
##########
@@ -2408,8 +2412,9 @@ case class Call(
override def simpleString(maxFields: Int): String = {
procedure match {
case ResolvedProcedure(catalog, ident, _) =>
- val name = s"${quoteIfNeeded(catalog.name)}.${ident.quoted}"
- simpleString(name, maxFields)
+ simpleString(V2TableUtil.toQualifiedName(catalog, ident), maxFields)
+ case ResolvedBoundProcedure(catalog, ident, _) =>
Review Comment:
Done, with a small sealed `ProcedureReference` trait.
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/procedures/UnboundProcedure.java:
##########
@@ -41,6 +41,11 @@ public interface UnboundProcedure extends Procedure {
* set to {@code true}. In such cases, the field name will match the name of
the target procedure
* parameter. If the argument is not named, {@link
ProcedureParameter#BY_NAME_METADATA_KEY} will
* not be set and the name will be assigned randomly.
+ * <p>
+ * When analyzing a CALL statement, Spark calls this method once, after all
arguments are
Review Comment:
Done.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala:
##########
@@ -1007,6 +1007,10 @@ trait CheckAnalysis extends LookupCatalog with
QueryErrorsBase with PlanToString
throw SparkException.internalError("Invalid input for
procedure")
}
+ case c: Call if c.resolved && !c.bound =>
Review Comment:
Done.
##########
sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/InvokeProcedures.scala:
##########
@@ -40,7 +40,7 @@ class InvokeProcedures(session: SparkSession) extends
Rule[LogicalPlan] {
private def invokeProcedures(plan: LogicalPlan): LogicalPlan = plan
resolveOperators {
case c: Call if c.resolved && c.bound && c.execute &&
c.checkArgTypes().isSuccess =>
session.sessionState.optimizer.execute(c) match {
- case Call(ResolvedProcedure(_, _, procedure: BoundProcedure), args, _)
=>
+ case Call(ResolvedBoundProcedure(_, _, procedure), args, _) =>
Review Comment:
Agreed. I'll fix this in a follow-up JIRA.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/PullOutNondeterministic.scala:
##########
@@ -36,6 +36,8 @@ object PullOutNondeterministic extends Rule[LogicalPlan] {
case p if !p.resolved => p // Skip unresolved nodes.
case p: Project => p
case f: Filter => f
+ // A CALL must keep its procedure as its child, which `Call.bound` and
`checkArgTypes` read.
+ case c: Call => c
Review Comment:
Will do, in a separate JIRA.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala:
##########
@@ -2644,18 +2644,25 @@ class Analyzer(
}
/**
- * A rule that binds procedures to the input types and rearranges arguments
as needed.
+ * A rule that binds procedures to the input types and rearranges arguments
as needed, and
+ * records the bound procedure in a [[ResolvedBoundProcedure]].
*/
object BindProcedures extends Rule[LogicalPlan] {
def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators {
- case Call(ResolvedProcedure(catalog, ident, unbound: UnboundProcedure),
args, execute)
+ case c @ Call(ResolvedProcedure(catalog, ident, procedure), args, _)
if args.forall(_.resolved) =>
- val inputType = extractInputType(args)
- val bound = unbound.bind(inputType)
- validateParameterModes(bound)
+ val boundProcedure = procedure match {
+ case unbound: UnboundProcedure =>
unbound.bind(extractInputType(args))
+ case bound: BoundProcedure => bound
Review Comment:
You're right, master didn't bind it. Rejecting those is intended, as for
other procedures. Added an `INOUT` test row and a sentence to the description.
--
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]