sadikovi commented on code in PR #37013:
URL: https://github.com/apache/spark/pull/37013#discussion_r909030210


##########
sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala:
##########
@@ -1939,17 +1939,22 @@ class JDBCSuite extends QueryTest
           val df = spark.sql(s"select timestamp_ntz '$datetime'")
           df.write.format("jdbc")
             .mode("overwrite")
+            .option("inferTimestampNTZType", "true")

Review Comment:
   `inferTimestampNTZType` is only applied for reads. Could you remove this 
option here?



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala:
##########
@@ -599,10 +610,13 @@ object JdbcUtils extends Logging with SQLConfHelper {
           stmt.setTimestamp(pos + 1, 
toJavaTimestamp(instantToMicros(row.getAs[Instant](pos))))
       } else {
         (stmt: PreparedStatement, row: Row, pos: Int) =>
-          stmt.setTimestamp(
-            pos + 1,
-            
toJavaTimestamp(localDateTimeToMicros(row.getAs[java.time.LocalDateTime](pos)))
-          )
+          val micros = 
localDateTimeToMicros(row.getAs[java.time.LocalDateTime](pos))
+          val seconds = Math.floorDiv(micros, 
DateTimeConstants.MICROS_PER_SECOND)
+          val nanos = (micros - seconds * DateTimeConstants.MICROS_PER_SECOND) 
*
+            DateTimeConstants.NANOS_PER_MICROS
+          val result = new java.sql.Timestamp(seconds * 
DateTimeConstants.MILLIS_PER_SECOND)

Review Comment:
   Isn't it what `toJavaTimestamp` does already?



-- 
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]

Reply via email to