MaxGekk commented on a change in pull request #26507: [WIP][SQL][2.4] Parse 
timestamps in microsecond precision in JSON datasource
URL: https://github.com/apache/spark/pull/26507#discussion_r345982915
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
 ##########
 @@ -1164,4 +1166,30 @@ object DateTimeUtils {
     threadLocalTimestampFormat.remove()
     threadLocalDateFormat.remove()
   }
+
+  class MicrosCalendar(tz: TimeZone) extends GregorianCalendar(tz, Locale.US) {
+    def getMicros(): SQLTimestamp = {
 
 Review comment:
   > Can we have some comments to explain the behavior? Seems to me it's
   > for .1, it's 1000 microseconds
   
   This is 100 * 1000 microsecond but `SimpleDateFormat` and `FastDateFormat` 
have weird behavior. The example below on 2.4 without my changes:
   ```scala
   scala> val df = Seq("""{"a":"2019-10-14T09:39:07.1Z"}""").toDF
   df: org.apache.spark.sql.DataFrame = [value: string]
   
   scala> val res = df.select(from_json('value, schema, Map("timestampFormat" 
-> "yyyy-MM-dd'T'HH:mm:ss.SXXX")))
   res: org.apache.spark.sql.DataFrame = [jsontostructs(value): struct<a: 
timestamp>]
   
   scala> res.show(false)
   +-------------------------+
   |jsontostructs(value)     |
   +-------------------------+
   |[2019-10-14 12:39:07.001]|
   +-------------------------+
   ```
   ```scala
   scala> val res = df.select(from_json('value, schema, Map("timestampFormat" 
-> "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")))
   res: org.apache.spark.sql.DataFrame = [jsontostructs(value): struct<a: 
timestamp>]
   
   scala> res.show(false)
   +-------------------------+
   |jsontostructs(value)     |
   +-------------------------+
   |[2019-10-14 12:39:07.001]|
   +-------------------------+
   ```
   So `.1` cannot be parsed correctly only `0.100`:
   ```scala
   scala> val df = Seq("""{"a":"2019-10-14T09:39:07.100Z"}""").toDF
   df: org.apache.spark.sql.DataFrame = [value: string]
   
   scala> val res = df.select(from_json('value, schema, Map("timestampFormat" 
-> "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")))
   res: org.apache.spark.sql.DataFrame = [jsontostructs(value): struct<a: 
timestamp>]
   
   scala> res.show(false)
   +-----------------------+
   |jsontostructs(value)   |
   +-----------------------+
   |[2019-10-14 12:39:07.1]|
   +-----------------------+
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to