Skip to content

[SPARK-45584][SQL] Fix subquery execution failure with TakeOrderedAndProjectExec - #43419

Closed
allisonwang-db wants to merge 2 commits into
apache:masterfrom
allisonwang-db:spark-45584-subquery-failure
Closed

[SPARK-45584][SQL] Fix subquery execution failure with TakeOrderedAndProjectExec#43419
allisonwang-db wants to merge 2 commits into
apache:masterfrom
allisonwang-db:spark-45584-subquery-failure

Conversation

@allisonwang-db

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR fixes a bug when there are subqueries in TakeOrderedAndProjectExec. The executeCollect method does not wait for subqueries to finish and it can result in IllegalArgumentException when executing a simple query.
For example this query:

WITH t2 AS (
SELECT * FROM t1 ORDER BY id
)
SELECT *, (SELECT COUNT(*) FROM t2) FROM t2 LIMIT 10

will fail with this error

 java.lang.IllegalArgumentException: requirement failed: Subquery subquery#242, [id=#109] has not finished

Why are the changes needed?

To fix a bug.

Does this PR introduce any user-facing change?

No

How was this patch tested?

New unit test

Was this patch authored or co-authored using generative AI tooling?

No

@allisonwang-db

Copy link
Copy Markdown
ContributorAuthor

cc @cloud-fan

}
}

private def prepareAndWaitForSubqueries(): Unit = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of adding this method, shall we just call executeQuery in executeCollect?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sg. Just want to make sure RDDOperationScope.withScope does not any side effect right?

@cloud-fancloud-fanOct 18, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same with this one, plus some tracking logic

@@ -283,6 +283,8 @@ case class TakeOrderedAndProjectExec(
}

override def executeCollect(): Array[InternalRow] = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
overridedefexecuteCollect():Array[InternalRow] = {
overridedefexecuteCollect():Array[InternalRow] =executeQuery {

@cloud-fan

Copy link
Copy Markdown
Contributor

thanks, merging to master/3.5!

cloud-fan pushed a commit that referenced this pull request Oct 20, 2023
…ProjectExec
This PR fixes a bug when there are subqueries in `TakeOrderedAndProjectExec`. The executeCollect method does not wait for subqueries to finish and it can result in IllegalArgumentException when executing a simple query.
For example this query:
```
WITH t2 AS (
SELECT * FROM t1 ORDER BY id
)
SELECT *, (SELECT COUNT(*) FROM t2) FROM t2 LIMIT 10
```
will fail with this error
```
java.lang.IllegalArgumentException: requirement failed: Subquery subquery#242, [id=#109] has not finished
```
To fix a bug.
No
New unit test
No
Closes#43419 from allisonwang-db/spark-45584-subquery-failure.
Authored-by: allisonwang-db <allison.wang@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit 8fd915f)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>

@belieferbeliefer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM later.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@allisonwang-db@cloud-fan@beliefer