You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "zml1206 (via GitHub)" <gi...@apache.org> on 2023/08/17 09:58:34 UTC

[GitHub] [spark] zml1206 opened a new pull request, #42531: [SPARK-44846][SQL] PushFoldableIntoBranches in complex grouping expressions may cause bi…

zml1206 opened a new pull request, #42531:
URL: https://github.com/apache/spark/pull/42531

   …ndReference error
   
   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'core/src/main/resources/error/README.md'.
   -->
   
   ### What changes were proposed in this pull request?
   When `groupingExpressions` is not all `NamedExpression`, do not trigger `PushFoldableIntoBranches` rule in this node.
   
   
   ### Why are the changes needed?
   When `groupingExpressions` is complex and `aggregateExpressions` has (if / case) branches, it is possible that `groupingExpressions` is no longer a subexpression of `aggregateExpressions` after execute `PushFoldableIntoBranches` rule, Then cause `boundReference` error.
   For example
   ```
   select c*2 as d from
   (select if(b > 1, 1, b) as c from
   (select if(a < 0, 0 ,a) as b from t group by b) t1
   group by c) t2 
   ```
   Before pr
   ```
   == Optimized Logical Plan ==
   Aggregate [if ((_groupingexpression#11 > 1)) 1 else _groupingexpression#11], [if ((_groupingexpression#11 > 1)) 2 else (_groupingexpression#11 * 2) AS d#8]
   +- Project [if ((value#1 < 0)) 0 else value#1 AS _groupingexpression#11]
      +- LocalRelation [value#1]
   ```
   ```
   == Error ==
   Couldn't find _groupingexpression#22 in [if ((_groupingexpression#22 > 1)) 1 else _groupingexpression#22#23]
   java.lang.IllegalStateException: Couldn't find _groupingexpression#22 in [if ((_groupingexpression#22 > 1)) 1 else _groupingexpression#22#23]
   	at org.apache.spark.sql.catalyst.expressions.BindReferences$$anonfun$bindReference$1.applyOrElse(BoundAttribute.scala:80)
   	at org.apache.spark.sql.catalyst.expressions.BindReferences$$anonfun$bindReference$1.applyOrElse(BoundAttribute.scala:73)
   	at org.apache.spark.sql.catalyst.trees.TreeNode.$anonfun$transformDownWithPruning$1(TreeNode.scala:461)
   	at org.apache.spark.sql.catalyst.trees.CurrentOrigin$.withOrigin(origin.scala:76)
   	at org.apache.spark.sql.catalyst.trees.TreeNode.transformDownWithPruning(TreeNode.scala:461)
           ......
   ```
   After pr
   ```
   == Optimized Logical Plan ==
   Aggregate [if ((_groupingexpression#11 > 1)) 1 else _groupingexpression#11], [(if ((_groupingexpression#11 > 1)) 1 else _groupingexpression#11 * 2) AS d#8]
   +- Project [if ((value#1 < 0)) 0 else value#1 AS _groupingexpression#11]
      +- LocalRelation [value#1]
   ```
   ### Does this PR introduce _any_ user-facing change?
   No
   
   
   ### How was this patch tested?
   UT


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] wangyum commented on a diff in pull request #42531: [SPARK-44846][SQL] PushFoldableIntoBranches in complex grouping expressions may cause bi…

