diff --git a/core/src/main/java/com/amazon/opendistroforelasticsearch/sql/expression/operator/arthmetic/MathematicalFunction.java b/core/src/main/java/com/amazon/opendistroforelasticsearch/sql/expression/operator/arthmetic/MathematicalFunction.java index 72308c7c0a..9e04909eeb 100644 --- a/core/src/main/java/com/amazon/opendistroforelasticsearch/sql/expression/operator/arthmetic/MathematicalFunction.java +++ b/core/src/main/java/com/amazon/opendistroforelasticsearch/sql/expression/operator/arthmetic/MathematicalFunction.java @@ -422,7 +422,8 @@ private static FunctionResolver round() { DOUBLE, FLOAT), FunctionDSL.impl( FunctionDSL.nullMissingHandling( - v -> new ExprDoubleValue((double) Math.round(v.doubleValue()))), + v -> new ExprDoubleValue(new BigDecimal(v.doubleValue()).setScale(0, + RoundingMode.HALF_UP).doubleValue())), DOUBLE, DOUBLE), // rand(x, d) diff --git a/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/sql/MathematicalFunctionIT.java b/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/sql/MathematicalFunctionIT.java index 7c55cbcc8e..85ebfe660f 100644 --- a/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/sql/MathematicalFunctionIT.java +++ b/integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/sql/MathematicalFunctionIT.java @@ -101,6 +101,14 @@ public void testRound() throws IOException { result = executeQuery("select round(-56, -1)"); verifySchema(result, schema("round(-56, -1)", null, "long")); verifyDataRows(result, rows(-60)); + + result = executeQuery("select round(3.5)"); + verifySchema(result, schema("round(3.5)", null, "double")); + verifyDataRows(result, rows(4.0)); + + result = executeQuery("select round(-3.5)"); + verifySchema(result, schema("round(-3.5)", null, "double")); + verifyDataRows(result, rows(-4.0)); } /** diff --git a/integ-test/src/test/resources/correctness/expressions/mathematical_functions.txt b/integ-test/src/test/resources/correctness/expressions/mathematical_functions.txt index c893e625da..c99ca6c7a9 100644 --- a/integ-test/src/test/resources/correctness/expressions/mathematical_functions.txt +++ b/integ-test/src/test/resources/correctness/expressions/mathematical_functions.txt @@ -31,6 +31,12 @@ power(2, -2) power(2.1, 2) power(2, -2.1) power(abs(2), 2) +round(3.4) +round(3.5) +round(3.6) +round(-3.4) +round(-3.5) +round(-3.6) sign(0) sign(-1) sign(1)