You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by mb...@apache.org on 2026/10/08 22:05:12 UTC
(asterixdb) 09/13: [NO ISSUE][RT] Locate duplicate field errors and test the field named
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git
commit ee47025379c36222e3e7749c8adcaee4973eadca
Author: Michael Blow <mi...@couchbase.com>
AuthorDate: Wed Oct 7 18:08:57 2026 -0400
[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 <no...@anthropic.com>
Change-Id: I0cfd0d9173c969cefa6f9d4adc7b1c63261e1e34
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/22015
Tested-by: Michael Blow <mb...@apache.org>
Reviewed-by: Murtadha Hubail <mh...@apache.org>
---
.../queries_sqlpp/objects/ObjectsQueries.xml | 8 ++++++++
.../object_merge_duplicate_fields.01.query.sqlpp | 21 +++++++++++++++++++++
.../object_merge_duplicate_fields.02.query.sqlpp | 21 +++++++++++++++++++++
.../object_merge_duplicate_fields.03.query.sqlpp | 21 +++++++++++++++++++++
.../object_merge_duplicate_fields.04.query.sqlpp | 21 +++++++++++++++++++++
.../object_merge_duplicate_fields.04.adm | 1 +
.../records/RecordAddFieldsDescriptor.java | 2 +-
.../functions/records/RecordMergeEvaluator.java | 2 +-
8 files changed, 95 insertions(+), 2 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 4eea44f7be..fcb3ca9cec 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
@@ -278,6 +278,14 @@
<expected-warn>Duplicate field name 'fname1' (in line 25, at column 45)</expected-warn>
</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>
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 0000000000..fab387715c
--- /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 0000000000..7b1ba4774a
--- /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 0000000000..edafbe6328
--- /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 0000000000..d0a5398f51
--- /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 0000000000..a6deea291b
--- /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 196d910f4a..5c616bca5e 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 @@ public class RecordAddFieldsDescriptor extends AbstractScalarFunctionDynamicDesc
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 7b9f49285e..b5d8f1077d 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 @@ public class RecordMergeEvaluator extends AbstractScalarEval {
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)));
}