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 2023/08/07 23:00:56 UTC

Change in asterixdb[master]: [NO ISSUE][*DB] Better error messages when type mismatch during inser...

From Peeyush Gupta <pe...@couchbase.com>:

Peeyush Gupta has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17705 )


Change subject: [NO ISSUE][*DB] Better error messages when type mismatch during inserts/upserts
......................................................................

[NO ISSUE][*DB] Better error messages when type mismatch during inserts/upserts

- user model changes: no
- storage format changes: no
- interface changes: yes

Change-Id: I7c58a0758887ff73f958b0b8f5f4ccea558ae189
---
M asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
M asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/cast/ARecordCaster.java
M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/operators/LSMPrimaryInsertOperatorNodePushable.java
M asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/LSMInsertDeleteOperatorNodePushable.java
M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
M asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
M hyracks-fullstack/algebricks/algebricks-runtime/src/main/java/org/apache/hyracks/algebricks/runtime/operators/std/AssignRuntimeFactory.java
7 files changed, 34 insertions(+), 20 deletions(-)



  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/05/17705/1

diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index c311681..08980e6 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -4154,7 +4154,7 @@
       <compilation-unit name="create-dataset-2">
         <output-dir compare="Clean-JSON">create-dataset-2</output-dir>
         <source-location>false</source-location>
-        <expected-error>type mismatch: missing a required closed field my_id: string</expected-error>
+        <expected-error>type mismatch: missing a required field my_id: string</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="ddl">
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/LSMInsertDeleteOperatorNodePushable.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/LSMInsertDeleteOperatorNodePushable.java
index 1a23ca8..8a1b6ca 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/LSMInsertDeleteOperatorNodePushable.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/LSMInsertDeleteOperatorNodePushable.java
@@ -172,7 +172,10 @@
                 }
             }
         } catch (HyracksDataException e) {
-            if (e.matches(ErrorCode.INVALID_OPERATOR_OPERATION)) {
+            if (e.matchesAny(ErrorCode.INVALID_OPERATOR_OPERATION,
+                    org.apache.asterix.common.exceptions.ErrorCode.TYPE_MISMATCH_MISSING_FIELD,
+                    org.apache.asterix.common.exceptions.ErrorCode.TYPE_MISMATCH_EXTRA_FIELD,
+                    org.apache.asterix.common.exceptions.ErrorCode.CASTING_FIELD)) {
                 throw e;
             } else {
                 throw HyracksDataException.create(ErrorCode.ERROR_PROCESSING_TUPLE, e, sourceLoc, i);
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
index 26e1bba..d25fbcb 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
@@ -87,6 +87,8 @@
     PARQUET_CONTAINS_OVERFLOWED_BIGINT(57),
     UNEXPECTED_ERROR_ENCOUNTERED(58),
     INVALID_PARQUET_FILE(59),
+    TYPE_MISMATCH_EXTRA_FIELD(60),
+    TYPE_MISMATCH_MISSING_FIELD(61),
 
     UNSUPPORTED_JRE(100),
 
diff --git a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
index 96c8843..d1f51f7 100644
--- a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
+++ b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
@@ -94,6 +94,8 @@
 57 = Parquet file(s) contain unsigned integer that is larger than the '%1$s' range
 58 = Error encountered: %1$s
 59 = Invalid Parquet file: %1$s. Reason: %2$s
+60 = Type mismatch: including an extra field %1$s
+61 = Type mismatch: missing a required field %1$s : %2$s
 
 100 = Unsupported JRE: %1$s
 
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/cast/ARecordCaster.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/cast/ARecordCaster.java
index 7354c1e..c6e1423 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/cast/ARecordCaster.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/cast/ARecordCaster.java
@@ -260,7 +260,7 @@
                 ps.print(typeTag);
 
                 //collect the output message and throw the exception
-                throw new HyracksDataException("type mismatch: including an extra field " + fieldBos.toString());
+                throw new RuntimeDataException(ErrorCode.TYPE_MISMATCH_EXTRA_FIELD, fieldBos.toString());
             }
         }
 
@@ -270,8 +270,8 @@
                 IAType t = cachedReqType.getFieldTypes()[i];
                 if (!NonTaggedFormatUtil.isOptional(t)) {
                     // no matched field in the input for a required closed field
-                    throw new HyracksDataException("type mismatch: missing a required closed field "
-                            + cachedReqType.getFieldNames()[i] + ": " + t.getTypeName());
+                    throw new RuntimeDataException(ErrorCode.TYPE_MISMATCH_MISSING_FIELD,
+                            cachedReqType.getFieldNames()[i], t.getTypeName());
                 }
             }
         }
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/operators/LSMPrimaryInsertOperatorNodePushable.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/operators/LSMPrimaryInsertOperatorNodePushable.java
index 2c89b61..346886f 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/operators/LSMPrimaryInsertOperatorNodePushable.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/operators/LSMPrimaryInsertOperatorNodePushable.java
@@ -184,8 +184,7 @@
                         flushPartialFrame();
                         // feed requires this nested exception to remove duplicated tuples
                         // TODO: a better way to treat duplicates?
