You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by sa...@apache.org on 2016/09/01 16:51:51 UTC
phoenix git commit: PHOENIX-2474 Cannot round to a negative precision
(to the left of the decimal) (Kevin Liew)
Repository: phoenix
Updated Branches:
refs/heads/master 1ce9845b8 -> b7d45ca66
PHOENIX-2474 Cannot round to a negative precision (to the left of the decimal) (Kevin Liew)
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/b7d45ca6
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/b7d45ca6
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/b7d45ca6
Branch: refs/heads/master
Commit: b7d45ca66729ae57c0896449e36b80f4fdcafb46
Parents: 1ce9845
Author: Samarth <sa...@salesforce.com>
Authored: Thu Sep 1 09:49:22 2016 -0700
Committer: Samarth <sa...@salesforce.com>
Committed: Thu Sep 1 09:49:22 2016 -0700
----------------------------------------------------------------------
.../expression/function/RoundDecimalExpression.java | 2 +-
.../expression/RoundFloorCeilExpressionsTest.java | 14 ++++++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/b7d45ca6/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDecimalExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDecimalExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDecimalExpression.java
index 65ffacb..055535e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDecimalExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDecimalExpression.java
@@ -100,7 +100,7 @@ public class RoundDecimalExpression extends ScalarFunction {
if(scaleValue != null) {
if (scaleType.isCoercibleTo(PInteger.INSTANCE, scaleValue)) {
int scale = (Integer) PInteger.INSTANCE.toObject(scaleValue, scaleType);
- if (scale >=0 && scale <= PDataType.MAX_PRECISION) {
+ if (scale <= PDataType.MAX_PRECISION) {
this.scale = scale;
return;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/b7d45ca6/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java b/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
index 5022e71..89058ba 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
@@ -79,6 +79,20 @@ public class RoundFloorCeilExpressionsTest {
}
@Test
+ public void testRoundNegativePrecisionDecimalExpression() throws Exception {
+ LiteralExpression decimalLiteral = LiteralExpression.newConstant(444.44, PDecimal.INSTANCE);
+ Expression roundDecimalExpression = RoundDecimalExpression.create(decimalLiteral, -2);
+
+ ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+ roundDecimalExpression.evaluate(null, ptr);
+ Object result = roundDecimalExpression.getDataType().toObject(ptr);
+
+ assertTrue(result instanceof BigDecimal);
+ BigDecimal resultDecimal = (BigDecimal)result;
+ assertEquals(0, BigDecimal.valueOf(400).compareTo(resultDecimal));
+ }
+
+ @Test
public void testRoundDecimalExpressionNoop() throws Exception {
LiteralExpression decimalLiteral = LiteralExpression.newConstant(5, PInteger.INSTANCE);
Expression roundDecimalExpression = RoundDecimalExpression.create(decimalLiteral, 3);