Skip to content

Commit 94dd587

Browse files
committed
test(spark): add regression test for datediff on dictionary-encoded timestamps
1 parent c5cf290 commit 94dd587

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

spark/src/test/scala/org/apache/spark/sql/comet/ParquetDatetimeRebaseSuite.scala

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,38 @@ abstract class ParquetDatetimeRebaseSuite extends CometTestBase {
116116
}
117117
}
118118

119+
test("datediff works with dictionary-encoded timestamp columns") {
120+
withSQLConf(
121+
"spark.sql.parquet.enableDictionary" -> "true",
122+
CometConf.COMET_ENABLED.key -> "true") {
123+
val df = spark
124+
.createDataFrame(
125+
Seq(
126+
("a", java.sql.Timestamp.valueOf("2024-01-02 10:00:00")),
127+
("b", java.sql.Timestamp.valueOf("2024-01-03 11:00:00"))))
128+
.toDF("id", "ts")
129+
130+
withTempPath { path =>
131+
df.write.mode("overwrite").parquet(path.getAbsolutePath)
132+
133+
val readDf = spark.read.parquet(path.getAbsolutePath)
134+
135+
val result = readDf
136+
.selectExpr("datediff(current_date(), ts)")
137+
.collect()
138+
139+
assert(result.length == 2)
140+
}
141+
142+
// This used to fail due to array length mismatch
143+
val result = readDf
144+
.selectExpr("datediff(current_date(), ts)")
145+
.collect()
146+
147+
assert(result.length == 2)
148+
}
149+
}
150+
119151
private def checkSparkNoRebaseAnswer(df: => DataFrame): Unit = {
120152
var expected: Array[Row] = Array.empty
121153

0 commit comments

Comments
 (0)