You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2020/10/13 11:21:41 UTC

[GitHub] [spark] ulysses-you opened a new pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

ulysses-you opened a new pull request #30029:
URL: https://github.com/apache/spark/pull/30029


   <!--
   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'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   Correct the resolution of having clause.
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   The method `ResolveAggregateFunctions.resolveFilterCondInAggregate` aims to do the two things
   1. resolve the expression in having.
   2. push the having extra agg expression to `Aggregate`
   
   However we only care about 2. If having clause resolution is successful but not exists extra agg expression, we will ignore the resolution. Here is a example:
   ```
   -- Works resolved by `ResolveReferences`
   select c1 from values (1) as t1(c1) group by grouping sets(t1.c1) having c1 = 1
   
   -- Works because of the extra expression c1
   select c1 as c2 from values (1) as t1(c1) group by grouping sets(t1.c1) having t1.c1 = 1
   
   -- Failed
   select c1 from values (1) as t1(c1) group by grouping sets(t1.c1) having t1.c1 = 1
   ```
   
   It wroks with `Aggregate` without grouping sets through `ResolveReferences`, but Grouping sets not works since the exprId has been changed.
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   Yes, bug fix.
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   -->
   add test.


----------------------------------------------------------------
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.

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] AmplabJenkins removed a comment on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708661641


   Merged build finished. Test FAILed.


----------------------------------------------------------------
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.

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] AmplabJenkins removed a comment on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708661651


   Test FAILed.
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/129748/
   Test FAILed.


