[HUDI-1794] Moved static COMMIT_FORMATTER to thread local variable as SimpleDateFormat is not thread safe. (#2819)
This commit is contained in:
@@ -293,12 +293,12 @@ object HoodieSqlUtils extends SparkAdapterSupport {
|
||||
*/
|
||||
def formatQueryInstant(queryInstant: String): String = {
|
||||
if (queryInstant.length == 19) { // for yyyy-MM-dd HH:mm:ss
|
||||
HoodieActiveTimeline.COMMIT_FORMATTER.format(defaultDateTimeFormat.parse(queryInstant))
|
||||
HoodieActiveTimeline.formatInstantTime(defaultDateTimeFormat.parse(queryInstant))
|
||||
} else if (queryInstant.length == 14) { // for yyyyMMddHHmmss
|
||||
HoodieActiveTimeline.COMMIT_FORMATTER.parse(queryInstant) // validate the format
|
||||
HoodieActiveTimeline.parseInstantTime(queryInstant) // validate the format
|
||||
queryInstant
|
||||
} else if (queryInstant.length == 10) { // for yyyy-MM-dd
|
||||
HoodieActiveTimeline.COMMIT_FORMATTER.format(defaultDateFormat.parse(queryInstant))
|
||||
HoodieActiveTimeline.formatInstantTime(defaultDateFormat.parse(queryInstant))
|
||||
} else {
|
||||
throw new IllegalArgumentException(s"Unsupported query instant time format: $queryInstant,"
|
||||
+ s"Supported time format are: 'yyyy-MM-dd: HH:mm:ss' or 'yyyy-MM-dd' or 'yyyyMMddHHmmss'")
|
||||
|
||||
@@ -179,10 +179,10 @@ class HoodieStreamSource(
|
||||
startOffset match {
|
||||
case INIT_OFFSET => startOffset.commitTime
|
||||
case HoodieSourceOffset(commitTime) =>
|
||||
val time = HoodieActiveTimeline.COMMIT_FORMATTER.parse(commitTime).getTime
|
||||
val time = HoodieActiveTimeline.parseInstantTime(commitTime).getTime
|
||||
// As we consume the data between (start, end], start is not included,
|
||||
// so we +1s to the start commit time here.
|
||||
HoodieActiveTimeline.COMMIT_FORMATTER.format(new Date(time + 1000))
|
||||
HoodieActiveTimeline.formatInstantTime(new Date(time + 1000))
|
||||
case _=> throw new IllegalStateException("UnKnow offset type.")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user