Skip to content
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

[BUG] ROUND function returns FP result for FP value #1138

Closed
Yury-Fridlyand opened this issue Dec 3, 2022 · 2 comments
Closed

[BUG] ROUND function returns FP result for FP value #1138

Yury-Fridlyand opened this issue Dec 3, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@Yury-Fridlyand
Copy link
Collaborator

What is the bug?

FunctionDSL.impl(
FunctionDSL.nullMissingHandling(
v -> new ExprDoubleValue((double) Math.round(v.floatValue()))),
DOUBLE, FLOAT),
FunctionDSL.impl(
FunctionDSL.nullMissingHandling(
v -> new ExprDoubleValue(new BigDecimal(v.doubleValue()).setScale(0,
RoundingMode.HALF_UP).doubleValue())),
DOUBLE, DOUBLE),

* (x: FLOAT [, y: INTEGER]) -> FLOAT
* (x: DOUBLE [, y: INTEGER]) -> DOUBLE

How can one reproduce the bug?

opensearchsql> select typeof(round(1.1)), round(1.1);
fetched rows / total rows = 1/1
+----------------------+--------------+
| typeof(round(1.1))   | round(1.1)   |
|----------------------+--------------|
| DOUBLE               | 1.0          |
+----------------------+--------------+

What is the expected behavior?
ROUND function should return an integer value (INTEGER or LONG).

It may happen that returned FP value is not an integer number (has digits after the point).

@matthewryanwells
Copy link
Contributor

@Yury-Fridlyand Currently if you put a double in you get a double out, and if you put a long in you get a long out.

If you put a double into round(x) should it return a long always? If you put a double into round(x, y) you can specify how many decimal points to return so sometimes it would have decimals and sometimes it wouldn't, should this always return a double?

@Yury-Fridlyand
Copy link
Collaborator Author

I expected round(double x) to return long and java's Math.round does. On another hand, MySQL returns double in that case, and we're aligning with MySQL.
Probably I got confused between these two behaviours and it is not a bug actually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants