Skip to content

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

@Yury-Fridlyand

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions