cloud-fan commented on code in PR #36325:
URL: https://github.com/apache/spark/pull/36325#discussion_r858278244


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2ScanRelationPushDown.scala:
##########
@@ -184,9 +184,16 @@ object V2ScanRelationPushDown extends Rule[LogicalPlan] 
with PredicateHelper wit
                   // scalastyle:on
                   val newOutput = scan.readSchema().toAttributes
                   assert(newOutput.length == groupingExpressions.length + 
finalAggregates.length)
+                  val groupByExprToOutputOrdinal = 
mutable.HashMap.empty[Expression, Int]
+                  var ordinal = 0
                   val groupAttrs = 
normalizedGroupingExpressions.zip(newOutput).map {
                     case (a: Attribute, b: Attribute) => b.withExprId(a.exprId)
-                    case (_, b) => b
+                    case (expr, b) =>
+                      if 
(!groupByExprToOutputOrdinal.contains(expr.canonicalized)) {
+                        groupByExprToOutputOrdinal(expr.canonicalized) = 
ordinal
+                        ordinal += 1

Review Comment:
   this looks incorrect. We use the ordinal to access `groupAttrs`, but here we 
skip incrementing `ordinal` if group by expression is an attribute. I think we 
should use `normalizedGroupingExpressions.zip(newOutput).zipWithIndex`.
   
   BTW, do we have a test for mixed group by attr and group by expr?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to