-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-31620][SQL] Fix reference binding failure in case of an final agg contains subquery #28496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
ba75e36
4dcc1b1
bc1b7e5
cbd891d
882467b
9a0b788
3fd39c5
64d13fc
89ae4bf
8aecd57
493157a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,7 +123,7 @@ case class ObjectHashAggregateExec( | |
| resultExpressions, | ||
| (expressions, inputSchema) => | ||
| MutableProjection.create(expressions, inputSchema), | ||
| child.output, | ||
| inputAttributes, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's actually another
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can open a new PR to remove dead code
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok.. |
||
| iter, | ||
| fallbackCountThreshold, | ||
| numOutputRows) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -973,4 +973,39 @@ class DataFrameAggregateSuite extends QueryTest | |
| assert(error.message.contains("function count_if requires boolean type")) | ||
| } | ||
| } | ||
|
|
||
| Seq(true, false).foreach { value => | ||
| test(s"SPARK-31620: agg with subquery (whole-stage-codegen = $value)") { | ||
| withSQLConf(SQLConf.WHOLESTAGE_CODEGEN_ENABLED.key -> value.toString) { | ||
| withTempView("t1", "t2") { | ||
| sql("create temporary view t1 as select * from values (1, 2) as t1(a, b)") | ||
| sql("create temporary view t2 as select * from values (3, 4) as t2(c, d)") | ||
|
|
||
| // test without grouping keys | ||
| checkAnswer(sql("select sum(if(c > (select a from t1), d, 0)) as csum from t2"), | ||
| Row(4) :: Nil) | ||
|
|
||
| // test with grouping keys | ||
| checkAnswer(sql("select c, sum(if(c > (select a from t1), d, 0)) as csum from " + | ||
| "t2 group by c"), Row(3, 4) :: Nil) | ||
|
|
||
| // test with distinct | ||
| checkAnswer(sql("select avg(distinct(d)), sum(distinct(if(c > (select a from t1)," + | ||
| " d, 0))) as csum from t2 group by c"), Row(4, 4) :: Nil) | ||
|
|
||
| // test subquery with agg | ||
| checkAnswer(sql("select sum(distinct(if(c > (select sum(distinct(a)) from t1)," + | ||
| " d, 0))) as csum from t2 group by c"), Row(4) :: Nil) | ||
|
|
||
| // test SortAggregateExec | ||
| checkAnswer(sql("select max(if(c > (select a from t1), 'str1', 'str2')) as csum from t2"), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's better to check the physical plan and make sure it's sort agg |
||
| Row("str1") :: Nil) | ||
|
|
||
| // test ObjectHashAggregateExec | ||
|
cloud-fan marked this conversation as resolved.
|
||
| checkAnswer(sql("select collect_list(d), sum(if(c > (select a from t1), d, 0)) as csum" + | ||
| " from t2"), Row(Array(4), 4) :: Nil) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I try to fix like this before, but I forgot to change child's output here then output column can't work well.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your confirm.