uros-b commented on code in PR #57629:
URL: https://github.com/apache/spark/pull/57629#discussion_r3689594976
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InsertMapSortExpression.scala:
##########
@@ -17,18 +17,21 @@
package org.apache.spark.sql.catalyst.optimizer
+import scala.collection.immutable.VectorMap
import scala.collection.mutable
-import org.apache.spark.sql.catalyst.expressions.{Alias, ArrayTransform,
CreateNamedStruct, Expression, GetStructField, If, IsNull, LambdaFunction,
Literal, MapFromArrays, MapKeys, MapSort, MapValues, NamedExpression,
NamedLambdaVariable}
+import org.apache.spark.sql.catalyst.expressions.{Alias, ArrayTransform,
Attribute, CreateNamedStruct, Expression, GetStructField, If, IsNull,
LambdaFunction, Literal, MapFromArrays, MapKeys, MapSort, MapValues,
NamedExpression, NamedLambdaVariable}
+import
org.apache.spark.sql.catalyst.expressions.aggregate.{AggregateExpression,
AggregateFunction}
import org.apache.spark.sql.catalyst.plans.logical.{Aggregate, LogicalPlan,
Project, RepartitionByExpression}
import org.apache.spark.sql.catalyst.rules.Rule
import org.apache.spark.sql.catalyst.trees.TreePattern.{AGGREGATE,
REPARTITION_OPERATION}
+import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types.{ArrayType, MapType, StructType}
import org.apache.spark.util.ArrayImplicits.SparkArrayOps
/**
- * Adds [[MapSort]] to [[Aggregate]] expressions containing map columns,
- * as the key/value pairs need to be in the correct order before grouping:
+ * Adds [[MapSort]] to grouping expressions and distinct aggregate arguments
that contain maps,
+ * ensuring key/value pairs have a consistent order before aggregation:
*
Review Comment:
Nit: the rule is still InsertMapSortInGroupingExpressions and every alias it
creates is named _groupingmapsort, including the ones that exist purely for a
distinct argument; so plans will show _groupingmapsort for a column that isn't
a grouping key. The object is nested inside the FinishAnalysis composite rule
and so isn't reachable through spark.sql.optimizer.excludedRules, which makes
renaming it low-risk; at minimum, give the distinct-only aliases their own
name. The scaladoc could also use a distinct-aggregate example alongside the
GROUP BY one, since that's the new behavior.
--
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]