Posted by "wangyum (via GitHub)" <gi...@apache.org>.
wangyum commented on code in PR #42531:
URL: https://github.com/apache/spark/pull/42531#discussion_r1297272752


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -644,6 +644,8 @@ object PushFoldableIntoBranches extends Rule[LogicalPlan] {
 
   def apply(plan: LogicalPlan): LogicalPlan = plan.transformWithPruning(
     _.containsAnyPattern(CASE_WHEN, IF), ruleId) {
+    case a @ Aggregate(groupingExpressions, _, _)
+      if !groupingExpressions.forall(_.isInstanceOf[NamedExpression]) => a

Review Comment:
   ```suggestion
       case a: Aggregate if !a.groupingExpressions.forall(_.isInstanceOf[NamedExpression]) => a
   ```
   ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] wangyum commented on a diff in pull request #42531: [SPARK-44846][SQL] PushFoldableIntoBranches in complex grouping expressions may cause bi…

Posted by "wangyum (via GitHub)" <gi...@apache.org>.
wangyum commented on code in PR #42531:
URL: https://github.com/apache/spark/pull/42531#discussion_r1298654837


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/RemoveRedundantAggregates.scala:
##########
@@ -42,11 +42,12 @@ object RemoveRedundantAggregates extends Rule[LogicalPlan] with AliasHelper {
       )
 
       // We might have introduces non-deterministic grouping expression
-      if (newAggregate.groupingExpressions.exists(!_.deterministic)) {
+      val _newAggregate = if (newAggregate.groupingExpressions.exists(!_.deterministic)) {

Review Comment:
   _newAggregate -> pulledOutAggregate?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] zml1206 commented on a diff in pull request #42531: [SPARK-44846][SQL] Pull out complex grouping expressions after remove redundant aggregates

Posted by "zml1206 (via GitHub)" <gi...@apache.org>.
zml1206 commented on code in PR #42531:
URL: https://github.com/apache/spark/pull/42531#discussion_r1302882580


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/RemoveRedundantAggregates.scala:
##########
@@ -42,11 +42,12 @@ object RemoveRedundantAggregates extends Rule[LogicalPlan] with AliasHelper {
       )
 
       // We might have introduces non-deterministic grouping expression

Review Comment:
   
   Thank you, I understand, I will resubmit a PR later.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] zml1206 commented on a diff in pull request #42531: [SPARK-44846][SQL] PushFoldableIntoBranches in complex grouping expressions may cause bi…

Posted by "zml1206 (via GitHub)" <gi...@apache.org>.
zml1206 commented on code in PR #42531:
URL: https://github.com/apache/spark/pull/42531#discussion_r1297935700


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -644,6 +644,8 @@ object PushFoldableIntoBranches extends Rule[LogicalPlan] {
 
   def apply(plan: LogicalPlan): LogicalPlan = plan.transformWithPruning(
     _.containsAnyPattern(CASE_WHEN, IF), ruleId) {
+    case a @ Aggregate(groupingExpressions, _, _)
+      if !groupingExpressions.forall(_.isInstanceOf[NamedExpression]) => a

Review Comment:
   Ok, later I will do something like `PullOutGroupingExpressions` after `RemoveRedundantAggregates` triggers Remove. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] wangyum commented on pull request #42531: [SPARK-44846][SQL] Pull out complex grouping expressions after remove redundant aggregates

Posted by "wangyum (via GitHub)" <gi...@apache.org>.
wangyum commented on PR #42531:
URL: https://github.com/apache/spark/pull/42531#issuecomment-1684698300

   cc @cloud-fan @peter-toth 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] zml1206 commented on a diff in pull request #42531: [SPARK-44846][SQL] Pull out complex grouping expressions after remove redundant aggregates

Posted by "zml1206 (via GitHub)" <gi...@apache.org>.
zml1206 commented on code in PR #42531:
URL: https://github.com/apache/spark/pull/42531#discussion_r1302692984


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/RemoveRedundantAggregates.scala:
##########
@@ -42,11 +42,12 @@ object RemoveRedundantAggregates extends Rule[LogicalPlan] with AliasHelper {
       )
 
       // We might have introduces non-deterministic grouping expression

Review Comment:
   @cloud-fan Thanks. I'm sorry I didn't understand. Before this PR, it will create a `Project` below the `Aggregate` to Pulls out nondeterministic grouping expressions. In this PR, I keep this logic, and create a `Project` below the `Aggregate` to Pulls out complex grouping expressions by rule `PullOutGroupingExpressions`. I do not put the new grouping expressions back to the `Aggregate`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a diff in pull request #42531: [SPARK-44846][SQL] Pull out complex grouping expressions after remove redundant aggregates

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #42531:
URL: https://github.com/apache/spark/pull/42531#discussion_r1302730815


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/RemoveRedundantAggregates.scala:
##########
@@ -42,11 +42,12 @@ object RemoveRedundantAggregates extends Rule[LogicalPlan] with AliasHelper {
       )
 
       // We might have introduces non-deterministic grouping expression

Review Comment:
   let me put it this way: if we can safely remove a distinct-like `Aggregate`, it means we can just turn it into a `Project` (e.g. `case a: Aggregate => Project(a.aggregateExpressions, a.child)`).
   
   The code today is merging the distinct-like `Aggregate` to the upper `Aggregate`, which is problematic and we have to pull something out to a `Project` case by case. This is fragile and this PR just finds another case.
   
   My proposal is to not merge. Just convert the distinct-like `Aggregate` to `Project`, and let other optimizer rules decide if we can merge it or not.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] zml1206 commented on pull request #42531: [SPARK-44846][SQL] Pull out complex grouping expressions after remove redundant aggregates

Posted by "zml1206 (via GitHub)" <gi...@apache.org>.
zml1206 commented on PR #42531:
URL: https://github.com/apache/spark/pull/42531#issuecomment-1684689815

   > Could you update the PR title and PR description?
   
   Done.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] zml1206 commented on pull request #42531: [SPARK-44846][SQL] Pull out complex grouping expressions after remove redundant aggregates

