Murtadha Hubail has submitted this change and it was merged. Change subject: [NO ISSUE][FUN] Implement array_position function ......................................................................
[NO ISSUE][FUN] Implement array_position function - user model changes: no - storage format changes: no - interface changes: no details: This is part of implementing array functions. The array_position() takes an input list and a value and returns the index of the value in the array or -1 if the value is not found. array_position(list, val). An error is thrown if val is object or list. Change-Id: I4604d347a22f98071a68abee43693fca9096b361 Reviewed-on: https://asterix-gerrit.ics.uci.edu/2714 Sonar-Qube: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Contrib: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Integration-Tests: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Reviewed-by: Till Westmann <ti...@apache.org> --- M asterixdb/asterix-app/src/test/java/org/apache/asterix/runtime/NullMissingTest.java A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.1.ddl.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.2.update.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.3.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.4.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.5.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.6.ddl.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/results/array_fun/array_position/array_position.3.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/types/ATypeTag.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/ArrayAppendDescriptor.java A asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/ArrayPositionDescriptor.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java M hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/exceptions/ErrorCode.java M hyracks-fullstack/hyracks/hyracks-api/src/main/resources/errormsg/en.properties 16 files changed, 339 insertions(+), 5 deletions(-) Approvals: Anon. E. Moose #1000171: Till Westmann: Looks good to me, approved Jenkins: Verified; No violations found; ; Verified diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/runtime/NullMissingTest.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/runtime/NullMissingTest.java index 89494c4..f6f617e 100644 --- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/runtime/NullMissingTest.java +++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/runtime/NullMissingTest.java @@ -41,18 +41,21 @@ public class NullMissingTest { + private static final String arrayAppend = "ArrayAppendDescriptor"; + @Test public void test() throws Exception { List<IFunctionDescriptorFactory> functions = FunctionCollection.createDefaultFunctionCollection().getFunctionDescriptorFactories(); int testedFunctions = 0; + String[] splits; for (IFunctionDescriptorFactory func : functions) { String className = func.getClass().getName(); // We test all generated functions except // record and cast functions, which requires type settings (we test them in runtime tests). - String[] splits = className.split("\\."); + splits = className.split("\\."); if (className.contains("Gen") && !className.contains("record") && !className.contains("Cast") - && !splits[splits.length - 1].startsWith("Array")) { + && !splits[splits.length - 1].startsWith(arrayAppend)) { testFunction(func); ++testedFunctions; } diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.1.ddl.sqlpp new file mode 100755 index 0000000..257c4dd --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.1.ddl.sqlpp @@ -0,0 +1,46 @@ +/* + * 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. + */ + +drop dataverse TinySocial if exists; +create dataverse TinySocial; + +use TinySocial; + + +create type TinySocial.TwitterUserType as +{ + `screen-name` : string, + lang : string, + friends_count : bigint, + statuses_count : bigint, + name : string, + followers_count : bigint +}; + +create type TinySocial.TweetMessageType as + closed { + tweetid : string, + user : TwitterUserType, + `sender-location` : point?, + `send-time` : datetime, + `referred-topics` : {{string}}, + `message-text` : string +}; + +create dataset TweetMessages(TweetMessageType) primary key tweetid hints (`CARDINALITY`=`100`); \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.2.update.sqlpp new file mode 100755 index 0000000..4a0e7ed --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.2.update.sqlpp @@ -0,0 +1,22 @@ +/* + * 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. + */ + +use TinySocial; + +load dataset TweetMessages using localfs ((`path`=`asterix_nc1://data/tinysocial/twm.adm`),(`format`=`adm`)); diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.3.query.sqlpp new file mode 100755 index 0000000..afdada2 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.3.query.sqlpp @@ -0,0 +1,34 @@ +/* + * 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. + */ + +use TinySocial; + +{ + "t1": (select array_position(t.`referred-topics`, "speed") from TweetMessages t order by t.tweetid), + "t2": (select array_position([3,8,98,40], 8)), + "t3": (select array_position([3,8,98,40], 40.0)), + "t4": (select array_position([3,8,98,40], -3)), + "t5": (select array_position([3,"sth",98,40], 98)), + "t6": (select array_position([3,8,98,40], null)), + "t7": (select array_position([3,8,98,40], missing)), + "t8": (select array_position(missing, 6)), + "t9": (select array_position(null, 6)), + "t10": (select array_position(5, "sth")), + "t11": (select array_position([5, {"id":77}, "sth"], "sth")) +}; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.4.query.sqlpp new file mode 100755 index 0000000..82ecbf0 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.4.query.sqlpp @@ -0,0 +1,22 @@ +/* + * 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. + */ + +use TinySocial; + +select array_position([5,1,9], [2,3]); \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.5.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.5.query.sqlpp new file mode 100755 index 0000000..3f9e4fc --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.5.query.sqlpp @@ -0,0 +1,22 @@ +/* + * 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. + */ + +use TinySocial; + +select array_position([5,{"id": 5},9], {"id": 5}); \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.6.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.6.ddl.sqlpp new file mode 100644 index 0000000..3f8c8ec --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/array_fun/array_position/array_position.6.ddl.sqlpp @@ -0,0 +1,20 @@ +/* + * 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. + */ + +drop dataverse TinySocial; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/array_fun/array_position/array_position.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/array_fun/array_position/array_position.3.adm new file mode 100644 index 0000000..e5f1b8f --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/array_fun/array_position/array_position.3.adm @@ -0,0 +1 @@ +{ "t1": [ { "$1": -1 }, { "$1": -1 }, { "$1": -1 }, { "$1": -1 }, { "$1": -1 }, { "$1": 1 }, { "$1": -1 }, { "$1": 1 }, { "$1": -1 }, { "$1": -1 }, { "$1": -1 }, { "$1": -1 } ], "t2": [ { "$2": 1 } ], "t3": [ { "$3": 3 } ], "t4": [ { "$4": -1 } ], "t5": [ { "$5": 2 } ], "t6": [ { "$6": null } ], "t7": [ { } ], "t8": [ { } ], "t9": [ { "$9": null } ], "t10": [ { "$10": null } ], "t11": [ { "$11": 2 } ] } 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 a6613cd..0934e56 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml @@ -988,6 +988,13 @@ <output-dir compare="Text">array_append</output-dir> </compilation-unit> </test-case> + <test-case FilePath="array_fun"> + <compilation-unit name="array_position"> + <output-dir compare="Text">array_position</output-dir> + <expected-error>HYR0115: Cannot compare non-primitive values (in line 22, at column 8)</expected-error> + <expected-error>HYR0115: Cannot compare non-primitive values (in line 22, at column 8)</expected-error> + </compilation-unit> + </test-case> </test-group> <test-group name="boolean"> <test-case FilePath="boolean"> 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 249e169..f73533c 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 @@ -185,6 +185,8 @@ // array functions public static final FunctionIdentifier ARRAY_APPEND = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "array-append", FunctionIdentifier.VARARGS); + public static final FunctionIdentifier ARRAY_POSITION = + new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "array-position", 2); // objects public static final FunctionIdentifier RECORD_MERGE = @@ -1461,6 +1463,7 @@ // array functions addFunction(ARRAY_APPEND, ArrayAppendTypeComputer.INSTANCE, true); + addFunction(ARRAY_POSITION, AInt32TypeComputer.INSTANCE, true); // objects addFunction(RECORD_MERGE, RecordMergeTypeComputer.INSTANCE, true); diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ATypeTag.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ATypeTag.java index a79588d..f2b004f 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ATypeTag.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ATypeTag.java @@ -135,6 +135,10 @@ return this == ATypeTag.OBJECT || this == ATypeTag.ARRAY || this == ATypeTag.MULTISET || this == ATypeTag.UNION; } + public final boolean isListType() { + return this == ATypeTag.ARRAY || this == ATypeTag.MULTISET; + } + @Override public String toString() { return this.name().toLowerCase(); diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/ArrayAppendDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/ArrayAppendDescriptor.java index a44397c..3792b8e 100755 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/ArrayAppendDescriptor.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/ArrayAppendDescriptor.java @@ -18,6 +18,8 @@ */ package org.apache.asterix.runtime.evaluators.functions; +import static org.apache.asterix.om.types.EnumDeserializer.ATYPETAGDESERIALIZER; + import java.io.IOException; import java.util.Arrays; @@ -29,7 +31,6 @@ import org.apache.asterix.om.functions.IFunctionDescriptorFactory; import org.apache.asterix.om.functions.IFunctionTypeInferer; import org.apache.asterix.om.pointables.base.DefaultOpenFieldType; -import org.apache.asterix.om.types.AOrderedListType; import org.apache.asterix.om.types.ATypeTag; import org.apache.asterix.om.types.AbstractCollectionType; import org.apache.asterix.om.types.IAType; @@ -144,8 +145,7 @@ } } - if (listArgType != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG - && listArgType != ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) { + if (!ATYPETAGDESERIALIZER.deserialize(listArgType).isListType()) { PointableHelper.setNull(result); return; } 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 new file mode 100755 index 0000000..caf93b0 --- /dev/null +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/ArrayPositionDescriptor.java @@ -0,0 +1,146 @@ +/* + * 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 static org.apache.asterix.om.types.EnumDeserializer.ATYPETAGDESERIALIZER; + +import java.io.IOException; + +import org.apache.asterix.dataflow.data.nontagged.comparators.AObjectAscBinaryComparatorFactory; +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.types.BuiltinType; +import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor; +import org.apache.asterix.runtime.evaluators.common.ListAccessor; +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.IBinaryComparator; +import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer; +import org.apache.hyracks.api.exceptions.ErrorCode; +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; + +public class ArrayPositionDescriptor extends AbstractScalarFunctionDynamicDescriptor { + private static final long serialVersionUID = 1L; + + public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() { + @Override + public IFunctionDescriptor createFunctionDescriptor() { + return new ArrayPositionDescriptor(); + } + }; + + @Override + public FunctionIdentifier getIdentifier() { + return BuiltinFunctions.ARRAY_POSITION; + } + + @Override + public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) + throws AlgebricksException { + return new IScalarEvaluatorFactory() { + private static final long serialVersionUID = 1L; + + @Override + public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException { + return new ArrayPositionFunction(args, ctx); + } + }; + } + + public class ArrayPositionFunction implements IScalarEvaluator { + private final ArrayBackedValueStorage storage; + private final IPointable listArg; + private final IPointable searchedValueArg; + private final IScalarEvaluator listEval; + private final IScalarEvaluator searchedValueEval; + private final IBinaryComparator comp; + private final ListAccessor listAccessor; + private final AMutableInt32 intValue; + private final ISerializerDeserializer intSerde; + + public ArrayPositionFunction(IScalarEvaluatorFactory[] args, IHyracksTaskContext ctx) + throws HyracksDataException { + storage = new ArrayBackedValueStorage(); + listArg = new VoidPointable(); + searchedValueArg = new VoidPointable(); + listEval = args[0].createScalarEvaluator(ctx); + searchedValueEval = args[1].createScalarEvaluator(ctx); + comp = AObjectAscBinaryComparatorFactory.INSTANCE.createBinaryComparator(); + listAccessor = new ListAccessor(); + intValue = new AMutableInt32(-1); + intSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32); + } + + @Override + public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException { + // 1st arg: list + listEval.evaluate(tuple, listArg); + byte[] listBytes = listArg.getByteArray(); + int listOffset = listArg.getStartOffset(); + + // 2nd arg: value to search for + searchedValueEval.evaluate(tuple, searchedValueArg); + byte[] valueBytes = searchedValueArg.getByteArray(); + int valueOffset = searchedValueArg.getStartOffset(); + int valueLength = searchedValueArg.getLength(); + + // for now, we don't support deep equality of object/lists. Throw an error if the value is of these types + if (ATYPETAGDESERIALIZER.deserialize(valueBytes[valueOffset]).isDerivedType()) { + throw HyracksDataException.create(ErrorCode.CANNOT_COMPARE_COMPLEX, sourceLoc); + } + + if (!ATYPETAGDESERIALIZER.deserialize(listBytes[listOffset]).isListType()) { + PointableHelper.setNull(result); + return; + } + + listAccessor.reset(listBytes, listOffset); + int numItems = listAccessor.size(); + intValue.setValue(-1); + + try { + for (int i = 0; i < numItems; i++) { + storage.reset(); + listAccessor.writeItem(i, storage.getDataOutput()); + if (comp.compare(storage.getByteArray(), storage.getStartOffset(), storage.getLength(), valueBytes, + valueOffset, valueLength) == 0) { + intValue.setValue(i); + break; + } + } + } catch (IOException e) { + throw HyracksDataException.create(e); + } + + storage.reset(); + intSerde.serialize(intValue, storage.getDataOutput()); + result.set(storage); + } + } +} diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java index 406c5b9..f64df0a 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java @@ -144,6 +144,7 @@ import org.apache.asterix.runtime.evaluators.functions.AndDescriptor; import org.apache.asterix.runtime.evaluators.functions.AnyCollectionMemberDescriptor; import org.apache.asterix.runtime.evaluators.functions.ArrayAppendDescriptor; +import org.apache.asterix.runtime.evaluators.functions.ArrayPositionDescriptor; import org.apache.asterix.runtime.evaluators.functions.CastTypeDescriptor; import org.apache.asterix.runtime.evaluators.functions.CastTypeLaxDescriptor; import org.apache.asterix.runtime.evaluators.functions.CheckUnknownDescriptor; @@ -372,6 +373,7 @@ // array functions fc.addGenerated(ArrayAppendDescriptor.FACTORY); + fc.addGenerated(ArrayPositionDescriptor.FACTORY); // unnesting functions fc.add(TidRunningAggregateDescriptor.FACTORY); diff --git a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/exceptions/ErrorCode.java b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/exceptions/ErrorCode.java index b6d7cc7..5f91e89 100644 --- a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/exceptions/ErrorCode.java +++ b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/exceptions/ErrorCode.java @@ -148,6 +148,7 @@ public static final int CANNOT_ADD_ELEMENT_TO_INVERTED_INDEX_SEARCH_RESULT = 112; public static final int UNDEFINED_INVERTED_LIST_MERGE_TYPE = 113; public static final int NODE_IS_NOT_ACTIVE = 114; + public static final int CANNOT_COMPARE_COMPLEX = 115; // Compilation error codes. public static final int RULECOLLECTION_NOT_INSTANCE_OF_LIST = 10000; diff --git a/hyracks-fullstack/hyracks/hyracks-api/src/main/resources/errormsg/en.properties b/hyracks-fullstack/hyracks/hyracks-api/src/main/resources/errormsg/en.properties index ef07038..ea58c3c 100644 --- a/hyracks-fullstack/hyracks/hyracks-api/src/main/resources/errormsg/en.properties +++ b/hyracks-fullstack/hyracks/hyracks-api/src/main/resources/errormsg/en.properties @@ -131,6 +131,7 @@ 112 = Cannot add an element to an inverted-index search result. 113 = Undefined inverted-list merge type: %1$s 114 = Node (%1$s) is not active +115 = Cannot compare non-primitive values 10000 = The given rule collection %1$s is not an instance of the List class. 10001 = Cannot compose partition constraint %1$s with %2$s -- To view, visit https://asterix-gerrit.ics.uci.edu/2714 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: merged Gerrit-Change-Id: I4604d347a22f98071a68abee43693fca9096b361 Gerrit-PatchSet: 5 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Ali Alsuliman <ali.al.solai...@gmail.com> Gerrit-Reviewer: Ali Alsuliman <ali.al.solai...@gmail.com> Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Dmitry Lychagin <dmitry.lycha...@couchbase.com> Gerrit-Reviewer: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Gerrit-Reviewer: Michael Blow <mb...@apache.org> Gerrit-Reviewer: Murtadha Hubail <mhub...@apache.org> Gerrit-Reviewer: Till Westmann <ti...@apache.org> Gerrit-Reviewer: abdullah alamoudi <bamou...@gmail.com>