[HUDI-2831] Securing usages of SimpleDateFormat to be thread-safe (#4073)
This commit is contained in:
@@ -48,7 +48,12 @@ import java.text.SimpleDateFormat
|
||||
import scala.collection.immutable.Map
|
||||
|
||||
object HoodieSqlUtils extends SparkAdapterSupport {
|
||||
private val defaultDateFormat = new SimpleDateFormat("yyyy-MM-dd")
|
||||
// NOTE: {@code SimpleDataFormat} is NOT thread-safe
|
||||
// TODO replace w/ DateTimeFormatter
|
||||
private val defaultDateFormat =
|
||||
ThreadLocal.withInitial(new java.util.function.Supplier[SimpleDateFormat] {
|
||||
override def get() = new SimpleDateFormat("yyyy-MM-dd")
|
||||
})
|
||||
|
||||
def isHoodieTable(table: CatalogTable): Boolean = {
|
||||
table.provider.map(_.toLowerCase(Locale.ROOT)).orNull == "hudi"
|
||||
@@ -298,7 +303,7 @@ object HoodieSqlUtils extends SparkAdapterSupport {
|
||||
HoodieActiveTimeline.parseDateFromInstantTime(queryInstant) // validate the format
|
||||
queryInstant
|
||||
} else if (instantLength == 10) { // for yyyy-MM-dd
|
||||
HoodieActiveTimeline.formatDate(defaultDateFormat.parse(queryInstant))
|
||||
HoodieActiveTimeline.formatDate(defaultDateFormat.get().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'")
|
||||
|
||||
Reference in New Issue
Block a user