Yingyi Bu has uploaded a new change for review. https://asterix-gerrit.ics.uci.edu/1086
Change subject: Add several unary numeric builtin functions. ...................................................................... Add several unary numeric builtin functions. - newly added functions include: acos, asin, atan, cos, exp, ln, log, sign, sin, sqrt and tan; - refactor and simplify numeric function implementations. Change-Id: Ic7f945450f3cf8da543b2d68c29ef6eb0f4699d7 --- M asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/acos/acos.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/asin/asin.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/atan/atan.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/cos/cos.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/exp/exp.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ln/ln.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/log/log.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/sign/sign.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/sin/sin.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/sqrt/sqrt.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/tan/tan.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/acos/acos.1.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/asin/asin.1.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/atan/atan.1.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/cos/cos.1.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/exp/exp.1.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ln/ln.1.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/log/log.1.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/sign/sign.1.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/sin/sin.1.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/sqrt/sqrt.1.adm A asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/tan/tan.1.adm M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml M asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractUnaryNumericDoubleFunctionEval.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractUnaryNumericFunctionEval.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericACosDescriptor.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericASinDescriptor.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericATanDescriptor.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericAbsDescriptor.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericCeilingDescriptor.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericCosDescriptor.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericExpDescriptor.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericFloorDescriptor.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericLnDescriptor.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericLogDescriptor.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSignDescriptor.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSinDescriptor.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSqrtDescriptor.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericTanDescriptor.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericUnaryMinusDescriptor.java 42 files changed, 1,745 insertions(+), 404 deletions(-) git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/86/1086/1 diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java index 3201d9e..ee4dc32 100644 --- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java +++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java @@ -163,18 +163,29 @@ import org.apache.asterix.runtime.evaluators.functions.IsUnknownDescriptor; import org.apache.asterix.runtime.evaluators.functions.LenDescriptor; import org.apache.asterix.runtime.evaluators.functions.NotDescriptor; +import org.apache.asterix.runtime.evaluators.functions.NumericACosDescriptor; +import org.apache.asterix.runtime.evaluators.functions.NumericASinDescriptor; +import org.apache.asterix.runtime.evaluators.functions.NumericATanDescriptor; import org.apache.asterix.runtime.evaluators.functions.NumericAbsDescriptor; import org.apache.asterix.runtime.evaluators.functions.NumericAddDescriptor; import org.apache.asterix.runtime.evaluators.functions.NumericCaretDescriptor; import org.apache.asterix.runtime.evaluators.functions.NumericCeilingDescriptor; +import org.apache.asterix.runtime.evaluators.functions.NumericCosDescriptor; import org.apache.asterix.runtime.evaluators.functions.NumericDivideDescriptor; +import org.apache.asterix.runtime.evaluators.functions.NumericExpDescriptor; import org.apache.asterix.runtime.evaluators.functions.NumericFloorDescriptor; +import org.apache.asterix.runtime.evaluators.functions.NumericLnDescriptor; +import org.apache.asterix.runtime.evaluators.functions.NumericLogDescriptor; import org.apache.asterix.runtime.evaluators.functions.NumericModuloDescriptor; import org.apache.asterix.runtime.evaluators.functions.NumericMultiplyDescriptor; 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.NumericSignDescriptor; +import org.apache.asterix.runtime.evaluators.functions.NumericSinDescriptor; +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.NumericUnaryMinusDescriptor; import org.apache.asterix.runtime.evaluators.functions.OrDescriptor; import org.apache.asterix.runtime.evaluators.functions.OrderedListConstructorDescriptor; @@ -428,6 +439,17 @@ functionsToInjectUnkownHandling.add(NumericRoundDescriptor.FACTORY); functionsToInjectUnkownHandling.add(NumericRoundHalfToEvenDescriptor.FACTORY); functionsToInjectUnkownHandling.add(NumericRoundHalfToEven2Descriptor.FACTORY); + functionsToInjectUnkownHandling.add(NumericACosDescriptor.FACTORY); + functionsToInjectUnkownHandling.add(NumericASinDescriptor.FACTORY); + functionsToInjectUnkownHandling.add(NumericATanDescriptor.FACTORY); + functionsToInjectUnkownHandling.add(NumericCosDescriptor.FACTORY); + functionsToInjectUnkownHandling.add(NumericSinDescriptor.FACTORY); + functionsToInjectUnkownHandling.add(NumericTanDescriptor.FACTORY); + functionsToInjectUnkownHandling.add(NumericExpDescriptor.FACTORY); + functionsToInjectUnkownHandling.add(NumericLnDescriptor.FACTORY); + functionsToInjectUnkownHandling.add(NumericLogDescriptor.FACTORY); + functionsToInjectUnkownHandling.add(NumericSqrtDescriptor.FACTORY); + functionsToInjectUnkownHandling.add(NumericSignDescriptor.FACTORY); // Comparisons. functionsToInjectUnkownHandling.add(EqualsDescriptor.FACTORY); diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/acos/acos.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/acos/acos.1.query.sqlpp new file mode 100644 index 0000000..c9ae50c --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/acos/acos.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": acos(10.0), + "b": acos(0.5f), + "c": acos(100), + "d": acos(int32("0")), + "e": acos(int8("-1")), + "f": acos(int16("1")), + "g": acos(null), + "h": acos(missing) +}; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/asin/asin.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/asin/asin.1.query.sqlpp new file mode 100644 index 0000000..4807859 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/asin/asin.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": asin(10.0), + "b": asin(0.5f), + "c": asin(100), + "d": asin(int32("0")), + "e": asin(int8("-1")), + "f": asin(int16("1")), + "g": asin(null), + "h": asin(missing) +}; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/atan/atan.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/atan/atan.1.query.sqlpp new file mode 100644 index 0000000..1ca0e6e --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/atan/atan.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": atan(10.0), + "b": atan(0.5f), + "c": atan(100), + "d": atan(int32("0")), + "e": atan(int8("-1")), + "f": atan(int16("1")), + "g": atan(null), + "h": atan(missing) +}; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/cos/cos.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/cos/cos.1.query.sqlpp new file mode 100644 index 0000000..78940b2 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/cos/cos.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": cos(120.0), + "b": cos(90.5f), + "c": cos(int32("90")), + "d": cos(int16("0")), + "e": cos(int8("-45")), + "f": cos(1), + "g": cos(null), + "h": cos(missing) +}; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/exp/exp.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/exp/exp.1.query.sqlpp new file mode 100644 index 0000000..b3f0354 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/exp/exp.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": exp(120.0), + "b": exp(90.5f), + "c": exp(int32("90")), + "d": exp(int16("0")), + "e": exp(int8("-45")), + "f": exp(1), + "g": exp(null), + "h": exp(missing) +}; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ln/ln.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ln/ln.1.query.sqlpp new file mode 100644 index 0000000..ac0b71e --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ln/ln.1.query.sqlpp @@ -0,0 +1,30 @@ +/* + * 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": ln(120.0), + "b": ln(90.5f), + "c": ln(int32("90")), + "d": ln(int16("0")), + "e": ln(int8("-45")), + "f": ln(1), + "g": ln(null), + "h": ln(missing) +}; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/log/log.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/log/log.1.query.sqlpp new file mode 100644 index 0000000..c9fc2f4 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/log/log.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": log(120.0), + "b": log(90.5f), + "c": log(int32("90")), + "d": log(int16("0")), + "e": log(int8("-45")), + "f": log(1), + "g": log(null), + "h": log(missing) +}; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/sign/sign.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/sign/sign.1.query.sqlpp new file mode 100644 index 0000000..a73cc55 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/sign/sign.1.query.sqlpp @@ -0,0 +1,30 @@ +/* + * 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": sign(120.0), + "b": sign(-90.5f), + "c": sign(int32("90")), + "d": sign(int16("0")), + "e": sign(int8("-45")), + "f": sign(1), + "g": sign(null), + "h": sign(missing) +}; + diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/sin/sin.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/sin/sin.1.query.sqlpp new file mode 100644 index 0000000..c847b01 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/sin/sin.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": sin(120.0), + "b": sin(90.5f), + "c": sin(int32("90")), + "d": sin(int16("0")), + "e": sin(int8("-45")), + "f": sin(1), + "g": sin(null), + "h": sin(missing) +}; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/sqrt/sqrt.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/sqrt/sqrt.1.query.sqlpp new file mode 100644 index 0000000..09b6160 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/sqrt/sqrt.1.query.sqlpp @@ -0,0 +1,30 @@ +/* + * 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": sqrt(120.0), + "b": sqrt(90.5f), + "c": sqrt(int32("90")), + "d": sqrt(int16("0")), + "e": sqrt(int8("-45")), + "f": sqrt(1), + "g": sqrt(null), + "h": sqrt(missing) +}; + diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/tan/tan.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/tan/tan.1.query.sqlpp new file mode 100644 index 0000000..3cfa8b6 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/tan/tan.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": tan(120.0), + "b": tan(90.5f), + "c": tan(int32("90")), + "d": tan(int16("0")), + "e": tan(int8("-45")), + "f": tan(1), + "g": tan(null), + "h": tan(missing) +}; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/acos/acos.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/acos/acos.1.adm new file mode 100644 index 0000000..1bbc6b6 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/acos/acos.1.adm @@ -0,0 +1 @@ +{ "a": NaN, "b": 1.0471975511965979, "c": NaN, "d": 1.5707963267948966, "e": 3.141592653589793, "f": 0.0, "g": null } diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/asin/asin.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/asin/asin.1.adm new file mode 100644 index 0000000..3208c37 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/asin/asin.1.adm @@ -0,0 +1 @@ +{ "a": NaN, "b": 0.5235987755982989, "c": NaN, "d": 0.0, "e": -1.5707963267948966, "f": 1.5707963267948966, "g": null } diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/atan/atan.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/atan/atan.1.adm new file mode 100644 index 0000000..1fb93a1 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/atan/atan.1.adm @@ -0,0 +1 @@ +{ "a": 1.4711276743037347, "b": 0.4636476090008061, "c": 1.5607966601082315, "d": 0.0, "e": -0.7853981633974483, "f": 0.7853981633974483, "g": null } diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/cos/cos.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/cos/cos.1.adm new file mode 100644 index 0000000..1ab47ee --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/cos/cos.1.adm @@ -0,0 +1 @@ +{ "a": 0.8141809705265618, "b": -0.8218264239151786, "c": -0.4480736161291702, "d": 1.0, "e": 0.5253219888177297, "f": 0.5403023058681398, "g": null } diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/exp/exp.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/exp/exp.1.adm new file mode 100644 index 0000000..7a2e352 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/exp/exp.1.adm @@ -0,0 +1 @@ +{ "a": 1.3041808783936323E52, "b": 2.012104870174333E39, "c": 1.2204032943178408E39, "d": 1.0, "e": 2.8625185805493937E-20, "f": 2.718281828459045, "g": null } diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ln/ln.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ln/ln.1.adm new file mode 100644 index 0000000..598faa4 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ln/ln.1.adm @@ -0,0 +1 @@ +{ "a": 4.787491742782046, "b": 4.505349850705881, "c": 4.499809670330265, "d": -Infinity, "e": NaN, "f": 0.0, "g": null } diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/log/log.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/log/log.1.adm new file mode 100644 index 0000000..5280bf9 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/log/log.1.adm @@ -0,0 +1 @@ +{ "a": 2.0791812460476247, "b": 1.9566485792052033, "c": 1.954242509439325, "d": -Infinity, "e": NaN, "f": 0.0, "g": null } diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/sign/sign.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/sign/sign.1.adm new file mode 100644 index 0000000..7c776f4 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/sign/sign.1.adm @@ -0,0 +1 @@ +{ "a": 10.954451150103322, "b": 9.513148795220223, "c": 9.486832980505138, "d": 0.0, "e": NaN, "f": 1.0, "g": null } diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/sin/sin.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/sin/sin.1.adm new file mode 100644 index 0000000..0c090f5 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/sin/sin.1.adm @@ -0,0 +1 @@ +{ "a": 0.5806111842123143, "b": 0.5697379476169631, "c": 0.8939966636005579, "d": 0.0, "e": -0.8509035245341184, "f": 0.8414709848078965, "g": null } diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/sqrt/sqrt.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/sqrt/sqrt.1.adm new file mode 100644 index 0000000..7c776f4 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/sqrt/sqrt.1.adm @@ -0,0 +1 @@ +{ "a": 10.954451150103322, "b": 9.513148795220223, "c": 9.486832980505138, "d": 0.0, "e": NaN, "f": 1.0, "g": null } diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/tan/tan.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/tan/tan.1.adm new file mode 100644 index 0000000..62a1053 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/tan/tan.1.adm @@ -0,0 +1 @@ +{ "a": 0.7131230097859091, "b": -0.6932582489897723, "c": -1.995200412208242, "d": 0.0, "e": -1.6197751905438615, "f": 1.5574077246549023, "g": null } 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 912b592..ad32047 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml @@ -4234,6 +4234,56 @@ <!-- <expected-error>org.apache.asterix.common.exceptions.AsterixException</expected-error> --> </compilation-unit> </test-case> + <test-case FilePath="numeric"> + <compilation-unit name="acos"> + <output-dir compare="Text">acos</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="numeric"> + <compilation-unit name="asin"> + <output-dir compare="Text">asin</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="numeric"> + <compilation-unit name="atan"> + <output-dir compare="Text">atan</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="numeric"> + <compilation-unit name="cos"> + <output-dir compare="Text">cos</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="tan"> + <output-dir compare="Text">tan</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="numeric"> + <compilation-unit name="exp"> + <output-dir compare="Text">exp</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="numeric"> + <compilation-unit name="ln"> + <output-dir compare="Text">ln</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="numeric"> + <compilation-unit name="log"> + <output-dir compare="Text">log</output-dir> + </compilation-unit> + </test-case> + <test-case FilePath="numeric"> + <compilation-unit name="sqrt"> + <output-dir compare="Text">sqrt</output-dir> + </compilation-unit> + </test-case> </test-group> <test-group name="open-closed"> <!-- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java index 97f0ace..d17be1a 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java @@ -199,6 +199,23 @@ "numeric-idiv", 2); public static final FunctionIdentifier CARET = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "caret", 2); public static final FunctionIdentifier NUMERIC_ABS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "abs", 1); + public static final FunctionIdentifier NUMERIC_ACOS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "acos", + 1); + public static final FunctionIdentifier NUMERIC_ASIN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "asin", + 1); + public static final FunctionIdentifier NUMERIC_ATAN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "atan", + 1); + public static final FunctionIdentifier NUMERIC_COS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "cos", 1); + public static final FunctionIdentifier NUMERIC_SIN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "sin", 1); + public static final FunctionIdentifier NUMERIC_TAN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "tan", 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); + public static final FunctionIdentifier NUMERIC_SQRT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "sqrt", + 1); + public static final FunctionIdentifier NUMERIC_SIGN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "sign", + 1); + public static final FunctionIdentifier NUMERIC_CEILING = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "ceiling", 1); public static final FunctionIdentifier NUMERIC_FLOOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "floor", @@ -816,6 +833,17 @@ addPrivateFunction(NUMERIC_MOD, NumericAddSubMulDivTypeComputer.INSTANCE, true); addPrivateFunction(NUMERIC_IDIV, AInt64TypeComputer.INSTANCE, true); addFunction(NUMERIC_ABS, NumericUnaryFunctionTypeComputer.INSTANCE, true); + addFunction(NUMERIC_ACOS, ADoubleTypeComputer.INSTANCE, true); + addFunction(NUMERIC_ASIN, ADoubleTypeComputer.INSTANCE, true); + addFunction(NUMERIC_ATAN, ADoubleTypeComputer.INSTANCE, true); + addFunction(NUMERIC_COS, ADoubleTypeComputer.INSTANCE, true); + addFunction(NUMERIC_SIN, ADoubleTypeComputer.INSTANCE, true); + addFunction(NUMERIC_TAN, ADoubleTypeComputer.INSTANCE, true); + addFunction(NUMERIC_EXP, ADoubleTypeComputer.INSTANCE, true); + addFunction(NUMERIC_LN, ADoubleTypeComputer.INSTANCE, true); + addFunction(NUMERIC_LOG, ADoubleTypeComputer.INSTANCE, true); + addFunction(NUMERIC_SQRT, ADoubleTypeComputer.INSTANCE, true); + addFunction(NUMERIC_SIGN, AInt8TypeComputer.INSTANCE, true); addFunction(NUMERIC_CEILING, NumericUnaryFunctionTypeComputer.INSTANCE, true); addFunction(NUMERIC_FLOOR, NumericUnaryFunctionTypeComputer.INSTANCE, true); addFunction(NUMERIC_ROUND, NumericUnaryFunctionTypeComputer.INSTANCE, true); diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractUnaryNumericDoubleFunctionEval.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractUnaryNumericDoubleFunctionEval.java new file mode 100644 index 0000000..35cf431 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractUnaryNumericDoubleFunctionEval.java @@ -0,0 +1,65 @@ +/* + * 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.hyracks.algebricks.common.exceptions.AlgebricksException; +import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory; +import org.apache.hyracks.api.context.IHyracksTaskContext; +import org.apache.hyracks.data.std.api.IMutableValueStorage; + +/** + * An abstract class for functions that take a double value as the input and output a double value. + */ +abstract class AbstractUnaryNumericDoubleFunctionEval extends AbstractUnaryNumericFunctionEval { + + public AbstractUnaryNumericDoubleFunctionEval(IHyracksTaskContext context, IScalarEvaluatorFactory argEvalFactory, + FunctionIdentifier funcID) throws AlgebricksException { + super(context, argEvalFactory, funcID); + } + + @Override + protected void processInt8(byte arg, IMutableValueStorage resultStorage) throws AlgebricksException { + processDouble(arg, resultStorage); + } + + @Override + protected void processInt16(short arg, IMutableValueStorage resultStorage) throws AlgebricksException { + processDouble(arg, resultStorage); + } + + @Override + protected void processInt32(int arg, IMutableValueStorage resultStorage) throws AlgebricksException { + processDouble(arg, resultStorage); + } + + @Override + protected void processInt64(long arg, IMutableValueStorage resultStorage) throws AlgebricksException { + processDouble(arg, resultStorage); + } + + @Override + protected void processFloat(float arg, IMutableValueStorage resultStorage) throws AlgebricksException { + processDouble(arg, resultStorage); + } + + @Override + protected abstract void processDouble(double arg, IMutableValueStorage resultStorage) throws AlgebricksException; +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractUnaryNumericFunctionEval.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractUnaryNumericFunctionEval.java new file mode 100644 index 0000000..32b2785 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractUnaryNumericFunctionEval.java @@ -0,0 +1,205 @@ +/* + * 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 java.io.IOException; + +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.AqlSerializerDeserializerProvider; +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.base.IAObject; +import org.apache.asterix.om.types.ATypeTag; +import org.apache.asterix.om.types.BuiltinType; +import org.apache.asterix.om.types.EnumDeserializer; +import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; +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.data.std.api.IMutableValueStorage; +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; + +/** + * An abstract class for functions that take a numeric value as input and output a numeric value. + */ +abstract class AbstractUnaryNumericFunctionEval implements IScalarEvaluator { + + private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage(); + + // For the argument. + private final IPointable argPtr = new VoidPointable(); + + // For the result. + protected final AMutableDouble aDouble = new AMutableDouble(0); + protected final AMutableFloat aFloat = new AMutableFloat(0); + protected final AMutableInt64 aInt64 = new AMutableInt64(0); + protected final AMutableInt32 aInt32 = new AMutableInt32(0); + protected final AMutableInt16 aInt16 = new AMutableInt16((short) 0); + protected final AMutableInt8 aInt8 = new AMutableInt8((byte) 0); + + // The evaluator for the argument expression. + private final IScalarEvaluator argEval; + + @SuppressWarnings("rawtypes") + protected ISerializerDeserializer int8Serde = AqlSerializerDeserializerProvider.INSTANCE + .getSerializerDeserializer(BuiltinType.AINT8); + @SuppressWarnings("rawtypes") + protected ISerializerDeserializer int16Serde = AqlSerializerDeserializerProvider.INSTANCE + .getSerializerDeserializer(BuiltinType.AINT16); + @SuppressWarnings("rawtypes") + protected ISerializerDeserializer int32Serde = AqlSerializerDeserializerProvider.INSTANCE + .getSerializerDeserializer(BuiltinType.AINT32); + @SuppressWarnings("rawtypes") + protected ISerializerDeserializer int64Serde = AqlSerializerDeserializerProvider.INSTANCE + .getSerializerDeserializer(BuiltinType.AINT64); + @SuppressWarnings("rawtypes") + protected ISerializerDeserializer floatSerde = AqlSerializerDeserializerProvider.INSTANCE + .getSerializerDeserializer(BuiltinType.AFLOAT); + @SuppressWarnings("rawtypes") + protected ISerializerDeserializer doubleSerde = AqlSerializerDeserializerProvider.INSTANCE + .getSerializerDeserializer(BuiltinType.ADOUBLE); + + // The function identifier, used for error messages. + private final FunctionIdentifier funcID; + + public AbstractUnaryNumericFunctionEval(IHyracksTaskContext context, IScalarEvaluatorFactory argEvalFactory, + FunctionIdentifier funcID) throws AlgebricksException { + this.argEval = argEvalFactory.createScalarEvaluator(context); + this.funcID = funcID; + } + + @SuppressWarnings("unchecked") + @Override + public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException { + resultStorage.reset(); + argEval.evaluate(tuple, argPtr); + byte[] data = argPtr.getByteArray(); + int offset = argPtr.getStartOffset(); + + if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) { + byte val = AInt8SerializerDeserializer.getByte(data, offset + 1); + processInt8(val, resultStorage); + } else if (data[offset] == ATypeTag.SERIALIZED_INT16_TYPE_TAG) { + short val = AInt16SerializerDeserializer.getShort(data, offset + 1); + processInt16(val, resultStorage); + } else if (data[offset] == ATypeTag.SERIALIZED_INT32_TYPE_TAG) { + int val = AInt32SerializerDeserializer.getInt(data, offset + 1); + processInt32(val, resultStorage); + } else if (data[offset] == ATypeTag.SERIALIZED_INT64_TYPE_TAG) { + long val = AInt64SerializerDeserializer.getLong(data, offset + 1); + processInt64(val, resultStorage); + } else if (data[offset] == ATypeTag.SERIALIZED_FLOAT_TYPE_TAG) { + float val = AFloatSerializerDeserializer.getFloat(data, offset + 1); + processFloat(val, resultStorage); + } else if (data[offset] == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) { + double val = ADoubleSerializerDeserializer.getDouble(data, offset + 1); + processDouble(val, resultStorage); + } else { + throw new AlgebricksException(funcID + " expects a numeric input type, but gets " + + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data[offset])); + } + result.set(resultStorage); + } + + /** + * Processes an int8 argument. + * + * @param arg + * , the value of the argument. + * @param resultStorage + * , the place for storing the result. + */ + protected abstract void processInt8(byte arg, IMutableValueStorage resultStorage) throws AlgebricksException; + + /** + * Processes an int16 argument. + * + * @param arg + * , the value of the argument. + * @param resultStorage + * , the place for storing the result. + */ + protected abstract void processInt16(short arg, IMutableValueStorage resultStorage) throws AlgebricksException; + + /** + * Processes an int32 argument. + * + * @param arg + * , the value of the argument. + * @param resultStorage + * , the place for storing the result. + */ + protected abstract void processInt32(int arg, IMutableValueStorage resultStorage) throws AlgebricksException; + + /** + * Processes an int64 argument. + * + * @param arg + * , the value of the argument. + * @param resultStorage + * , the place for storing the result. + */ + protected abstract void processInt64(long arg, IMutableValueStorage resultStorage) throws AlgebricksException; + + /** + * Processes a float argument. + * + * @param arg + * , the value of the argument. + * @param resultStorage + * , the place for storing the result. + */ + protected abstract void processFloat(float arg, IMutableValueStorage resultStorage) throws AlgebricksException; + + /** + * Processes a double argument. + * + * @param arg + * , the value of the argument. + * @param resultStorage + * , the place for storing the result. + */ + protected abstract void processDouble(double arg, IMutableValueStorage resultStorage) throws AlgebricksException; + + // Serializes result into the result storage. + @SuppressWarnings("unchecked") + protected void serialize(IAObject result, IMutableValueStorage resultStorage, ISerializerDeserializer serde) + throws AlgebricksException { + try { + serde.serialize(result, resultStorage.getDataOutput()); + } catch (IOException e) { + throw new AlgebricksException(e); + } + } +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericACosDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericACosDescriptor.java new file mode 100644 index 0000000..dfd7db2 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericACosDescriptor.java @@ -0,0 +1,72 @@ +/* + * 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.AsterixBuiltinFunctions; +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.common.exceptions.AlgebricksException; +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.data.std.api.IMutableValueStorage; + +public class NumericACosDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new NumericACosDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return AsterixBuiltinFunctions.NUMERIC_ACOS; + } + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException { + return new NumericACosEvaluator(ctx, args[0]); + } + }; + } + + private class NumericACosEvaluator extends AbstractUnaryNumericDoubleFunctionEval { + + private NumericACosEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory argEvalFactory) + throws AlgebricksException { + super(context, argEvalFactory, NumericACosDescriptor.this.getIdentifier()); + } + + @Override + protected void processDouble(double arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aDouble.setValue(Math.acos(arg)); + serialize(aDouble, resultStorage, doubleSerde); + } + } + +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericASinDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericASinDescriptor.java new file mode 100644 index 0000000..d5afa9e --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericASinDescriptor.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.AsterixBuiltinFunctions; +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.common.exceptions.AlgebricksException; +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.data.std.api.IMutableValueStorage; + +public class NumericASinDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new NumericASinDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return AsterixBuiltinFunctions.NUMERIC_ASIN; + } + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException { + return new NumericASinEvaluator(ctx, args[0]); + } + }; + } + + private class NumericASinEvaluator extends AbstractUnaryNumericDoubleFunctionEval { + + private NumericASinEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory argEvalFactory) + throws AlgebricksException { + super(context, argEvalFactory, NumericASinDescriptor.this.getIdentifier()); + } + + @Override + protected void processDouble(double arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aDouble.setValue(Math.asin(arg)); + serialize(aDouble, resultStorage, doubleSerde); + } + } + +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericATanDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericATanDescriptor.java new file mode 100644 index 0000000..82d1314 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericATanDescriptor.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.AsterixBuiltinFunctions; +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.common.exceptions.AlgebricksException; +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.data.std.api.IMutableValueStorage; + +public class NumericATanDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new NumericATanDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return AsterixBuiltinFunctions.NUMERIC_ATAN; + } + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException { + return new NumericATanEvaluator(ctx, args[0]); + } + }; + } + + private class NumericATanEvaluator extends AbstractUnaryNumericDoubleFunctionEval { + + private NumericATanEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory argEvalFactory) + throws AlgebricksException { + super(context, argEvalFactory, NumericATanDescriptor.this.getIdentifier()); + } + + @Override + protected void processDouble(double arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aDouble.setValue(Math.atan(arg)); + serialize(aDouble, resultStorage, doubleSerde); + } + } + +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericAbsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericAbsDescriptor.java index 373547e..609d557 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericAbsDescriptor.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericAbsDescriptor.java @@ -23,40 +23,16 @@ */ package org.apache.asterix.runtime.evaluators.functions; -import java.io.DataOutput; - -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.AqlSerializerDeserializerProvider; -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.AsterixBuiltinFunctions; 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.om.types.EnumDeserializer; import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor; import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; -import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException; 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; +import org.apache.hyracks.data.std.api.IMutableValueStorage; public class NumericAbsDescriptor extends AbstractScalarFunctionDynamicDescriptor { private static final long serialVersionUID = 1L; @@ -73,86 +49,59 @@ } @Override - public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) { + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { return new IScalarEvaluatorFactory() { private static final long serialVersionUID = 1L; @Override - public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException { - - 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 AlgebricksException { - resultStorage.reset(); - eval.evaluate(tuple, argPtr); - byte[] data = argPtr.getByteArray(); - int offset = argPtr.getStartOffset(); - - try { - if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) { - serde = AqlSerializerDeserializerProvider.INSTANCE - .getSerializerDeserializer(BuiltinType.AINT8); - byte val = AInt8SerializerDeserializer.getByte(data, offset + 1); - aInt8.setValue((val <= 0) ? (byte) (0 - val) : val); - serde.serialize(aInt8, out); - } else if (data[offset] == ATypeTag.SERIALIZED_INT16_TYPE_TAG) { - serde = AqlSerializerDeserializerProvider.INSTANCE - .getSerializerDeserializer(BuiltinType.AINT16); - short val = AInt16SerializerDeserializer.getShort(data, offset + 1); - aInt16.setValue((val <= 0) ? (short) (0 - val) : val); - serde.serialize(aInt16, out); - } else if (data[offset] == ATypeTag.SERIALIZED_INT32_TYPE_TAG) { - serde = AqlSerializerDeserializerProvider.INSTANCE - .getSerializerDeserializer(BuiltinType.AINT32); - int val = AInt32SerializerDeserializer.getInt(data, offset + 1); - aInt32.setValue((val <= 0) ? (0 - val) : val); - serde.serialize(aInt32, out); - } else if (data[offset] == ATypeTag.SERIALIZED_INT64_TYPE_TAG) { - serde = AqlSerializerDeserializerProvider.INSTANCE - .getSerializerDeserializer(BuiltinType.AINT64); - long val = AInt64SerializerDeserializer.getLong(data, offset + 1); - aInt64.setValue((val <= 0L) ? (0L - val) : val); - serde.serialize(aInt64, out); - } else if (data[offset] == ATypeTag.SERIALIZED_FLOAT_TYPE_TAG) { - serde = AqlSerializerDeserializerProvider.INSTANCE - .getSerializerDeserializer(BuiltinType.AFLOAT); - float val = AFloatSerializerDeserializer.getFloat(data, offset + 1); - aFloat.setValue((val <= 0.0f) ? 0.0f - val : val); - serde.serialize(aFloat, out); - } else if (data[offset] == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) { - serde = AqlSerializerDeserializerProvider.INSTANCE - .getSerializerDeserializer(BuiltinType.ADOUBLE); - double val = ADoubleSerializerDeserializer.getDouble(data, offset + 1); - aDouble.setValue((val <= 0.0D) ? 0.0D - val : val); - serde.serialize(aDouble, out); - } else { - throw new NotImplementedException( - AsterixBuiltinFunctions.NUMERIC_ABS.getName() + ": not implemented for " - + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data[offset])); - } - } catch (HyracksDataException e) { - throw new AlgebricksException(e); - } - result.set(resultStorage); - } - }; + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException { + return new NumericAbsEvaluator(ctx, args[0]); } }; } + private class NumericAbsEvaluator extends AbstractUnaryNumericFunctionEval { + + private NumericAbsEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory argEvalFactory) + throws AlgebricksException { + super(context, argEvalFactory, NumericAbsDescriptor.this.getIdentifier()); + } + + @Override + protected void processInt8(byte arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt8.setValue(arg <= 0 ? (byte) (0 - arg) : arg); + serialize(aInt8, resultStorage, int8Serde); + } + + @Override + protected void processInt16(short arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt16.setValue(arg <= 0 ? (short) (0 - arg) : arg); + serialize(aInt16, resultStorage, int16Serde); + } + + @Override + protected void processInt32(int arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt32.setValue(arg <= 0 ? 0 - arg : arg); + serialize(aInt32, resultStorage, int32Serde); + } + + @Override + protected void processInt64(long arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt64.setValue(arg <= 0L ? 0L - arg : arg); + serialize(aInt64, resultStorage, int64Serde); + } + + @Override + protected void processFloat(float arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aFloat.setValue(arg <= 0.0f ? 0.0f - arg : arg); + serialize(aFloat, resultStorage, floatSerde); + } + + @Override + protected void processDouble(double arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aDouble.setValue(arg <= 0.0d ? 0.0d - arg : arg); + serialize(aDouble, resultStorage, doubleSerde); + } + } + } diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericCeilingDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericCeilingDescriptor.java index 89854fc..e73684f 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericCeilingDescriptor.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericCeilingDescriptor.java @@ -16,47 +16,18 @@ * specific language governing permissions and limitations * under the License. */ -/* - * Numeric function ceiling - * Author : Xiaoyu Ma@UC Irvine - * 01/30/2012 - */ package org.apache.asterix.runtime.evaluators.functions; -import java.io.DataOutput; - -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.AqlSerializerDeserializerProvider; -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.AsterixBuiltinFunctions; 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.om.types.EnumDeserializer; import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor; import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; -import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException; 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; +import org.apache.hyracks.data.std.api.IMutableValueStorage; public class NumericCeilingDescriptor extends AbstractScalarFunctionDynamicDescriptor { @@ -74,86 +45,59 @@ } @Override - public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) { + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { return new IScalarEvaluatorFactory() { private static final long serialVersionUID = 1L; @Override - public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException { - - 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 AlgebricksException { - resultStorage.reset(); - eval.evaluate(tuple, argPtr); - byte[] data = argPtr.getByteArray(); - int offset = argPtr.getStartOffset(); - - try { - if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) { - serde = AqlSerializerDeserializerProvider.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 = AqlSerializerDeserializerProvider.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 = AqlSerializerDeserializerProvider.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 = AqlSerializerDeserializerProvider.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 = AqlSerializerDeserializerProvider.INSTANCE - .getSerializerDeserializer(BuiltinType.AFLOAT); - float val = AFloatSerializerDeserializer.getFloat(data, offset + 1); - aFloat.setValue((float) Math.ceil(val)); - serde.serialize(aFloat, out); - } else if (data[offset] == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) { - serde = AqlSerializerDeserializerProvider.INSTANCE - .getSerializerDeserializer(BuiltinType.ADOUBLE); - double val = ADoubleSerializerDeserializer.getDouble(data, offset + 1); - aDouble.setValue(Math.ceil(val)); - serde.serialize(aDouble, out); - } else { - throw new NotImplementedException( - AsterixBuiltinFunctions.NUMERIC_CEILING.getName() + ": not implemented for " - + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data[offset])); - } - result.set(resultStorage); - } catch (HyracksDataException e) { - throw new AlgebricksException(e); - } - } - }; + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException { + return new NumericCeilingEvaluator(ctx, args[0]); } }; } + private class NumericCeilingEvaluator extends AbstractUnaryNumericFunctionEval { + + private NumericCeilingEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory argEvalFactory) + throws AlgebricksException { + super(context, argEvalFactory, NumericCeilingDescriptor.this.getIdentifier()); + } + + @Override + protected void processInt8(byte arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt8.setValue(arg); + serialize(aInt8, resultStorage, int8Serde); + } + + @Override + protected void processInt16(short arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt16.setValue(arg); + serialize(aInt16, resultStorage, int16Serde); + } + + @Override + protected void processInt32(int arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt32.setValue(arg); + serialize(aInt32, resultStorage, int32Serde); + } + + @Override + protected void processInt64(long arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt64.setValue(arg); + serialize(aInt64, resultStorage, int64Serde); + } + + @Override + protected void processFloat(float arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aFloat.setValue((float) Math.ceil(arg)); + serialize(aFloat, resultStorage, floatSerde); + } + + @Override + protected void processDouble(double arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aDouble.setValue(Math.ceil(arg)); + serialize(aDouble, resultStorage, doubleSerde); + } + } + } diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericCosDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericCosDescriptor.java new file mode 100644 index 0000000..891b528 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericCosDescriptor.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.AsterixBuiltinFunctions; +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.common.exceptions.AlgebricksException; +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.data.std.api.IMutableValueStorage; + +public class NumericCosDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new NumericCosDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return AsterixBuiltinFunctions.NUMERIC_COS; + } + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException { + return new NumericCosEvaluator(ctx, args[0]); + } + }; + } + + private class NumericCosEvaluator extends AbstractUnaryNumericDoubleFunctionEval { + + private NumericCosEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory argEvalFactory) + throws AlgebricksException { + super(context, argEvalFactory, NumericCosDescriptor.this.getIdentifier()); + } + + @Override + protected void processDouble(double arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aDouble.setValue(Math.cos(arg)); + serialize(aDouble, resultStorage, doubleSerde); + } + } + +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericExpDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericExpDescriptor.java new file mode 100644 index 0000000..a7ee9de --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericExpDescriptor.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.AsterixBuiltinFunctions; +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.common.exceptions.AlgebricksException; +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.data.std.api.IMutableValueStorage; + +public class NumericExpDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new NumericExpDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return AsterixBuiltinFunctions.NUMERIC_EXP; + } + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException { + return new NumericExpEvaluator(ctx, args[0]); + } + }; + } + + private class NumericExpEvaluator extends AbstractUnaryNumericDoubleFunctionEval { + + private NumericExpEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory argEvalFactory) + throws AlgebricksException { + super(context, argEvalFactory, NumericExpDescriptor.this.getIdentifier()); + } + + @Override + protected void processDouble(double arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aDouble.setValue(Math.exp(arg)); + serialize(aDouble, resultStorage, doubleSerde); + } + } + +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericFloorDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericFloorDescriptor.java index 336bf15..548d103 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericFloorDescriptor.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericFloorDescriptor.java @@ -23,40 +23,16 @@ */ package org.apache.asterix.runtime.evaluators.functions; -import java.io.DataOutput; - -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.AqlSerializerDeserializerProvider; -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.AsterixBuiltinFunctions; 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.om.types.EnumDeserializer; import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor; import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; -import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException; 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; +import org.apache.hyracks.data.std.api.IMutableValueStorage; public class NumericFloorDescriptor extends AbstractScalarFunctionDynamicDescriptor { private static final long serialVersionUID = 1L; @@ -73,86 +49,59 @@ } @Override - public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) { + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { return new IScalarEvaluatorFactory() { private static final long serialVersionUID = 1L; @Override - public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException { - - 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 AlgebricksException { - resultStorage.reset(); - eval.evaluate(tuple, argPtr); - byte[] data = argPtr.getByteArray(); - int offset = argPtr.getStartOffset(); - - try { - if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) { - serde = AqlSerializerDeserializerProvider.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 = AqlSerializerDeserializerProvider.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 = AqlSerializerDeserializerProvider.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 = AqlSerializerDeserializerProvider.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 = AqlSerializerDeserializerProvider.INSTANCE - .getSerializerDeserializer(BuiltinType.AFLOAT); - float val = AFloatSerializerDeserializer.getFloat(data, offset + 1); - aFloat.setValue((float) Math.floor(val)); - serde.serialize(aFloat, out); - } else if (data[offset] == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) { - serde = AqlSerializerDeserializerProvider.INSTANCE - .getSerializerDeserializer(BuiltinType.ADOUBLE); - double val = ADoubleSerializerDeserializer.getDouble(data, offset + 1); - aDouble.setValue(Math.floor(val)); - serde.serialize(aDouble, out); - } else { - throw new NotImplementedException( - AsterixBuiltinFunctions.NUMERIC_FLOOR.getName() + ": not implemented for " - + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data[offset])); - } - result.set(resultStorage); - } catch (HyracksDataException e) { - throw new AlgebricksException(e); - } - } - }; + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException { + return new NumericFloorEvaluator(ctx, args[0]); } }; } + private class NumericFloorEvaluator extends AbstractUnaryNumericFunctionEval { + + private NumericFloorEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory argEvalFactory) + throws AlgebricksException { + super(context, argEvalFactory, NumericFloorDescriptor.this.getIdentifier()); + } + + @Override + protected void processInt8(byte arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt8.setValue(arg); + serialize(aInt8, resultStorage, int8Serde); + } + + @Override + protected void processInt16(short arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt16.setValue(arg); + serialize(aInt16, resultStorage, int16Serde); + } + + @Override + protected void processInt32(int arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt32.setValue(arg); + serialize(aInt32, resultStorage, int32Serde); + } + + @Override + protected void processInt64(long arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt64.setValue(arg); + serialize(aInt64, resultStorage, int64Serde); + } + + @Override + protected void processFloat(float arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aFloat.setValue((float) Math.floor(arg)); + serialize(aFloat, resultStorage, floatSerde); + } + + @Override + protected void processDouble(double arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aDouble.setValue(Math.floor(arg)); + serialize(aDouble, resultStorage, doubleSerde); + } + } + } diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericLnDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericLnDescriptor.java new file mode 100644 index 0000000..002421f --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericLnDescriptor.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.AsterixBuiltinFunctions; +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.common.exceptions.AlgebricksException; +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.data.std.api.IMutableValueStorage; + +public class NumericLnDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new NumericLnDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return AsterixBuiltinFunctions.NUMERIC_LN; + } + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException { + return new NumericLnEvaluator(ctx, args[0]); + } + }; + } + + private class NumericLnEvaluator extends AbstractUnaryNumericDoubleFunctionEval { + + private NumericLnEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory argEvalFactory) + throws AlgebricksException { + super(context, argEvalFactory, NumericLnDescriptor.this.getIdentifier()); + } + + @Override + protected void processDouble(double arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aDouble.setValue(Math.log(arg)); + serialize(aDouble, resultStorage, doubleSerde); + } + } + +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericLogDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericLogDescriptor.java new file mode 100644 index 0000000..86ace23 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericLogDescriptor.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.AsterixBuiltinFunctions; +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.common.exceptions.AlgebricksException; +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.data.std.api.IMutableValueStorage; + +public class NumericLogDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new NumericLogDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return AsterixBuiltinFunctions.NUMERIC_LOG; + } + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException { + return new NumericLogEvaluator(ctx, args[0]); + } + }; + } + + private class NumericLogEvaluator extends AbstractUnaryNumericDoubleFunctionEval { + + private NumericLogEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory argEvalFactory) + throws AlgebricksException { + super(context, argEvalFactory, NumericLogDescriptor.this.getIdentifier()); + } + + @Override + protected void processDouble(double arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aDouble.setValue(Math.log10(arg)); + serialize(aDouble, resultStorage, doubleSerde); + } + } + +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSignDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSignDescriptor.java new file mode 100644 index 0000000..05f27a3 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSignDescriptor.java @@ -0,0 +1,103 @@ +/* + * 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.AsterixBuiltinFunctions; +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.common.exceptions.AlgebricksException; +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.data.std.api.IMutableValueStorage; + +public class NumericSignDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new NumericSignDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return AsterixBuiltinFunctions.NUMERIC_SIGN; + } + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException { + return new NumericSignEvaluator(ctx, args[0]); + } + }; + } + + private class NumericSignEvaluator extends AbstractUnaryNumericFunctionEval { + + private NumericSignEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory argEvalFactory) + throws AlgebricksException { + super(context, argEvalFactory, NumericSignDescriptor.this.getIdentifier()); + } + + @Override + protected void processInt8(byte arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt8.setValue(arg >= 0 ? (byte) (arg == 0 ? 0 : 1) : -1); + serialize(aInt8, resultStorage, int8Serde); + } + + @Override + protected void processInt16(short arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt8.setValue(arg >= 0 ? (byte) (arg == 0 ? 0 : 1) : -1); + serialize(aInt8, resultStorage, int8Serde); + } + + @Override + protected void processInt32(int arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt8.setValue(arg >= 0 ? (byte) (arg == 0 ? 0 : 1) : -1); + serialize(aInt8, resultStorage, int8Serde); + } + + @Override + protected void processInt64(long arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt8.setValue(arg >= 0L ? (byte) (arg == 0L ? 0 : 1) : -1); + serialize(aInt8, resultStorage, int8Serde); + } + + @Override + protected void processFloat(float arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt8.setValue(arg >= 0.0f ? (byte) (arg == 0.0f ? 0 : 1) : -1); + serialize(aInt8, resultStorage, int8Serde); + } + + @Override + protected void processDouble(double arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt8.setValue(arg >= 0.0d ? (byte) (arg == 0.0d ? 0 : 1) : -1); + serialize(aInt8, resultStorage, int8Serde); + } + } + +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSinDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSinDescriptor.java new file mode 100644 index 0000000..bc7aad3 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSinDescriptor.java @@ -0,0 +1,83 @@ +/* + * 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 java.io.IOException; + +import org.apache.asterix.om.functions.AsterixBuiltinFunctions; +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.common.exceptions.AlgebricksException; +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.data.std.api.IMutableValueStorage; + +public class NumericSinDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new NumericSinDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return AsterixBuiltinFunctions.NUMERIC_SIN; + } + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException { + return new NumericSinEvaluator(ctx, args[0]); + } + }; + } + + private class NumericSinEvaluator extends AbstractUnaryNumericDoubleFunctionEval { + + private NumericSinEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory argEvalFactory) + throws AlgebricksException { + super(context, argEvalFactory, NumericSinDescriptor.this.getIdentifier()); + } + + @Override + protected void processDouble(double arg, IMutableValueStorage resultStorage) throws AlgebricksException { + serialize(Math.sin(arg), resultStorage); + } + + private void serialize(double result, IMutableValueStorage resultStorage) throws AlgebricksException { + try { + aDouble.setValue(result); + doubleSerde.serialize(aDouble, resultStorage.getDataOutput()); + } catch (IOException e) { + throw new AlgebricksException(e); + } + } + } + +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSqrtDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSqrtDescriptor.java new file mode 100644 index 0000000..a40f0ef --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSqrtDescriptor.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.AsterixBuiltinFunctions; +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.common.exceptions.AlgebricksException; +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.data.std.api.IMutableValueStorage; + +public class NumericSqrtDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new NumericSqrtDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return AsterixBuiltinFunctions.NUMERIC_SQRT; + } + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException { + return new NumericSqrtEvaluator(ctx, args[0]); + } + }; + } + + private class NumericSqrtEvaluator extends AbstractUnaryNumericDoubleFunctionEval { + + private NumericSqrtEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory argEvalFactory) + throws AlgebricksException { + super(context, argEvalFactory, NumericSqrtDescriptor.this.getIdentifier()); + } + + @Override + protected void processDouble(double arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aDouble.setValue(Math.sqrt(arg)); + serialize(aDouble, resultStorage, doubleSerde); + } + } + +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericTanDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericTanDescriptor.java new file mode 100644 index 0000000..f160f3a --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericTanDescriptor.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.AsterixBuiltinFunctions; +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.common.exceptions.AlgebricksException; +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.data.std.api.IMutableValueStorage; + +public class NumericTanDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new NumericTanDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return AsterixBuiltinFunctions.NUMERIC_TAN; + } + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException { + return new NumericTanEvaluator(ctx, args[0]); + } + }; + } + + private class NumericTanEvaluator extends AbstractUnaryNumericDoubleFunctionEval { + + private NumericTanEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory argEvalFactory) + throws AlgebricksException { + super(context, argEvalFactory, NumericTanDescriptor.this.getIdentifier()); + } + + @Override + protected void processDouble(double arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aDouble.setValue(Math.tan(arg)); + serialize(aDouble, resultStorage, doubleSerde); + } + } + +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericUnaryMinusDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericUnaryMinusDescriptor.java index 422ab49..098b7b1 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericUnaryMinusDescriptor.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericUnaryMinusDescriptor.java @@ -18,40 +18,16 @@ */ package org.apache.asterix.runtime.evaluators.functions; -import java.io.DataOutput; - -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.AqlSerializerDeserializerProvider; -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.AsterixBuiltinFunctions; 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.om.types.EnumDeserializer; import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor; import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; -import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException; 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; +import org.apache.hyracks.data.std.api.IMutableValueStorage; public class NumericUnaryMinusDescriptor extends AbstractScalarFunctionDynamicDescriptor { @@ -64,85 +40,63 @@ }; @Override - public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) { - return new IScalarEvaluatorFactory() { - private static final long serialVersionUID = 1L; - - @Override - public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException { - - 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 AlgebricksException { - resultStorage.reset(); - eval.evaluate(tuple, argPtr); - byte[] data = argPtr.getByteArray(); - int offset = argPtr.getStartOffset(); - - try { - if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) { - serde = AqlSerializerDeserializerProvider.INSTANCE - .getSerializerDeserializer(BuiltinType.AINT8); - aInt8.setValue((byte) -AInt8SerializerDeserializer.getByte(data, offset + 1)); - serde.serialize(aInt8, out); - } else if (data[offset] == ATypeTag.SERIALIZED_INT16_TYPE_TAG) { - serde = AqlSerializerDeserializerProvider.INSTANCE - .getSerializerDeserializer(BuiltinType.AINT16); - aInt16.setValue((short) -AInt16SerializerDeserializer.getShort(data, offset + 1)); - serde.serialize(aInt16, out); - } else if (data[offset] == ATypeTag.SERIALIZED_INT32_TYPE_TAG) { - serde = AqlSerializerDeserializerProvider.INSTANCE - .getSerializerDeserializer(BuiltinType.AINT32); - aInt32.setValue(-AInt32SerializerDeserializer.getInt(data, offset + 1)); - serde.serialize(aInt32, out); - } else if (data[offset] == ATypeTag.SERIALIZED_INT64_TYPE_TAG) { - serde = AqlSerializerDeserializerProvider.INSTANCE - .getSerializerDeserializer(BuiltinType.AINT64); - aInt64.setValue(-AInt64SerializerDeserializer.getLong(data, offset + 1)); - serde.serialize(aInt64, out); - } else if (data[offset] == ATypeTag.SERIALIZED_FLOAT_TYPE_TAG) { - serde = AqlSerializerDeserializerProvider.INSTANCE - .getSerializerDeserializer(BuiltinType.AFLOAT); - aFloat.setValue(-AFloatSerializerDeserializer.getFloat(data, offset + 1)); - serde.serialize(aFloat, out); - } else if (data[offset] == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) { - serde = AqlSerializerDeserializerProvider.INSTANCE - .getSerializerDeserializer(BuiltinType.ADOUBLE); - aDouble.setValue(-ADoubleSerializerDeserializer.getDouble(data, offset + 1)); - serde.serialize(aDouble, out); - } else { - throw new NotImplementedException( - AsterixBuiltinFunctions.NUMERIC_UNARY_MINUS.getName() + ": not implemented for " - + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data[offset])); - } - } catch (HyracksDataException e) { - throw new AlgebricksException(e); - } - result.set(resultStorage); - } - }; - } - }; - } - - @Override public FunctionIdentifier getIdentifier() { return AsterixBuiltinFunctions.NUMERIC_UNARY_MINUS; } + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException { + return new NumericUnaryMinusEvaluator(ctx, args[0]); + } + }; + } + + private class NumericUnaryMinusEvaluator extends AbstractUnaryNumericFunctionEval { + + private NumericUnaryMinusEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory argEvalFactory) + throws AlgebricksException { + super(context, argEvalFactory, NumericUnaryMinusDescriptor.this.getIdentifier()); + } + + @Override + protected void processInt8(byte arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt8.setValue((byte) -arg); + serialize(aInt8, resultStorage, int8Serde); + } + + @Override + protected void processInt16(short arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt16.setValue((short) -arg); + serialize(aInt16, resultStorage, int16Serde); + } + + @Override + protected void processInt32(int arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt32.setValue(-arg); + serialize(aInt32, resultStorage, int32Serde); + } + + @Override + protected void processInt64(long arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aInt64.setValue(-arg); + serialize(aInt64, resultStorage, int64Serde); + } + + @Override + protected void processFloat(float arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aFloat.setValue(-arg); + serialize(aFloat, resultStorage, floatSerde); + } + + @Override + protected void processDouble(double arg, IMutableValueStorage resultStorage) throws AlgebricksException { + aDouble.setValue(-arg); + serialize(aDouble, resultStorage, doubleSerde); + } + } } -- To view, visit https://asterix-gerrit.ics.uci.edu/1086 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic7f945450f3cf8da543b2d68c29ef6eb0f4699d7 Gerrit-PatchSet: 1 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Yingyi Bu <buyin...@gmail.com>