asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ali Alsuliman (Code Review)" <do-not-re...@asterixdb.incubator.apache.org>
Subject Change in asterixdb[master]: [NO ISSUE][FUN][COMP] fix ifnan(), ifnanorinf(), ifinf()
Date Tue, 02 Oct 2018 17:51:18 GMT
Ali Alsuliman has submitted this change and it was merged.

Change subject: [NO ISSUE][FUN][COMP] fix ifnan(), ifnanorinf(), ifinf()
......................................................................


[NO ISSUE][FUN][COMP] fix ifnan(), ifnanorinf(), ifinf()

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
This patch is to fix the mentioned functions. The fix is
to make ifnan() & ifnanorinf() skip the argument being
inspected if it's a missing value and check the next one.
For ifinf(), it should return missing if the argument
being inspected is a missing value. Also, number of args
is checked now.

Change-Id: Ib7cc3d18ca0443857ae271b6e14f2c9e920f1c1f
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2981
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Dmitry Lychagin <dmitry.lychagin@couchbase.com>
---
M asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifinf/ifinf.1.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifinf/ifinf.2.query.sqlpp
M asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifnan/ifnan.1.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifnan/ifnan.2.query.sqlpp
M asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifnanorinf/ifnanorinf.1.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifnanorinf/ifnanorinf.2.query.sqlpp
M asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ifinf/ifinf.1.adm
M asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ifnan/ifnan.1.adm
M asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ifnanorinf/ifnanorinf.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/BuiltinFunctions.java
M asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/IfNanOrInfTypeComputer.java
M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IfInfDescriptor.java
M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IfNanDescriptor.java
M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IfNanOrInfDescriptor.java
15 files changed, 178 insertions(+), 55 deletions(-)

Approvals:
  Anon. E. Moose #1000171: 
  Jenkins: Verified; ; Verified
  Dmitry Lychagin: Looks good to me, approved

Objections:
  Jenkins: Violations found



diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifinf/ifinf.1.query.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifinf/ifinf.1.query.sqlpp
index 479e290..243663f 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifinf/ifinf.1.query.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifinf/ifinf.1.query.sqlpp
@@ -19,19 +19,18 @@
 
 select value t
 from [
-    [ 0, isnull(ifinf()) ],
-    [ 1, isnull(ifinf(null)) ],
-    [ 2, ismissing(ifinf(missing)) ],
-    [ 3, isnull(ifinf(double("INF"))) ],
-    [ 4, isnull(ifinf(double("-INF"))) ],
-    [ 5, isnull(ifinf(float("INF"))) ],
-    [ 6, isnull(ifinf(float("-INF"))) ],
-    [ 7, ifinf(tinyint("1")) ],
-    [ 8, ifinf(smallint("2")) ],
-    [ 9, ifinf(integer("3")) ],
-    [ 10, ifinf(bigint("4")) ],
-    [ 11, ifinf(float("1.5")) ],
-    [ 12, ifinf(double("2.5")) ],
+    [ 1, isnull(ifinf(null, null)) ],
+    [ 2, ismissing(ifinf(missing, null)) ],
+    [ 3, isnull(ifinf(double("INF"), double("INF"))) ],
+    [ 4, isnull(ifinf(double("-INF"), double("-INF"))) ],
+    [ 5, isnull(ifinf(float("INF"), float("INF"))) ],
+    [ 6, isnull(ifinf(float("-INF"), float("-INF"))) ],
+    [ 7, ifinf(tinyint("1"), 5) ],
+    [ 8, ifinf(smallint("2"), 5) ],
+    [ 9, ifinf(integer("3"), 5) ],
+    [ 10, ifinf(bigint("4"), 5) ],
+    [ 11, ifinf(float("1.5"), 5) ],
+    [ 12, ifinf(double("2.5"), 5) ],
     [ 13, ifinf(2, null, missing) ],
     [ 14, isnull(ifinf(null, missing, 2)) ],
     [ 15, ismissing(ifinf(missing, null, 2)) ],
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifinf/ifinf.2.query.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifinf/ifinf.2.query.sqlpp
new file mode 100644
index 0000000..d1daed0
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifinf/ifinf.2.query.sqlpp
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+/*
+* Description  : Testing correct number of arguments required
+* Expected Res : Error, min is 2
+*/
+
+select value ifinf(15);
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifnan/ifnan.1.query.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifnan/ifnan.1.query.sqlpp
index 40a55d1..d20468e 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifnan/ifnan.1.query.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifnan/ifnan.1.query.sqlpp
@@ -19,24 +19,23 @@
 
 select value t
 from [
-    [ 0, isnull(ifnan()) ],
-    [ 1, isnull(ifnan(null)) ],
-    [ 2, ismissing(ifnan(missing)) ],
-    [ 3, isnull(ifnan(double("NaN"))) ],
-    [ 5, isnull(ifnan(float("NaN"))) ],
-    [ 7, ifnan(tinyint("1")) ],
-    [ 8, ifnan(smallint("2")) ],
-    [ 9, ifnan(integer("3")) ],
-    [ 10, ifnan(bigint("4")) ],
-    [ 11, ifnan(float("1.5")) ],
-    [ 12, ifnan(double("2.5")) ],
+    [ 1, isnull(ifnan(null, null)) ],
+    [ 2, isnull(ifnan(missing, missing)) ],
+    [ 3, isnull(ifnan(double("NaN"), double("NaN"))) ],
+    [ 5, isnull(ifnan(float("NaN"), float("NaN"))) ],
+    [ 7, ifnan(tinyint("1"), 14) ],
+    [ 8, ifnan(smallint("2"), 14) ],
+    [ 9, ifnan(integer("3"), 14) ],
+    [ 10, ifnan(bigint("4"), 14) ],
+    [ 11, ifnan(float("1.5"), 2.4) ],
+    [ 12, ifnan(double("2.5"), 4.4) ],
     [ 13, ifnan(2, null, missing) ],
     [ 14, isnull(ifnan(null, missing, 2)) ],
-    [ 15, ismissing(ifnan(missing, null, 2)) ],
+    [ 15, isnull(ifnan(missing, null, 2)) ],
     [ 16, ifnan(double("NaN"), 2) ],
     [ 17, ifnan(float("NaN"), 2) ],
     [ 18, isnull(ifnan(double("NaN"), [], 2)) ],
-    [ 19, ismissing(if_nan(double("NaN"), missing, 2)) ],
+    [ 19, if_nan(double("NaN"), missing, 2) ],
     [ 20, tostring(ifnan(double("NaN"), double("INF"), 2)) ],
     [ 21, tostring(ifnan(float("NaN"), float("-INF"), 2)) ]
 ] t
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifnan/ifnan.2.query.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifnan/ifnan.2.query.sqlpp
new file mode 100644
index 0000000..a2a018f
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifnan/ifnan.2.query.sqlpp
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+/*
+* Description  : Testing correct number of arguments required
+* Expected Res : Error, min is 2
+*/
+
+select value ifnan(12);
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifnanorinf/ifnanorinf.1.query.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifnanorinf/ifnanorinf.1.query.sqlpp
index d4b1863..34db5c2 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifnanorinf/ifnanorinf.1.query.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifnanorinf/ifnanorinf.1.query.sqlpp
@@ -19,24 +19,23 @@
 
 select value t
 from [
-    [ 0, isnull(ifnanorinf()) ],
-    [ 1, isnull(ifnanorinf(null)) ],
-    [ 2, ismissing(ifnanorinf(missing)) ],
-    [ 3, isnull(ifnanorinf(double("NaN"))) ],
-    [ 5, isnull(ifnanorinf(float("INF"))) ],
-    [ 7, ifnanorinf(tinyint("1")) ],
-    [ 8, ifnanorinf(smallint("2")) ],
-    [ 9, ifnanorinf(integer("3")) ],
-    [ 10, ifnanorinf(bigint("4")) ],
-    [ 11, ifnanorinf(float("1.5")) ],
-    [ 12, ifnanorinf(double("2.5")) ],
+    [ 1, isnull(ifnanorinf(null, null)) ],
+    [ 2, isnull(ifnanorinf(missing, missing)) ],
+    [ 3, isnull(ifnanorinf(double("NaN"), double("NaN"))) ],
+    [ 5, isnull(ifnanorinf(float("INF"), float("NaN"))) ],
+    [ 7, ifnanorinf(tinyint("1"), 5) ],
+    [ 8, ifnanorinf(smallint("2"), 5) ],
+    [ 9, ifnanorinf(integer("3"), 5) ],
+    [ 10, ifnanorinf(bigint("4"), 5) ],
+    [ 11, ifnanorinf(float("1.5"), 5) ],
+    [ 12, ifnanorinf(double("2.5"), "5") ],
     [ 13, ifnanorinf(2, null, missing) ],
     [ 14, isnull(ifnanorinf(null, missing, 2)) ],
-    [ 15, ismissing(ifnanorinf(missing, null, 2)) ],
+    [ 15, isnull(ifnanorinf(missing, null, 2)) ],
     [ 16, ifnanorinf(double("-INF"), 2) ],
     [ 17, ifnanorinf(float("NaN"), 2) ],
     [ 18, isnull(ifnanorinf(double("NaN"), [], 2)) ],
-    [ 19, ismissing(if_nan_or_inf(double("NaN"), missing, 2)) ],
+    [ 19, if_nan_or_inf(double("NaN"), missing, 2) ],
     [ 20, ifnanorinf(double("NaN"), double("INF"), 2) ],
     [ 21, ifnanorinf(float("NaN"), float("-INF"), 2) ]
 ] t
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifnanorinf/ifnanorinf.2.query.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifnanorinf/ifnanorinf.2.query.sqlpp
new file mode 100644
index 0000000..9c1f5c4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/ifnanorinf/ifnanorinf.2.query.sqlpp
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+/*
+* Description  : Testing correct number of arguments required
+* Expected Res : Error, min is 2
+*/
+
+select value ifnanorinf(15);
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ifinf/ifinf.1.adm
b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ifinf/ifinf.1.adm
index 852db4b..8b239c2 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ifinf/ifinf.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ifinf/ifinf.1.adm
@@ -1,4 +1,3 @@
-[ 0, true ]
 [ 1, true ]
 [ 2, true ]
 [ 3, true ]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ifnan/ifnan.1.adm
b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ifnan/ifnan.1.adm
index ec02746..5680b0d 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ifnan/ifnan.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ifnan/ifnan.1.adm
@@ -1,4 +1,3 @@
-[ 0, true ]
 [ 1, true ]
 [ 2, true ]
 [ 3, true ]
@@ -15,6 +14,6 @@
 [ 16, 2 ]
 [ 17, 2 ]
 [ 18, true ]
-[ 19, true ]
+[ 19, 2 ]
 [ 20, "INF" ]
 [ 21, "-INF" ]
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ifnanorinf/ifnanorinf.1.adm
b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ifnanorinf/ifnanorinf.1.adm
index 34476cc..d49ebcb 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ifnanorinf/ifnanorinf.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ifnanorinf/ifnanorinf.1.adm
@@ -1,4 +1,3 @@
-[ 0, true ]
 [ 1, true ]
 [ 2, true ]
 [ 3, true ]
@@ -15,6 +14,6 @@
 [ 16, 2 ]
 [ 17, 2 ]
 [ 18, true ]
-[ 19, true ]
+[ 19, 2 ]
 [ 20, 2 ]
 [ 21, 2 ]
\ No newline at end of file
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 18e93e1..35b1a93 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -5142,16 +5142,19 @@
     <test-case FilePath="numeric">
       <compilation-unit name="ifinf">
         <output-dir compare="Text">ifinf</output-dir>
+        <expected-error>Invalid number of arguments for function if-inf (in line 25,
at column 14)</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="numeric">
       <compilation-unit name="ifnan">
         <output-dir compare="Text">ifnan</output-dir>
+        <expected-error>Invalid number of arguments for function if-nan (in line 25,
at column 14)</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="numeric">
       <compilation-unit name="ifnanorinf">
         <output-dir compare="Text">ifnanorinf</output-dir>
+        <expected-error>Invalid number of arguments for function if-nan-or-inf (in
line 25, at column 14)</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="numeric">
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
index 49db062..f2be330 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
@@ -1309,8 +1309,8 @@
         addFunction(IF_MISSING, IfMissingTypeComputer.INSTANCE, true);
         addFunction(IF_MISSING_OR_NULL, IfMissingOrNullTypeComputer.INSTANCE, true);
         addFunction(IF_NULL, IfNullTypeComputer.INSTANCE, true);
-        addFunction(IF_NAN, IfNanOrInfTypeComputer.INSTANCE, true);
-        addFunction(IF_NAN_OR_INF, IfNanOrInfTypeComputer.INSTANCE, true);
+        addFunction(IF_NAN, IfNanOrInfTypeComputer.INSTANCE_SKIP_MISSING, true);
+        addFunction(IF_NAN_OR_INF, IfNanOrInfTypeComputer.INSTANCE_SKIP_MISSING, true);
 
         addFunction(MISSING_IF, MissingIfTypeComputer.INSTANCE, true);
         addFunction(NULL_IF, NullIfTypeComputer.INSTANCE, true);
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/IfNanOrInfTypeComputer.java
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/IfNanOrInfTypeComputer.java
index bb9fa38..a0423cd 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/IfNanOrInfTypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/IfNanOrInfTypeComputer.java
@@ -19,21 +19,33 @@
 
 package org.apache.asterix.om.typecomputer.impl;
 
+import org.apache.asterix.common.exceptions.CompilationException;
+import org.apache.asterix.common.exceptions.ErrorCode;
 import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer;
 import org.apache.asterix.om.types.AUnionType;
 import org.apache.asterix.om.types.BuiltinType;
 import org.apache.asterix.om.types.IAType;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
 
 public class IfNanOrInfTypeComputer extends AbstractResultTypeComputer {
 
-    public static final IfNanOrInfTypeComputer INSTANCE = new IfNanOrInfTypeComputer();
+    public static final IfNanOrInfTypeComputer INSTANCE = new IfNanOrInfTypeComputer(false);
+    public static final IfNanOrInfTypeComputer INSTANCE_SKIP_MISSING = new IfNanOrInfTypeComputer(true);
+
+    private final boolean skipMissing;
+
+    private IfNanOrInfTypeComputer(boolean skipMissing) {
+        this.skipMissing = skipMissing;
+    }
 
     @Override
     protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes)
throws AlgebricksException {
-        if (strippedInputTypes.length == 0) {
-            return BuiltinType.ANULL;
+        if (strippedInputTypes.length < 2 || strippedInputTypes.length > Short.MAX_VALUE)
{
+            String functionName = ((AbstractFunctionCallExpression) expr).getFunctionIdentifier().getName();
+            throw new CompilationException(ErrorCode.COMPILATION_INVALID_NUM_OF_ARGS, expr.getSourceLocation(),
+                    functionName);
         }
 
         boolean any = false;
@@ -50,8 +62,12 @@
         }
 
         switch (currentType.getTypeTag()) {
-            case ANY:
             case MISSING:
+                if (skipMissing) {
+                    // i.e. all args have been inspected and couldn't find a candidate value,
so return null
+                    return BuiltinType.ANULL;
+                }
+            case ANY:
             case BIGINT:
             case INTEGER:
             case SMALLINT:
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IfInfDescriptor.java
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IfInfDescriptor.java
index 0ff08a4..ee26b62 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IfInfDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IfInfDescriptor.java
@@ -28,6 +28,16 @@
 import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 
+/**
+ * ifinf(arg1, arg2, ...) scans the list of arguments in order and returns the first numeric
argument it encounters.
+ * If the argument being inspected is infinity as determined by the mathematical definition
of floating-points, then
+ * it skips the argument and inspects the next one. It returns missing if the argument being
inspected is missing.
+ * It returns null if:
+ * 1. the argument being inspected is not numeric.
+ * 2. all the arguments have been inspected and no candidate value has been found.
+ *
+ * Number of arguments: Min is 2. Max is {@link Short#MAX_VALUE}
+ */
 public class IfInfDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
@@ -40,7 +50,7 @@
 
             @Override
             public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx)
throws HyracksDataException {
-                return new IfNanOrInfDescriptor.AbstractIfInfOrNanEval(ctx, args) {
+                return new IfNanOrInfDescriptor.AbstractIfInfOrNanEval(ctx, args, false)
{
                     @Override
                     protected boolean skipDouble(double d) {
                         return Double.isInfinite(d);
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IfNanDescriptor.java
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IfNanDescriptor.java
index 9c1f024..e811190 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IfNanDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IfNanDescriptor.java
@@ -28,6 +28,15 @@
 import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 
+/**
+ * ifnan(arg1, arg2, ...) scans the list of arguments in order and returns the first numeric
argument it encounters.
+ * If the argument being inspected is missing or NaN as determined by the mathematical definition
of floating-points,
+ * then it skips the argument and inspects the next one. It returns null if:
+ * 1. the argument being inspected is not numeric.
+ * 2. all the arguments have been inspected and no candidate value has been found.
+ *
+ * Number of arguments: Min is 2. Max is {@link Short#MAX_VALUE}
+ */
 public class IfNanDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
@@ -40,7 +49,7 @@
 
             @Override
             public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx)
throws HyracksDataException {
-                return new IfNanOrInfDescriptor.AbstractIfInfOrNanEval(ctx, args) {
+                return new IfNanOrInfDescriptor.AbstractIfInfOrNanEval(ctx, args, true) {
                     @Override
                     protected boolean skipDouble(double d) {
                         return Double.isNaN(d);
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IfNanOrInfDescriptor.java
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IfNanOrInfDescriptor.java
index bf61922..375da4f 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IfNanOrInfDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IfNanOrInfDescriptor.java
@@ -36,6 +36,16 @@
 import org.apache.hyracks.data.std.primitive.VoidPointable;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
+/**
+ * ifnanorinf(arg1, arg2, ...) scans the list of arguments in order and returns the first
numeric argument it
+ * encounters.
+ * If the argument being inspected is missing or NaN/Infinity as determined by the mathematical
definition of
+ * floating-points, then it skips the argument and inspects the next one. It returns null
if:
+ * 1. the argument being inspected is not numeric.
+ * 2. all the arguments have been inspected and no candidate value has been found.
+ *
+ * Number of arguments: Min is 2. Max is {@link Short#MAX_VALUE}
+ */
 public class IfNanOrInfDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
@@ -48,7 +58,7 @@
 
             @Override
             public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx)
throws HyracksDataException {
-                return new AbstractIfInfOrNanEval(ctx, args) {
+                return new AbstractIfInfOrNanEval(ctx, args, true) {
                     @Override
                     protected boolean skipDouble(double d) {
                         return Double.isInfinite(d) || Double.isNaN(d);
@@ -78,13 +88,16 @@
         private final IScalarEvaluator[] argEvals;
 
         private final IPointable argPtr;
+        private final boolean skipMissing;
 
-        AbstractIfInfOrNanEval(IHyracksTaskContext ctx, IScalarEvaluatorFactory[] args) throws
HyracksDataException {
+        AbstractIfInfOrNanEval(IHyracksTaskContext ctx, IScalarEvaluatorFactory[] args, boolean
skipMissing)
+                throws HyracksDataException {
             argEvals = new IScalarEvaluator[args.length];
             for (int i = 0; i < argEvals.length; i++) {
                 argEvals[i] = args[i].createScalarEvaluator(ctx);
             }
             argPtr = new VoidPointable();
+            this.skipMissing = skipMissing;
         }
 
         @Override
@@ -110,11 +123,14 @@
                         }
                         result.set(argPtr);
                         return;
+                    case MISSING:
+                        if (skipMissing) {
+                            continue;
+                        }
                     case BIGINT:
                     case INTEGER:
                     case SMALLINT:
                     case TINYINT:
-                    case MISSING:
                         result.set(argPtr);
                         return;
                     default:

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/2981
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib7cc3d18ca0443857ae271b6e14f2c9e920f1c1f
Gerrit-PatchSet: 3
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Ali Alsuliman <ali.al.solaiman@gmail.com>
Gerrit-Reviewer: Ali Alsuliman <ali.al.solaiman@gmail.com>
Gerrit-Reviewer: Anon. E. Moose #1000171
Gerrit-Reviewer: Dmitry Lychagin <dmitry.lychagin@couchbase.com>
Gerrit-Reviewer: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Till Westmann <tillw@apache.org>

Mime
View raw message