diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashMapGenerator.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashMapGenerator.scala index e1c8582325..9b7ef23cd9 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashMapGenerator.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashMapGenerator.scala @@ -158,8 +158,8 @@ abstract class HashMapGenerator( dataType match { case BooleanType => hashInt(s"$input ? 1 : 0") - case ByteType | ShortType | IntegerType | DateType => hashInt(input) - case LongType | TimestampType => hashLong(input) + case ByteType | ShortType | IntegerType | DateType | YearMonthIntervalType => hashInt(input) + case LongType | TimestampType | DayTimeIntervalType => hashLong(input) case FloatType => hashInt(s"Float.floatToIntBits($input)") case DoubleType => hashLong(s"Double.doubleToLongBits($input)") case d: DecimalType => diff --git a/sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala index c6f6cbdbf0..a01e7e4c89 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala @@ -1196,6 +1196,13 @@ class DataFrameAggregateSuite extends QueryTest val avgDF4 = df3.groupBy($"class").agg(avg($"year-month"), avg($"day-time")) checkAnswer(avgDF4, Nil) } + + test("SPARK-35412: groupBy of year-month/day-time intervals should work") { + val df1 = Seq(Duration.ofDays(1)).toDF("a").groupBy("a").count() + checkAnswer(df1, Row(Duration.ofDays(1), 1)) + val df2 = Seq(Period.ofYears(1)).toDF("a").groupBy("a").count() + checkAnswer(df2, Row(Period.ofYears(1), 1)) + } } case class B(c: Option[Double])