Skip to content

Commit e16fabf

Browse files
committed
[SPARK-13087][SQL] Fix group by function for sort based aggregation
1 parent 51b03b7 commit e16fabf

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/utils.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@ object Utils {
3333
resultExpressions: Seq[NamedExpression],
3434
child: SparkPlan): Seq[SparkPlan] = {
3535

36-
val groupingAttributes = groupingExpressions.map(_.toAttribute)
3736
val completeAggregateExpressions = aggregateExpressions.map(_.copy(mode = Complete))
3837
val completeAggregateAttributes = completeAggregateExpressions.map {
3938
expr => aggregateFunctionToAttribute(expr.aggregateFunction, expr.isDistinct)
4039
}
4140

4241
SortBasedAggregate(
43-
requiredChildDistributionExpressions = Some(groupingAttributes),
44-
groupingExpressions = groupingAttributes,
42+
requiredChildDistributionExpressions = Some(groupingExpressions),
43+
groupingExpressions = groupingExpressions,
4544
aggregateExpressions = completeAggregateExpressions,
4645
aggregateAttributes = completeAggregateAttributes,
4746
initialInputBufferOffset = 0,

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/AggregationQuerySuite.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ abstract class AggregationQuerySuite extends QueryTest with SQLTestUtils with Te
193193
sqlContext.dropTempTable("emptyTable")
194194
}
195195

196+
test("group by function") {
197+
Seq((1, 2)).toDF("a", "b").registerTempTable("data")
198+
199+
checkAnswer(
200+
sql("SELECT floor(a) AS a, collect_set(b) FROM data GROUP BY floor(a) ORDER BY a"),
201+
Row(1, Array(2)) :: Nil)
202+
}
203+
196204
test("empty table") {
197205
// If there is no GROUP BY clause and the table is empty, we will generate a single row.
198206
checkAnswer(

0 commit comments

Comments
 (0)