You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by al...@apache.org on 2019/09/23 23:50:57 UTC
[asterixdb] branch master updated: [NO ISSUE][COMP] Fix type
computers of some array functions
This is an automated email from the ASF dual-hosted git repository.
alsuliman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git
The following commit(s) were added to refs/heads/master by this push:
new 3925712 [NO ISSUE][COMP] Fix type computers of some array functions
3925712 is described below
commit 3925712bbf35576d22b49680638d258068a4b341
Author: Ali Alsuliman <al...@gmail.com>
AuthorDate: Sat Sep 21 18:04:19 2019 -0700
[NO ISSUE][COMP] Fix type computers of some array functions
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
Fix the type computer of some array functions to return a nullable
type if the function might return NULL.
Change-Id: I21b747f3116e78f4dcbec079a38972c1f1abc2ce
Reviewed-on: https://asterix-gerrit.ics.uci.edu/3570
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
Reviewed-by: Dmitry Lychagin <dm...@couchbase.com>
Contrib: Till Westmann <ti...@apache.org>
---
.../apache/asterix/om/functions/BuiltinFunctions.java | 7 ++++---
...uter.java => ABooleanArrayContainsTypeComputer.java} | 12 +++++++-----
...mputer.java => AInt32ArrayPositionTypeComputer.java} | 12 +++++++-----
.../om/typecomputer/impl/ArrayRangeTypeComputer.java | 4 +++-
.../om/typecomputer/impl/ArrayRepeatTypeComputer.java | 5 ++++-
.../evaluators/functions/ArrayContainsDescriptor.java | 17 ++++-------------
.../evaluators/functions/ArrayPositionDescriptor.java | 17 ++++-------------
7 files changed, 33 insertions(+), 41 deletions(-)
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 417fa13..eba5100 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
@@ -24,7 +24,6 @@ import static org.apache.asterix.om.functions.BuiltinFunctions.WindowFunctionPro
import static org.apache.asterix.om.functions.BuiltinFunctions.WindowFunctionProperty.INJECT_ORDER_ARGS;
import static org.apache.asterix.om.functions.BuiltinFunctions.WindowFunctionProperty.MATERIALIZE_PARTITION;
import static org.apache.asterix.om.functions.BuiltinFunctions.WindowFunctionProperty.NO_FRAME_CLAUSE;
-import static org.apache.asterix.om.functions.BuiltinFunctions.WindowFunctionProperty.NO_ORDER_CLAUSE;
import java.util.Collections;
import java.util.EnumSet;
@@ -38,6 +37,7 @@ import org.apache.asterix.common.functions.FunctionConstants;
import org.apache.asterix.common.functions.FunctionSignature;
import org.apache.asterix.om.typecomputer.base.IResultTypeComputer;
import org.apache.asterix.om.typecomputer.impl.ABinaryTypeComputer;
+import org.apache.asterix.om.typecomputer.impl.ABooleanArrayContainsTypeComputer;
import org.apache.asterix.om.typecomputer.impl.ABooleanTypeComputer;
import org.apache.asterix.om.typecomputer.impl.ACircleTypeComputer;
import org.apache.asterix.om.typecomputer.impl.ADateTimeTypeComputer;
@@ -48,6 +48,7 @@ import org.apache.asterix.om.typecomputer.impl.ADurationTypeComputer;
import org.apache.asterix.om.typecomputer.impl.AFloatTypeComputer;
import org.apache.asterix.om.typecomputer.impl.AGeometryTypeComputer;
import org.apache.asterix.om.typecomputer.impl.AInt16TypeComputer;
+import org.apache.asterix.om.typecomputer.impl.AInt32ArrayPositionTypeComputer;
import org.apache.asterix.om.typecomputer.impl.AInt32TypeComputer;
import org.apache.asterix.om.typecomputer.impl.AInt64TypeComputer;
import org.apache.asterix.om.typecomputer.impl.AInt8TypeComputer;
@@ -2165,10 +2166,10 @@ public class BuiltinFunctions {
addFunction(ARRAY_PREPEND, AListTypeComputer.INSTANCE_PREPEND, true);
addFunction(ARRAY_APPEND, AListTypeComputer.INSTANCE_APPEND, true);
addFunction(ARRAY_INSERT, AListTypeComputer.INSTANCE_INSERT, true);
- addFunction(ARRAY_POSITION, AInt32TypeComputer.INSTANCE, true);
+ addFunction(ARRAY_POSITION, AInt32ArrayPositionTypeComputer.INSTANCE, true);
addFunction(ARRAY_REPEAT, ArrayRepeatTypeComputer.INSTANCE, true);
addFunction(ARRAY_REVERSE, AListFirstTypeComputer.INSTANCE, true);
- addFunction(ARRAY_CONTAINS, ABooleanTypeComputer.INSTANCE, true);
+ addFunction(ARRAY_CONTAINS, ABooleanArrayContainsTypeComputer.INSTANCE, true);
addFunction(ARRAY_SORT, AListFirstTypeComputer.INSTANCE, true);
addFunction(ARRAY_DISTINCT, AListFirstTypeComputer.INSTANCE, true);
addFunction(ARRAY_UNION, AListMultiListArgsTypeComputer.INSTANCE, true);
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ArrayRepeatTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ABooleanArrayContainsTypeComputer.java
similarity index 72%
copy from asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ArrayRepeatTypeComputer.java
copy to asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ABooleanArrayContainsTypeComputer.java
index 28c61bb..9f99b0c 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ArrayRepeatTypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ABooleanArrayContainsTypeComputer.java
@@ -19,20 +19,22 @@
package org.apache.asterix.om.typecomputer.impl;
import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer;
-import org.apache.asterix.om.types.AOrderedListType;
+import org.apache.asterix.om.types.AUnionType;
+import org.apache.asterix.om.types.BuiltinType;
import org.apache.asterix.om.types.IAType;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
-public class ArrayRepeatTypeComputer extends AbstractResultTypeComputer {
+public class ABooleanArrayContainsTypeComputer extends AbstractResultTypeComputer {
- public static final ArrayRepeatTypeComputer INSTANCE = new ArrayRepeatTypeComputer();
+ public static final ABooleanArrayContainsTypeComputer INSTANCE = new ABooleanArrayContainsTypeComputer();
- private ArrayRepeatTypeComputer() {
+ private ABooleanArrayContainsTypeComputer() {
}
@Override
protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException {
- return new AOrderedListType(strippedInputTypes[0], null);
+ return strippedInputTypes[0].getTypeTag().isListType() ? BuiltinType.ABOOLEAN
+ : AUnionType.createNullableType(BuiltinType.ABOOLEAN);
}
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ArrayRepeatTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/AInt32ArrayPositionTypeComputer.java
similarity index 72%
copy from asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ArrayRepeatTypeComputer.java
copy to asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/AInt32ArrayPositionTypeComputer.java
index 28c61bb..2a6e406 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ArrayRepeatTypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/AInt32ArrayPositionTypeComputer.java
@@ -19,20 +19,22 @@
package org.apache.asterix.om.typecomputer.impl;
import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer;
-import org.apache.asterix.om.types.AOrderedListType;
+import org.apache.asterix.om.types.AUnionType;
+import org.apache.asterix.om.types.BuiltinType;
import org.apache.asterix.om.types.IAType;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
-public class ArrayRepeatTypeComputer extends AbstractResultTypeComputer {
+public class AInt32ArrayPositionTypeComputer extends AbstractResultTypeComputer {
- public static final ArrayRepeatTypeComputer INSTANCE = new ArrayRepeatTypeComputer();
+ public static final AInt32ArrayPositionTypeComputer INSTANCE = new AInt32ArrayPositionTypeComputer();
- private ArrayRepeatTypeComputer() {
+ private AInt32ArrayPositionTypeComputer() {
}
@Override
protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException {
- return new AOrderedListType(strippedInputTypes[0], null);
+ return strippedInputTypes[0].getTypeTag().isListType() ? BuiltinType.AINT32
+ : AUnionType.createNullableType(BuiltinType.AINT32);
}
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ArrayRangeTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ArrayRangeTypeComputer.java
index cfd7340..9fba3d2 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ArrayRangeTypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ArrayRangeTypeComputer.java
@@ -22,6 +22,7 @@ package org.apache.asterix.om.typecomputer.impl;
import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer;
import org.apache.asterix.om.types.AOrderedListType;
import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.AUnionType;
import org.apache.asterix.om.types.BuiltinType;
import org.apache.asterix.om.types.IAType;
import org.apache.asterix.om.types.hierachy.ATypeHierarchy;
@@ -49,7 +50,8 @@ public class ArrayRangeTypeComputer extends AbstractResultTypeComputer {
} else if (ATypeHierarchy.canPromote(startNum.getTypeTag(), ATypeTag.DOUBLE)
&& ATypeHierarchy.canPromote(endNum.getTypeTag(), ATypeTag.DOUBLE)
&& (step == null || ATypeHierarchy.canPromote(step.getTypeTag(), ATypeTag.DOUBLE))) {
- return DOUBLE_LIST;
+ // even if the args types are valid, range function might return NULL if the doubles turn out to be Nan/Inf
+ return AUnionType.createNullableType(DOUBLE_LIST);
} else {
return BuiltinType.ANY;
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ArrayRepeatTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ArrayRepeatTypeComputer.java
index 28c61bb..7dc00a4 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ArrayRepeatTypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ArrayRepeatTypeComputer.java
@@ -20,6 +20,7 @@ package org.apache.asterix.om.typecomputer.impl;
import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer;
import org.apache.asterix.om.types.AOrderedListType;
+import org.apache.asterix.om.types.AUnionType;
import org.apache.asterix.om.types.IAType;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
@@ -33,6 +34,8 @@ public class ArrayRepeatTypeComputer extends AbstractResultTypeComputer {
@Override
protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException {
- return new AOrderedListType(strippedInputTypes[0], null);
+ // return type is always nullable since even if the args are valid, array repeat might return null if the 2nd
+ // arg turns out to be NaN/Inf at runtime (2nd arg is number of times to repeat the value (1st arg))
+ return AUnionType.createNullableType(new AOrderedListType(strippedInputTypes[0], null));
}
}
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/ArrayContainsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/ArrayContainsDescriptor.java
index 683de8e..69eed4f 100755
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/ArrayContainsDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/ArrayContainsDescriptor.java
@@ -23,13 +23,12 @@ import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider;
import org.apache.asterix.om.base.ABoolean;
import org.apache.asterix.om.base.AMutableInt32;
import org.apache.asterix.om.functions.BuiltinFunctions;
-import org.apache.asterix.om.functions.IFunctionDescriptor;
import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
-import org.apache.asterix.om.functions.IFunctionTypeInferer;
import org.apache.asterix.om.types.BuiltinType;
import org.apache.asterix.om.types.IAType;
import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
import org.apache.asterix.runtime.functions.FunctionTypeInferers;
+import org.apache.asterix.runtime.utils.DescriptorFactoryUtil;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
import org.apache.hyracks.algebricks.runtime.base.IEvaluatorContext;
@@ -57,20 +56,12 @@ import org.apache.hyracks.data.std.api.IPointable;
@MissingNullInOutFunction
public class ArrayContainsDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
private static final long serialVersionUID = 1L;
private IAType[] argTypes;
- public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
- @Override
- public IFunctionDescriptor createFunctionDescriptor() {
- return new ArrayContainsDescriptor();
- }
-
- @Override
- public IFunctionTypeInferer createFunctionTypeInferer() {
- return FunctionTypeInferers.SET_ARGUMENTS_TYPE;
- }
- };
+ public static final IFunctionDescriptorFactory FACTORY =
+ DescriptorFactoryUtil.createFactory(ArrayContainsDescriptor::new, FunctionTypeInferers.SET_ARGUMENTS_TYPE);
@Override
public FunctionIdentifier getIdentifier() {
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/ArrayPositionDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/ArrayPositionDescriptor.java
index f590d88..ed3949c 100755
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/ArrayPositionDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/ArrayPositionDescriptor.java
@@ -22,13 +22,12 @@ import org.apache.asterix.common.annotations.MissingNullInOutFunction;
import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider;
import org.apache.asterix.om.base.AMutableInt32;
import org.apache.asterix.om.functions.BuiltinFunctions;
-import org.apache.asterix.om.functions.IFunctionDescriptor;
import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
-import org.apache.asterix.om.functions.IFunctionTypeInferer;
import org.apache.asterix.om.types.BuiltinType;
import org.apache.asterix.om.types.IAType;
import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
import org.apache.asterix.runtime.functions.FunctionTypeInferers;
+import org.apache.asterix.runtime.utils.DescriptorFactoryUtil;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
import org.apache.hyracks.algebricks.runtime.base.IEvaluatorContext;
@@ -56,20 +55,12 @@ import org.apache.hyracks.data.std.api.IPointable;
@MissingNullInOutFunction
public class ArrayPositionDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
private static final long serialVersionUID = 1L;
private IAType[] argTypes;
- public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
- @Override
- public IFunctionDescriptor createFunctionDescriptor() {
- return new ArrayPositionDescriptor();
- }
-
- @Override
- public IFunctionTypeInferer createFunctionTypeInferer() {
- return FunctionTypeInferers.SET_ARGUMENTS_TYPE;
- }
- };
+ public static final IFunctionDescriptorFactory FACTORY =
+ DescriptorFactoryUtil.createFactory(ArrayPositionDescriptor::new, FunctionTypeInferers.SET_ARGUMENTS_TYPE);
@Override
public FunctionIdentifier getIdentifier() {