Murtadha Hubail has uploaded a new change for review.
https://asterix-gerrit.ics.uci.edu/2693
Change subject: [NO ISSUE][FUN] Implement object-remove()
......................................................................
[NO ISSUE][FUN] Implement object-remove()
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- Implement object-remove function that removes a field from
a given object.
- Add object-remove-restrict version that throws exception
if the function arguments aren't the expected types.
- Add new function to docs.
- Add test case.
Change-Id: I8d4acfa0ef00ccdcb95e189b989a16f06acf0119
---
M
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/ObjectsQueries.xml
A
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_remove/object_remove.1.ddl.sqlpp
A
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_remove/object_remove.2.update.sqlpp
A
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_remove/object_remove.3.query.sqlpp
A
asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_remove/object_remove.3.adm
M asterixdb/asterix-doc/src/main/markdown/builtins/8_record.md
M
asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
A
asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveDescriptor.java
A
asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveEvalFactory.java
A
asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveStrictDescriptor.java
M
asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
M
hyracks-fullstack/hyracks/hyracks-data/hyracks-data-std/src/main/java/org/apache/hyracks/data/std/primitive/UTF8StringPointable.java
12 files changed, 526 insertions(+), 1 deletion(-)
git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb
refs/changes/93/2693/1
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/ObjectsQueries.xml
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/ObjectsQueries.xml
index cb83d4b..54eb49d 100644
---
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/ObjectsQueries.xml
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/ObjectsQueries.xml
@@ -118,6 +118,11 @@
</compilation-unit>
</test-case>
<test-case FilePath="objects">
+ <compilation-unit name="object_remove">
+ <output-dir compare="Text">object_remove</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="objects">
<compilation-unit name="object_pairs">
<output-dir compare="Text">object_pairs</output-dir>
</compilation-unit>
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_remove/object_remove.1.ddl.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_remove/object_remove.1.ddl.sqlpp
new file mode 100644
index 0000000..b3dafba
--- /dev/null
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_remove/object_remove.1.ddl.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 object_remove under different queries.
+ * Expected Res : Success
+ */
+
+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
+};
+
+create type TinySocial.TweetMessageType as closed {
+ tweetid : string,
+ user : TwitterUserType,
+ `sender-location` : point?,
+ `send-time` : datetime,
+ `referred-topics` : {{string}},
+ `message-text` : string
+};
+
+create dataset TwitterUsers(TwitterUserType) primary key `screen-name`;
+
+create dataset TweetMessages(TweetMessageType) primary key tweetid;
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_remove/object_remove.2.update.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_remove/object_remove.2.update.sqlpp
new file mode 100644
index 0000000..2d03f92
--- /dev/null
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_remove/object_remove.2.update.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.
+ */
+
+/*
+ * Description : Testing object_remove under different queries.
+ * Expected Res : Success
+ */
+
+use TinySocial;
+
+load dataset TwitterUsers using localfs
((`path`=`asterix_nc1://data/tinysocial/twu.adm`),(`format`=`adm`));
+
+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/objects/object_remove/object_remove.3.query.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_remove/object_remove.3.query.sqlpp
new file mode 100644
index 0000000..387b45b
--- /dev/null
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_remove/object_remove.3.query.sqlpp
@@ -0,0 +1,57 @@
+/*
+ * 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 object_remove under different queries.
+ * Expected Res : Success
+ */
+
+use TinySocial;
+
+{
+ "t1": [
+ object_remove(missing, missing) is missing,
+ object_remove(null, missing) is missing,
+ object_remove("{}", missing) is missing,
+ object_remove("{}", null) is null
+ ],
+ "t2": object_remove({"a":1, "b":2}, "a"),
+ "t3": object_remove({"a":1, "b":2}, "b"),
+ "t4": object_remove({"a":1, "b":2}, "c"),
+
+ /* open type */
+ "t5": (
+ select value object_remove(o, "lang")
+ from (
+ select name, lang
+ from TwitterUsers as u
+ ) o
+ order by 1
+ ),
+
+ /* closed type */
+ "t6": (
+ select value object_remove(o, "user")
+ from (
+ select tweetid, user, `sender-location`
+ from TweetMessages as m
+ ) o
+ order by 1
+ )
+};
\ No newline at end of file
diff --git
a/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_remove/object_remove.3.adm
b/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_remove/object_remove.3.adm
new file mode 100644
index 0000000..135f2af
--- /dev/null
+++
b/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_remove/object_remove.3.adm
@@ -0,0 +1 @@
+{ "t1": [ true, true, true, true ], "t2": { "b": 2 }, "t3": { "a": 1 }, "t4":
{ "a": 1, "b": 2 }, "t5": [ { "name": "Chang Ewing" }, { "name": "Coline Geyer"
}, { "name": "Nathan Giesen" }, { "name": "Nila Milliron" } ], "t6": [ {
"tweetid": "11", "sender-location": point("37.59,68.42") }, { "tweetid": "2",
"sender-location": point("32.84,67.14") }, { "tweetid": "4", "sender-location":
point("39.28,70.48") }, { "tweetid": "9", "sender-location":
point("36.86,74.62") }, { "tweetid": "1", "sender-location":
point("47.44,80.65") }, { "tweetid": "5", "sender-location":
point("40.09,92.69") }, { "tweetid": "3", "sender-location":
point("29.72,75.8") }, { "tweetid": "6", "sender-location":
point("47.51,83.99") }, { "tweetid": "7", "sender-location":
point("36.21,72.6") }, { "tweetid": "10", "sender-location":
point("29.15,76.53") }, { "tweetid": "12", "sender-location":
point("24.82,94.63") }, { "tweetid": "8", "sender-location":
point("46.05,93.34") } ] }
\ No newline at end of file
diff --git a/asterixdb/asterix-doc/src/main/markdown/builtins/8_record.md
b/asterixdb/asterix-doc/src/main/markdown/builtins/8_record.md
index fefdb7b..91a95b5 100644
--- a/asterixdb/asterix-doc/src/main/markdown/builtins/8_record.md
+++ b/asterixdb/asterix-doc/src/main/markdown/builtins/8_record.md
@@ -287,3 +287,35 @@
[ "id", "project", "address" ]
+### object_remove ###
+ * Syntax:
+
+ object_remove(input_object, field_name)
+
+ * Returns A new object that has the same fields as the input object except
the field to be removed
+ * Arguments:
+ * `input_object` : an object value.
+ * `field_name` : a string field name.
+ * Return Value:
+ * A new object that has the same fields as `input_object` except the field
`field_name`,
+ * `missing` if the argument `field_name` is missing,
+ * `null` if the argument `field_name` is null or any other non-string
value,
+ * `null` if the argument `input_object` is `null` or any other non-object
value
+
+ * Example:
+
+ object_remove(
+ {
+ "id": 1,
+ "project": "AsterixDB",
+ "address": {"city": "Irvine", "state": "CA"}
+ }
+ , "address"
+ );
+
+ * The expected result is:
+
+ {
+ "id": "1",
+ "project": "AsterixDB",
+ }
\ No newline at end of file
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 c40d550..2737824 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
@@ -68,9 +68,9 @@
import org.apache.asterix.om.typecomputer.impl.FieldAccessNestedResultType;
import
org.apache.asterix.om.typecomputer.impl.FullTextContainsResultTypeComputer;
import
org.apache.asterix.om.typecomputer.impl.GetOverlappingInvervalTypeComputer;
-import org.apache.asterix.om.typecomputer.impl.IfNanOrInfTypeComputer;
import org.apache.asterix.om.typecomputer.impl.IfMissingOrNullTypeComputer;
import org.apache.asterix.om.typecomputer.impl.IfMissingTypeComputer;
+import org.apache.asterix.om.typecomputer.impl.IfNanOrInfTypeComputer;
import org.apache.asterix.om.typecomputer.impl.IfNullTypeComputer;
import org.apache.asterix.om.typecomputer.impl.InjectFailureTypeComputer;
import org.apache.asterix.om.typecomputer.impl.LocalAvgTypeComputer;
@@ -220,6 +220,10 @@
new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
"object-pairs", FunctionIdentifier.VARARGS);
public static final FunctionIdentifier GEOMETRY_CONSTRUCTOR =
new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
"st-geom-from-geojson", FunctionIdentifier.VARARGS);
+ public static final FunctionIdentifier RECORD_REMOVE =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
"object-remove", 2);
+ public static final FunctionIdentifier RECORD_REMOVE_STRICT =
+ new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
"object-remove-strict", 2);
// numeric
public static final FunctionIdentifier NUMERIC_UNARY_MINUS =
@@ -1460,6 +1464,8 @@
addFunction(RECORD_NAMES,
OrderedListOfAStringTypeComputer.INSTANCE_NULLABLE, true);
addFunction(RECORD_PAIRS, RecordPairsTypeComputer.INSTANCE, true);
addFunction(GEOMETRY_CONSTRUCTOR, AGeometryTypeComputer.INSTANCE,
true);
+ addFunction(RECORD_REMOVE, OpenARecordTypeComputer.INSTANCE, true);
+ addFunction(RECORD_REMOVE_STRICT, OpenARecordTypeComputer.INSTANCE,
true);
// temporal type accessors
addFunction(ACCESSOR_TEMPORAL_YEAR, AInt64TypeComputer.INSTANCE, true);
diff --git
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveDescriptor.java
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveDescriptor.java
new file mode 100644
index 0000000..9b53796
--- /dev/null
+++
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveDescriptor.java
@@ -0,0 +1,62 @@
+/*
+ * 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.records;
+
+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.ARecordType;
+import
org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import org.apache.asterix.runtime.functions.FunctionTypeInferers;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+
+public class RecordRemoveDescriptor extends
AbstractScalarFunctionDynamicDescriptor {
+
+ public static final IFunctionDescriptorFactory FACTORY = new
IFunctionDescriptorFactory() {
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new RecordRemoveDescriptor();
+ }
+
+ @Override
+ public IFunctionTypeInferer createFunctionTypeInferer() {
+ return FunctionTypeInferers.RecordAccessorTypeInferer.INSTANCE_LAX;
+ }
+ };
+
+ private static final long serialVersionUID = 1L;
+ private ARecordType recordType;
+
+ @Override
+ public void setImmutableStates(Object... states) {
+ recordType = (ARecordType) states[0];
+ }
+
+ @Override
+ public IScalarEvaluatorFactory createEvaluatorFactory(final
IScalarEvaluatorFactory[] args) {
+ return new RecordRemoveEvalFactory(args, recordType, false, sourceLoc);
+ }
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return BuiltinFunctions.RECORD_REMOVE;
+ }
+}
diff --git
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveEvalFactory.java
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveEvalFactory.java
new file mode 100644
index 0000000..f615fe2
--- /dev/null
+++
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveEvalFactory.java
@@ -0,0 +1,207 @@
+/*
+ * 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.records;
+
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.asterix.builders.RecordBuilder;
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.pointables.ARecordVisitablePointable;
+import org.apache.asterix.om.pointables.base.DefaultOpenFieldType;
+import org.apache.asterix.om.pointables.base.IVisitablePointable;
+import org.apache.asterix.om.pointables.cast.ACastVisitor;
+import org.apache.asterix.om.types.ARecordType;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.IAType;
+import org.apache.asterix.runtime.exceptions.TypeMismatchException;
+import org.apache.hyracks.algebricks.common.utils.Triple;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.exceptions.SourceLocation;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
+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;
+
+class RecordRemoveEvalFactory implements IScalarEvaluatorFactory {
+
+ private static final long serialVersionUID = 1L;
+ private static final int OBJECT_ARG_IDX = 0;
+ private static final int FIELD_NAME_ARG_IDX = 1;
+ private final IScalarEvaluatorFactory[] args;
+ private final ARecordType recType;
+ private final boolean failOnArgTypeMismatch;
+ private final SourceLocation sourceLoc;
+
+ RecordRemoveEvalFactory(IScalarEvaluatorFactory[] args, ARecordType
recType, boolean failOnArgTypeMismatch,
+ SourceLocation sourceLoc) {
+ this.args = args;
+ this.recType = recType;
+ this.failOnArgTypeMismatch = failOnArgTypeMismatch;
+ this.sourceLoc = sourceLoc;
+ }
+
+ @Override
+ public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx)
throws HyracksDataException {
+ final IScalarEvaluator[] argEvals = new IScalarEvaluator[args.length];
+ for (int i = 0; i < args.length; i++) {
+ argEvals[i] = args[i].createScalarEvaluator(ctx);
+ }
+ return new RecordRemoveEvaluator(argEvals);
+ }
+
+ private final class RecordRemoveEvaluator implements IScalarEvaluator {
+
+ private final IScalarEvaluator[] argsEvals;
+ private final IPointable[] argsPointables;
+ private ARecordVisitablePointable recordVisitablePointable;
+ private final ArrayBackedValueStorage resultStorage;
+ private final DataOutput resultOutput;
+
+ private RecordRemoveEvaluator(IScalarEvaluator[] argEvals) {
+ this.argsEvals = argEvals;
+ argsPointables = new IPointable[args.length];
+ resultStorage = new ArrayBackedValueStorage();
+ resultOutput = resultStorage.getDataOutput();
+ }
+
+ @Override
+ public void evaluate(IFrameTupleReference tuple, IPointable result)
throws HyracksDataException {
+ resultStorage.reset();
+ if (hasStringFieldToRemoveArg(tuple) && hasValidObjectArg(tuple)) {
+ evaluate();
+ }
+ result.set(resultStorage);
+ }
+
+ private boolean hasStringFieldToRemoveArg(IFrameTupleReference tuple)
throws HyracksDataException {
+ final IPointable pointable = new VoidPointable();
+ argsPointables[FIELD_NAME_ARG_IDX] = pointable;
+ argsEvals[FIELD_NAME_ARG_IDX].evaluate(tuple, pointable);
+ final byte[] data = pointable.getByteArray();
+ final int offset = pointable.getStartOffset();
+ final byte typeTag = data[offset];
+ if (typeTag == ATypeTag.SERIALIZED_MISSING_TYPE_TAG) {
+ writeTypeTag(ATypeTag.SERIALIZED_MISSING_TYPE_TAG);
+ return false;
+ } else if (typeTag != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+ if (failOnArgTypeMismatch) {
+ throw new TypeMismatchException(sourceLoc,
BuiltinFunctions.RECORD_REMOVE, 2, typeTag,
+ ATypeTag.SERIALIZED_STRING_TYPE_TAG);
+ }
+ writeTypeTag(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
+ return false;
+ }
+ return true;
+ }
+
+ private boolean hasValidObjectArg(IFrameTupleReference tuple) throws
HyracksDataException {
+ final IPointable pointable = new VoidPointable();
+ argsPointables[OBJECT_ARG_IDX] = pointable;
+ argsEvals[OBJECT_ARG_IDX].evaluate(tuple, pointable);
+ final byte[] data = pointable.getByteArray();
+ final int offset = pointable.getStartOffset();
+ final byte typeTag = data[offset];
+ if (typeTag != ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
+ if (failOnArgTypeMismatch) {
+ throw new TypeMismatchException(sourceLoc,
BuiltinFunctions.RECORD_REMOVE, 1, typeTag,
+ ATypeTag.SERIALIZED_RECORD_TYPE_TAG);
+ }
+ writeTypeTag(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
+ return false;
+ }
+ return true;
+ }
+
+ private void evaluate() throws HyracksDataException {
+ resultStorage.reset();
+ try {
+ final String fieldToRemove = getFieldToRemove();
+ final ARecordVisitablePointable inputRecord =
getInputRecordVisitablePointable();
+ buildOutputRecord(inputRecord, fieldToRemove);
+ } catch (IOException e) {
+ throw HyracksDataException.create(e);
+ }
+ }
+
+ private String getFieldToRemove() {
+ return
UTF8StringPointable.ofAStringPointable(argsPointables[FIELD_NAME_ARG_IDX]).toString();
+ }
+
+ private void buildOutputRecord(ARecordVisitablePointable inputRecord,
String fieldToRemove)
+ throws HyracksDataException {
+ final RecordBuilder outRecordBuilder = new RecordBuilder();
+
outRecordBuilder.reset(DefaultOpenFieldType.NESTED_OPEN_RECORD_TYPE);
+ outRecordBuilder.init();
+ final List<IVisitablePointable> fieldNames =
inputRecord.getFieldNames();
+ final List<IVisitablePointable> fieldValues =
inputRecord.getFieldValues();
+ final UTF8StringPointable utf8StringPointable = new
UTF8StringPointable();
+ for (int i = 0, fieldCount = fieldNames.size(); i < fieldCount;
i++) {
+ final IVisitablePointable fieldName = fieldNames.get(i);
+ UTF8StringPointable.setAStringPointable(utf8StringPointable,
fieldName);
+ if (!utf8StringPointable.toString().equals(fieldToRemove)) {
+ outRecordBuilder.addField(fieldName, fieldValues.get(i));
+ }
+ }
+ outRecordBuilder.write(resultOutput, true);
+ }
+
+ private ARecordVisitablePointable getInputRecordVisitablePointable()
throws HyracksDataException {
+ recordVisitablePointable = new ARecordVisitablePointable(recType);
+ recordVisitablePointable.set(argsPointables[OBJECT_ARG_IDX]);
+ if (hasDerivedType(recType.getFieldTypes())) {
+ return castToOpenRecord();
+ }
+ return recordVisitablePointable;
+ }
+
+ private boolean hasDerivedType(IAType[] types) {
+ for (IAType type : types) {
+ if (type.getTypeTag().isDerivedType()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private ARecordVisitablePointable castToOpenRecord() throws
HyracksDataException {
+ final ARecordVisitablePointable openRecordPointable =
+ new
ARecordVisitablePointable(DefaultOpenFieldType.NESTED_OPEN_RECORD_TYPE);
+ final ACastVisitor castVisitor = new ACastVisitor();
+ final Triple<IVisitablePointable, IAType, Boolean> castVisitorArg =
+ new Triple<>(openRecordPointable,
openRecordPointable.getInputRecordType(), Boolean.FALSE);
+ recordVisitablePointable.accept(castVisitor, castVisitorArg);
+ return openRecordPointable;
+ }
+
+ private void writeTypeTag(byte typeTag) throws HyracksDataException {
+ try {
+ resultOutput.writeByte(typeTag);
+ } catch (IOException e) {
+ throw HyracksDataException.create(e);
+ }
+ }
+ }
+}
diff --git
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveStrictDescriptor.java
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveStrictDescriptor.java
new file mode 100644
index 0000000..ae1cf2e
--- /dev/null
+++
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveStrictDescriptor.java
@@ -0,0 +1,62 @@
+/*
+ * 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.records;
+
+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.ARecordType;
+import
org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import org.apache.asterix.runtime.functions.FunctionTypeInferers;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+
+public class RecordRemoveStrictDescriptor extends
AbstractScalarFunctionDynamicDescriptor {
+
+ public static final IFunctionDescriptorFactory FACTORY = new
IFunctionDescriptorFactory() {
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new RecordRemoveStrictDescriptor();
+ }
+
+ @Override
+ public IFunctionTypeInferer createFunctionTypeInferer() {
+ return FunctionTypeInferers.RecordAccessorTypeInferer.INSTANCE_LAX;
+ }
+ };
+
+ private static final long serialVersionUID = 1L;
+ private ARecordType recordType;
+
+ @Override
+ public void setImmutableStates(Object... states) {
+ recordType = (ARecordType) states[0];
+ }
+
+ @Override
+ public IScalarEvaluatorFactory createEvaluatorFactory(final
IScalarEvaluatorFactory[] args) {
+ return new RecordRemoveEvalFactory(args, recordType, true, sourceLoc);
+ }
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return BuiltinFunctions.RECORD_REMOVE_STRICT;
+ }
+}
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 9fecf34..dfe8ad1 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
@@ -281,7 +281,9 @@
import
org.apache.asterix.runtime.evaluators.functions.records.RecordMergeDescriptor;
import
org.apache.asterix.runtime.evaluators.functions.records.RecordNamesDescriptor;
import
org.apache.asterix.runtime.evaluators.functions.records.RecordPairsDescriptor;
+import
org.apache.asterix.runtime.evaluators.functions.records.RecordRemoveDescriptor;
import
org.apache.asterix.runtime.evaluators.functions.records.RecordRemoveFieldsDescriptor;
+import
org.apache.asterix.runtime.evaluators.functions.records.RecordRemoveStrictDescriptor;
import
org.apache.asterix.runtime.evaluators.functions.temporal.AdjustDateTimeForTimeZoneDescriptor;
import
org.apache.asterix.runtime.evaluators.functions.temporal.AdjustTimeForTimeZoneDescriptor;
import
org.apache.asterix.runtime.evaluators.functions.temporal.CalendarDuartionFromDateDescriptor;
@@ -644,6 +646,8 @@
fc.addGenerated(RecordRemoveFieldsDescriptor.FACTORY);
fc.addGenerated(RecordLengthDescriptor.FACTORY);
fc.addGenerated(RecordNamesDescriptor.FACTORY);
+ fc.add(RecordRemoveDescriptor.FACTORY);
+ fc.add(RecordRemoveStrictDescriptor.FACTORY);
// Spatial and temporal type accessors
fc.addGenerated(TemporalYearAccessor.FACTORY);
diff --git
a/hyracks-fullstack/hyracks/hyracks-data/hyracks-data-std/src/main/java/org/apache/hyracks/data/std/primitive/UTF8StringPointable.java
b/hyracks-fullstack/hyracks/hyracks-data/hyracks-data-std/src/main/java/org/apache/hyracks/data/std/primitive/UTF8StringPointable.java
index 376307d..4e97782 100644
---
a/hyracks-fullstack/hyracks/hyracks-data/hyracks-data-std/src/main/java/org/apache/hyracks/data/std/primitive/UTF8StringPointable.java
+++
b/hyracks-fullstack/hyracks/hyracks-data/hyracks-data-std/src/main/java/org/apache/hyracks/data/std/primitive/UTF8StringPointable.java
@@ -652,4 +652,15 @@
return true;
}
+
+ public static UTF8StringPointable ofAStringPointable(IPointable
aStringPointable) {
+ final UTF8StringPointable pointable = new UTF8StringPointable();
+ setAStringPointable(pointable, aStringPointable);
+ return pointable;
+ }
+
+ public static void setAStringPointable(UTF8StringPointable
utf8StringPointable, IPointable aStringPointable) {
+ utf8StringPointable.set(aStringPointable.getByteArray(),
aStringPointable.getStartOffset() + 1,
+ aStringPointable.getLength() - 1);
+ }
}
--
To view, visit https://asterix-gerrit.ics.uci.edu/2693
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8d4acfa0ef00ccdcb95e189b989a16f06acf0119
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Murtadha Hubail <[email protected]>