pig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From knogu...@apache.org
Subject svn commit: r1822370 - in /pig/trunk: ./ src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/ src/org/apache/pig/data/ test/org/apache/pig/test/
Date Sat, 27 Jan 2018 04:17:13 GMT
Author: knoguchi
Date: Sat Jan 27 04:17:13 2018
New Revision: 1822370

URL: http://svn.apache.org/viewvc?rev=1822370&view=rev
Log:
PIG-5328: expressionOperator Divide.equalsZero(DataType.BIGDECIMAL) is invalid (michaelthoward
via knoguchi)

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Divide.java
    pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java
    pig/trunk/src/org/apache/pig/data/DataType.java
    pig/trunk/test/org/apache/pig/test/TestDivide.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1822370&r1=1822369&r2=1822370&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Sat Jan 27 04:17:13 2018
@@ -63,6 +63,7 @@ PIG-5251: Bump joda-time to 2.9.9 (dbist
 OPTIMIZATIONS
  
 BUG FIXES
+PIG-5328: expressionOperator Divide.equalsZero(DataType.BIGDECIMAL) is invalid (michaelthoward
via knoguchi)
 
 PIG-5320: TestCubeOperator#testRollupBasic is flaky on Spark 2.2 (nkollar via szita)
 

Modified: pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Divide.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Divide.java?rev=1822370&r1=1822369&r2=1822370&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Divide.java
(original)
+++ pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Divide.java
Sat Jan 27 04:17:13 2018
@@ -110,7 +110,7 @@ public class Divide extends BinaryExpres
         case DataType.BIGINTEGER:
             return BigInteger.ZERO.equals((BigInteger) a);
         case DataType.BIGDECIMAL:
-            return BigDecimal.ZERO.equals((BigDecimal) a);
+            return ((BigDecimal) a).signum() == 0;
         default:
             throw new ExecException("Called on unsupported Number class " + DataType.findTypeName(dataType));
         }

Modified: pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java?rev=1822370&r1=1822369&r2=1822370&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java
(original)
+++ pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java
Sat Jan 27 04:17:13 2018
@@ -468,7 +468,7 @@ public class POCast extends ExpressionOp
             BigDecimal bd = null;
             Result res = in.getNextBigDecimal();
             if (res.returnStatus == POStatus.STATUS_OK && res.result != null) {
-                res.result = Boolean.valueOf(!BigDecimal.ZERO.equals((BigDecimal)res.result));
+                res.result = Boolean.valueOf(((BigDecimal)res.result).signum() != 0);
             }
             return res;
         }
@@ -1431,7 +1431,7 @@ public class POCast extends ExpressionOp
                 result = Boolean.valueOf(!BigInteger.ZERO.equals((BigInteger)obj));
                 break;
             case DataType.BIGDECIMAL:
-                result = Boolean.valueOf(!BigDecimal.ZERO.equals((BigDecimal)obj));
+                result = Boolean.valueOf(((BigDecimal)obj).signum() != 0);
                 break;
             default:
                 throw new ExecException("Cannot convert "+ obj + " to " + fs, 1120, PigException.INPUT);

Modified: pig/trunk/src/org/apache/pig/data/DataType.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/data/DataType.java?rev=1822370&r1=1822369&r2=1822370&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/data/DataType.java (original)
+++ pig/trunk/src/org/apache/pig/data/DataType.java Sat Jan 27 04:17:13 2018
@@ -662,7 +662,7 @@ public class DataType {
             case BIGINTEGER:
                 return Boolean.valueOf(!BigInteger.ZERO.equals(((BigInteger) o)));
             case BIGDECIMAL:
-                return Boolean.valueOf(!BigDecimal.ZERO.equals(((BigDecimal) o)));
+                return Boolean.valueOf(((BigDecimal) o).signum() != 0);
             case FLOAT:
                 return Boolean.valueOf(((Float) o).floatValue() != 0.0F);
             case DOUBLE:

Modified: pig/trunk/test/org/apache/pig/test/TestDivide.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestDivide.java?rev=1822370&r1=1822369&r2=1822370&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestDivide.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestDivide.java Sat Jan 27 04:17:13 2018
@@ -274,10 +274,13 @@ public class TestDivide {
                 resf = op.getNextBigDecimal();
                 assertEquals(null, (BigDecimal)resf.result);
                 // test divide by 0
-                lt.setValue(inpf1);
-                rt.setValue(new BigDecimal(0.0f,mc));
-                resf = op.getNextBigDecimal();
-                assertEquals(null, (BigDecimal)resf.result);
+				String[] zeroStrings = new String[] { "0", "-0", "0.0", "-0.0", "0.000000", "-0.000000"
};
+				for (String zeroString : zeroStrings) {
+					lt.setValue(inpf1);
+					rt.setValue(new BigDecimal(zeroString));
+					resf = op.getNextBigDecimal();
+					assertEquals(null, (BigDecimal)resf.result);
+				}
                 break;
             }
             case DataType.DATETIME:



Mime
View raw message