-
Notifications
You must be signed in to change notification settings - Fork 141
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
Add TIME_FORMAT()
Function To SQL Plugin
#1301
Add TIME_FORMAT()
Function To SQL Plugin
#1301
Conversation
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## main #1301 +/- ##
=========================================
Coverage 98.36% 98.37%
- Complexity 3643 3680 +37
=========================================
Files 343 343
Lines 9010 9065 +55
Branches 585 585
=========================================
+ Hits 8863 8918 +55
Misses 142 142
Partials 5 5
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
@@ -636,7 +636,7 @@ public void testDateFormat() throws IOException { | |||
String timestamp = "1998-01-31 13:14:15.012345"; | |||
String timestampFormat = "%a %b %c %D %d %e %f %H %h %I %i %j %k %l %M " | |||
+ "%m %p %r %S %s %T %% %P"; | |||
String timestampFormatted = "Sat Jan 01 31st 31 31 12345 13 01 01 14 031 13 1 " | |||
String timestampFormatted = "Sat Jan 01 31st 31 31 012345 13 01 01 14 031 13 1 " |
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.
what is the change? 12345 -> 012345
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.
For DATE_FORMAT
and TIME_FORMAT
functions, microseconds should be padded with 0s on the left side according to both MySQL and our documentation (6 digits of precision should always be returned when using %f
). This was fixed and the test was changed.
@@ -846,6 +847,12 @@ private DefaultFunctionResolver date_format() { | |||
STRING, DATE, STRING), | |||
impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedDate), | |||
STRING, DATETIME, STRING), | |||
implWithProperties( |
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.
update javadoc also.
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.
Updated in 1af5666
31fdec6
Signed-off-by: GabeFernandez310 <[email protected]>
31fdec6
to
406ce81
Compare
@@ -61,7 +66,7 @@ interface DateTimeFormatHandler { | |||
.put("%D", (date) -> // %w - Day of month with English suffix | |||
String.format("'%d%s'", date.getDayOfMonth(), getSuffix(date.getDayOfMonth()))) | |||
.put("%f", (date) -> // %f - Microseconds | |||
String.format("'%d'", (date.getNano() / 1000))) | |||
String.format(NANO_SEC_FORMAT, (date.getNano() / 1000))) |
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.
Love it - but I feel like we should use a constant for all of the surrounding format strings.
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.
minor requests
DSL.literal("%h")), | ||
Arguments.of( | ||
DSL.literal("61:11:12"), | ||
DSL.literal("%h")) |
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.
- nanoseconds test would be good
Arguments.of("%V"), | ||
Arguments.of("%v"), | ||
Arguments.of("%X"), | ||
Arguments.of("%x") |
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.
you could also test formats without %
or with extra characters like %%h
or %hh
or wrong order or extra spaces like h%
or %h
84756c7
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.
LGTM @GabeFernandez310.
Signed-off-by: GabeFernandez310 [email protected]
Description
Adds the
time_format
function to the SQL plugin. The function takes aDATE
/DATETIME
/TIME
/TIMESTAMP
/STRING
in a valid format, and a formatting string (e.g.,"%h %p"
) and outputs a formatted string. If aDATE
is passed in, it treats the argument as if it is taken at midnight (i.e.,00:00:00
).Example:
Issues Resolved
#722
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.