Skip to content

Commit 23c01c5

Browse files
committed
Fix for ArrayOutofBoundsException while converting string to timestamp
1 parent 6d4cc7b commit 23c01c5

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ object DateTimeUtils {
286286
i += 1
287287
}
288288
} else {
289-
if (b == ':' || b == ' ') {
289+
if (i < 9 && (b == ':' || b == ' ')) {
290290
segments(i) = currentSegmentValue
291291
currentSegmentValue = 0
292292
i += 1

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DateTimeUtilsSuite.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,13 @@ class DateTimeUtilsSuite extends SparkFunSuite with Matchers {
456456
}
457457
}
458458

459+
test("trailing characters while converting string to timestamp") {
460+
val s = UTF8String.fromString("2019-10-31T10:59:23Z:::")
461+
println(s)
462+
val time = DateTimeUtils.stringToTimestamp(s, defaultZoneId)
463+
assert(time == None)
464+
}
465+
459466
test("truncTimestamp") {
460467
def testTrunc(
461468
level: Int,

0 commit comments

Comments
 (0)