Skip to content

Conversation

@peter-toth
Copy link
Contributor

What changes were proposed in this pull request?

Unfortunately #32298 introduced a regression from Spark 3.2 to 3.3 as after that change a merged subquery can contain multiple distict type aggregates. Those aggregates need to be rewritten by the RewriteDistinctAggregates rule to get the correct results. This PR fixed that.

Why are the changes needed?

The following query:

SELECT
  (SELECT count(distinct c1) FROM t1),
  (SELECT count(distinct c2) FROM t1)

currently fails with:

java.lang.IllegalStateException: You hit a query analyzer bug. Please report your query to Spark user mailing list.
	at org.apache.spark.sql.execution.SparkStrategies$Aggregation$.apply(SparkStrategies.scala:538)

but works again after this PR.

Does this PR introduce any user-facing change?

Yes, the above query works again.

How was this patch tested?

Added new UT.

@github-actions github-actions bot added the SQL label Feb 5, 2023
@peter-toth
Copy link
Contributor Author

cc @cloud-fan, @viirya, @wangyum

@RobinL
Copy link

RobinL commented Feb 5, 2023

Thanks so much @peter-toth! Amazing to have a fix so quickly

@wangyum wangyum closed this in 5940b98 Feb 6, 2023
@cloud-fan
Copy link
Contributor

late LGTM

wangyum pushed a commit that referenced this pull request Feb 6, 2023
### What changes were proposed in this pull request?

Unfortunately #32298 introduced a regression from Spark 3.2 to 3.3 as after that change a merged subquery can contain multiple distict type aggregates. Those aggregates need to be rewritten by the `RewriteDistinctAggregates` rule to get the correct results. This PR fixed that.

### Why are the changes needed?
The following query:
```
SELECT
  (SELECT count(distinct c1) FROM t1),
  (SELECT count(distinct c2) FROM t1)
```
currently fails with:
```
java.lang.IllegalStateException: You hit a query analyzer bug. Please report your query to Spark user mailing list.
	at org.apache.spark.sql.execution.SparkStrategies$Aggregation$.apply(SparkStrategies.scala:538)
```
but works again after this PR.

### Does this PR introduce _any_ user-facing change?
Yes, the above query works again.

### How was this patch tested?
Added new UT.

Closes #39887 from peter-toth/SPARK-42346-rewrite-distinct-aggregates-after-subquery-merge.

Authored-by: Peter Toth <[email protected]>
Signed-off-by: Yuming Wang <[email protected]>
(cherry picked from commit 5940b98)
Signed-off-by: Yuming Wang <[email protected]>
wangyum pushed a commit that referenced this pull request Feb 6, 2023
### What changes were proposed in this pull request?

Unfortunately #32298 introduced a regression from Spark 3.2 to 3.3 as after that change a merged subquery can contain multiple distict type aggregates. Those aggregates need to be rewritten by the `RewriteDistinctAggregates` rule to get the correct results. This PR fixed that.

### Why are the changes needed?
The following query:
```
SELECT
  (SELECT count(distinct c1) FROM t1),
  (SELECT count(distinct c2) FROM t1)
```
currently fails with:
```
java.lang.IllegalStateException: You hit a query analyzer bug. Please report your query to Spark user mailing list.
	at org.apache.spark.sql.execution.SparkStrategies$Aggregation$.apply(SparkStrategies.scala:538)
```
but works again after this PR.

### Does this PR introduce _any_ user-facing change?
Yes, the above query works again.

### How was this patch tested?
Added new UT.

Closes #39887 from peter-toth/SPARK-42346-rewrite-distinct-aggregates-after-subquery-merge.

Authored-by: Peter Toth <[email protected]>
Signed-off-by: Yuming Wang <[email protected]>
(cherry picked from commit 5940b98)
Signed-off-by: Yuming Wang <[email protected]>
@wangyum
Copy link
Member

wangyum commented Feb 6, 2023

Merged to master, branch-3.4 and branch-3.3.

@peter-toth
Copy link
Contributor Author

Thanks for the review!

snmvaughan pushed a commit to snmvaughan/spark that referenced this pull request Jun 20, 2023
### What changes were proposed in this pull request?

Unfortunately apache#32298 introduced a regression from Spark 3.2 to 3.3 as after that change a merged subquery can contain multiple distict type aggregates. Those aggregates need to be rewritten by the `RewriteDistinctAggregates` rule to get the correct results. This PR fixed that.

### Why are the changes needed?
The following query:
```
SELECT
  (SELECT count(distinct c1) FROM t1),
  (SELECT count(distinct c2) FROM t1)
```
currently fails with:
```
java.lang.IllegalStateException: You hit a query analyzer bug. Please report your query to Spark user mailing list.
	at org.apache.spark.sql.execution.SparkStrategies$Aggregation$.apply(SparkStrategies.scala:538)
```
but works again after this PR.

### Does this PR introduce _any_ user-facing change?
Yes, the above query works again.

### How was this patch tested?
Added new UT.

Closes apache#39887 from peter-toth/SPARK-42346-rewrite-distinct-aggregates-after-subquery-merge.

Authored-by: Peter Toth <[email protected]>
Signed-off-by: Yuming Wang <[email protected]>
(cherry picked from commit 5940b98)
Signed-off-by: Yuming Wang <[email protected]>
Sign up for free to 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.

5 participants