Skip to content

[SPARK-52626][SQL] Allow grouping by the time type #51325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ abstract class HashMapGenerator(
case BooleanType => hashInt(s"$input ? 1 : 0")
case ByteType | ShortType | IntegerType | DateType | _: YearMonthIntervalType =>
hashInt(input)
case LongType | TimestampType | TimestampNTZType | _: DayTimeIntervalType => hashLong(input)
case LongType | TimestampType | TimestampNTZType | _: DayTimeIntervalType | _: TimeType =>
hashLong(input)
case FloatType => hashInt(s"Float.floatToIntBits($input)")
case DoubleType => hashLong(s"Double.doubleToLongBits($input)")
case d: DecimalType =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.spark.sql

import java.sql.{Date, Timestamp}
import java.time.{Duration, LocalDateTime, Period}
import java.time.{Duration, LocalDateTime, LocalTime, Period}

import scala.util.Random

Expand Down Expand Up @@ -2902,6 +2902,17 @@ class DataFrameAggregateSuite extends QueryTest
)
assert(badAgg2.checkInputDataTypes().isFailure)
}

test("SPARK-52626: Support group by Time column") {
val ts1 = "15:00:00"
val ts2 = "22:00:00"
val localTime = Seq(ts1, ts1, ts2).map(LocalTime.parse)
val df = localTime.toDF("t").groupBy("t").count().orderBy("t")
val expectedSchema =
new StructType().add(StructField("t", TimeType())).add("count", LongType, false)
assert (df.schema == expectedSchema)
checkAnswer(df, Seq(Row(LocalTime.parse(ts1), 2), Row(LocalTime.parse(ts2), 1)))
}
}

case class B(c: Option[Double])
Expand Down