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

Fix Round fix issue when input is negative and end with .5 #914

Merged
merged 1 commit into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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