Skip to content

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

Closed

Description

@Yury-Fridlyand

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).

Activity

  1. added
    bug
    on Dec 3, 2022
  2. matthewryanwells commented on Jun 9, 2023

    @matthewryanwells
    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?

  3. Yury-Fridlyand commented on Jun 13, 2023

    @Yury-Fridlyand
    CollaboratorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions