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 2021/01/04 00:20:46 UTC

[GitHub] [spark] maropu commented on a change in pull request #30781: [SPARK-22748][SQL] Analyze grouping__id bug when grouping__id is used as a column reference of subquery

maropu commented on a change in pull request #30781:
URL: https://github.com/apache/spark/pull/30781#discussion_r551074219



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -2099,9 +2099,14 @@ class Analyzer(override val catalogManager: CatalogManager)
         ResolvedFunc(Identifier.of(funcIdent.database.toArray, funcIdent.funcName))
 
       case q: LogicalPlan =>
+        val isGroupingIdAllowed = q match {
+          case _: Aggregate | _: GroupingSets | _: Filter | _: Sort => true
+          case _ => false
+        }
         q transformExpressions {
           case u if !u.childrenResolved => u // Skip until children are resolved.
-          case u: UnresolvedAttribute if resolver(u.name, VirtualColumn.hiveGroupingIdName) =>

Review comment:
       This PR can make some error messages change? If yes, could you add some tests for the case? e.g.,
   
   ```
   scala> sql("""select `grouping__id` from values (1, 1)  t(a, b)""").explain(true)
   org.apache.spark.sql.AnalysisException: grouping_id() can only be used with GroupingSets/Cube/Rollup;;
   !Project [grouping_id() AS grouping__id#22]
   +- SubqueryAlias t
      +- LocalRelation [a#23, b#24]
   ```




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