-
Notifications
You must be signed in to change notification settings - Fork 2k
[Enhancement]Enhance datetime format #39986
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
Conversation
int withMs = str.contains(".") ? 1 : 0; | ||
int withSplitT = str.contains("T") ? 1 : 0; | ||
DateTimeFormatter formatter = DATETIME_FORMATTERS[isTwoDigit][withMs][withSplitT]; | ||
DateTimeFormatter formatter = DATETIME_FORMATTERS[isTwoDigit][withMs][withSplitT][withSec]; | ||
return parseStringWithDefaultHSM(str, formatter); | ||
} else { | ||
// date |
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.
The most risky bug in this code is:
Missing DateTimeFormatter initializations for when milliseconds are not included (withMs
is 0
) but seconds are included (withSec
is 1
).
You can modify the code like this:
@@ -91,19 +91,23 @@ public class DateUtils {
...
+ // Initialization for cases when withMs is 0 and withSec is 1
+ DATETIME_FORMATTERS[0][0][0][1] = unixDatetimeStrictFormatter("%Y-%m-%e %H:%i:%s", false);
+ DATETIME_FORMATTERS[0][0][1][1] = unixDatetimeStrictFormatter("%Y-%m-%eT%H:%i:%s", false);
+ DATETIME_FORMATTERS[1][0][0][1] = unixDatetimeStrictFormatter("%y-%m-%e %H:%i:%s", false);
+ DATETIME_FORMATTERS[1][0][1][1] = unixDatetimeStrictFormatter("%y-%m-%eT%H:%i:%s", false);
The final initializations should look like this:
DATETIME_FORMATTERS[0][0][0][0] = unixDatetimeStrictFormatter("%Y-%m-%e %H:%i", false);
DATETIME_FORMATTERS[0][0][0][1] = unixDatetimeStrictFormatter("%Y-%m-%e %H:%i:%s", false);
// ... continued original initialization for other options...
DATETIME_FORMATTERS[0][1][1][1] = unixDatetimeStrictFormatter("%Y-%m-%eT%H:%i:%s.%f", false);
// New initializations for missing formatters
DATETIME_FORMATTERS[0][0][1][1] = unixDatetimeStrictFormatter("%Y-%m-%eT%H:%i:%s", false);
DATETIME_FORMATTERS[1][0][0][1] = unixDatetimeStrictFormatter("%y-%m-%e %H:%i:%s", false);
DATETIME_FORMATTERS[1][0][1][1] = unixDatetimeStrictFormatter("%y-%m-%eT%H:%i:%s", false);
Note that each new formatter I've added assumes %s
must be formatted strictly (which you will want to verify).
it's best to add sql test about iceberg |
DATETIME_FORMATTERS[1][0][1][0] = unixDatetimeStrictFormatter("%y-%m-%eT%H:%i", false); | ||
DATETIME_FORMATTERS[1][0][1][1] = unixDatetimeStrictFormatter("%y-%m-%eT%H:%i:%s", false); | ||
DATETIME_FORMATTERS[1][1][0][1] = unixDatetimeStrictFormatter("%y-%m-%e %H:%i:%s.%f", false); | ||
DATETIME_FORMATTERS[1][1][1][1] = unixDatetimeStrictFormatter("%y-%m-%eT%H:%i:%s.%f", false); | ||
} | ||
|
||
public static String formatDateTimeUnix(LocalDateTime dateTime) { |
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.
Could you add some unit tests for this method?
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.
Hi @packy92 i add ut for DateUtils.parseStrictDateTime(s) method. This PR not affect formatDateTimeUnix method.
Signed-off-by: leoyy0316 <[email protected]>
Signed-off-by: leoyy0316 <[email protected]>
Signed-off-by: leoyy0316 <[email protected]>
|
[FE Incremental Coverage Report]✅ pass : 15 / 15 (100.00%) file detail
|
[BE Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
@Mergifyio backport branch-3.2 |
✅ Backports have been created
|
@Mergifyio backport branch-3.1 |
https://github.com/Mergifyio backport branch-3.0 |
@Mergifyio backport branch-2.5 |
Signed-off-by: leoyy0316 <[email protected]> (cherry picked from commit 20e682c)
✅ Backports have been created
|
✅ Backports have been created
|
✅ Backports have been created
|
Signed-off-by: leoyy0316 <[email protected]> (cherry picked from commit 20e682c)
Signed-off-by: leoyy0316 <[email protected]> (cherry picked from commit 20e682c)
Signed-off-by: leoyy0316 <[email protected]> (cherry picked from commit 20e682c)
Co-authored-by: leoyy0316 <[email protected]>
Signed-off-by: leoyy0316 <[email protected]>
Signed-off-by: leoyy0316 <[email protected]>
Co-authored-by: leoyy0316 <[email protected]>
Why I'm doing:
What I'm doing:
Fixes #issue
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: