>From Michael Blow <[email protected]>: Michael Blow has submitted this change. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/22015?usp=email )
Change subject: [NO ISSUE][RT] Locate duplicate field errors and test the field named ...................................................................... [NO ISSUE][RT] Locate duplicate field errors and test the field named - user model changes: no - storage format changes: no - interface changes: no Details: object_merge() and object_add_fields() raised DUPLICATE_FIELD_NAME without a source location, so the error did not say where in the statement the conflict arose, unlike the other duplicate field errors. Pass the function's source location. Add object_merge_duplicate_fields, which pins the field name and location for a top-level conflict, a conflict inside a nested object, and object_add_fields(), using multi-character names so a wrong offset would show; and checks that equal values for a shared field still merge. Ext-ref: MB-74440 Generated-by: Claude Opus 5.5 <[email protected]> Change-Id: I0cfd0d9173c969cefa6f9d4adc7b1c63261e1e34 Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/22015 Tested-by: Michael Blow <[email protected]> Reviewed-by: Murtadha Hubail <[email protected]> --- 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_merge_duplicate_fields/object_merge_duplicate_fields.01.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_merge_duplicate_fields/object_merge_duplicate_fields.02.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_merge_duplicate_fields/object_merge_duplicate_fields.03.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_merge_duplicate_fields/object_merge_duplicate_fields.04.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_merge_duplicate_fields/object_merge_duplicate_fields.04.adm M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordAddFieldsDescriptor.java M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeEvaluator.java 8 files changed, 95 insertions(+), 2 deletions(-) Approvals: Murtadha Hubail: Looks good to me, approved Michael Blow: Verified 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 4eea44f..fcb3ca9 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 @@ -279,6 +279,14 @@ </compilation-unit> </test-case> <test-case FilePath="objects"> + <compilation-unit name="object_merge_duplicate_fields"> + <output-dir compare="Text">object_merge_duplicate_fields</output-dir> + <expected-error>ASX0013: Duplicate field name 'price' (in line 21, at column 1)</expected-error> + <expected-error>ASX0013: Duplicate field name 'city' (in line 21, at column 1)</expected-error> + <expected-error>ASX0013: Duplicate field name 'price' (in line 21, at column 1)</expected-error> + </compilation-unit> + </test-case> + <test-case FilePath="objects"> <compilation-unit name="load-record-fields"> <output-dir compare="Text">load-record-fields</output-dir> </compilation-unit> diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_merge_duplicate_fields/object_merge_duplicate_fields.01.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_merge_duplicate_fields/object_merge_duplicate_fields.01.query.sqlpp new file mode 100644 index 0000000..fab3877 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_merge_duplicate_fields/object_merge_duplicate_fields.01.query.sqlpp @@ -0,0 +1,21 @@ +/* + * 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. + */ + +-- Conflicting values for one field: the error names that field +object_merge({"id": 1, "price": 10}, {"id": 1, "price": 12}); diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_merge_duplicate_fields/object_merge_duplicate_fields.02.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_merge_duplicate_fields/object_merge_duplicate_fields.02.query.sqlpp new file mode 100644 index 0000000..7b1ba47 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_merge_duplicate_fields/object_merge_duplicate_fields.02.query.sqlpp @@ -0,0 +1,21 @@ +/* + * 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. + */ + +-- The conflict is inside a nested object: the error names the nested field +object_merge({"id": 1, "address": {"city": "Irvine"}}, {"id": 1, "address": {"city": "Austin"}}); diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_merge_duplicate_fields/object_merge_duplicate_fields.03.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_merge_duplicate_fields/object_merge_duplicate_fields.03.query.sqlpp new file mode 100644 index 0000000..edafbe6 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_merge_duplicate_fields/object_merge_duplicate_fields.03.query.sqlpp @@ -0,0 +1,21 @@ +/* + * 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. + */ + +-- Conflicting values for one field: the error names that field +object_add_fields({"id": 1, "price": 10}, [{"field-name": "price", "field-value": 12}]); diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_merge_duplicate_fields/object_merge_duplicate_fields.04.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_merge_duplicate_fields/object_merge_duplicate_fields.04.query.sqlpp new file mode 100644 index 0000000..d0a5398 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_merge_duplicate_fields/object_merge_duplicate_fields.04.query.sqlpp @@ -0,0 +1,21 @@ +/* + * 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. + */ + +-- Equal values for a shared field are not a conflict +object_merge({"id": 1, "price": 10}, {"id": 1, "qty": 3}); diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_merge_duplicate_fields/object_merge_duplicate_fields.04.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_merge_duplicate_fields/object_merge_duplicate_fields.04.adm new file mode 100644 index 0000000..a6deea2 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_merge_duplicate_fields/object_merge_duplicate_fields.04.adm @@ -0,0 +1 @@ +{ "id": 1, "price": 10, "qty": 3 } diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordAddFieldsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordAddFieldsDescriptor.java index 196d910..5c616bc 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordAddFieldsDescriptor.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordAddFieldsDescriptor.java @@ -253,7 +253,7 @@ tempValReference.set(entry.getBuf(), entry.getOffset(), entry.getLength()); // If value is not equal throw conflicting duplicate field, otherwise ignore if (!PointableHelper.byteArrayEqual(valuePointable, tempValReference)) { - throw new RuntimeDataException(ErrorCode.DUPLICATE_FIELD_NAME, + throw new RuntimeDataException(ErrorCode.DUPLICATE_FIELD_NAME, sourceLoc, LogRedactionUtil .userData(UTF8StringUtil.toString(namePointable.getByteArray(), namePointable.getStartOffset() + 1))); diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeEvaluator.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeEvaluator.java index 7b9f492..b5d8f10 100644 --- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeEvaluator.java +++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeEvaluator.java @@ -194,7 +194,7 @@ else { // Ignore and take left field if ignore duplicate flag is true, otherwise, throw an exception if (!isIgnoreDuplicates) { - throw new RuntimeDataException(ErrorCode.DUPLICATE_FIELD_NAME, + throw new RuntimeDataException(ErrorCode.DUPLICATE_FIELD_NAME, srcLoc, LogRedactionUtil.userData(UTF8StringUtil.toString(leftName.getByteArray(), leftName.getStartOffset() + 1))); } -- To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/22015?usp=email To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: asterixdb Gerrit-Branch: helios Gerrit-Change-Id: I0cfd0d9173c969cefa6f9d4adc7b1c63261e1e34 Gerrit-Change-Number: 22015 Gerrit-PatchSet: 3 Gerrit-Owner: Michael Blow <[email protected]> Gerrit-Reviewer: Hussain Altowileb <[email protected]> Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Michael Blow <[email protected]> Gerrit-Reviewer: Murtadha Hubail <[email protected]> Gerrit-CC: Anon. E. Moose #1000171
