You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@asterixdb.apache.org by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu> on 2022/06/28 22:30:40 UTC

Change in asterixdb[neo]: [ASTERIXDB-3044][FUN] object_concat(), issue a warning on duplicate f...

From Ali Alsuliman <al...@gmail.com>:

Ali Alsuliman has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/16743 )


Change subject: [ASTERIXDB-3044][FUN] object_concat(), issue a warning on duplicate field
......................................................................

[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
---
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_concat/object_concat.4.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_concat/object_concat.4.adm
M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordConcatEvalFactory.java
4 files changed, 47 insertions(+), 3 deletions(-)



  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/43/16743/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 bf48a7b..2400aff 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 0000000..ba22920
--- /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 0000000..ad527c3
--- /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 bc1cacc..890bb13 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.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.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 @@
         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 @@
         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 @@
                 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))));
+                    }
                 }
             }
         }

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/16743
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: neo
Gerrit-Change-Id: I3acb6cfdaf7190c62fe9c2f50f6f6c9367cfcb32
Gerrit-Change-Number: 16743
Gerrit-PatchSet: 1
Gerrit-Owner: Ali Alsuliman <al...@gmail.com>
Gerrit-MessageType: newchange

Change in asterixdb[neo]: [ASTERIXDB-3044][FUN] object_concat(), issue a warning on duplicate f...

Posted by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu>.
From Ali Alsuliman <al...@gmail.com>:

Ali Alsuliman has posted comments on this change. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/16743 )

Change subject: [ASTERIXDB-3044][FUN] object_concat(), issue a warning on duplicate field
......................................................................


Patch Set 1: Verified+1


-- 
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/16743
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: neo
Gerrit-Change-Id: I3acb6cfdaf7190c62fe9c2f50f6f6c9367cfcb32
Gerrit-Change-Number: 16743
Gerrit-PatchSet: 1
Gerrit-Owner: Ali Alsuliman <al...@gmail.com>
Gerrit-Reviewer: Ali Alsuliman <al...@gmail.com>
Gerrit-Reviewer: Jenkins <je...@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Murtadha Hubail <mh...@apache.org>
Gerrit-Reviewer: Wail Alkowaileet <wa...@gmail.com>
Gerrit-CC: Anon. E. Moose #1000171
Gerrit-Comment-Date: Thu, 30 Jun 2022 16:22:46 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

Change in asterixdb[neo]: [ASTERIXDB-3044][FUN] object_concat(), issue a warning on duplicate f...

Posted by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu>.
From Ali Alsuliman <al...@gmail.com>:

Ali Alsuliman has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/16743 )


Change subject: [ASTERIXDB-3044][FUN] object_concat(), issue a warning on duplicate field
......................................................................

[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
---
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_concat/object_concat.4.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_concat/object_concat.4.adm
M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordConcatEvalFactory.java
4 files changed, 47 insertions(+), 3 deletions(-)



  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/43/16743/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 bf48a7b..2400aff 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 0000000..ba22920
--- /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 0000000..ad527c3
--- /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 bc1cacc..890bb13 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.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.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 @@
         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 @@
         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 @@
                 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))));
+                    }
                 }
             }
         }

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/16743
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: neo
Gerrit-Change-Id: I3acb6cfdaf7190c62fe9c2f50f6f6c9367cfcb32
Gerrit-Change-Number: 16743
Gerrit-PatchSet: 1
Gerrit-Owner: Ali Alsuliman <al...@gmail.com>
Gerrit-MessageType: newchange

Change in asterixdb[neo]: [ASTERIXDB-3044][FUN] object_concat(), issue a warning on duplicate f...

Posted by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu>.
From Jenkins <je...@fulliautomatix.ics.uci.edu>:

Jenkins has posted comments on this change. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/16743 )

Change subject: [ASTERIXDB-3044][FUN] object_concat(), issue a warning on duplicate field
......................................................................


Patch Set 1: Integration-Tests+1

Integration Tests Successful

https://asterix-jenkins.ics.uci.edu/job/asterix-gerrit-integration-tests/13238/ : SUCCESS


-- 
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/16743
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: neo
Gerrit-Change-Id: I3acb6cfdaf7190c62fe9c2f50f6f6c9367cfcb32
Gerrit-Change-Number: 16743
Gerrit-PatchSet: 1
Gerrit-Owner: Ali Alsuliman <al...@gmail.com>
Gerrit-Reviewer: Ali Alsuliman <al...@gmail.com>
Gerrit-Reviewer: Jenkins <je...@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Murtadha Hubail <mh...@apache.org>
Gerrit-Reviewer: Wail Alkowaileet <wa...@gmail.com>
Gerrit-CC: Anon. E. Moose #1000171
Gerrit-Comment-Date: Tue, 28 Jun 2022 23:34:46 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

Change in asterixdb[neo]: [ASTERIXDB-3044][FUN] object_concat(), issue a warning on duplicate f...

Posted by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu>.
From Wail Alkowaileet <wa...@gmail.com>:

Wail Alkowaileet has posted comments on this change. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/16743 )

Change subject: [ASTERIXDB-3044][FUN] object_concat(), issue a warning on duplicate field
......................................................................


