Max Gekk created SPARK-57759:
--------------------------------

             Summary: Function resolution masks FORBIDDEN_OPERATION as 
UNRESOLVED_ROUTINE
                 Key: SPARK-57759
                 URL: https://issues.apache.org/jira/browse/SPARK-57759
             Project: Spark
          Issue Type: Improvement
          Components: SQL
    Affects Versions: 4.3.0
            Reporter: Max Gekk


h2. Summary

During function/table-function/procedure resolution, {{FunctionResolution}} 
catches
{{AnalysisException}} whose condition is {{FORBIDDEN_OPERATION}} and treats it 
as a
"not found" miss, continuing to the next candidate in the search path. When no 
later
candidate resolves, the user sees {{UNRESOLVED_ROUTINE}} instead of the genuine
permission/forbidden-operation error. This can hide the real cause (e.g. a 
catalog
denying access to a function) and report the routine as non-existent.

h2. Where

In 
{{sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionResolution.scala}}:

* {{resolveFunctionCandidate}}:
{code:scala}
case e: AnalysisException if e.getCondition == "FORBIDDEN_OPERATION" =>
  None
{code}
* {{resolveTableFunctionCandidate}}: same {{FORBIDDEN_OPERATION -> None}} catch.
* {{tryRethrowNotTableFunction}}: same condition swallowed.
* {{lookupFunctionType}}: {{FORBIDDEN_OPERATION}} treated as a miss in the 
persistent-candidate loop.
* {{resolveProcedure}}: candidate failures are swallowed for single-part names.

h2. Steps to reproduce

A function exists in an external catalog the user cannot access; the catalog 
throws
{{AnalysisException}} with condition {{FORBIDDEN_OPERATION}} on 
{{loadFunction}} /
{{functionExists}}. Referencing the function by an unqualified or qualified 
name yields:

{noformat}
[UNRESOLVED_ROUTINE] Cannot resolve routine `...` on search path [...]
{noformat}

instead of the underlying forbidden-operation error.

h2. Expected behavior

A genuine {{FORBIDDEN_OPERATION}} error should surface to the user rather than 
being
converted into {{UNRESOLVED_ROUTINE}}. Resolution should only treat true
"does not exist" signals ({{NoSuchFunctionException}}, 
{{NoSuchNamespaceException}},
{{CatalogNotFoundException}}) as a miss.

h2. Notes

* For single-part (unqualified) names searched across a multi-entry path, there 
is a
  tension: a {{FORBIDDEN_OPERATION}} from one catalog should arguably not abort 
the
  search if a later path entry can legitimately resolve the name. The fix 
should decide
  between (a) always propagating {{FORBIDDEN_OPERATION}}, or (b) propagating it 
only when
  no other candidate resolves (defer-and-rethrow). Option (b) preserves 
path-search
  semantics while still surfacing the real error when resolution ultimately 
fails.
* Discovered while investigating SPARK-57758; the swallowing predates that 
change.

h2. Component / Type

* Component: SQL
* Type: Bug



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to