----------------------------------------------------------------
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.

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] SparkQA commented on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708661237


   **[Test build #129748 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/129748/testReport)** for PR 30029 at commit [`d3893b2`](https://github.com/apache/spark/commit/d3893b23a908f4f77a2c3e0575ce0f17791e6e10).
    * This patch **fails Spark unit tests**.
    * This patch merges cleanly.
    * This patch adds no public classes.


----------------------------------------------------------------
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.

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] ulysses-you commented on a change in pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on a change in pull request #30029:
URL: https://github.com/apache/spark/pull/30029#discussion_r504509715



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -646,9 +646,9 @@ class Analyzer(
         // Since the exprId of extraAggExprs will be changed in the constructed aggregate, and the
         // aggregateExpressions keeps the input order. So here we build an exprMap to resolve the
         // condition again.
-        val exprMap = extraAggExprs.zip(
-          newChild.asInstanceOf[Aggregate].aggregateExpressions.takeRight(
-            extraAggExprs.length)).toMap
+        // We also add the original aggregateExpressions in Map to avoid extraAggExprs is empty.

Review comment:
       If we resolved the having condition but extraAggExprs is empty, that means the resolution is in original aggregateExpressions.
   
   We need use original aggregateExpressions mapping having condition NamedExpression to the new since grouping sets constructAggregate will build the new alias for it.




----------------------------------------------------------------
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.

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 change in pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #30029:
URL: https://github.com/apache/spark/pull/30029#discussion_r504515443



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -646,9 +646,9 @@ class Analyzer(
         // Since the exprId of extraAggExprs will be changed in the constructed aggregate, and the
         // aggregateExpressions keeps the input order. So here we build an exprMap to resolve the
         // condition again.
-        val exprMap = extraAggExprs.zip(
-          newChild.asInstanceOf[Aggregate].aggregateExpressions.takeRight(
-            extraAggExprs.length)).toMap
+        // We also add the original aggregateExpressions in Map to avoid extraAggExprs is empty.

Review comment:
       I don't get it. The comment says
   ```
           // Since the exprId of extraAggExprs will be changed in the constructed aggregate, and the
           // aggregateExpressions keeps the input order. So here we build an exprMap to resolve the
           // condition again.
   ```
   I don't see why we need to include the original aggregateExpressions in `exprMap`.




----------------------------------------------------------------
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.

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] SparkQA removed a comment on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708878641


   **[Test build #129791 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/129791/testReport)** for PR 30029 at commit [`a4c2028`](https://github.com/apache/spark/commit/a4c2028cf1fa7a785e9a8f728fbbd2e5d0d09801).


----------------------------------------------------------------
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.

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] AmplabJenkins commented on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708947651






----------------------------------------------------------------
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.

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 change in pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #30029:
URL: https://github.com/apache/spark/pull/30029#discussion_r505208099



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -470,7 +470,7 @@ class Analyzer(
      */
     private def constructGroupByAlias(groupByExprs: Seq[Expression]): Seq[Alias] = {
       groupByExprs.map {
-        case e: NamedExpression => Alias(e, e.name)()
+        case e: NamedExpression => Alias(e, e.name)(qualifier = e.qualifier)

Review comment:
       ah this is a good catch! do we have this bug in 3.0 and 2.4?




----------------------------------------------------------------
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.

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] ulysses-you commented on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708723826


   Seems this way will introduce unexpect thing.
   
   We want to return the resolved having condition which is extra expression or exists in grouping expression.  Current pr implementation will break such sql
   ```
   select c1, count(*) as c2 from values(1, 2) as t(c1, c2) group by c1 having c1 = 1 and c2 = 1;
   ```
   
   Let me find an another way to solve it.
   


----------------------------------------------------------------
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.

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] ulysses-you commented on a change in pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on a change in pull request #30029:
URL: https://github.com/apache/spark/pull/30029#discussion_r505077399



##########
File path: sql/core/src/test/resources/sql-tests/results/having.sql.out
##########
@@ -81,3 +81,35 @@ SELECT SUM(a) AS b FROM VALUES (1, 10), (2, 20) AS T(a, b) GROUP BY ROLLUP(a, b)
 struct<b:bigint>
 -- !query output
 2
+
+
+-- !query
+SELECT c1 FROM VALUES (1, 2) as t(c1, c2) GROUP BY GROUPING SETS(t.c1) HAVING t.c1 = 1
+-- !query schema
+struct<c1:int>
+-- !query output
+1
+
+
+-- !query
+SELECT c1 FROM VALUES (1, 2) as t(c1, c2) GROUP BY CUBE(t.c1) HAVING t.c1 = 1
+-- !query schema
+struct<c1:int>
+-- !query output
+1
+
+
+-- !query
+SELECT c1 FROM VALUES (1, 2) as t(c1, c2) GROUP BY ROLLUP(t.c1) HAVING t.c1 = 1
+-- !query schema
+struct<c1:int>
+-- !query output
+1
+
+
+-- !query
+SELECT c1 FROM VALUES (1, 2) as t(c1, c2) GROUP BY t.c1 HAVING t.c1 = 1

Review comment:
       Yeah this test is just for better coverage.




----------------------------------------------------------------
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.

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] AmplabJenkins removed a comment on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708947665


   Test FAILed.
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/129791/
   Test FAILed.


----------------------------------------------------------------
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.

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 change in pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #30029:
URL: https://github.com/apache/spark/pull/30029#discussion_r504430506



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -2334,9 +2335,13 @@ class Analyzer(
       // Push the aggregate expressions into the aggregate (if any).
       if (resolvedInfo.nonEmpty) {
         val (aggregateExpressions, resolvedHavingCond) = resolvedInfo.get
-        Project(agg.output,
-          Filter(resolvedHavingCond,
-            agg.copy(aggregateExpressions = agg.aggregateExpressions ++ aggregateExpressions)))
+        if (aggregateExpressions.nonEmpty) {

Review comment:
       This seems to conflict with 
   ```
   // We need to return the resolved having condition
   Some(Seq.empty, transformedAggregateFilter.asInstanceOf[Alias].child)
   ```




----------------------------------------------------------------
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.

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 change in pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #30029:
URL: https://github.com/apache/spark/pull/30029#discussion_r504430337



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -646,9 +646,9 @@ class Analyzer(
         // Since the exprId of extraAggExprs will be changed in the constructed aggregate, and the
         // aggregateExpressions keeps the input order. So here we build an exprMap to resolve the
         // condition again.
-        val exprMap = extraAggExprs.zip(
-          newChild.asInstanceOf[Aggregate].aggregateExpressions.takeRight(
-            extraAggExprs.length)).toMap
+        // We also add the original aggregateExpressions in Map to avoid extraAggExprs is empty.

Review comment:
       what's wrong if `extraAggExprs` is empty?




----------------------------------------------------------------
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.

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] AmplabJenkins removed a comment on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708903867






----------------------------------------------------------------
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.

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] SparkQA commented on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708903853


   Kubernetes integration test status success
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/34398/
   


----------------------------------------------------------------
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.

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] SparkQA commented on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708636941


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/34354/
   


----------------------------------------------------------------
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.

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] SparkQA commented on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708878641


   **[Test build #129791 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/129791/testReport)** for PR 30029 at commit [`a4c2028`](https://github.com/apache/spark/commit/a4c2028cf1fa7a785e9a8f728fbbd2e5d0d09801).


----------------------------------------------------------------
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.

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] SparkQA commented on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708946595


   **[Test build #129791 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/129791/testReport)** for PR 30029 at commit [`a4c2028`](https://github.com/apache/spark/commit/a4c2028cf1fa7a785e9a8f728fbbd2e5d0d09801).
    * This patch **fails due to an unknown error code, -9**.
    * This patch merges cleanly.
    * This patch adds no public classes.


----------------------------------------------------------------
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.

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] maropu commented on a change in pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
maropu commented on a change in pull request #30029:
URL: https://github.com/apache/spark/pull/30029#discussion_r504717835



##########
File path: sql/core/src/test/resources/sql-tests/results/having.sql.out
##########
@@ -81,3 +81,35 @@ SELECT SUM(a) AS b FROM VALUES (1, 10), (2, 20) AS T(a, b) GROUP BY ROLLUP(a, b)
 struct<b:bigint>
 -- !query output
 2
+
+
+-- !query
+SELECT c1 FROM VALUES (1, 2) as t(c1, c2) GROUP BY GROUPING SETS(t.c1) HAVING t.c1 = 1
+-- !query schema
+struct<c1:int>
+-- !query output
+1
+
+
+-- !query
+SELECT c1 FROM VALUES (1, 2) as t(c1, c2) GROUP BY CUBE(t.c1) HAVING t.c1 = 1
+-- !query schema
+struct<c1:int>
+-- !query output
+1
+
+
+-- !query
+SELECT c1 FROM VALUES (1, 2) as t(c1, c2) GROUP BY ROLLUP(t.c1) HAVING t.c1 = 1
+-- !query schema
+struct<c1:int>
+-- !query output
+1
+
+
+-- !query
+SELECT c1 FROM VALUES (1, 2) as t(c1, c2) GROUP BY t.c1 HAVING t.c1 = 1

Review comment:
       It seems this test can pass even in master.




----------------------------------------------------------------
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.

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 pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-709988668


   GA passed, thanks, merging to master!


----------------------------------------------------------------
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.

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] ulysses-you commented on a change in pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on a change in pull request #30029:
URL: https://github.com/apache/spark/pull/30029#discussion_r505284595



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -470,7 +470,7 @@ class Analyzer(
      */
     private def constructGroupByAlias(groupByExprs: Seq[Expression]): Seq[Alias] = {
       groupByExprs.map {
-        case e: NamedExpression => Alias(e, e.name)()
+        case e: NamedExpression => Alias(e, e.name)(qualifier = e.qualifier)

Review comment:
       Yeah, seems it's a long time bug.




----------------------------------------------------------------
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.

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] AmplabJenkins commented on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708661651






----------------------------------------------------------------
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.

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 closed pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
cloud-fan closed pull request #30029:
URL: https://github.com/apache/spark/pull/30029


   


----------------------------------------------------------------
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.

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] ulysses-you commented on a change in pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on a change in pull request #30029:
URL: https://github.com/apache/spark/pull/30029#discussion_r504524266



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -646,9 +646,9 @@ class Analyzer(
         // Since the exprId of extraAggExprs will be changed in the constructed aggregate, and the
         // aggregateExpressions keeps the input order. So here we build an exprMap to resolve the
         // condition again.
-        val exprMap = extraAggExprs.zip(
-          newChild.asInstanceOf[Aggregate].aggregateExpressions.takeRight(
-            extraAggExprs.length)).toMap
+        // We also add the original aggregateExpressions in Map to avoid extraAggExprs is empty.

Review comment:
       The comment is right if we not return the resolved having condition when `exprMap` is empty.
   
   This pr break the behavior that return it. If we not add the original aggregateExpressions, we can't mapping the resolved having condition since `exprMap` is empty.
   




----------------------------------------------------------------
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.

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] ulysses-you commented on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-710081710


   @cloud-fan sure will do it tomorrow.


----------------------------------------------------------------
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.

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] SparkQA commented on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708896743


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/34398/
   


