-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
SQL: Fix milliseconds handling in intervals #51675
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,8 +129,14 @@ public static String toString(Object value) { | |
sb.append(":"); | ||
durationInSec = durationInSec % SECONDS_PER_MINUTE; | ||
sb.append(indent(durationInSec)); | ||
sb.append("."); | ||
sb.append(TimeUnit.NANOSECONDS.toMillis(d.getNano())); | ||
long millis = TimeUnit.NANOSECONDS.toMillis(d.getNano()); | ||
if (millis > 0) { | ||
sb.append("."); | ||
while (millis % 10 == 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
millis /= 10; | ||
} | ||
sb.append(millis); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -341,6 +341,10 @@ TemporalAmount parse(Source source, String string) { | |
+ ": negative value [{}] not allowed (negate the entire interval instead)", | ||
v); | ||
} | ||
if (units.get(unitIndex) == TimeUnit.MILLISECOND && number.length() < 3) { | ||
// normalize the number past DOT to millis | ||
v *= number.length() < 2 ? 100 : 10; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same concept here, you could avoid the multiplication by creating a string with right zero padding and then read is as number. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be changed later if we ever bring the nanos to intervals and a multiplication might be more succinct. But yes, also here debatable. |
||
} | ||
values[unitIndex++] = v; | ||
} catch (QlIllegalArgumentException siae) { | ||
throw new ParsingException(source, invalidIntervalMessage(string), siae.getMessage()); | ||
|
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.
Alternatively you could just iterate on the string millis from end->start and remove all zeroes.
Don't know if performance wise makes sense...
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.
I've also fluttered a bit between the two approaches. I went with this approach since generally arithmetic operations should be faster. But anyways, micro-optimisations.