-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-29904][SQL][2.4] Parse timestamps in microsecond precision by JSON/CSV datasources #26507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
897bf33
b18c61a
915a755
3d7a611
453ee5c
86ac2b2
9c82538
9a446aa
ef8284c
638c640
eb58d03
274f25a
66d1100
69c1bb4
0bdb523
7d9a19d
810a061
1a6608f
31d7877
8db95ca
1852511
1cbd35b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,8 @@ import java.sql.{Date, Timestamp} | |
| import java.text.SimpleDateFormat | ||
| import java.util.{Calendar, Locale, TimeZone} | ||
|
|
||
| import org.apache.commons.lang3.time.FastDateFormat | ||
|
|
||
| import org.apache.spark.SparkFunSuite | ||
| import org.apache.spark.sql.catalyst.util.DateTimeUtils._ | ||
| import org.apache.spark.unsafe.types.UTF8String | ||
|
|
@@ -692,4 +694,31 @@ class DateTimeUtilsSuite extends SparkFunSuite { | |
| } | ||
| } | ||
| } | ||
|
|
||
| test("fast parse to micros") { | ||
dongjoon-hyun marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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") | ||
|
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.