----------------------------------------------------------------
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.

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] ulysses-you commented on a change in pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on a change in pull request #30029:
URL: https://github.com/apache/spark/pull/30029#discussion_r503871136



##########
File path: sql/core/src/test/resources/sql-tests/inputs/having.sql
##########
@@ -24,3 +24,9 @@ SELECT SUM(a) AS b, CAST('2020-01-01' AS DATE) AS fake FROM VALUES (1, 10), (2,
 SELECT SUM(a) AS b FROM VALUES (1, 10), (2, 20) AS T(a, b) GROUP BY GROUPING SETS ((b), (a, b)) HAVING b > 10;
 SELECT SUM(a) AS b FROM VALUES (1, 10), (2, 20) AS T(a, b) GROUP BY CUBE(a, b) HAVING b > 10;
 SELECT SUM(a) AS b FROM VALUES (1, 10), (2, 20) AS T(a, b) GROUP BY ROLLUP(a, b) HAVING b > 10;
+
+-- SPARK-33131: Grouping sets with having clause can not resolve qualified col name.
+SELECT c1 FROM VALUES (1, 2) as t(c1, c2) GROUP BY GROUPING SETS(t.c1) HAVING t.c1 = 1;
+SELECT c1 FROM VALUES (1, 2) as t(c1, c2) GROUP BY CUBE(t.c1) HAVING t.c1 = 1;
+SELECT c1 FROM VALUES (1, 2) as t(c1, c2) GROUP BY ROLLUP(t.c1) HAVING t.c1 = 1;
+SELECT c1 FROM VALUES (1, 2) as t(c1, c2) GROUP BY t.c1 HAVING t.c1 = 1;

Review comment:
       this test is just ensure we support it.




----------------------------------------------------------------
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.

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] SparkQA commented on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708648484


   Kubernetes integration test status success
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/34354/
   


