This is an automated email from the ASF dual-hosted git repository. htowaileb pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/asterixdb.git
commit 0e3e90a8a697d2c209e430ab817c5369e288ff3f Author: Ali Alsuliman <[email protected]> AuthorDate: Wed Jun 29 01:27:27 2022 +0300 [ASTERIXDB-3044][FUN] object_concat(), issue a warning on duplicate field - user model changes: no - storage format changes: no - interface changes: no When concatenating the fields of the input objects, issue a warning when encountering a duplicate field. Change-Id: I3acb6cfdaf7190c62fe9c2f50f6f6c9367cfcb32 Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/16743 Reviewed-by: Ali Alsuliman <[email protected]> Reviewed-by: Wail Alkowaileet <[email protected]> Integration-Tests: Jenkins <[email protected]> Tested-by: Ali Alsuliman <[email protected]> --- .../queries_sqlpp/objects/ObjectsQueries.xml | 3 ++- .../object_concat/object_concat.4.query.sqlpp | 28 ++++++++++++++++++++++ .../objects/object_concat/object_concat.4.adm | 1 + .../functions/records/RecordConcatEvalFactory.java | 18 ++++++++++++-- 4 files changed, 47 insertions(+), 3 deletions(-) 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 bf48a7b007..2400affb79 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 @@ -120,9 +120,10 @@ <expected-error>ASX1001: Syntax error: Cannot infer field name</expected-error> </compilation-unit> </test-case> - <test-case FilePath="objects"> + <test-case FilePath="objects" check-warnings="true"> <compilation-unit name="object_concat"> <output-dir compare="Text">object_concat</output-dir> + <expected-warn>ASX0013: Duplicate field name 'v'</expected-warn> </compilation-unit> </test-case> <test-case FilePath="objects"> diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_concat/object_concat.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_concat/object_concat.4.query.sqlpp new file mode 100644 index 0000000000..ba22920b40 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_concat/object_concat.4.query.sqlpp @@ -0,0 +1,28 @@ +/* + * 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. + */ + +// test that object_concat() issues a warning when encountering a duplicate field + +// requesttype=application/json +// param max-warnings:json=10 +WITH t AS ( +SELECT v AS v +FROM [{"id": 1, "f": 3}, {"id": 2, "f": 3}] AS v +) +SELECT OBJECT_CONCAT(t); \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_concat/object_concat.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_concat/object_concat.4.adm new file mode 100644 index 0000000000..ad527c35da --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_concat/object_concat.4.adm @@ -0,0 +1 @@ +{ "$1": { "v": { "id": 2, "f": 3 } } } \ No newline at end of file diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordConcatEvalFactory.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordConcatEvalFactory.java index bc1cacc8f6..890bb13570 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordConcatEvalFactory.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordConcatEvalFactory.java @@ -25,6 +25,7 @@ import java.util.BitSet; import java.util.List; import org.apache.asterix.builders.RecordBuilder; +import org.apache.asterix.common.exceptions.ErrorCode; import org.apache.asterix.om.functions.BuiltinFunctions; import org.apache.asterix.om.pointables.ARecordVisitablePointable; import org.apache.asterix.om.pointables.base.DefaultOpenFieldType; @@ -41,12 +42,16 @@ import org.apache.hyracks.algebricks.runtime.base.IEvaluatorContext; import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator; import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory; import org.apache.hyracks.api.exceptions.HyracksDataException; +import org.apache.hyracks.api.exceptions.IWarningCollector; import org.apache.hyracks.api.exceptions.SourceLocation; +import org.apache.hyracks.api.exceptions.Warning; 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.data.std.util.BinaryEntry; import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference; +import org.apache.hyracks.util.LogRedactionUtil; +import org.apache.hyracks.util.string.UTF8StringUtil; class RecordConcatEvalFactory implements IScalarEvaluatorFactory { @@ -77,7 +82,7 @@ class RecordConcatEvalFactory implements IScalarEvaluatorFactory { for (int i = 0; i < args.length; i++) { argEvals[i] = args[i].createScalarEvaluator(ctx); } - return new RecordConcatEvaluator(argEvals); + return new RecordConcatEvaluator(argEvals, ctx.getWarningCollector()); } private final class RecordConcatEvaluator implements IScalarEvaluator { @@ -109,10 +114,13 @@ class RecordConcatEvalFactory implements IScalarEvaluatorFactory { private final BinaryEntry keyEntry; private final BinaryEntry valEntry; + private final IWarningCollector warningCollector; + private int numRecords; - private RecordConcatEvaluator(IScalarEvaluator[] argEvals) { + private RecordConcatEvaluator(IScalarEvaluator[] argEvals, IWarningCollector warningCollector) { this.argEvals = argEvals; + this.warningCollector = warningCollector; firstArg = new VoidPointable(); openRecordPointable = new ARecordVisitablePointable(DefaultOpenFieldType.NESTED_OPEN_RECORD_TYPE); @@ -309,6 +317,12 @@ class RecordConcatEvalFactory implements IScalarEvaluatorFactory { if (canAppendField(fieldName.getByteArray(), fieldName.getStartOffset() + 1, fieldName.getLength() - 1)) { outRecordBuilder.addField(fieldName, fieldValues.get(i)); + } else { + if (warningCollector.shouldWarn()) { + warningCollector.warn(Warning.of(sourceLoc, ErrorCode.DUPLICATE_FIELD_NAME, + LogRedactionUtil.userData(UTF8StringUtil.toString(fieldName.getByteArray(), + fieldName.getStartOffset() + 1)))); + } } } }
