MaxGekk commented on a change in pull request #27710: [SPARK-30960][SQL] add 
back the legacy date/timestamp format support in CSV/JSON parser
URL: https://github.com/apache/spark/pull/27710#discussion_r384923946
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/csv/UnivocityParser.scala
 ##########
 @@ -175,10 +175,30 @@ class UnivocityParser(
       }
 
     case _: TimestampType => (d: String) =>
-      nullSafeDatum(d, name, nullable, options)(timestampFormatter.parse)
+      nullSafeDatum(d, name, nullable, options) { datum =>
+        try {
+          timestampFormatter.parse(datum)
+        } catch {
+          case NonFatal(e) =>
+            // If fails to parse, then tries the way used in 2.0 and 1.x for 
backwards
+            // compatibility.
+            val str = UTF8String.fromString(datum)
+            DateTimeUtils.stringToTimestamp(str, 
options.zoneId).getOrElse(throw e)
 
 Review comment:
   My five cents, besides of the calendar problem the fallback function 
`DateTimeUtils.stringToTime()` didn't take into account the session time zone 
(`spark.sql.session.timeZone`). This can lead to the situation when there are 
values in a column parsed in different time zones. I do think this is serious 
problem of the fallback mechanism. If we are going to restore it to only don't 
get nulls, this will make users life harder in troubleshooting wrong results. 

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