This is an automated email from the ASF dual-hosted git repository.
dongjoon-hyun pushed a commit to branch branch-4.x
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-4.x by this push:
new 92dce791b3f5 [SPARK-61553][SQL] Fix CALL silently doing nothing when
`ProcedureCatalog.loadProcedure` returns null
92dce791b3f5 is described below
commit 92dce791b3f5fa8a5355de4e0cd225d9a8fddd2f
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Thu Nov 12 23:36:21 2026 -0800
[SPARK-61553][SQL] Fix CALL silently doing nothing when
`ProcedureCatalog.loadProcedure` returns null
### What changes were proposed in this pull request?
This PR aims to fix `FunctionResolution.resolveProcedure` to treat `null`
from `ProcedureCatalog.loadProcedure` as a procedure that is not found, instead
of resolving the name to `ResolvedProcedure(catalog, ident, null)`.
- An unqualified name moves on to the next entry of the SQL path, as it
does when `loadProcedure` throws.
- A qualified name fails with the existing `UNRESOLVED_ROUTINE` error.
### Why are the changes needed?
`ProcedureCatalog.loadProcedure` does not specify what happens when the
procedure does not exist. When a connector returns `null` instead of throwing,
the analyzer keeps the `null` procedure.
- `BindProcedures` skips it because its type pattern does not match `null`,
and `CheckAnalysis` checks only a bound `CALL`. So `CALL cat.ns.missing()`
passes the analysis and invokes nothing. An action on the result fails with an
`UnsupportedOperationException` without a message from
`ExplainOnlySparkPlan.doExecute`.
- For an unqualified name, the search stops at the first path entry whose
catalog returns `null`, so a procedure in a later path entry is never found.
- `DESC PROCEDURE cat.ns.missing` fails with `INTERNAL_ERROR` (`Invalid
procedure identifier`).
This PR keeps the `ProcedureCatalog` API as it is. Spark has no
procedure-specific not-found exception, and existing connectors such as Apache
Iceberg's `BaseCatalog` throw an exception for an unknown procedure. So this is
a defensive fix in the analyzer.
### Does this PR introduce _any_ user-facing change?
Yes, only for a connector whose `loadProcedure` returns `null` for an
unknown procedure. Connectors that throw an exception are not affected.
| Statement | BEFORE | AFTER |
|---|---|---|
| `CALL cat.ns.missing()` | No error, nothing is invoked, and an action
fails with `UnsupportedOperationException` | `UNRESOLVED_ROUTINE` |
| `CALL sum(1, 2)` after `SET PATH = cat.ns_miss, cat2.ns_hit` | Stops at
`cat.ns_miss`, and an action fails with `UnsupportedOperationException` |
Invokes `cat2.ns_hit.sum` |
| `DESC PROCEDURE cat.ns.missing` | `INTERNAL_ERROR` | `UNRESOLVED_ROUTINE`
|
### How was this patch tested?
Pass the CIs with the newly added test case in `ProcedureSuite`. It uses a
test catalog whose `loadProcedure` returns `null` for an unknown procedure, and
fails without this patch.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5
Closes #60396 from dongjoon-hyun/SPARK-61553.
Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
(cherry picked from commit 0313df6ce1b6f186153cce02dfdd1dd6edbae14e)
Signed-off-by: Dongjoon Hyun <[email protected]>
skip-checks: true
---
.../sql/catalyst/analysis/FunctionResolution.scala | 6 +++-
.../spark/sql/connector/ProcedureSuite.scala | 36 ++++++++++++++++++++++
2 files changed, 41 insertions(+), 1 deletion(-)
diff --git
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionResolution.scala
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionResolution.scala
index 1ac3c093eb4a..f50707c0b08b 100644
---
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionResolution.scala
+++
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionResolution.scala
@@ -873,7 +873,11 @@ class FunctionResolution(
case pc: ProcedureCatalog =>
try {
val procedure = pc.loadProcedure(ident)
- return ResolvedProcedure(pc, ident, procedure)
+ // A null means the catalog has no such procedure. Treat it as
a miss, so an
+ // unqualified name keeps searching PATH and a qualified one
fails as unresolved.
+ if (procedure != null) {
+ return ResolvedProcedure(pc, ident, procedure)
+ }
} catch {
// ProcedureCatalog has no standard "not found" exception type
today. For
// unqualified names searched through PATH, treat candidate
failures as misses and
diff --git
a/sql/core/src/test/scala/org/apache/spark/sql/connector/ProcedureSuite.scala
b/sql/core/src/test/scala/org/apache/spark/sql/connector/ProcedureSuite.scala
index 5ca66a0d8feb..b1a77711b2ea 100644
---
a/sql/core/src/test/scala/org/apache/spark/sql/connector/ProcedureSuite.scala
+++
b/sql/core/src/test/scala/org/apache/spark/sql/connector/ProcedureSuite.scala
@@ -254,6 +254,37 @@ class ProcedureSuite extends SharedSparkSession with
BeforeAndAfter {
}
}
+ test("SPARK-61553: a null from loadProcedure means the procedure is not
found") {
+ withSQLConf("spark.sql.catalog.nullcat" ->
classOf[NullReturningProcedureCatalog].getName) {
+ checkError(
+ exception = intercept[AnalysisException](sql("CALL
nullcat.ns.missing()")),
+ condition = "UNRESOLVED_ROUTINE",
+ parameters = Map(
+ "routineName" -> "`nullcat`.`ns`.`missing`",
+ "searchPath" -> "[`system`.`builtin`, `system`.`session`,
`spark_catalog`.`default`]"),
+ context = ExpectedContext(fragment = "CALL nullcat.ns.missing()",
start = 0, stop = 24))
+
+ checkError(
+ exception = intercept[AnalysisException](sql("DESC PROCEDURE
nullcat.ns.missing")),
+ condition = "UNRESOLVED_ROUTINE",
+ parameters = Map(
+ "routineName" -> "`nullcat`.`ns`.`missing`",
+ "searchPath" -> "[`system`.`builtin`, `system`.`session`,
`spark_catalog`.`default`]"),
+ context = ExpectedContext(
+ fragment = "DESC PROCEDURE nullcat.ns.missing", start = 0, stop =
32))
+
+ withSQLConf(SQLConf.PATH_ENABLED.key -> "true") {
+ try {
+ catalog("cat2").createProcedure(Identifier.of(Array("ns_hit"),
"sum"), UnboundLongSum)
+ sql("SET PATH = nullcat.ns_miss, cat2.ns_hit")
+ checkAnswer(sql("CALL sum(1, 2)"), Row(3L) :: Nil)
+ } finally {
+ sql("SET PATH = DEFAULT_PATH")
+ }
+ }
+ }
+ }
+
test("required parameter not found") {
catalog.createProcedure(Identifier.of(Array("ns"), "sum"), UnboundSum)
checkError(
@@ -1001,3 +1032,8 @@ class ProcedureSuite extends SharedSparkSession with
BeforeAndAfter {
override def call(input: InternalRow): java.util.Iterator[Scan] =
Collections.emptyIterator
}
}
+
+/** A procedure catalog that returns null for an unknown procedure instead of
throwing. */
+class NullReturningProcedureCatalog extends InMemoryCatalog {
+ override def loadProcedure(ident: Identifier): UnboundProcedure =
procedures.get(ident)
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]