----------------------------------------------------------------
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.

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 change in pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #30029:
URL: https://github.com/apache/spark/pull/30029#discussion_r504606381



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -646,9 +646,9 @@ class Analyzer(
         // Since the exprId of extraAggExprs will be changed in the constructed aggregate, and the
         // aggregateExpressions keeps the input order. So here we build an exprMap to resolve the
         // condition again.
-        val exprMap = extraAggExprs.zip(
-          newChild.asInstanceOf[Aggregate].aggregateExpressions.takeRight(
-            extraAggExprs.length)).toMap
+        // We also add the original aggregateExpressions in Map to avoid extraAggExprs is empty.

Review comment:
       can you make the comment clearer?




----------------------------------------------------------------
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.

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] AmplabJenkins commented on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708903867






----------------------------------------------------------------
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.

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] SparkQA removed a comment on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708601848


   **[Test build #129748 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/129748/testReport)** for PR 30029 at commit [`d3893b2`](https://github.com/apache/spark/commit/d3893b23a908f4f77a2c3e0575ce0f17791e6e10).


----------------------------------------------------------------
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.

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] AmplabJenkins commented on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708648521






----------------------------------------------------------------
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.

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] ulysses-you commented on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708171740


   @maropu @cloud-fan do you have time to take a look ?


----------------------------------------------------------------
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.

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] AmplabJenkins removed a comment on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708947651


   Merged build finished. Test FAILed.


----------------------------------------------------------------
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.

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] ulysses-you commented on a change in pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on a change in pull request #30029:
URL: https://github.com/apache/spark/pull/30029#discussion_r504509029



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -2334,9 +2335,13 @@ class Analyzer(
       // Push the aggregate expressions into the aggregate (if any).
       if (resolvedInfo.nonEmpty) {
         val (aggregateExpressions, resolvedHavingCond) = resolvedInfo.get
-        Project(agg.output,
-          Filter(resolvedHavingCond,
-            agg.copy(aggregateExpressions = agg.aggregateExpressions ++ aggregateExpressions)))
+        if (aggregateExpressions.nonEmpty) {

Review comment:
       updated.




----------------------------------------------------------------
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.

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] AmplabJenkins removed a comment on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708648521






----------------------------------------------------------------
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.

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] SparkQA commented on pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-708601848


   **[Test build #129748 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/129748/testReport)** for PR 30029 at commit [`d3893b2`](https://github.com/apache/spark/commit/d3893b23a908f4f77a2c3e0575ce0f17791e6e10).


----------------------------------------------------------------
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.

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] ulysses-you commented on a change in pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on a change in pull request #30029:
URL: https://github.com/apache/spark/pull/30029#discussion_r504524266



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -646,9 +646,9 @@ class Analyzer(
         // Since the exprId of extraAggExprs will be changed in the constructed aggregate, and the
         // aggregateExpressions keeps the input order. So here we build an exprMap to resolve the
         // condition again.
-        val exprMap = extraAggExprs.zip(
-          newChild.asInstanceOf[Aggregate].aggregateExpressions.takeRight(
-            extraAggExprs.length)).toMap
+        // We also add the original aggregateExpressions in Map to avoid extraAggExprs is empty.

Review comment:
       The comment is right if we not return the resolved having condition when `exprMap` is empty, this pr break the behavior that return it.
   
   If we not add the original aggregateExpressions, we can't mapping the resolved having condition since `exprMap` is empty.
   




----------------------------------------------------------------
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.

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 change in pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #30029:
URL: https://github.com/apache/spark/pull/30029#discussion_r504606568



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -2315,7 +2315,8 @@ class Analyzer(
           if (aggregateExpressions.nonEmpty) {
             Some(aggregateExpressions.toSeq, transformedAggregateFilter)
           } else {
-            None
+            // We need to return the resolved having condition
+            Some(Seq.empty, transformedAggregateFilter.asInstanceOf[Alias].child)

Review comment:
       what if we don't trim the `Alias` here?




----------------------------------------------------------------
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.

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 pull request #30029: [SPARK-33131][SQL] Fix grouping sets with having clause can not resolve qualified col name

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #30029:
URL: https://github.com/apache/spark/pull/30029#issuecomment-709989015


   @ulysses-you  can you send backport PRs for 3.0 and 2.4? thanks!


----------------------------------------------------------------
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.

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