Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Fixed issue in round() when input is negative and end with .5
Browse files Browse the repository at this point in the history
Add IT
Add UT
  • Loading branch information
harold-wang committed Dec 10, 2020
1 parent d170da3 commit 5635846
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5635846

Please sign in to comment.