Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,14 @@ class LegacyFastTimestampFormatter(

override def parseOptional(s: String): Option[Long] = {
cal.clear() // Clear the calendar because it can be re-used many times
if (fastDateFormat.parse(s, new ParsePosition(0), cal)) {
Some(extractMicros(cal))
} else {
None
try {
if (fastDateFormat.parse(s, new ParsePosition(0), cal)) {
Some(extractMicros(cal))
} else {
None
}
} catch {
case NonFatal(_) => None
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,11 @@ class TimestampFormatterSuite extends DatetimeFormatterSuite {

assert(fastFormatter.parseOptional("2023-12-31 23:59:59.9990").contains(1704067199999000L))
assert(fastFormatter.parseOptional("abc").isEmpty)
assert(fastFormatter.parseOptional("23012150952").isEmpty)

assert(simpleFormatter.parseOptional("2023-12-31 23:59:59.9990").contains(1704067208990000L))
assert(simpleFormatter.parseOptional("abc").isEmpty)

assert(simpleFormatter.parseOptional("23012150952").isEmpty)
}

test("SPARK-45424: do not return optional parse results when only prefix match") {
Expand Down