Skip to content

Commit 1890589

Browse files
committed
Use Java 8 time API classes in SQLQueryTestSuite
1 parent cc4c07d commit 1890589

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/HiveResult.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package org.apache.spark.sql.execution
1919

2020
import java.nio.charset.StandardCharsets
2121
import java.sql.{Date, Timestamp}
22+
import java.time.{Instant, LocalDate}
2223

2324
import org.apache.spark.sql.Row
2425
import org.apache.spark.sql.catalyst.util.{DateFormatter, DateTimeUtils, TimestampFormatter}
@@ -67,8 +68,12 @@ object HiveResult {
6768
case (null, _) => if (nested) "null" else "NULL"
6869
case (b, BooleanType) => b.toString
6970
case (d: Date, DateType) => dateFormatter.format(DateTimeUtils.fromJavaDate(d))
71+
case (ld: LocalDate, DateType) =>
72+
dateFormatter.format(DateTimeUtils.localDateToDays(ld))
7073
case (t: Timestamp, TimestampType) =>
7174
timestampFormatter.format(DateTimeUtils.fromJavaTimestamp(t))
75+
case (i: Instant, TimestampType) =>
76+
timestampFormatter.format(DateTimeUtils.instantToMicros(i))
7277
case (bin: Array[Byte], BinaryType) => new String(bin, StandardCharsets.UTF_8)
7378
case (decimal: java.math.BigDecimal, DecimalType()) => decimal.toPlainString
7479
case (n, _: NumericType) => n.toString

sql/core/src/test/resources/sql-tests/results/postgreSQL/date.sql.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -800,15 +800,15 @@ SELECT DATE_TRUNC('MILLENNIUM', TIMESTAMP '1970-03-20 04:30:00.00000')
800800
-- !query schema
801801
struct<date_trunc(MILLENNIUM, TIMESTAMP '1970-03-20 04:30:00'):timestamp>
802802
-- !query output
803-
1001-01-01 00:07:02
803+
1001-01-01 00:00:00
804804

805805

806806
-- !query
807807
SELECT DATE_TRUNC('MILLENNIUM', DATE '1970-03-20')
808808
-- !query schema
809809
struct<date_trunc(MILLENNIUM, CAST(DATE '1970-03-20' AS TIMESTAMP)):timestamp>
810810
-- !query output
811-
1001-01-01 00:07:02
811+
1001-01-01 00:00:00
812812

813813

814814
-- !query
@@ -840,15 +840,15 @@ SELECT DATE_TRUNC('CENTURY', DATE '0002-02-04')
840840
-- !query schema
841841
struct<date_trunc(CENTURY, CAST(DATE '0002-02-04' AS TIMESTAMP)):timestamp>
842842
-- !query output
843-
0001-01-01 00:07:02
843+
0001-01-01 00:00:00
844844

845845

846846
-- !query
847847
SELECT DATE_TRUNC('CENTURY', TO_DATE('0055-08-10 BC', 'yyyy-MM-dd G'))
848848
-- !query schema
849849
struct<date_trunc(CENTURY, CAST(to_date('0055-08-10 BC', 'yyyy-MM-dd G') AS TIMESTAMP)):timestamp>
850850
-- !query output
851-
-0099-01-01 00:07:02
851+
-0099-01-01 00:00:00
852852

853853

854854
-- !query
@@ -864,15 +864,15 @@ SELECT DATE_TRUNC('DECADE', DATE '0004-12-25')
864864
-- !query schema
865865
struct<date_trunc(DECADE, CAST(DATE '0004-12-25' AS TIMESTAMP)):timestamp>
866866
-- !query output
867-
0000-01-01 00:07:02
867+
0000-01-01 00:00:00
868868

869869

870870
-- !query
871871
SELECT DATE_TRUNC('DECADE', TO_DATE('0002-12-31 BC', 'yyyy-MM-dd G'))
872872
-- !query schema
873873
struct<date_trunc(DECADE, CAST(to_date('0002-12-31 BC', 'yyyy-MM-dd G') AS TIMESTAMP)):timestamp>
874874
-- !query output
875-
-0010-01-01 00:07:02
875+
-0010-01-01 00:00:00
876876

877877

878878
-- !query

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession {
337337
localSparkSession.conf.set(SQLConf.ANSI_ENABLED.key, true)
338338
case _ =>
339339
}
340+
localSparkSession.conf.set(SQLConf.DATETIME_JAVA8API_ENABLED.key, true)
340341

341342
if (configSet.nonEmpty) {
342343
// Execute the list of set operation in order to add the desired configs

0 commit comments

Comments
 (0)