Hussain Towaileb has uploaded a new change for review. https://asterix-gerrit.ics.uci.edu/3041
Change subject: [ASTERIXDB-2484][FUN] Supporting SINH, COSH and TANH functions ...................................................................... [ASTERIXDB-2484][FUN] Supporting SINH, COSH and TANH functions - user model changes: yes - storage format changes: no - interface changes: no Details: - Added support for sinh, cosh and tanh Math functions. - Added sinh, cosh and tanh test cases. - Added sinh, cosh and tanh documentation. Change-Id: I0853bfe4511ad5b087b875005719957ee23e8575 --- A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/cosh/cosh.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/sinh/sinh.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/tanh/tanh.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/cosh/cosh.1.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/sinh/sinh.1.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/tanh/tanh.1.adm M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml M asterixdb/asterix-doc/src/main/markdown/builtins/1_numeric_common.md M asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericCoshDescriptor.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSinhDescriptor.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericTanhDescriptor.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java 13 files changed, 412 insertions(+), 0 deletions(-) git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/41/3041/1 diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/cosh/cosh.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/cosh/cosh.1.query.sqlpp new file mode 100644 index 0000000..723fe4d --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/cosh/cosh.1.query.sqlpp @@ -0,0 +1,29 @@ +/* + * 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. + */ + +{ + "a": cosh(120.0), + "b": cosh(90.5f), + "c": cosh(integer("90")), + "d": cosh(smallint("0")), + "e": cosh(tinyint("-45")), + "f": cosh(1), + "g": cosh(null) IS NULL, + "h": cosh(missing) IS MISSING +}; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/sinh/sinh.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/sinh/sinh.1.query.sqlpp new file mode 100644 index 0000000..d49a923 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/sinh/sinh.1.query.sqlpp @@ -0,0 +1,29 @@ +/* + * 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. + */ + +{ + "a": sinh(120.0), + "b": sinh(90.5f), + "c": sinh(integer("90")), + "d": sinh(smallint("0")), + "e": sinh(tinyint("-45")), + "f": sinh(1), + "g": sinh(null) IS NULL, + "h": sinh(missing) IS MISSING +}; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/tanh/tanh.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/tanh/tanh.1.query.sqlpp new file mode 100644 index 0000000..9c6712b --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/tanh/tanh.1.query.sqlpp @@ -0,0 +1,29 @@ +/* + * 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. + */ + +{ + "a": tanh(120.0), + "b": tanh(90.5f), + "c": tanh(integer("90")), + "d": tanh(smallint("0")), + "e": tanh(tinyint("-45")), + "f": tanh(1), + "g": tanh(null) IS NULL, + "h": tanh(missing) IS MISSING +}; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/cosh/cosh.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/cosh/cosh.1.adm new file mode 100644 index 0000000..bf95782 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/cosh/cosh.1.adm @@ -0,0 +1 @@ +{ "a": 6.520904391968161E51, "b": 1.0060524350871665E39, "c": 6.102016471589204E38, "d": 1.0, "e": 1.7467135528742547E19, "f": 1.543080634815244, "g": true, "h": true } diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/sinh/sinh.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/sinh/sinh.1.adm new file mode 100644 index 0000000..9a319db --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/sinh/sinh.1.adm @@ -0,0 +1 @@ +{ "a": 6.520904391968161E51, "b": 1.0060524350871665E39, "c": 6.102016471589204E38, "d": 0.0, "e": -1.7467135528742547E19, "f": 1.1752011936438014, "g": true, "h": true } diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/tanh/tanh.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/tanh/tanh.1.adm new file mode 100644 index 0000000..8050344 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/tanh/tanh.1.adm @@ -0,0 +1 @@ +{ "a": 1.0, "b": 1.0, "c": 1.0, "d": 0.0, "e": -1.0, "f": 0.7615941559557649, "g": true, "h": true } diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml index 56dbfa1..f5dd480 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml @@ -6227,16 +6227,31 @@ </compilation-unit> </test-case> <test-case FilePath="numeric"> + <compilation-unit name="cosh"> + <output-dir compare="Text">cosh</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="numeric"> <compilation-unit name="sin"> <output-dir compare="Text">sin</output-dir> </compilation-unit> </test-case> <test-case FilePath="numeric"> + <compilation-unit name="sinh"> + <output-dir compare="Text">sinh</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="numeric"> <compilation-unit name="tan"> <output-dir compare="Text">tan</output-dir> </compilation-unit> </test-case> <test-case FilePath="numeric"> + <compilation-unit name="tanh"> + <output-dir compare="Text">tanh</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="numeric"> <compilation-unit name="exp"> <output-dir compare="Text">exp</output-dir> </compilation-unit> diff --git a/asterixdb/asterix-doc/src/main/markdown/builtins/1_numeric_common.md b/asterixdb/asterix-doc/src/main/markdown/builtins/1_numeric_common.md index b95e778c..611d82d 100644 --- a/asterixdb/asterix-doc/src/main/markdown/builtins/1_numeric_common.md +++ b/asterixdb/asterix-doc/src/main/markdown/builtins/1_numeric_common.md @@ -198,6 +198,30 @@ { "v1": 0.5403023058681398, "v2": -0.4161468365471424, "v3": 1.0, "v4": 0.8775825618903728, "v5": 0.562379076290703 } +### cosh ### + * Syntax: + + cosh(numeric_value) + + * Computes the hyperbolic cosine value of the argument. + * Arguments: + * `numeric_value`: a `tinyint`/`smallint`/`integer`/`bigint`/`float`/`double` value. + * Return Value: + * the `double` hyperbolic cosine value for the argument, + * `missing` if the argument is a `missing` value, + * `null` if the argument is a `null` value, + * any other non-numeric input value will cause a type error. + + * Example: + + { "v1": cosh(1), "v2": cosh(2), "v3": cosh(0), "v4": cosh(float("0.5")), "v5": cosh(double("8")) }; + + + * The expected result is: + + { "v1": 1.5430806348152437, "v2": 3.7621956910836314, "v3": 1.0, "v4": 1.1276259652063807, "v5": 1490.479161252178 } + + ### degrees ### * Syntax: @@ -487,6 +511,30 @@ { "v1": 0.8414709848078965, "v2": 0.9092974268256817, "v3": 0.0, "v4": 0.479425538604203, "v5": 0.8268795405320025 } +### sinh ### + * Syntax: + + sinh(numeric_value) + + * Computes the hyperbolic sine value of the argument. + * Arguments: + * `numeric_value`: a `tinyint`/`smallint`/`integer`/`bigint`/`float`/`double` value. + * Return Value: + * the `double` hyperbolic sine value for the argument, + * `missing` if the argument is a `missing` value, + * `null` if the argument is a `null` value, + * any other non-numeric input value will cause a type error. + + * Example: + + { "v1": sinh(1), "v2": sinh(2), "v3": sinh(0), "v4": sinh(float("0.5")), "v5": sinh(double("8")) }; + + + * The expected result is: + + { "v1": 1.1752011936438014, "v2": 3.626860407847019, "v3": 0.0, "v4": 0.5210953054937474, "v5": 1490.4788257895502 } + + ### sqrt ### * Syntax: @@ -535,6 +583,30 @@ { "v1": 1.5574077246549023, "v2": -2.185039863261519, "v3": 0.0, "v4": 0.5463024898437905, "v5": 1.4703241557027185 } +### tanh ### + * Syntax: + + tanh(numeric_value) + + * Computes the hyperbolic tangent value of the argument. + * Arguments: + * `numeric_value`: a `tinyint`/`smallint`/`integer`/`bigint`/`float`/`double` value. + * Return Value: + * the `double` hyperbolic tangent value for the argument, + * `missing` if the argument is a `missing` value, + * `null` if the argument is a `null` value, + * any other non-numeric input value will cause a type error. + + * Example: + + { "v1": tanh(1), "v2": tanh(2), "v3": tanh(0), "v4": tanh(float("0.5")), "v5": tanh(double("8")) }; + + + * The expected result is: + + { "v1": 0.7615941559557649, "v2": 0.964027580075817, "v3": 0.0, "v4": 0.4621171572600098, "v5": 0.999999774929676 } + + ### trunc ### * Syntax: 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 9a52f55..90ad540 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 @@ -319,8 +319,14 @@ public static final FunctionIdentifier NUMERIC_RADIANS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "radians", 1); public static final FunctionIdentifier NUMERIC_COS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "cos", 1); + public static final FunctionIdentifier NUMERIC_COSH = + new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "cosh", 1); public static final FunctionIdentifier NUMERIC_SIN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "sin", 1); + public static final FunctionIdentifier NUMERIC_SINH = + new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "sinh", 1); public static final FunctionIdentifier NUMERIC_TAN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "tan", 1); + public static final FunctionIdentifier NUMERIC_TANH = + new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "tanh", 1); public static final FunctionIdentifier NUMERIC_EXP = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "exp", 1); public static final FunctionIdentifier NUMERIC_LN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "ln", 1); public static final FunctionIdentifier NUMERIC_LOG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "log", 1); @@ -1475,8 +1481,11 @@ addFunction(NUMERIC_DEGREES, NumericDoubleOutputFunctionTypeComputer.INSTANCE, true); addFunction(NUMERIC_RADIANS, NumericDoubleOutputFunctionTypeComputer.INSTANCE, true); addFunction(NUMERIC_COS, NumericDoubleOutputFunctionTypeComputer.INSTANCE, true); + addFunction(NUMERIC_COSH, NumericDoubleOutputFunctionTypeComputer.INSTANCE, true); addFunction(NUMERIC_SIN, NumericDoubleOutputFunctionTypeComputer.INSTANCE, true); + addFunction(NUMERIC_SINH, NumericDoubleOutputFunctionTypeComputer.INSTANCE, true); addFunction(NUMERIC_TAN, NumericDoubleOutputFunctionTypeComputer.INSTANCE, true); + addFunction(NUMERIC_TANH, NumericDoubleOutputFunctionTypeComputer.INSTANCE, true); addFunction(NUMERIC_E, ADoubleTypeComputer.INSTANCE, true); addFunction(NUMERIC_EXP, NumericDoubleOutputFunctionTypeComputer.INSTANCE, true); addFunction(NUMERIC_LN, NumericDoubleOutputFunctionTypeComputer.INSTANCE, true); diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericCoshDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericCoshDescriptor.java new file mode 100644 index 0000000..b7b4c90 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericCoshDescriptor.java @@ -0,0 +1,73 @@ +/* + * 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. + */ + +package org.apache.asterix.runtime.evaluators.functions; + +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.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; +import org.apache.hyracks.data.std.api.IPointable; + +public class NumericCoshDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new NumericCoshDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return BuiltinFunctions.NUMERIC_COSH; + } + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException { + return new NumericCoshEvaluator(ctx, args[0]); + } + }; + } + + public class NumericCoshEvaluator extends AbstractUnaryNumericDoubleFunctionEval { + + public NumericCoshEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory argEvalFactory) + throws HyracksDataException { + super(context, argEvalFactory, NumericCoshDescriptor.this.getIdentifier(), sourceLoc); + } + + @Override + protected void processDouble(double arg, IPointable resultPointable) throws HyracksDataException { + aDouble.setValue(Math.cosh(arg)); + serialize(aDouble, doubleSerde, resultPointable); + } + } + +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSinhDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSinhDescriptor.java new file mode 100644 index 0000000..7624ac3 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSinhDescriptor.java @@ -0,0 +1,74 @@ +/* + * 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. + */ + +package org.apache.asterix.runtime.evaluators.functions; + +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.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; +import org.apache.hyracks.data.std.api.IPointable; + +public class NumericSinhDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new NumericSinhDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return BuiltinFunctions.NUMERIC_SINH; + } + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException { + return new NumericSinhEvaluator(ctx, args[0]); + } + }; + } + + public class NumericSinhEvaluator extends AbstractUnaryNumericDoubleFunctionEval { + + public NumericSinhEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory argEvalFactory) + throws HyracksDataException { + super(context, argEvalFactory, NumericSinhDescriptor.this.getIdentifier(), sourceLoc); + } + + @Override + protected void processDouble(double arg, IPointable resultPointable) throws HyracksDataException { + aDouble.setValue(Math.sinh(arg)); + serialize(aDouble, doubleSerde, resultPointable); + } + + } + +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericTanhDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericTanhDescriptor.java new file mode 100644 index 0000000..460434f --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericTanhDescriptor.java @@ -0,0 +1,73 @@ +/* + * 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. + */ + +package org.apache.asterix.runtime.evaluators.functions; + +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.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; +import org.apache.hyracks.data.std.api.IPointable; + +public class NumericTanhDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new NumericTanhDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return BuiltinFunctions.NUMERIC_TANH; + } + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException { + return new NumericTanhEvaluator(ctx, args[0]); + } + }; + } + + public class NumericTanhEvaluator extends AbstractUnaryNumericDoubleFunctionEval { + + public NumericTanhEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory argEvalFactory) + throws HyracksDataException { + super(context, argEvalFactory, NumericTanhDescriptor.this.getIdentifier(), sourceLoc); + } + + @Override + protected void processDouble(double arg, IPointable resultPointable) throws HyracksDataException { + aDouble.setValue(Math.tanh(arg)); + serialize(aDouble, doubleSerde, resultPointable); + } + } + +} 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 dd1d862..e0831e6 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 @@ -290,6 +290,7 @@ import org.apache.asterix.runtime.evaluators.functions.NumericAddDescriptor; import org.apache.asterix.runtime.evaluators.functions.NumericCeilingDescriptor; import org.apache.asterix.runtime.evaluators.functions.NumericCosDescriptor; +import org.apache.asterix.runtime.evaluators.functions.NumericCoshDescriptor; import org.apache.asterix.runtime.evaluators.functions.NumericDegreesDescriptor; import org.apache.asterix.runtime.evaluators.functions.NumericDivDescriptor; import org.apache.asterix.runtime.evaluators.functions.NumericDivideDescriptor; @@ -306,9 +307,11 @@ import org.apache.asterix.runtime.evaluators.functions.NumericRoundHalfToEvenDescriptor; import org.apache.asterix.runtime.evaluators.functions.NumericSignDescriptor; import org.apache.asterix.runtime.evaluators.functions.NumericSinDescriptor; +import org.apache.asterix.runtime.evaluators.functions.NumericSinhDescriptor; import org.apache.asterix.runtime.evaluators.functions.NumericSqrtDescriptor; import org.apache.asterix.runtime.evaluators.functions.NumericSubDescriptor; import org.apache.asterix.runtime.evaluators.functions.NumericTanDescriptor; +import org.apache.asterix.runtime.evaluators.functions.NumericTanhDescriptor; import org.apache.asterix.runtime.evaluators.functions.NumericTruncDescriptor; import org.apache.asterix.runtime.evaluators.functions.NumericUnaryMinusDescriptor; import org.apache.asterix.runtime.evaluators.functions.OrDescriptor; @@ -741,8 +744,11 @@ fc.addGenerated(NumericDegreesDescriptor.FACTORY); fc.addGenerated(NumericRadiansDescriptor.FACTORY); fc.addGenerated(NumericCosDescriptor.FACTORY); + fc.addGenerated(NumericCoshDescriptor.FACTORY); fc.addGenerated(NumericSinDescriptor.FACTORY); + fc.addGenerated(NumericSinhDescriptor.FACTORY); fc.addGenerated(NumericTanDescriptor.FACTORY); + fc.addGenerated(NumericTanhDescriptor.FACTORY); fc.addGenerated(NumericExpDescriptor.FACTORY); fc.addGenerated(NumericLnDescriptor.FACTORY); fc.addGenerated(NumericLogDescriptor.FACTORY); -- To view, visit https://asterix-gerrit.ics.uci.edu/3041 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0853bfe4511ad5b087b875005719957ee23e8575 Gerrit-PatchSet: 1 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Hussain Towaileb <[email protected]>
