-
Notifications
You must be signed in to change notification settings - Fork 28.1k
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
[SPARK-46623][CORE][MLLIB][SQL] Replace SimpleDateFormat with DateTimeFormatter #44616
Conversation
cc @MaxGekk BTW, we would have to replace |
c27cdbe
to
9f1c744
Compare
9f1c744
to
348b333
Compare
cc @mridulm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+CC @srowen as well
@@ -58,7 +59,10 @@ private[deploy] class Master( | |||
private val appIdPattern = conf.get(APP_ID_PATTERN) | |||
|
|||
// For application IDs | |||
private def createDateFormat = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US) | |||
private lazy val dateTimeFormatter = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Does not need to be lazy
and can be moved to object Master
, same in other places as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
@transient | ||
private val dateTimeFormatter = | ||
DateTimeFormatter | ||
.ofPattern("yyyyMMddHHmmss", Locale.US) | ||
.withZone(ZoneId.systemDefault()) | ||
|
||
private val jobTrackerId: String = dateTimeFormatter.format(new Date().toInstant) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We dont need this field
@transient | |
private val dateTimeFormatter = | |
DateTimeFormatter | |
.ofPattern("yyyyMMddHHmmss", Locale.US) | |
.withZone(ZoneId.systemDefault()) | |
private val jobTrackerId: String = dateTimeFormatter.format(new Date().toInstant) | |
private val jobTrackerId: String = { | |
val dateTimeFormatter = | |
DateTimeFormatter | |
.ofPattern("yyyyMMddHHmmss", Locale.US) | |
.withZone(ZoneId.systemDefault()) | |
dateTimeFormatter.format(new Date().toInstant) | |
} |
348b333
to
f771604
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. +CC @LuciferYang as well.
@@ -821,7 +820,7 @@ private[deploy] class Worker( | |||
} | |||
|
|||
private def generateWorkerId(): String = { | |||
workerIdPattern.format(createDateFormat.format(new Date), host, port) | |||
workerIdPattern.format(Worker.DATE_TIME_FORMATTER.format(new Date().toInstant), host, port) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to directly use Instant.now()
instead of new Date().toInstant
?
DateTimeFormatter | ||
.ofPattern("yyyyMMddHHmmss", Locale.US) | ||
.withZone(ZoneId.systemDefault()) | ||
dateTimeFormatter.format(new Date().toInstant) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
@@ -34,7 +40,7 @@ private[mllib] trait PMMLModelExport { | |||
val version = getClass.getPackage.getImplementationVersion | |||
val app = new Application("Apache Spark MLlib").setVersion(version) | |||
val timestamp = new Timestamp() | |||
.addContent(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US).format(new Date())) | |||
.addContent(DATE_TIME_FORMATTER.format(new Date().toInstant)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
Timestamp.valueOf( | ||
TextSocketReader.DATE_FORMAT.format(Calendar.getInstance().getTime())) | ||
Timestamp.valueOf(TextSocketReader.DATE_TIME_FORMATTER.format( | ||
Calendar.getInstance().getTime().toInstant)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to directly use Instant.now()
instead of new alendar.getInstance().getTime().toInstant
?
@@ -41,6 +42,11 @@ class HiveTempPath(session: SparkSession, val hadoopConf: Configuration, path: P | |||
|
|||
lazy val externalTempPath: Path = getExternalTmpPath(path) | |||
|
|||
private lazy val dateTimeFormatter = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This definition can also be moved to object HiveTempPath
The GA failure is unrelated. |
Merged to master. |
I had to manually resolve the jira @beliefer - can you please check if I assigned it to you ? There were two id's with same name. |
@mridulm @LuciferYang @HyukjinKwon Thank you! |
I checked. It's OK. Thank you! |
What changes were proposed in this pull request?
This PR propose to replace
SimpleDateFormat
withDateTimeFormatter
.Why are the changes needed?
According to the javadoc of
![1](https://private-user-images.githubusercontent.com/8486025/294687122-97b16bbb-e5b7-4b3f-9bc8-0b0b8c907542.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk2ODczMjcsIm5iZiI6MTcxOTY4NzAyNywicGF0aCI6Ii84NDg2MDI1LzI5NDY4NzEyMi05N2IxNmJiYi1lNWI3LTRiM2YtOWJjOC0wYjBiOGM5MDc1NDIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjlUMTg1MDI3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YmI1ZDVhY2Y0NTE1YzE0OTZjOTA3YTkyMGZhM2I0MzIxOTZjNjk0ODlkY2Q2ZDM5ZWEyNGU2ZTk1OWYzZmY4ZiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.s79TidnU9vnp6jwo_PWaXyq9DACKJGpVyKFjQ-eYW8E)
SimpleDateFormat
, it recommended to useDateTimeFormatter
too.In addition,
DateTimeFormatter
have better performance thanSimpleDateFormat
too.Note:
SimpleDateFormat
andDateTimeFormatter
are not completely compatible, for example, the formats supported byparse
are not exactly the same.Does this PR introduce any user-facing change?
'No'.
How was this patch tested?
GA and manual test.
Was this patch authored or co-authored using generative AI tooling?
'No'.