-
Notifications
You must be signed in to change notification settings - Fork 166
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
feat: add round function #322
Conversation
Where did this come from? Based on #307 I thought we weren't going to do rounding to multiple. Rounding to some number of digits is exactly the same thing, just restricted to powers of 10. That rounding argument is also really weird, there's no such thing as an optional value argument and using an integer for this is really weird. If we are going to do a round-to-multiple I feel like we should just reuse the existing rounding mode option to determine how to round. Based on #307 I would expect simply |
I think we will want to implement rounding and tie-breaking options similar to the ones in Acero's |
|
@jvanstraten I was referring to the SQL definition here. I see your point on WDYT? cc @ianmcook |
IIUC, I think we can just implement a rounding mode option, and make |
I figured we could just reuse the floating point rounding mode. I also generalized it to integers for quantile earlier. Wouldn't Note that dedicated ceil and floor functions already exist. I guess we should get rid of those if we go the option route. |
Ah, yes, I think that all makes sense. Since a lot of thought went into ensuring that Acero's
So this raises some questions:
|
Hm. I guess that makes sense for round, and adding more variants is cheap. I don't think it makes sense to do it for all floating point functions though, since IEEE is pretty explicit about what the possible rounding modes are. |
94fcb33
to
f6af6fe
Compare
cc @jvanstraten I added the round options. Does it reflect what you expected? |
No, because you didn't add the rounding modes @ianmcook was talking about, and the supposedly-optional |
75f55b2
to
3e47415
Compare
@jvanstraten I added other options. Should we create documentation for this too? In this PR itself or a separate PR? |
It should just be in the description of the function in this case; this option argument is basically specific to |
@jvanstraten I had the doubt though. I will update it. |
|
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.
@vibhatha when you get a moment can you update this to the new format for optional arguments?
sure @westonpace, thanks for the ping. I will update it. |
aa17207
to
e2c9f4d
Compare
@vibhatha can you update this when you get a chance? |
@westonpace will update it tomorrow. Sorry about the delay. |
@westonpace sorry about the long wait. I updated the PR, although I see |
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.
Thanks for the update. It still says out of date but a rebase should have fixed that. Did you make sure you had updated your local main
branch before rebasing?
extensions/functions_rounding.yaml
Outdated
to round it. For floating point numbers, it specifies the IEEE | ||
754 rounding mode (as it does for all other floating point | ||
operations). For integer types: |
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 removed this test below (in the fp64/i32 kernel). Can you also remove it here (in the fp32/i32 kernel)
|
@westonpace I think now the branch is in sync with the base branch. |
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.
Thanks for adding integer kernels. I think the description will need to be slightly different for these kernels.
- TIE_TO_EVEN: round to nearest value; if exactly halfway, tie | ||
to the even option. | ||
- TIE_AWAY_FROM_ZERO: round to nearest value; if exactly | ||
halfway, tie away from zero. | ||
- TRUNCATE: always round toward zero. | ||
- CEILING: always round toward positive infinity. | ||
- FLOOR: always round toward negative infinity. | ||
- AWAY_FROM_ZERO: round negative values with FLOOR rule, round positive values with CEILING rule | ||
- TIE_DOWN: round ties with FLOOR rule | ||
- TIE_UP: round ties with CEILING rule | ||
- TIE_TOWARDS_ZERO: round ties with TRUNCATE rule | ||
- TIE_TO_ODD: round to nearest value; if exactly halfway, tie | ||
to the odd option. |
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 does TIE_TO_EVEN
and TIE_TO_ODD
mean for negative values of s
?
CC @ianmcook
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.
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.
It is not quite clear from this definition either: https://dev.mysql.com/doc/refman/5.7/en/mathematical-functions.html#function_round
🤔
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.
Ok. I did some investigation. As an example, consider 15 when s=-1
. The two choices are 10
and 20
which are both even. However, when we drop the trailing 0's so the choices are 1
and 2
and 2
is the even one so we get 20
.
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 don't think we need to clarify. I don't think we can easily do so without writing a novel.
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 played with Mysql a bit, but with the round function, can we specify such options?
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.
Alright, I think this looks good. @EpsilonPrime did you want to take another look?
@westonpace a CI is failing and this happened a few times. Seems like unrelated, though not very sure about it. |
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
Unrelated to this PR. I created #439 which should address it. |
This PR adds
round
function.