Skip to content

Commit dd0cf60

Browse files
author
Mariam-Almesfer
committed
Adds validation tests for several previously untested timestamp functions in the Velox backend
1 parent 985b19a commit dd0cf60

2 files changed

Lines changed: 98 additions & 0 deletions

File tree

backends-velox/src/test/scala/org/apache/gluten/functions/DateFunctionsValidateSuite.scala

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,12 @@ class DateFunctionsValidateSuite extends FunctionsValidateSuite {
262262
}
263263
}
264264

265+
test("timestamp_seconds") {
266+
runQueryAndCompare("select timestamp_seconds(l_orderkey) from lineitem") {
267+
checkGlutenPlan[ProjectExecTransformer]
268+
}
269+
}
270+
265271
test("timestampadd") {
266272
withTempPath {
267273
path =>
@@ -341,6 +347,45 @@ class DateFunctionsValidateSuite extends FunctionsValidateSuite {
341347
}
342348
}
343349

350+
test("last_day") {
351+
withTempPath {
352+
path =>
353+
Seq(
354+
java.sql.Date.valueOf("2022-02-15"),
355+
java.sql.Date.valueOf("2022-03-20"),
356+
java.sql.Date.valueOf("2020-02-10")
357+
)
358+
.toDF("dt")
359+
.write
360+
.parquet(path.getCanonicalPath)
361+
362+
spark.read.parquet(path.getCanonicalPath).createOrReplaceTempView("view")
363+
364+
runQueryAndCompare("SELECT last_day(dt) FROM view") {
365+
checkGlutenPlan[ProjectExecTransformer]
366+
}
367+
}
368+
}
369+
370+
test("next_day") {
371+
withTempPath {
372+
path =>
373+
Seq(
374+
java.sql.Date.valueOf("2022-02-15"),
375+
java.sql.Date.valueOf("2022-03-20")
376+
)
377+
.toDF("dt")
378+
.write
379+
.parquet(path.getCanonicalPath)
380+
381+
spark.read.parquet(path.getCanonicalPath).createOrReplaceTempView("view")
382+
383+
runQueryAndCompare("SELECT next_day(dt, 'Monday') FROM view") {
384+
checkGlutenPlan[ProjectExecTransformer]
385+
}
386+
}
387+
}
388+
344389
test("trunc") {
345390
withTempPath {
346391
path =>
@@ -473,6 +518,40 @@ class DateFunctionsValidateSuite extends FunctionsValidateSuite {
473518
}
474519
}
475520

521+
test("to_unix_timestamp") {
522+
withTempPath {
523+
path =>
524+
Seq(
525+
(Timestamp.valueOf("2016-04-08 13:10:15"), "yyyy-MM-dd HH:mm:ss"),
526+
(Timestamp.valueOf("2017-05-19 18:25:30"), "yyyy-MM-dd HH:mm:ss")
527+
).toDF("ts", "fmt").write.parquet(path.getCanonicalPath)
528+
529+
spark.read
530+
.parquet(path.getCanonicalPath)
531+
.createOrReplaceTempView("to_unix_timestamp_test")
532+
533+
runQueryAndCompare("SELECT to_unix_timestamp(ts, fmt) FROM to_unix_timestamp_test") {
534+
checkGlutenPlan[ProjectExecTransformer]
535+
}
536+
}
537+
}
538+
539+
test("from_unixtime") {
540+
withTempPath {
541+
path =>
542+
Seq(
543+
(1460118615L, "yyyy-MM-dd HH:mm:ss"),
544+
(1495211130L, "MM/dd/yyyy HH:mm:ss")
545+
).toDF("unix_time", "fmt").write.parquet(path.getCanonicalPath)
546+
547+
spark.read.parquet(path.getCanonicalPath).createOrReplaceTempView("from_unixtime_test")
548+
549+
runQueryAndCompare("SELECT from_unixtime(unix_time, fmt) FROM from_unixtime_test") {
550+
checkGlutenPlan[ProjectExecTransformer]
551+
}
552+
}
553+
}
554+
476555
test("months_between") {
477556
withTempPath {
478557
path =>
@@ -489,4 +568,5 @@ class DateFunctionsValidateSuite extends FunctionsValidateSuite {
489568
}
490569
}
491570
}
571+
492572
}

backends-velox/src/test/scala/org/apache/gluten/functions/ScalarFunctionsValidateSuite.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,24 @@ abstract class ScalarFunctionsValidateSuite extends FunctionsValidateSuite {
226226
sql("INSERT INTO t1 VALUES(1, NOW())")
227227
runQueryAndCompare("SELECT c1, HOUR(c2) FROM t1 LIMIT 1")(df => checkFallbackOperators(df, 0))
228228
}
229+
230+
test("MINUTE") {
231+
withTable("t1") {
232+
sql("create table t1 (c1 int, c2 timestamp) USING PARQUET")
233+
sql("INSERT INTO t1 VALUES(1, NOW())")
234+
runQueryAndCompare("SELECT c1, MINUTE(c2) FROM t1 LIMIT 1")(
235+
df => checkFallbackOperators(df, 0))
236+
}
237+
}
238+
239+
test("SECOND") {
240+
withTable("t1") {
241+
sql("create table t1 (c1 int, c2 timestamp) USING PARQUET")
242+
sql("INSERT INTO t1 VALUES(1, NOW())")
243+
runQueryAndCompare("SELECT c1, SECOND(c2) FROM t1 LIMIT 1")(
244+
df => checkFallbackOperators(df, 0))
245+
}
246+
}
229247
}
230248

231249
test("map extract - getmapvalue") {

0 commit comments

Comments
 (0)