Repository: asterixdb
Updated Branches:
  refs/heads/master 0e70ad65b -> 6b1b52c1f


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b1b52c1/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericDivDescriptor.java
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericDivDescriptor.java
 
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericDivDescriptor.java
index 56d90f7..2eeefe8 100644
--- 
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericDivDescriptor.java
+++ 
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericDivDescriptor.java
@@ -19,8 +19,8 @@
 
 package org.apache.asterix.runtime.evaluators.functions;
 
-import org.apache.asterix.common.exceptions.ErrorCode;
-import org.apache.asterix.common.exceptions.RuntimeDataException;
+import org.apache.asterix.om.base.AMutableDouble;
+import org.apache.asterix.om.base.AMutableInt64;
 import org.apache.asterix.om.functions.BuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
@@ -46,28 +46,37 @@ public class NumericDivDescriptor extends 
AbstractNumericArithmeticEval {
     }
 
     @Override
-    protected double evaluateDouble(double lhs, double rhs) {
-        return lhs / rhs;
+    protected boolean evaluateDouble(double lhs, double rhs, AMutableDouble 
result) {
+        if (rhs == 0) {
+            return false; // result = NULL
+        }
+        double res = lhs / rhs;
+        result.setValue(res);
+        return true;
     }
 
     @Override
-    protected long evaluateInteger(long lhs, long rhs) throws 
HyracksDataException {
+    protected boolean evaluateInteger(long lhs, long rhs, AMutableInt64 
result) throws HyracksDataException {
         if (rhs == 0) {
-            throw new RuntimeDataException(ErrorCode.DIVISION_BY_ZERO);
+            return false; // result = NULL
         }
         if ((lhs == Long.MIN_VALUE) && (rhs == -1L)) {
             throw new OverflowException(sourceLoc, getIdentifier());
         }
-        return lhs / rhs;
+        long res = lhs / rhs;
+        result.setValue(res);
+        return true;
     }
 
     @Override
-    protected long evaluateTimeDurationArithmetic(long chronon, int yearMonth, 
long dayTime, boolean isTimeOnly) {
+    protected boolean evaluateTimeDurationArithmetic(long chronon, int 
yearMonth, long dayTime, boolean isTimeOnly,
+            AMutableInt64 result) {
         throw new NotImplementedException("Divide operation is not defined for 
temporal types");
     }
 
     @Override
-    protected long evaluateTimeInstanceArithmetic(long chronon0, long 
chronon1) throws HyracksDataException {
+    protected boolean evaluateTimeInstanceArithmetic(long chronon0, long 
chronon1, AMutableInt64 result)
+            throws HyracksDataException {
         throw new UnsupportedTypeException(sourceLoc, getIdentifier(), 
ATypeTag.SERIALIZED_TIME_TYPE_TAG);
     }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b1b52c1/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericDivideDescriptor.java
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericDivideDescriptor.java
 
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericDivideDescriptor.java
index 0c1a3eb..6e6b5a8 100644
--- 
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericDivideDescriptor.java
+++ 
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericDivideDescriptor.java
@@ -18,6 +18,8 @@
  */
 package org.apache.asterix.runtime.evaluators.functions;
 
+import org.apache.asterix.om.base.AMutableDouble;
+import org.apache.asterix.om.base.AMutableInt64;
 import org.apache.asterix.om.functions.BuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
@@ -47,22 +49,29 @@ public class NumericDivideDescriptor extends 
AbstractNumericArithmeticEval {
     }
 
     @Override
-    protected double evaluateDouble(double lhs, double rhs) {
-        return lhs / rhs;
+    protected boolean evaluateDouble(double lhs, double rhs, AMutableDouble 
result) {
+        if (rhs == 0) {
+            return false; // result = NULL
+        }
+        double res = lhs / rhs;
+        result.setValue(res);
+        return true;
     }
 
     @Override
-    protected long evaluateInteger(long lhs, long rhs) {
+    protected boolean evaluateInteger(long lhs, long rhs, AMutableInt64 
result) {
         throw new IllegalStateException();
     }
 
     @Override
-    protected long evaluateTimeDurationArithmetic(long chronon, int yearMonth, 
long dayTime, boolean isTimeOnly) {
+    protected boolean evaluateTimeDurationArithmetic(long chronon, int 
yearMonth, long dayTime, boolean isTimeOnly,
+            AMutableInt64 result) {
         throw new NotImplementedException("Divide operation is not defined for 
temporal types");
     }
 
     @Override
-    protected long evaluateTimeInstanceArithmetic(long chronon0, long 
chronon1) throws HyracksDataException {
+    protected boolean evaluateTimeInstanceArithmetic(long chronon0, long 
chronon1, AMutableInt64 result)
+            throws HyracksDataException {
         throw new UnsupportedTypeException(sourceLoc, getIdentifier(), 
ATypeTag.SERIALIZED_TIME_TYPE_TAG);
     }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b1b52c1/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericModuloDescriptor.java
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericModuloDescriptor.java
 
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericModuloDescriptor.java
index a967162..e737841 100644
--- 
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericModuloDescriptor.java
+++ 
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericModuloDescriptor.java
@@ -18,6 +18,8 @@
  */
 package org.apache.asterix.runtime.evaluators.functions;
 
+import org.apache.asterix.om.base.AMutableDouble;
+import org.apache.asterix.om.base.AMutableInt64;
 import org.apache.asterix.om.functions.BuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
@@ -43,23 +45,34 @@ public class NumericModuloDescriptor extends 
AbstractNumericArithmeticEval {
     }
 
     @Override
-    protected long evaluateInteger(long lhs, long rhs) throws 
HyracksDataException {
-        return lhs % rhs;
+    protected boolean evaluateInteger(long lhs, long rhs, AMutableInt64 
result) throws HyracksDataException {
+        if (rhs == 0) {
+            return false; // result = NULL
+        }
+        long res = lhs % rhs;
+        result.setValue(res);
+        return true;
     }
 
     @Override
-    protected double evaluateDouble(double lhs, double rhs) throws 
HyracksDataException {
-        return lhs % rhs;
+    protected boolean evaluateDouble(double lhs, double rhs, AMutableDouble 
result) throws HyracksDataException {
+        if (rhs == 0) {
+            return false; // result = NULL
+        }
+        double res = lhs % rhs;
+        result.setValue(res);
+        return true;
     }
 
     @Override
-    protected long evaluateTimeDurationArithmetic(long chronon, int yearMonth, 
long dayTime, boolean isTimeOnly)
-            throws HyracksDataException {
+    protected boolean evaluateTimeDurationArithmetic(long chronon, int 
yearMonth, long dayTime, boolean isTimeOnly,
+            AMutableInt64 result) throws HyracksDataException {
         throw new UnsupportedTypeException(sourceLoc, getIdentifier(), 
ATypeTag.SERIALIZED_DURATION_TYPE_TAG);
     }
 
     @Override
-    protected long evaluateTimeInstanceArithmetic(long chronon0, long 
chronon1) throws HyracksDataException {
+    protected boolean evaluateTimeInstanceArithmetic(long chronon0, long 
chronon1, AMutableInt64 result)
+            throws HyracksDataException {
         throw new UnsupportedTypeException(sourceLoc, getIdentifier(), 
ATypeTag.SERIALIZED_TIME_TYPE_TAG);
     }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b1b52c1/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericMultiplyDescriptor.java
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericMultiplyDescriptor.java
 
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericMultiplyDescriptor.java
index 57de132..64fa2b2 100644
--- 
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericMultiplyDescriptor.java
+++ 
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericMultiplyDescriptor.java
@@ -18,10 +18,13 @@
  */
 package org.apache.asterix.runtime.evaluators.functions;
 
+import org.apache.asterix.om.base.AMutableDouble;
+import org.apache.asterix.om.base.AMutableInt64;
 import org.apache.asterix.om.functions.BuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.runtime.exceptions.OverflowException;
 import org.apache.asterix.runtime.exceptions.UnsupportedTypeException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
@@ -41,23 +44,32 @@ public class NumericMultiplyDescriptor extends 
AbstractNumericArithmeticEval {
     }
 
     @Override
-    protected long evaluateInteger(long lhs, long rhs) throws 
HyracksDataException {
-        return Math.multiplyExact(lhs, rhs);
+    protected boolean evaluateInteger(long lhs, long rhs, AMutableInt64 
result) throws HyracksDataException {
+        try {
+            long res = Math.multiplyExact(lhs, rhs);
+            result.setValue(res);
+            return true;
+        } catch (ArithmeticException e) {
+            throw new OverflowException(sourceLoc, getIdentifier());
+        }
     }
 
     @Override
-    protected double evaluateDouble(double lhs, double rhs) throws 
HyracksDataException {
-        return lhs * rhs;
+    protected boolean evaluateDouble(double lhs, double rhs, AMutableDouble 
result) throws HyracksDataException {
+        double res = lhs * rhs;
+        result.setValue(res);
+        return true;
     }
 
     @Override
-    protected long evaluateTimeDurationArithmetic(long chronon, int yearMonth, 
long dayTime, boolean isTimeOnly)
-            throws HyracksDataException {
+    protected boolean evaluateTimeDurationArithmetic(long chronon, int 
yearMonth, long dayTime, boolean isTimeOnly,
+            AMutableInt64 result) throws HyracksDataException {
         throw new UnsupportedTypeException(sourceLoc, getIdentifier(), 
ATypeTag.SERIALIZED_DURATION_TYPE_TAG);
     }
 
     @Override
-    protected long evaluateTimeInstanceArithmetic(long chronon0, long 
chronon1) throws HyracksDataException {
+    protected boolean evaluateTimeInstanceArithmetic(long chronon0, long 
chronon1, AMutableInt64 result)
+            throws HyracksDataException {
         throw new UnsupportedTypeException(sourceLoc, getIdentifier(), 
ATypeTag.SERIALIZED_TIME_TYPE_TAG);
     }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b1b52c1/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericPowerDescriptor.java
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericPowerDescriptor.java
 
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericPowerDescriptor.java
index a5312b9..68ed6e8 100644
--- 
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericPowerDescriptor.java
+++ 
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericPowerDescriptor.java
@@ -18,6 +18,8 @@
  */
 package org.apache.asterix.runtime.evaluators.functions;
 
+import org.apache.asterix.om.base.AMutableDouble;
+import org.apache.asterix.om.base.AMutableInt64;
 import org.apache.asterix.om.functions.BuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
@@ -43,19 +45,27 @@ public class NumericPowerDescriptor extends 
AbstractNumericArithmeticEval {
      * @see 
org.apache.asterix.runtime.evaluators.functions.AbstractNumericArithmeticEval#evaluateInteger(long,
 long)
      */
     @Override
-    protected long evaluateInteger(long lhs, long rhs) throws 
HyracksDataException {
+    protected boolean evaluateInteger(long lhs, long rhs, AMutableInt64 
result) throws HyracksDataException {
         if (rhs > Integer.MAX_VALUE) {
             throw new OverflowException(sourceLoc, getIdentifier());
         }
-        return LongMath.checkedPow(lhs, (int) rhs);
+        try {
+            long res = LongMath.checkedPow(lhs, (int) rhs);
+            result.setValue(res);
+            return true;
+        } catch (ArithmeticException e) {
+            throw new OverflowException(sourceLoc, getIdentifier());
+        }
     }
 
     /* (non-Javadoc)
      * @see 
org.apache.asterix.runtime.evaluators.functions.AbstractNumericArithmeticEval#evaluateDouble(double,
 double)
      */
     @Override
-    protected double evaluateDouble(double lhs, double rhs) throws 
HyracksDataException {
-        return Math.pow(lhs, rhs);
+    protected boolean evaluateDouble(double lhs, double rhs, AMutableDouble 
result) throws HyracksDataException {
+        double res = Math.pow(lhs, rhs);
+        result.setValue(res);
+        return true;
     }
 
     /* (non-Javadoc)
@@ -67,14 +77,14 @@ public class NumericPowerDescriptor extends 
AbstractNumericArithmeticEval {
     }
 
     @Override
-    protected long evaluateTimeDurationArithmetic(long chronon, int yearMonth, 
long dayTime, boolean isTimeOnly)
-            throws HyracksDataException {
+    protected boolean evaluateTimeDurationArithmetic(long chronon, int 
yearMonth, long dayTime, boolean isTimeOnly,
+            AMutableInt64 result) throws HyracksDataException {
         throw new UnsupportedTypeException(sourceLoc, 
getIdentifier().getName(), ATypeTag.SERIALIZED_DURATION_TYPE_TAG);
     }
 
     @Override
-    protected long evaluateTimeInstanceArithmetic(long chronon0, long 
chronon1) throws HyracksDataException {
+    protected boolean evaluateTimeInstanceArithmetic(long chronon0, long 
chronon1, AMutableInt64 result)
+            throws HyracksDataException {
         throw new UnsupportedTypeException(sourceLoc, 
getIdentifier().getName(), ATypeTag.SERIALIZED_TIME_TYPE_TAG);
     }
-
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/6b1b52c1/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSubDescriptor.java
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSubDescriptor.java
 
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSubDescriptor.java
index f694226..30f6dda 100644
--- 
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSubDescriptor.java
+++ 
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSubDescriptor.java
@@ -18,10 +18,13 @@
  */
 package org.apache.asterix.runtime.evaluators.functions;
 
+import org.apache.asterix.om.base.AMutableDouble;
+import org.apache.asterix.om.base.AMutableInt64;
 import org.apache.asterix.om.base.temporal.DurationArithmeticOperations;
 import org.apache.asterix.om.functions.BuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.runtime.exceptions.OverflowException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 
@@ -43,33 +46,43 @@ public class NumericSubDescriptor extends 
AbstractNumericArithmeticEval {
      * @see 
org.apache.asterix.runtime.evaluators.functions.AbstractNumericArithmeticEval#evaluateInteger(long,
 long)
      */
     @Override
-    protected long evaluateInteger(long lhs, long rhs) throws 
HyracksDataException {
-        return Math.subtractExact(lhs, rhs);
+    protected boolean evaluateInteger(long lhs, long rhs, AMutableInt64 
result) throws HyracksDataException {
+        try {
+            long res = Math.subtractExact(lhs, rhs);
+            result.setValue(res);
+            return true;
+        } catch (ArithmeticException e) {
+            throw new OverflowException(sourceLoc, getIdentifier());
+        }
     }
 
     /* (non-Javadoc)
      * @see 
org.apache.asterix.runtime.evaluators.functions.AbstractNumericArithmeticEval#evaluateDouble(double,
 double)
      */
     @Override
-    protected double evaluateDouble(double lhs, double rhs) throws 
HyracksDataException {
-        return lhs - rhs;
+    protected boolean evaluateDouble(double lhs, double rhs, AMutableDouble 
result) throws HyracksDataException {
+        double res = lhs - rhs;
+        result.setValue(res);
+        return true;
     }
 
     /* (non-Javadoc)
      * @see 
org.apache.asterix.runtime.evaluators.functions.AbstractNumericArithmeticEval#evaluateTimeDurationArithmetic(long,
 int, long, boolean)
      */
     @Override
-    protected long evaluateTimeDurationArithmetic(long chronon, int yearMonth, 
long dayTime, boolean isTimeOnly)
-            throws HyracksDataException {
-        return DurationArithmeticOperations.addDuration(chronon, -1 * 
yearMonth, -1 * dayTime, isTimeOnly);
+    protected boolean evaluateTimeDurationArithmetic(long chronon, int 
yearMonth, long dayTime, boolean isTimeOnly,
+            AMutableInt64 result) throws HyracksDataException {
+        long res = DurationArithmeticOperations.addDuration(chronon, -1 * 
yearMonth, -1 * dayTime, isTimeOnly);
+        result.setValue(res);
+        return true;
     }
 
     /* (non-Javadoc)
      * @see 
org.apache.asterix.runtime.evaluators.functions.AbstractNumericArithmeticEval#evaluateTimeInstanceArithmetic(long,
 long)
      */
     @Override
-    protected long evaluateTimeInstanceArithmetic(long chronon0, long 
chronon1) throws HyracksDataException {
-        return evaluateInteger(chronon0, chronon1);
+    protected boolean evaluateTimeInstanceArithmetic(long chronon0, long 
chronon1, AMutableInt64 result)
+            throws HyracksDataException {
+        return evaluateInteger(chronon0, chronon1, result);
     }
-
 }

Reply via email to