phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sama...@apache.org
Subject phoenix git commit: Cannot round to a negative precision (to the left of the decimal) (Kevin Liew)
Date Thu, 01 Sep 2016 16:48:06 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.1 f9b94f521 -> 94261a29c


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/94261a29
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/94261a29
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/94261a29

Branch: refs/heads/4.x-HBase-1.1
Commit: 94261a29ceae9c1bb94e9e1214cd6bde9633facf
Parents: f9b94f5
Author: Samarth <samarth.jain@salesforce.com>
Authored: Thu Sep 1 09:47:57 2016 -0700
Committer: Samarth <samarth.jain@salesforce.com>
Committed: Thu Sep 1 09:47:57 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/94261a29/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/94261a29/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);


Mime
View raw message