Skip to content

Conversation

@beliefer
Copy link
Contributor

@beliefer beliefer commented Jan 7, 2024

What changes were proposed in this pull request?

This PR propose to replace SimpleDateFormat with DateTimeFormatter.

Why are the changes needed?

According to the javadoc of SimpleDateFormat, it recommended to use DateTimeFormatter too.
1
In addition, DateTimeFormatter have better performance than SimpleDateFormat too.

Note: SimpleDateFormat and DateTimeFormatter are not completely compatible, for example, the formats supported by parse 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'.

@github-actions github-actions bot added the CORE label Jan 7, 2024
@HyukjinKwon
Copy link
Member

cc @MaxGekk BTW, we would have to replace FastDateFormat too if possible.

@beliefer beliefer force-pushed the replace-sdf-with-dtf branch from c27cdbe to 9f1c744 Compare January 8, 2024 05:49
@beliefer beliefer changed the title [WIP][CORE] Replace SimpleDateFormat with DateTimeFormatter [WIP][CORE][MLLIB][SQL] Replace SimpleDateFormat with DateTimeFormatter Jan 8, 2024
@beliefer beliefer force-pushed the replace-sdf-with-dtf branch from 9f1c744 to 348b333 Compare January 8, 2024 10:00
@beliefer beliefer changed the title [WIP][CORE][MLLIB][SQL] Replace SimpleDateFormat with DateTimeFormatter [SPARK-46623][CORE][MLLIB][SQL] Replace SimpleDateFormat with DateTimeFormatter Jan 8, 2024
@beliefer beliefer requested a review from dongjoon-hyun January 8, 2024 13:35
@beliefer
Copy link
Contributor Author

beliefer commented Jan 8, 2024

ping @dongjoon-hyun @srowen @LuciferYang

@beliefer
Copy link
Contributor Author

cc @mridulm

Copy link
Contributor

@mridulm mridulm left a 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

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Comment on lines 107 to 113
Copy link
Contributor

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

Suggested change
@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)
}

@beliefer beliefer force-pushed the replace-sdf-with-dtf branch from 348b333 to f771604 Compare January 16, 2024 08:19
Copy link
Contributor

@mridulm mridulm left a 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.


private def generateWorkerId(): String = {
workerIdPattern.format(createDateFormat.format(new Date), host, port)
workerIdPattern.format(Worker.DATE_TIME_FORMATTER.format(new Date().toInstant), host, port)
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

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))
Copy link
Contributor

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))
Copy link
Contributor

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?


lazy val externalTempPath: Path = getExternalTmpPath(path)

private lazy val dateTimeFormatter =
Copy link
Contributor

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

@beliefer
Copy link
Contributor Author

The GA failure is unrelated.

@mridulm mridulm closed this in bede614 Jan 18, 2024
@mridulm
Copy link
Contributor

mridulm commented Jan 18, 2024

Merged to master.
Thanks for fixing this @beliefer !
Thanks for the review @LuciferYang :-)

@mridulm
Copy link
Contributor

mridulm commented Jan 18, 2024

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.

@beliefer
Copy link
Contributor Author

@mridulm @LuciferYang @HyukjinKwon Thank you!

@beliefer
Copy link
Contributor Author

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.

I checked. It's OK. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants