[
https://issues.apache.org/jira/browse/SPARK-60096?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Ivan Sadikov updated SPARK-60096:
---------------------------------
Description:
Spark Connect turns DataFrame subqueries such as `col.isin(df)`, `df.scalar()`,
`df.exists()`, and table arguments into `UnresolvedPlanId` expressions
(`UnresolvedInSubqueryPlanId`, `UnresolvedScalarSubqueryPlanId`,
`UnresolvedExistsPlanId`, `UnresolvedTableArgPlanId`). These expressions point
to the subquery plan by plan id. Only
`SparkConnectPlanner.transformWithRelations` replaces them with the real plan,
and it only does so when the root relation is wrapped in a `WithRelations` that
contains the referenced plan.
If the referenced plan is never attached (for example, the root relation is not
wrapped in `WithRelations`), the `UnresolvedPlanId` stays in the tree through
analysis. No analyzer rule resolves it, and CheckAnalysis has no specific case
for it. It therefore reaches the generic unresolved-operator check and fails
with an internal error:
{code:java}
[INTERNAL_ERROR] Found the unresolved operator: ... SQLSTATE: XX000 {code}
This is a resolution error caused by an illegal subquery reference, not a Spark
bug. It should be reported the same way as the existing
`CANNOT_RESOLVE_DATAFRAME_COLUMN` error, which is raised for an illegal
DataFrame column reference.
Valid queries are not affected. The only change is the error class and SQLSTATE
for queries that already fail.
was:
Spark Connect turns DataFrame subqueries such as `col.isin(df)`, `df.scalar()`,
`df.exists()`, and table arguments into `UnresolvedPlanId` expressions
(`UnresolvedInSubqueryPlanId`,
`UnresolvedScalarSubqueryPlanId`, `UnresolvedExistsPlanId`,
`UnresolvedTableArgPlanId`). These
expressions point to the subquery plan by plan id. Only
`SparkConnectPlanner.transformWithRelations`
replaces them with the real plan, and it only does so when the root relation
is wrapped in a
`WithRelations` that contains the referenced plan.
If the referenced plan is never attached (for example, the root relation is
not wrapped in
`WithRelations`), the `UnresolvedPlanId` stays in the tree through analysis.
No analyzer rule
resolves it, and CheckAnalysis has no specific case for it. It therefore
reaches the generic
unresolved-operator check and fails with an internal error:
[INTERNAL_ERROR] Found the unresolved operator: ... SQLSTATE: XX000
This is a resolution error caused by an illegal subquery reference, not a
Spark bug. It should
be reported the same way as the existing `CANNOT_RESOLVE_DATAFRAME_COLUMN`
error, which is raised
for an illegal DataFrame column reference.
Proposed change:
- Add a new error condition `CANNOT_RESOLVE_DATAFRAME_SUBQUERY` (SQLSTATE
42704):
"Cannot resolve the DataFrame subquery referenced by plan id <planId>. It's
probably because of
an illegal subquery reference, such as using a subquery DataFrame that is
not part of the
current query."
- In `CheckAnalysis.checkAnalysis0`, match `UnresolvedPlanId` in the
expression-level checks and
throw this `AnalysisException`, with the expression's origin, instead of
the generic
INTERNAL_ERROR.
- Add a test to `SparkConnectProtoSuite`: build an IN-subquery with a plan id
that is not
attached, nested inside `when(...)`. Check that the planner leaves an
`UnresolvedInSubqueryPlanId` in the plan and that analysis now fails with
`CANNOT_RESOLVE_DATAFRAME_SUBQUERY`.
Valid queries are not affected. The only change is the error class and
SQLSTATE for queries
that already fail.
> Raise a user-facing error instead of INTERNAL_ERROR for an unresolved Spark
> Connect DataFrame subquery plan id
> --------------------------------------------------------------------------------------------------------------
>
> Key: SPARK-60096
> URL: https://issues.apache.org/jira/browse/SPARK-60096
> Project: Spark
> Issue Type: Improvement
> Components: Connect, SQL
> Affects Versions: 4.3.0
> Reporter: Ivan Sadikov
> Priority: Major
>
> Spark Connect turns DataFrame subqueries such as `col.isin(df)`,
> `df.scalar()`, `df.exists()`, and table arguments into `UnresolvedPlanId`
> expressions (`UnresolvedInSubqueryPlanId`, `UnresolvedScalarSubqueryPlanId`,
> `UnresolvedExistsPlanId`, `UnresolvedTableArgPlanId`). These expressions
> point to the subquery plan by plan id. Only
> `SparkConnectPlanner.transformWithRelations` replaces them with the real
> plan, and it only does so when the root relation is wrapped in a
> `WithRelations` that contains the referenced plan.
> If the referenced plan is never attached (for example, the root relation is
> not wrapped in `WithRelations`), the `UnresolvedPlanId` stays in the tree
> through analysis. No analyzer rule resolves it, and CheckAnalysis has no
> specific case for it. It therefore reaches the generic unresolved-operator
> check and fails with an internal error:
> {code:java}
> [INTERNAL_ERROR] Found the unresolved operator: ... SQLSTATE: XX000 {code}
> This is a resolution error caused by an illegal subquery reference, not a
> Spark bug. It should be reported the same way as the existing
> `CANNOT_RESOLVE_DATAFRAME_COLUMN` error, which is raised for an illegal
> DataFrame column reference.
>
> Valid queries are not affected. The only change is the error class and
> SQLSTATE for queries that already fail.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]