cloud-fan commented on code in PR #57698:
URL: https://github.com/apache/spark/pull/57698#discussion_r3752263295
##########
sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala:
##########
@@ -837,6 +838,76 @@ class JDBCSuite extends SharedSparkSession {
}
}
+ test("SPARK-57460: JDBC TIMESTAMP keeps microsecond mapping by default") {
+ // Without preferTimestampNanos, a driver TIMESTAMP(9) still infers as
microsecond
+ // TimestampType even when the nanos preview feature is enabled.
+ withSQLConf(SQLConf.TIMESTAMP_NANOS_TYPES_ENABLED.key -> "true") {
+ val conn = java.sql.DriverManager.getConnection(urlWithUserAndPass)
+ try {
+ conn.createStatement().execute("CREATE TABLE TEST.TS_DEFAULT (t
TIMESTAMP(9))")
+ conn.createStatement().execute(
+ "INSERT INTO TEST.TS_DEFAULT VALUES (TIMESTAMP '2020-02-02
04:13:14.123456789')")
+ val df = spark.read.jdbc(urlWithUserAndPass, "TEST.TS_DEFAULT", new
Properties())
+ assert(df.schema("T").dataType === TimestampType)
+ } finally {
+ conn.createStatement().execute("DROP TABLE IF EXISTS TEST.TS_DEFAULT")
+ conn.close()
+ }
+ }
+ }
+
+ test("SPARK-57460: JDBC TIMESTAMP reads nanosecond LTZ precision when
requested") {
+ withSQLConf(SQLConf.TIMESTAMP_NANOS_TYPES_ENABLED.key -> "true") {
+ val conn = java.sql.DriverManager.getConnection(urlWithUserAndPass)
+ try {
+ conn.createStatement().execute("CREATE TABLE TEST.TS_NANOS_LTZ (t
TIMESTAMP(9))")
+ conn.createStatement().execute(
+ "INSERT INTO TEST.TS_NANOS_LTZ VALUES (TIMESTAMP '2020-02-02
04:13:14.123456789')")
+ val df = spark.read
+ .option("preferTimestampNanos", "true")
+ .jdbc(urlWithUserAndPass, "TEST.TS_NANOS_LTZ", new Properties())
+ assert(df.schema("T").dataType === TimestampLTZNanosType(9))
+ val result = df.collect()
+ // H2 stores TIMESTAMP as local wall-clock; the LTZ read binds it to
the session zone.
+ val expected = java.time.LocalDateTime.of(2020, 2, 2, 4, 13, 14,
123456789)
+ .atZone(java.time.ZoneId.systemDefault()).toInstant
+ assert(result(0).getAs[java.time.Instant](0) === expected)
+ } finally {
+ conn.createStatement().execute("DROP TABLE IF EXISTS
TEST.TS_NANOS_LTZ")
+ conn.close()
+ }
+ }
+ }
+
+ test("SPARK-57460: JDBC TIMESTAMP reads nanosecond NTZ precision when
requested") {
+ // Pin the JVM default zone so the driver's local <-> java.sql.Timestamp
conversion (and thus
Review Comment:
This comment describes the old `java.sql.Timestamp` conversion path, but
`TimestampNTZNanosGetter` now requests `LocalDateTime` directly and bypasses
that zone-dependent conversion. Please remove the comment and the unnecessary
`withDefaultTimeZone` wrapper, or update them to document an actual remaining
dependency.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]