Posted by "zml1206 (via GitHub)" <gi...@apache.org>.
zml1206 commented on PR #42531:
URL: https://github.com/apache/spark/pull/42531#issuecomment-1690104976

   New PR: [#42633](https://github.com/apache/spark/pull/42633)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] zml1206 commented on a diff in pull request #42531: [SPARK-44846][SQL] PushFoldableIntoBranches in complex grouping expressions may cause bi…

Posted by "zml1206 (via GitHub)" <gi...@apache.org>.
zml1206 commented on code in PR #42531:
URL: https://github.com/apache/spark/pull/42531#discussion_r1298910328


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/RemoveRedundantAggregates.scala:
##########
@@ -42,11 +42,12 @@ object RemoveRedundantAggregates extends Rule[LogicalPlan] with AliasHelper {
       )
 
       // We might have introduces non-deterministic grouping expression
-      if (newAggregate.groupingExpressions.exists(!_.deterministic)) {
+      val _newAggregate = if (newAggregate.groupingExpressions.exists(!_.deterministic)) {

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a diff in pull request #42531: [SPARK-44846][SQL] Pull out complex grouping expressions after remove redundant aggregates

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #42531:
URL: https://github.com/apache/spark/pull/42531#discussion_r1302472237


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/RemoveRedundantAggregates.scala:
##########
@@ -42,11 +42,12 @@ object RemoveRedundantAggregates extends Rule[LogicalPlan] with AliasHelper {
       )
 
       // We might have introduces non-deterministic grouping expression

Review Comment:
   I have a different idea. I think it's risky to put the new grouping expressions back to the `Aggregate`, as the grouping expression contains things in the SELECT list. This is a long-standing issue and I feel it's better to just create a `Project` below the `Aggregate` to calculate grouping expressions, and other optimizer rules can merge/eliminate this extra `Project` if it only contains `Attributes`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] zml1206 closed pull request #42531: [SPARK-44846][SQL] Pull out complex grouping expressions after remove redundant aggregates

Posted by "zml1206 (via GitHub)" <gi...@apache.org>.
zml1206 closed pull request #42531: [SPARK-44846][SQL] Pull out complex grouping expressions after remove redundant aggregates
URL: https://github.com/apache/spark/pull/42531


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] wangyum commented on a diff in pull request #42531: [SPARK-44846][SQL] PushFoldableIntoBranches in complex grouping expressions may cause bi…

Posted by "wangyum (via GitHub)" <gi...@apache.org>.
wangyum commented on code in PR #42531:
URL: https://github.com/apache/spark/pull/42531#discussion_r1297310457


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -644,6 +644,8 @@ object PushFoldableIntoBranches extends Rule[LogicalPlan] {
 
   def apply(plan: LogicalPlan): LogicalPlan = plan.transformWithPruning(
     _.containsAnyPattern(CASE_WHEN, IF), ruleId) {
+    case a @ Aggregate(groupingExpressions, _, _)
+      if !groupingExpressions.forall(_.isInstanceOf[NamedExpression]) => a

Review Comment:
   This is because the aggregate contains complex grouping expressions after `RemoveRedundantAggregates`. So could we fix it there.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -644,6 +644,8 @@ object PushFoldableIntoBranches extends Rule[LogicalPlan] {
 
   def apply(plan: LogicalPlan): LogicalPlan = plan.transformWithPruning(
     _.containsAnyPattern(CASE_WHEN, IF), ruleId) {
+    case a @ Aggregate(groupingExpressions, _, _)
+      if !groupingExpressions.forall(_.isInstanceOf[NamedExpression]) => a

Review Comment:
   We had a similar issue before: https://issues.apache.org/jira/browse/SPARK-34581



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] wangyum commented on pull request #42531: [SPARK-44846][SQL] PushFoldableIntoBranches in complex grouping expressions may cause bi…

Posted by "wangyum (via GitHub)" <gi...@apache.org>.
wangyum commented on PR #42531:
URL: https://github.com/apache/spark/pull/42531#issuecomment-1684576840

   Could you update the PR title and PR description? 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] wangyum commented on a diff in pull request #42531: [SPARK-44846][SQL] PushFoldableIntoBranches in complex grouping expressions may cause bi…

Posted by "wangyum (via GitHub)" <gi...@apache.org>.
wangyum commented on code in PR #42531:
URL: https://github.com/apache/spark/pull/42531#discussion_r1297274165


##########
sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala:
##########
@@ -3674,6 +3674,21 @@ class DataFrameSuite extends QueryTest
         parameters = Map("viewName" -> "AUTHORIZATION"))
     }
   }
