Hussain Towaileb has uploaded this change for review. (
https://asterix-gerrit.ics.uci.edu/3433
Change subject: [ASTERIXDB-2584][FUN][WIP] Support rounding digit for round()
......................................................................
[ASTERIXDB-2584][FUN][WIP] Support rounding digit for round()
- user model changes: yes
- user can pass optional 2nd argument to round() function
to specify the digit to round to.
- storage format changes: no
- interface changes: no
Details:
- Add support for 2nd optional round-to digit parameter for
round() function
Change-Id: Ibdde2745e8bc440556e45ed07262eb33327f842b
---
M
asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
A
asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericRoundFunctionTypeComputer.java
M
asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundDescriptor.java
A
asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundEvaluator.java
A
asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundWithDeigitsDescriptor.java
M
asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
6 files changed, 331 insertions(+), 107 deletions(-)
git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb
refs/changes/33/3433/1
diff --git
a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
index e53d0bd..8730fcd 100644
---
a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
+++
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
@@ -105,6 +105,7 @@
import
org.apache.asterix.om.typecomputer.impl.NumericDoubleOutputFunctionTypeComputer;
import
org.apache.asterix.om.typecomputer.impl.NumericInt8OutputFunctionTypeComputer;
import org.apache.asterix.om.typecomputer.impl.NumericRound2TypeComputer;
+import
org.apache.asterix.om.typecomputer.impl.NumericRoundFunctionTypeComputer;
import org.apache.asterix.om.typecomputer.impl.NumericSumAggTypeComputer;
import
org.apache.asterix.om.typecomputer.impl.NumericUnaryFunctionTypeComputer;
import org.apache.asterix.om.typecomputer.impl.OpenARecordTypeComputer;
@@ -360,6 +361,8 @@
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "floor", 1);
public static final FunctionIdentifier NUMERIC_ROUND =
new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "round", 1);
+ public static final FunctionIdentifier NUMERIC_ROUND_WITH_DIGITS =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "round", 2);
public static final FunctionIdentifier NUMERIC_ROUND_HALF_TO_EVEN =
new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
"round-half-to-even", 1);
public static final FunctionIdentifier NUMERIC_ROUND_HALF_TO_EVEN2 =
@@ -1707,7 +1710,8 @@
addFunction(NUMERIC_SIGN,
NumericInt8OutputFunctionTypeComputer.INSTANCE, true);
addFunction(NUMERIC_CEILING,
NumericUnaryFunctionTypeComputer.INSTANCE, true);
addFunction(NUMERIC_FLOOR, NumericUnaryFunctionTypeComputer.INSTANCE,
true);
- addFunction(NUMERIC_ROUND, NumericUnaryFunctionTypeComputer.INSTANCE,
true);
+ addFunction(NUMERIC_ROUND, NumericRoundFunctionTypeComputer.INSTANCE,
true);
+ addFunction(NUMERIC_ROUND_WITH_DIGITS,
NumericRoundFunctionTypeComputer.INSTANCE, true);
addFunction(NUMERIC_ROUND_HALF_TO_EVEN,
NumericUnaryFunctionTypeComputer.INSTANCE, true);
addFunction(NUMERIC_ROUND_HALF_TO_EVEN2,
NumericRound2TypeComputer.INSTANCE, true);
addFunction(NUMERIC_TRUNC, NumericRound2TypeComputer.INSTANCE, true);
diff --git
a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericRoundFunctionTypeComputer.java
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericRoundFunctionTypeComputer.java
new file mode 100644
index 0000000..eb34222
--- /dev/null
+++
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericRoundFunctionTypeComputer.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Numeric Unary Functions like abs
+ * Author : Xiaoyu Ma@UC Irvine
+ * 01/30/2012
+ */
+package org.apache.asterix.om.typecomputer.impl;
+
+import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.AUnionType;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+
+public class NumericRoundFunctionTypeComputer extends
AbstractResultTypeComputer {
+ public static final NumericRoundFunctionTypeComputer INSTANCE = new
NumericRoundFunctionTypeComputer();
+
+ private NumericRoundFunctionTypeComputer() {
+ }
+
+ @Override
+ protected IAType getResultType(ILogicalExpression expr, IAType...
strippedInputTypes) throws AlgebricksException {
+ IAType returnType;
+ ATypeTag firstArgType = strippedInputTypes[0].getTypeTag();
+ ATypeTag secondArgType = strippedInputTypes.length > 1 ?
strippedInputTypes[1].getTypeTag() : null;
+
+ switch (firstArgType) {
+ case TINYINT:
+ case SMALLINT:
+ case INTEGER:
+ case BIGINT:
+ case FLOAT:
+ case DOUBLE:
+ case ANY:
+ returnType = strippedInputTypes[0];
+ break;
+ default:
+ return BuiltinType.ANULL;
+ }
+
+ // No second argument
+ if (secondArgType == null) {
+ return returnType;
+ }
+
+ switch (secondArgType) {
+ case TINYINT:
+ case SMALLINT:
+ case INTEGER:
+ case BIGINT:
+ case ANY:
+ return returnType;
+ case FLOAT:
+ case DOUBLE:
+ return AUnionType.createNullableType(returnType);
+ default:
+ return BuiltinType.ANULL;
+ }
+ }
+}
diff --git
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundDescriptor.java
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundDescriptor.java
index 9b0dd20..5158463 100644
---
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundDescriptor.java
+++
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundDescriptor.java
@@ -23,49 +23,20 @@
*/
package org.apache.asterix.runtime.evaluators.functions;
-import java.io.DataOutput;
-
import org.apache.asterix.common.annotations.MissingNullInOutFunction;
-import
org.apache.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
-import
org.apache.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
-import
org.apache.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
-import
org.apache.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
-import
org.apache.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
-import
org.apache.asterix.dataflow.data.nontagged.serde.AInt8SerializerDeserializer;
-import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider;
-import org.apache.asterix.om.base.AMutableDouble;
-import org.apache.asterix.om.base.AMutableFloat;
-import org.apache.asterix.om.base.AMutableInt16;
-import org.apache.asterix.om.base.AMutableInt32;
-import org.apache.asterix.om.base.AMutableInt64;
-import org.apache.asterix.om.base.AMutableInt8;
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.om.types.BuiltinType;
import
org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import org.apache.asterix.runtime.exceptions.TypeMismatchException;
import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
import org.apache.hyracks.api.context.IHyracksTaskContext;
-import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
import org.apache.hyracks.api.exceptions.HyracksDataException;
-import org.apache.hyracks.data.std.api.IPointable;
-import org.apache.hyracks.data.std.primitive.VoidPointable;
-import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
-import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
@MissingNullInOutFunction
public class NumericRoundDescriptor extends
AbstractScalarFunctionDynamicDescriptor {
private static final long serialVersionUID = 1L;
- public static final IFunctionDescriptorFactory FACTORY = new
IFunctionDescriptorFactory() {
- @Override
- public IFunctionDescriptor createFunctionDescriptor() {
- return new NumericRoundDescriptor();
- }
- };
+ public static final IFunctionDescriptorFactory FACTORY =
NumericRoundDescriptor::new;
@Override
public FunctionIdentifier getIdentifier() {
@@ -79,82 +50,7 @@
@Override
public IScalarEvaluator createScalarEvaluator(final
IHyracksTaskContext ctx) throws HyracksDataException {
-
- return new IScalarEvaluator() {
-
- private ArrayBackedValueStorage resultStorage = new
ArrayBackedValueStorage();
- private DataOutput out = resultStorage.getDataOutput();
- private IPointable argPtr = new VoidPointable();
- private IScalarEvaluator eval =
args[0].createScalarEvaluator(ctx);
- private AMutableDouble aDouble = new AMutableDouble(0);
- private AMutableFloat aFloat = new AMutableFloat(0);
- private AMutableInt64 aInt64 = new AMutableInt64(0);
- private AMutableInt32 aInt32 = new AMutableInt32(0);
- private AMutableInt16 aInt16 = new AMutableInt16((short)
0);
- private AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
- @SuppressWarnings("rawtypes")
- private ISerializerDeserializer serde;
-
- @SuppressWarnings("unchecked")
- @Override
- public void evaluate(IFrameTupleReference tuple,
IPointable result) throws HyracksDataException {
- resultStorage.reset();
- eval.evaluate(tuple, argPtr);
-
- if (PointableHelper.checkAndSetMissingOrNull(result,
argPtr)) {
- return;
- }
-
- byte[] data = argPtr.getByteArray();
- int offset = argPtr.getStartOffset();
-
- if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG)
{
- serde = SerializerDeserializerProvider.INSTANCE
-
.getSerializerDeserializer(BuiltinType.AINT8);
- byte val =
AInt8SerializerDeserializer.getByte(data, offset + 1);
- aInt8.setValue(val);
- serde.serialize(aInt8, out);
- } else if (data[offset] ==
ATypeTag.SERIALIZED_INT16_TYPE_TAG) {
- serde = SerializerDeserializerProvider.INSTANCE
-
.getSerializerDeserializer(BuiltinType.AINT16);
- short val =
AInt16SerializerDeserializer.getShort(data, offset + 1);
- aInt16.setValue(val);
- serde.serialize(aInt16, out);
- } else if (data[offset] ==
ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
- serde = SerializerDeserializerProvider.INSTANCE
-
.getSerializerDeserializer(BuiltinType.AINT32);
- int val =
AInt32SerializerDeserializer.getInt(data, offset + 1);
- aInt32.setValue(val);
- serde.serialize(aInt32, out);
- } else if (data[offset] ==
ATypeTag.SERIALIZED_INT64_TYPE_TAG) {
- serde = SerializerDeserializerProvider.INSTANCE
-
.getSerializerDeserializer(BuiltinType.AINT64);
- long val =
AInt64SerializerDeserializer.getLong(data, offset + 1);
- aInt64.setValue(val);
- serde.serialize(aInt64, out);
- } else if (data[offset] ==
ATypeTag.SERIALIZED_FLOAT_TYPE_TAG) {
- serde = SerializerDeserializerProvider.INSTANCE
-
.getSerializerDeserializer(BuiltinType.AFLOAT);
- float val =
AFloatSerializerDeserializer.getFloat(data, offset + 1);
- val = Math.round(val);
- aFloat.setValue(val);
- serde.serialize(aFloat, out);
- } else if (data[offset] ==
ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
- serde = SerializerDeserializerProvider.INSTANCE
-
.getSerializerDeserializer(BuiltinType.ADOUBLE);
- double val =
ADoubleSerializerDeserializer.getDouble(data, offset + 1);
- val = Math.round(val);
- aDouble.setValue(val);
- serde.serialize(aDouble, out);
- } else {
- throw new TypeMismatchException(sourceLoc,
getIdentifier(), 0, data[offset],
- ATypeTag.SERIALIZED_INT8_TYPE_TAG,
ATypeTag.SERIALIZED_INT16_TYPE_TAG,
- ATypeTag.SERIALIZED_INT32_TYPE_TAG,
ATypeTag.SERIALIZED_INT64_TYPE_TAG,
- ATypeTag.SERIALIZED_FLOAT_TYPE_TAG,
ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
- }
- result.set(resultStorage);
- }
- };
+ return new NumericRoundEvaluator(ctx, args, getIdentifier(),
sourceLoc);
}
};
}
diff --git
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundEvaluator.java
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundEvaluator.java
new file mode 100644
index 0000000..66cb68a
--- /dev/null
+++
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundEvaluator.java
@@ -0,0 +1,184 @@
+package org.apache.asterix.runtime.evaluators.functions;
+
+import java.text.DecimalFormat;
+
+import
org.apache.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import
org.apache.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
+import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider;
+import org.apache.asterix.om.base.AMutableDouble;
+import org.apache.asterix.om.base.AMutableFloat;
+import org.apache.asterix.om.base.AMutableInt16;
+import org.apache.asterix.om.base.AMutableInt32;
+import org.apache.asterix.om.base.AMutableInt64;
+import org.apache.asterix.om.base.AMutableInt8;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.EnumDeserializer;
+import org.apache.asterix.om.types.hierachy.ATypeHierarchy;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.exceptions.SourceLocation;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
+import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+class NumericRoundEvaluator extends AbstractScalarEval {
+
+ // Result members
+ private ArrayBackedValueStorage resultStorage = new
ArrayBackedValueStorage();
+ private AMutableDouble aDouble = new AMutableDouble(0);
+ private AMutableFloat aFloat = new AMutableFloat(0);
+ private AMutableInt64 aInt64 = new AMutableInt64(0);
+ private AMutableInt32 aInt32 = new AMutableInt32(0);
+ private AMutableInt16 aInt16 = new AMutableInt16((short) 0);
+ private AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
+
+ // Evaluators and Pointables
+ private final IScalarEvaluator valueEvaluator;
+ private IScalarEvaluator digitsEvaluator;
+ private final IPointable valuePointable;
+ private IPointable digitsPointable;
+
+ // Serializers/Deserializers
+ @SuppressWarnings("rawtypes")
+ private ISerializerDeserializer serde;
+
+ private DecimalFormat formatter;
+
+ NumericRoundEvaluator(IHyracksTaskContext context,
IScalarEvaluatorFactory[] argEvaluatorFactories,
+ FunctionIdentifier functionIdentifier, SourceLocation
sourceLocation) throws HyracksDataException {
+ super(sourceLocation, functionIdentifier);
+
+ valueEvaluator =
argEvaluatorFactories[0].createScalarEvaluator(context);
+ valuePointable = new VoidPointable();
+
+ // 2nd argument if it exists
+ if (argEvaluatorFactories.length > 1) {
+ digitsEvaluator =
argEvaluatorFactories[1].createScalarEvaluator(context);
+ digitsPointable = new VoidPointable();
+ formatter = new DecimalFormat();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void evaluate(IFrameTupleReference tuple, IPointable result) throws
HyracksDataException {
+ resultStorage.reset();
+ valueEvaluator.evaluate(tuple, valuePointable);
+
+ if (digitsEvaluator != null) {
+ digitsEvaluator.evaluate(tuple, digitsPointable);
+ }
+
+ if (PointableHelper.checkAndSetMissingOrNull(result, valuePointable,
digitsPointable)) {
+ return;
+ }
+
+ byte[] valueBytes = valuePointable.getByteArray();
+ int valueOffset = valuePointable.getStartOffset();
+ ATypeTag valueTypeTag =
EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(valueBytes[valueOffset]);
+
+ byte[] digitsBytes = null;
+ int digitsOffset = 0;
+
+ if (digitsEvaluator != null) {
+ digitsBytes = digitsPointable.getByteArray();
+ digitsOffset = digitsPointable.getStartOffset();
+ }
+
+ // Validity of arguments
+ if (!ATypeHierarchy.canPromote(valueTypeTag, ATypeTag.DOUBLE)) {
+ PointableHelper.setNull(result);
+ return;
+ }
+
+ // Validity of arguments
+ if (digitsEvaluator != null &&
!PointableHelper.isValidLongValue(digitsBytes, digitsOffset, true)) {
+ PointableHelper.setNull(result);
+ return;
+ }
+
+ // No second argument, normal rounding
+ if (digitsEvaluator == null) {
+ switch (valueTypeTag) {
+ // If digit rounding is not providing, then no rounding to do
on integer values
+ case TINYINT:
+ case SMALLINT:
+ case INTEGER:
+ case BIGINT:
+ resultStorage.set(valuePointable);
+ break;
+ case FLOAT:
+ serde =
SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AFLOAT);
+ float floatValue =
AFloatSerializerDeserializer.getFloat(valueBytes, valueOffset + 1);
+ aFloat.setValue(Math.round(floatValue));
+ serde.serialize(aFloat, resultStorage.getDataOutput());
+ break;
+ case DOUBLE:
+ serde =
SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
+ double doubleValue =
ADoubleSerializerDeserializer.getDouble(valueBytes, valueOffset + 1);
+ aDouble.setValue(Math.round(doubleValue));
+ serde.serialize(aDouble, resultStorage.getDataOutput());
+ break;
+ default:
+ PointableHelper.setNull(result);
+ return;
+ }
+ }
+ // Second argument exists, digits-based rounding
+ else {
+ long digits =
ATypeHierarchy.getLongValue(functionIdentifier.getName(), 2, digitsBytes,
digitsOffset);
+
+ // Right of decimal
+ if (digits >= 0) {
+ switch (valueTypeTag) {
+ // For zero or positive digit rounding, no need to do
anything for integers
+ case TINYINT:
+ case SMALLINT:
+ case INTEGER:
+ case BIGINT:
+ resultStorage.set(valuePointable);
+ break;
+ case FLOAT:
+ serde =
SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AFLOAT);
+ float floatValue =
AFloatSerializerDeserializer.getFloat(valueBytes, valueOffset + 1);
+
+ if (digits == 0) {
+ aFloat.setValue(Math.round(floatValue));
+ } else {
+ float fMultiplier = (float) Math.pow(10, digits);
+ aFloat.setValue(Math.round(floatValue *
fMultiplier) / fMultiplier);
+ }
+ serde.serialize(aFloat, resultStorage.getDataOutput());
+ break;
+ case DOUBLE:
+ serde =
SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
+ double doubleValue =
ADoubleSerializerDeserializer.getDouble(valueBytes, valueOffset + 1);
+
+ if (digits == 0) {
+ aDouble.setValue(Math.round(doubleValue));
+ } else {
+ double dMultiplier = Math.pow(10, digits);
+ aDouble.setValue(Math.round(doubleValue *
dMultiplier) / dMultiplier);
+ }
+ serde.serialize(aDouble,
resultStorage.getDataOutput());
+ break;
+ default:
+ PointableHelper.setNull(result);
+ return;
+ }
+ }
+ // Left of decimal (negative digits value)
+ else {
+
+ }
+ }
+
+ result.set(resultStorage);
+ }
+}
diff --git
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundWithDeigitsDescriptor.java
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundWithDeigitsDescriptor.java
new file mode 100644
index 0000000..fd195f0
--- /dev/null
+++
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundWithDeigitsDescriptor.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Numeric function Round
+ * Author : Xiaoyu Ma@UC Irvine
+ * 01/30/2012
+ */
+package org.apache.asterix.runtime.evaluators.functions;
+
+import org.apache.asterix.common.annotations.MissingNullInOutFunction;
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import
org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+@MissingNullInOutFunction
+public class NumericRoundWithDeigitsDescriptor extends
AbstractScalarFunctionDynamicDescriptor {
+
+ private static final long serialVersionUID = 1L;
+ public static final IFunctionDescriptorFactory FACTORY =
NumericRoundWithDeigitsDescriptor::new;
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return BuiltinFunctions.NUMERIC_ROUND_WITH_DIGITS;
+ }
+
+ @Override
+ public IScalarEvaluatorFactory createEvaluatorFactory(final
IScalarEvaluatorFactory[] args) {
+ return new IScalarEvaluatorFactory() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public IScalarEvaluator createScalarEvaluator(final
IHyracksTaskContext ctx) throws HyracksDataException {
+ return new NumericRoundEvaluator(ctx, args, getIdentifier(),
sourceLoc);
+ }
+ };
+ }
+
+}
diff --git
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
index 2e9c688..1b8326e 100644
---
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
+++
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
@@ -373,6 +373,7 @@
import org.apache.asterix.runtime.evaluators.functions.NumericRoundDescriptor;
import
org.apache.asterix.runtime.evaluators.functions.NumericRoundHalfToEven2Descriptor;
import
org.apache.asterix.runtime.evaluators.functions.NumericRoundHalfToEvenDescriptor;
+import
org.apache.asterix.runtime.evaluators.functions.NumericRoundWithDeigitsDescriptor;
import org.apache.asterix.runtime.evaluators.functions.NumericSignDescriptor;
import org.apache.asterix.runtime.evaluators.functions.NumericSinDescriptor;
import org.apache.asterix.runtime.evaluators.functions.NumericSinhDescriptor;
@@ -885,6 +886,7 @@
fc.add(NumericCeilingDescriptor.FACTORY);
fc.add(NumericFloorDescriptor.FACTORY);
fc.add(NumericRoundDescriptor.FACTORY);
+ fc.add(NumericRoundWithDeigitsDescriptor.FACTORY);
fc.add(NumericRoundHalfToEvenDescriptor.FACTORY);
fc.add(NumericRoundHalfToEven2Descriptor.FACTORY);
fc.add(NumericACosDescriptor.FACTORY);
--
To view, visit https://asterix-gerrit.ics.uci.edu/3433
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibdde2745e8bc440556e45ed07262eb33327f842b
Gerrit-Change-Number: 3433
Gerrit-PatchSet: 1
Gerrit-Owner: Hussain Towaileb <[email protected]>