Skip to content

Commit 8ae5f65

Browse files
committed
Add the case of DecimalType.Unlimited to Average.
1 parent 30a6e0d commit 8ae5f65

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregates.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ case class Average(child: Expression) extends PartialAggregate with trees.UnaryN
326326

327327
override def asPartial: SplitEvaluation = {
328328
child.dataType match {
329-
case DecimalType.Fixed(_, _) =>
329+
case DecimalType.Fixed(_, _) | DecimalType.Unlimited =>
330330
// Turn the child to unlimited decimals for calculation, before going back to fixed
331331
val partialSum = Alias(Sum(Cast(child, DecimalType.Unlimited)), "PartialSum")()
332332
val partialCount = Alias(Count(child), "PartialCount")()

sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,4 +531,13 @@ class DataFrameSuite extends QueryTest {
531531
val df = TestSQLContext.createDataFrame(rowRDD, schema)
532532
df.rdd.collect()
533533
}
534+
535+
test("SPARK-6899") {
536+
val originalValue = TestSQLContext.conf.codegenEnabled
537+
TestSQLContext.setConf(SQLConf.CODEGEN_ENABLED, "true")
538+
checkAnswer(
539+
decimalData.agg(avg('a)),
540+
Row(new java.math.BigDecimal(2.0)))
541+
TestSQLContext.setConf(SQLConf.CODEGEN_ENABLED, originalValue.toString)
542+
}
534543
}

0 commit comments

Comments
 (0)