+
+  test("SPARK-44846: PushFoldableIntoBranches in complex grouping expressions " +

Review Comment:
   Move the test to https://github.com/apache/spark/blob/master/sql/core/src/test/resources/sql-tests/inputs/group-by.sql?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] wangyum commented on a diff in pull request #42531: [SPARK-44846][SQL] PushFoldableIntoBranches in complex grouping expressions may cause bi…

Posted by "wangyum (via GitHub)" <gi...@apache.org>.
wangyum commented on code in PR #42531:
URL: https://github.com/apache/spark/pull/42531#discussion_r1298634329


##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/RemoveRedundantAggregatesSuite.scala:
##########
@@ -96,7 +96,7 @@ class RemoveRedundantAggregatesSuite extends PlanTest {
         .groupBy($"a" + $"b")(($"a" + $"b") as "c")
         .analyze
       val optimized = Optimize.execute(query)
-      comparePlans(optimized, expected)
+      comparePlans(optimized, PullOutGroupingExpressions.apply(expected))

Review Comment:
   ```scala
         val expected = relation
           .select($"a", $"b", ($"a" + $"b") as "_groupingexpression")
           .groupBy($"_groupingexpression")($"_groupingexpression" as "c")
           .analyze
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] wangyum commented on a diff in pull request #42531: [SPARK-44846][SQL] PushFoldableIntoBranches in complex grouping expressions may cause bi…

Posted by "wangyum (via GitHub)" <gi...@apache.org>.
wangyum commented on code in PR #42531:
URL: https://github.com/apache/spark/pull/42531#discussion_r1297310457


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -644,6 +644,8 @@ object PushFoldableIntoBranches extends Rule[LogicalPlan] {
 
   def apply(plan: LogicalPlan): LogicalPlan = plan.transformWithPruning(
     _.containsAnyPattern(CASE_WHEN, IF), ruleId) {
+    case a @ Aggregate(groupingExpressions, _, _)
+      if !groupingExpressions.forall(_.isInstanceOf[NamedExpression]) => a

Review Comment:
   This is because the aggregate contains complex grouping expressions after `RedundantAggregates`. So could we fix it there.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] wangyum commented on a diff in pull request #42531: [SPARK-44846][SQL] PushFoldableIntoBranches in complex grouping expressions may cause bi…

Posted by "wangyum (via GitHub)" <gi...@apache.org>.
wangyum commented on code in PR #42531:
URL: https://github.com/apache/spark/pull/42531#discussion_r1297272752


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -644,6 +644,8 @@ object PushFoldableIntoBranches extends Rule[LogicalPlan] {
 
   def apply(plan: LogicalPlan): LogicalPlan = plan.transformWithPruning(
     _.containsAnyPattern(CASE_WHEN, IF), ruleId) {
+    case a @ Aggregate(groupingExpressions, _, _)
+      if !groupingExpressions.forall(_.isInstanceOf[NamedExpression]) => a

Review Comment:
   ```suggestion
       case a: Aggregate if !a.groupingExpressions.forall(_.isInstanceOf[NamedExpression]) => a
   ```
   ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] zml1206 commented on a diff in pull request #42531: [SPARK-44846][SQL] PushFoldableIntoBranches in complex grouping expressions may cause bi…

Posted by "zml1206 (via GitHub)" <gi...@apache.org>.
zml1206 commented on code in PR #42531:
URL: https://github.com/apache/spark/pull/42531#discussion_r1297486130


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -644,6 +644,8 @@ object PushFoldableIntoBranches extends Rule[LogicalPlan] {
 
   def apply(plan: LogicalPlan): LogicalPlan = plan.transformWithPruning(
     _.containsAnyPattern(CASE_WHEN, IF), ruleId) {
+    case a @ Aggregate(groupingExpressions, _, _)
+      if !groupingExpressions.forall(_.isInstanceOf[NamedExpression]) => a

Review Comment:
   Thanks. In `PhysicalAggregation`,if the expression is not a NamedExpressions, it add an alias. Also I'm not sure if complex expressions are generated anywhere else other than `RemoveRedundantAggregates`. So is it safer to fix `PushFoldableIntoBranches`, and the impact is smaller?



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -644,6 +644,8 @@ object PushFoldableIntoBranches extends Rule[LogicalPlan] {
 
   def apply(plan: LogicalPlan): LogicalPlan = plan.transformWithPruning(
     _.containsAnyPattern(CASE_WHEN, IF), ruleId) {
+    case a @ Aggregate(groupingExpressions, _, _)
+      if !groupingExpressions.forall(_.isInstanceOf[NamedExpression]) => a

Review Comment:
   Thanks. In `PhysicalAggregation`,if the expression is not a NamedExpressions, it add an alias. Also I'm not sure if complex expressions are generated anywhere else other than `RemoveRedundantAggregates`. So is it safer to fix `PushFoldableIntoBranches`, and the impact is smaller?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org