-                        throw HyracksDataException.create(ErrorCode.ERROR_PROCESSING_TUPLE,
-                                HyracksDataException.create(ErrorCode.DUPLICATE_KEY), sourceLoc, index);
+                        throw HyracksDataException.create(ErrorCode.DUPLICATE_KEY);
                     }
                     processedTuples.add(index);
                 }
diff --git a/hyracks-fullstack/algebricks/algebricks-runtime/src/main/java/org/apache/hyracks/algebricks/runtime/operators/std/AssignRuntimeFactory.java b/hyracks-fullstack/algebricks/algebricks-runtime/src/main/java/org/apache/hyracks/algebricks/runtime/operators/std/AssignRuntimeFactory.java
index 5343069..3d98d65 100644
--- a/hyracks-fullstack/algebricks/algebricks-runtime/src/main/java/org/apache/hyracks/algebricks/runtime/operators/std/AssignRuntimeFactory.java
+++ b/hyracks-fullstack/algebricks/algebricks-runtime/src/main/java/org/apache/hyracks/algebricks/runtime/operators/std/AssignRuntimeFactory.java
@@ -29,7 +29,6 @@
 import org.apache.hyracks.algebricks.runtime.operators.base.AbstractOneInputOneOutputRuntimeFactory;
 import org.apache.hyracks.api.comm.IFrameTupleAccessor;
 import org.apache.hyracks.api.context.IHyracksTaskContext;
-import org.apache.hyracks.api.exceptions.ErrorCode;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.api.IPointable;
 import org.apache.hyracks.data.std.primitive.VoidPointable;
@@ -154,19 +153,15 @@
 
             private void produceTuple(ArrayTupleBuilder tb, IFrameTupleAccessor accessor, int tIndex,
                     FrameTupleReference tupleRef) throws HyracksDataException {
-                try {
-                    tb.reset();
-                    for (int f = 0; f < projectionList.length; f++) {
-                        int k = projectionToOutColumns[f];
-                        if (k >= 0) {
-                            eval[k].evaluate(tupleRef, result);
-                            tb.addField(result.getByteArray(), result.getStartOffset(), result.getLength());
-                        } else {
-                            tb.addField(accessor, tIndex, projectionList[f]);
-                        }
+                tb.reset();
+                for (int f = 0; f < projectionList.length; f++) {
+                    int k = projectionToOutColumns[f];
+                    if (k >= 0) {
+                        eval[k].evaluate(tupleRef, result);
+                        tb.addField(result.getByteArray(), result.getStartOffset(), result.getLength());
+                    } else {
+                        tb.addField(accessor, tIndex, projectionList[f]);
                     }
-                } catch (HyracksDataException e) {
-                    throw HyracksDataException.create(ErrorCode.ERROR_PROCESSING_TUPLE, e, sourceLoc, tupleIndex);
                 }
             }
 

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

Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: I7c58a0758887ff73f958b0b8f5f4ccea558ae189
Gerrit-Change-Number: 17705
Gerrit-PatchSet: 1
Gerrit-Owner: Peeyush Gupta <pe...@couchbase.com>
Gerrit-MessageType: newchange