Patch Set 1: Code-Review+2


-- 
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/16743
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: neo
Gerrit-Change-Id: I3acb6cfdaf7190c62fe9c2f50f6f6c9367cfcb32
Gerrit-Change-Number: 16743
Gerrit-PatchSet: 1
Gerrit-Owner: Ali Alsuliman <al...@gmail.com>
Gerrit-Reviewer: Ali Alsuliman <al...@gmail.com>
Gerrit-Reviewer: Murtadha Hubail <mh...@apache.org>
Gerrit-Reviewer: Wail Alkowaileet <wa...@gmail.com>
Gerrit-CC: Anon. E. Moose #1000171
Gerrit-CC: Jenkins <je...@fulliautomatix.ics.uci.edu>
Gerrit-Comment-Date: Tue, 28 Jun 2022 23:24:29 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

Change in asterixdb[neo]: [ASTERIXDB-3044][FUN] object_concat(), issue a warning on duplicate f...

Posted by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu>.
Anon. E. Moose #1000171 has posted comments on this change. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/16743 )

Change subject: [ASTERIXDB-3044][FUN] object_concat(), issue a warning on duplicate field
......................................................................


Patch Set 1:

Analytics Compatibility Compilation Successful
https://cbjenkins.page.link/Bdqe3EJUVuEmbLtu7 : SUCCESS


-- 
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/16743
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: neo
Gerrit-Change-Id: I3acb6cfdaf7190c62fe9c2f50f6f6c9367cfcb32
Gerrit-Change-Number: 16743
Gerrit-PatchSet: 1
Gerrit-Owner: Ali Alsuliman <al...@gmail.com>
Gerrit-Reviewer: Ali Alsuliman <al...@gmail.com>
Gerrit-Reviewer: Murtadha Hubail <mh...@apache.org>
Gerrit-Reviewer: Wail Alkowaileet <wa...@gmail.com>
Gerrit-CC: Anon. E. Moose #1000171
Gerrit-CC: Jenkins <je...@fulliautomatix.ics.uci.edu>
Gerrit-Comment-Date: Tue, 28 Jun 2022 22:41:39 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

Change in asterixdb[neo]: [ASTERIXDB-3044][FUN] object_concat(), issue a warning on duplicate f...

Posted by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu>.
From Ali Alsuliman <al...@gmail.com>:

Ali Alsuliman has posted comments on this change. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/16743 )

Change subject: [ASTERIXDB-3044][FUN] object_concat(), issue a warning on duplicate field
......................................................................


Patch Set 1: Code-Review+1


-- 
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/16743
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: neo
Gerrit-Change-Id: I3acb6cfdaf7190c62fe9c2f50f6f6c9367cfcb32
Gerrit-Change-Number: 16743
Gerrit-PatchSet: 1
Gerrit-Owner: Ali Alsuliman <al...@gmail.com>
Gerrit-Reviewer: Ali Alsuliman <al...@gmail.com>
Gerrit-Reviewer: Murtadha Hubail <mh...@apache.org>
Gerrit-Reviewer: Wail Alkowaileet <wa...@gmail.com>
Gerrit-CC: Jenkins <je...@fulliautomatix.ics.uci.edu>
Gerrit-Comment-Date: Tue, 28 Jun 2022 22:33:36 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

Change in asterixdb[neo]: [ASTERIXDB-3044][FUN] object_concat(), issue a warning on duplicate f...

Posted by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu>.
From Ali Alsuliman <al...@gmail.com>:

Ali Alsuliman has submitted this change. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/16743 )

Change subject: [ASTERIXDB-3044][FUN] object_concat(), issue a warning on duplicate field
......................................................................

[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 <al...@gmail.com>
Reviewed-by: Wail Alkowaileet <wa...@gmail.com>
Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
Tested-by: Ali Alsuliman <al...@gmail.com>
---
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_concat/object_concat.4.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_concat/object_concat.4.adm
M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordConcatEvalFactory.java
4 files changed, 47 insertions(+), 3 deletions(-)

Approvals:
  Wail Alkowaileet: Looks good to me, approved
  Ali Alsuliman: Looks good to me, but someone else must approve; Verified
  Jenkins: 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 bf48a7b..2400aff 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 0000000..ba22920
--- /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 0000000..ad527c3
--- /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 bc1cacc..890bb13 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.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.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 @@
         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 @@
         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 @@
                 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))));
+                    }
                 }
             }
         }

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/16743
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: neo
Gerrit-Change-Id: I3acb6cfdaf7190c62fe9c2f50f6f6c9367cfcb32
Gerrit-Change-Number: 16743
Gerrit-PatchSet: 2
Gerrit-Owner: Ali Alsuliman <al...@gmail.com>
Gerrit-Reviewer: Ali Alsuliman <al...@gmail.com>
Gerrit-Reviewer: Jenkins <je...@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Murtadha Hubail <mh...@apache.org>
Gerrit-Reviewer: Wail Alkowaileet <wa...@gmail.com>
Gerrit-CC: Anon. E. Moose #1000171
Gerrit-MessageType: merged