cloud-fan 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_r346290892
##########
File path:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DateTimeUtilsSuite.scala
##########
@@ -692,4 +694,31 @@ class DateTimeUtilsSuite extends SparkFunSuite {
}
}
}
+
+ test("fast parse to micros") {
+ val timeZone = TimeZoneUTC
+ def check(pattern: String, input: String, reference: String): Unit = {
+ val parser = getDateTimeParser(
+ FastDateFormat.getInstance(pattern, timeZone, Locale.US),
+ timeZone)
+ val expected = DateTimeUtils.stringToTimestamp(
+ UTF8String.fromString(reference), timeZone).get
+ val actual = parser.parse(input)
+ assert(actual === expected)
+ }
+ check("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSXXX",
+ "2019-10-14T09:39:07.3220000Z", "2019-10-14T09:39:07.322Z")
+ check("yyyy-MM-dd'T'HH:mm:ss.SSSSSSXXX",
+ "2019-10-14T09:39:07.322000Z", "2019-10-14T09:39:07.322Z")
+ check("yyyy-MM-dd'T'HH:mm:ss.SSSX",
+ "2019-10-14T09:39:07.322Z", "2019-10-14T09:39:07.322Z")
+ check("yyyy-MM-dd'T'HH:mm:ss.SSSSSSX",
+ "2019-10-14T09:39:07.123456Z", "2019-10-14T09:39:07.123456Z")
+ check("yyyy-MM-dd'T'HH:mm:ss.SSSSSSX",
+ "2019-10-14T09:39:07.000010Z", "2019-10-14T09:39:07.000010Z")
+ check("yyyy-MM-dd'T'HH:mm:ss.SX",
+ "2019-10-14T09:39:07.1Z", "2019-10-14T09:39:07.1Z")
+ check("yyyy-MM-dd'T'HH:mm:ss.SSX",
+ "2019-10-14T09:39:07.10Z", "2019-10-14T09:39:07.1Z")
Review comment:
can we add some negative tests?
----------------------------------------------------------------
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]