asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From buyin...@apache.org
Subject [2/3] asterixdb git commit: Runtime ErrorCode fix in external data
Date Sun, 08 Jan 2017 04:13:45 GMT
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/RuntimeExternalFunctionUtil.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/RuntimeExternalFunctionUtil.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/RuntimeExternalFunctionUtil.java
index f40bfe2..33d508e 100755
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/RuntimeExternalFunctionUtil.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/RuntimeExternalFunctionUtil.java
@@ -22,6 +22,8 @@ import java.nio.ByteBuffer;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.asterix.common.exceptions.ErrorCode;
+import org.apache.asterix.common.exceptions.RuntimeDataException;
 import org.apache.asterix.om.base.AMutableInt32;
 import org.apache.asterix.om.base.AMutableString;
 import org.apache.asterix.om.base.IAObject;
@@ -29,18 +31,18 @@ import org.apache.asterix.om.functions.IExternalFunctionInfo;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.types.IAType;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException;
 import org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo;
 
 public class RuntimeExternalFunctionUtil {
 
     private static Map<String, ClassLoader> libraryClassLoaders = new HashMap<String, ClassLoader>();
 
-    public static void registerLibraryClassLoader(String dataverseName, String libraryName, ClassLoader classLoader) {
+    public static void registerLibraryClassLoader(String dataverseName, String libraryName, ClassLoader classLoader)
+            throws RuntimeDataException {
         String key = dataverseName + "." + libraryName;
         synchronized (libraryClassLoaders) {
             if (libraryClassLoaders.get(dataverseName) != null) {
-                throw new IllegalStateException("library class loader already registered!");
+                throw new RuntimeDataException(ErrorCode.LIBRARY_EXTERNAL_LIBRARY_CLASS_REGISTERED);
             }
             libraryClassLoaders.put(key, classLoader);
         }
@@ -53,15 +55,15 @@ public class RuntimeExternalFunctionUtil {
         }
     }
 
-    public static IFunctionDescriptor getFunctionDescriptor(IFunctionInfo finfo) {
+    public static IFunctionDescriptor getFunctionDescriptor(IFunctionInfo finfo) throws RuntimeDataException {
         switch (((IExternalFunctionInfo) finfo).getKind()) {
             case SCALAR:
                 return getScalarFunctionDescriptor(finfo);
             case AGGREGATE:
             case UNNEST:
             case STATEFUL:
-                throw new NotImplementedException("External " + finfo.getFunctionIdentifier().getName()
-                        + " not supported");
+                throw new RuntimeDataException(ErrorCode.LIBRARY_EXTERNAL_FUNCTION_UNSUPPORTED_NAME,
+                        finfo.getFunctionIdentifier().getName());
         }
         return null;
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectAccessors.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectAccessors.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectAccessors.java
index ab908bf..1f1c139 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectAccessors.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectAccessors.java
@@ -19,6 +19,8 @@
 package org.apache.asterix.external.library.java;
 
 import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.ErrorCode;
+import org.apache.asterix.common.exceptions.RuntimeDataException;
 import org.apache.asterix.dataflow.data.nontagged.serde.ABooleanSerializerDeserializer;
 import org.apache.asterix.dataflow.data.nontagged.serde.ACircleSerializerDeserializer;
 import org.apache.asterix.dataflow.data.nontagged.serde.ADateSerializerDeserializer;
@@ -558,8 +560,8 @@ public class JObjectAccessors {
                             listItem = pointableVisitor.visit((AListVisitablePointable) itemPointable, typeInfo);
                             break;
                         case ANY:
-                            throw new IllegalArgumentException(
-                                    "Cannot parse list item of type " + listType.getTypeTag());
+                            throw new RuntimeDataException(ErrorCode.LIBRARY_JOBJECT_ACCESSOR_CANNOT_PARSE_TYPE,
+                                    listType.getTypeTag());
                         default:
                             listItem = pointableVisitor.visit((AFlatValuePointable) itemPointable, typeInfo);
                     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectUtil.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectUtil.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectUtil.java
index ec55cf0..95e566b 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectUtil.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectUtil.java
@@ -22,6 +22,8 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.asterix.common.exceptions.ErrorCode;
+import org.apache.asterix.common.exceptions.RuntimeDataException;
 import org.apache.asterix.dataflow.data.nontagged.serde.AStringSerializerDeserializer;
 import org.apache.asterix.dataflow.data.nontagged.serde.SerializerDeserializerUtil;
 import org.apache.asterix.external.api.IJObject;
@@ -388,7 +390,7 @@ public class JObjectUtil {
                 }
 
             default:
-                throw new IllegalStateException("Argument type: " + typeTag);
+                throw new RuntimeDataException(ErrorCode.LIBRARY_JOBJECT_UTIL_ILLEGAL_ARGU_TYPE, typeTag);
         }
         return jObject;
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjects.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjects.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjects.java
index ebda69c..78b14e7 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjects.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjects.java
@@ -33,7 +33,8 @@ import java.util.Map.Entry;
 import org.apache.asterix.builders.IAsterixListBuilder;
 import org.apache.asterix.builders.RecordBuilder;
 import org.apache.asterix.builders.UnorderedListBuilder;
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.ErrorCode;
+import org.apache.asterix.common.exceptions.RuntimeDataException;
 import org.apache.asterix.dataflow.data.nontagged.serde.ABooleanSerializerDeserializer;
 import org.apache.asterix.dataflow.data.nontagged.serde.ACircleSerializerDeserializer;
 import org.apache.asterix.dataflow.data.nontagged.serde.ADateSerializerDeserializer;
@@ -990,18 +991,18 @@ public class JObjects {
             this.openFields = openFields;
         }
 
-        public void addField(String fieldName, IJObject fieldValue) throws AsterixException {
+        public void addField(String fieldName, IJObject fieldValue) throws HyracksDataException {
             int pos = getFieldPosByName(fieldName);
             if (pos >= 0) {
-                throw new AsterixException("field already defined in closed part");
+                throw new RuntimeDataException(ErrorCode.LIBRARY_JAVA_JOBJECTS_FIELD_ALREADY_DEFINED, "closed");
             }
             if (openFields.get(fieldName) != null) {
-                throw new AsterixException("field already defined in open part");
+                throw new RuntimeDataException(ErrorCode.LIBRARY_JAVA_JOBJECTS_FIELD_ALREADY_DEFINED, "open");
             }
             openFields.put(fieldName, fieldValue);
         }
 
-        public IJObject getValueByName(String fieldName) throws AsterixException, IOException {
+        public IJObject getValueByName(String fieldName) throws HyracksDataException {
             // check closed part
             int fieldPos = getFieldPosByName(fieldName);
             if (fieldPos >= 0) {
@@ -1010,7 +1011,7 @@ public class JObjects {
                 // check open part
                 IJObject fieldValue = openFields.get(fieldName);
                 if (fieldValue == null) {
-                    throw new AsterixException("unknown field: " + fieldName);
+                    throw new RuntimeDataException(ErrorCode.LIBRARY_JAVA_JOBJECTS_UNKNOWN_FIELD, fieldName);
                 }
                 return fieldValue;
             }
@@ -1025,7 +1026,7 @@ public class JObjects {
             return recordType.getTypeTag();
         }
 
-        public void setField(String fieldName, IJObject fieldValue) throws AsterixException {
+        public void setField(String fieldName, IJObject fieldValue) throws HyracksDataException {
             int pos = getFieldPosByName(fieldName);
             if (pos >= 0) {
                 fields[pos] = fieldValue;
@@ -1033,7 +1034,7 @@ public class JObjects {
                 if (openFields.get(fieldName) != null) {
                     openFields.put(fieldName, fieldValue);
                 } else {
-                    throw new AsterixException("unknown field: " + fieldName);
+                    throw new RuntimeDataException(ErrorCode.LIBRARY_JAVA_JOBJECTS_UNKNOWN_FIELD, fieldName);
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/ExternalFilesIndexOperatorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/ExternalFilesIndexOperatorDescriptor.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/ExternalFilesIndexOperatorDescriptor.java
index 02aa715..ec82ede 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/ExternalFilesIndexOperatorDescriptor.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/ExternalFilesIndexOperatorDescriptor.java
@@ -96,7 +96,6 @@ public class ExternalFilesIndexOperatorDescriptor extends AbstractTreeIndexOpera
                     try {
                         IIndex index = indexHelper.getIndexInstance();
                         // Create bulk loader
-
                         IIndexBulkLoader bulkLoader = index.createBulkLoader(BTree.DEFAULT_FILL_FACTOR, false,
                                 files.size(), false);
                         // Load files
@@ -104,7 +103,7 @@ public class ExternalFilesIndexOperatorDescriptor extends AbstractTreeIndexOpera
                             bulkLoader.add(filesTupleTranslator.getTupleFromFile(file));
                         }
                         bulkLoader.end();
-                    } catch (IndexException | IOException | AsterixException e) {
+                    } catch (IndexException | IOException e) {
                         throw new HyracksDataException(e);
                     } finally {
                         indexHelper.close();
@@ -132,7 +131,7 @@ public class ExternalFilesIndexOperatorDescriptor extends AbstractTreeIndexOpera
                             }
                         }
                         bulkLoader.end();
-                    } catch (IndexException | IOException | AsterixException e) {
+                    } catch (IndexException | IOException e) {
                         if (bulkLoader != null) {
                             bulkLoader.abort();
                         }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/ExternalRTreeSearchOperatorNodePushable.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/ExternalRTreeSearchOperatorNodePushable.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/ExternalRTreeSearchOperatorNodePushable.java
index 97a38747..237e2c0 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/ExternalRTreeSearchOperatorNodePushable.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/ExternalRTreeSearchOperatorNodePushable.java
@@ -58,7 +58,7 @@ public class ExternalRTreeSearchOperatorNodePushable extends RTreeSearchOperator
                 try {
                     nonMatchWriter.writeMissing(out);
                 } catch (IOException e) {
-                    e.printStackTrace();
+                    throw new HyracksDataException(e);
                 }
                 nonMatchTupleBuild.addFieldEndOffset();
             }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/FeedIntakeOperatorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/FeedIntakeOperatorDescriptor.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/FeedIntakeOperatorDescriptor.java
index 309055a..5f478c3 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/FeedIntakeOperatorDescriptor.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/FeedIntakeOperatorDescriptor.java
@@ -23,6 +23,8 @@ import java.util.logging.Logger;
 
 import org.apache.asterix.active.EntityId;
 import org.apache.asterix.common.api.IAppRuntimeContext;
+import org.apache.asterix.common.exceptions.ErrorCode;
+import org.apache.asterix.common.exceptions.RuntimeDataException;
 import org.apache.asterix.common.library.ILibraryManager;
 import org.apache.asterix.external.api.IAdapterFactory;
 import org.apache.asterix.external.feed.api.IFeed;
@@ -119,10 +121,11 @@ public class FeedIntakeOperatorDescriptor extends AbstractSingleActivityOperator
                 throw new HyracksDataException(e);
             }
         } else {
-            String message = "Unable to create adapter as class loader not configured for library " + adaptorLibraryName
-                    + " in dataverse " + feedId.getDataverse();
-            LOGGER.severe(message);
-            throw new IllegalArgumentException(message);
+            RuntimeDataException err = new RuntimeDataException(
+                    ErrorCode.OPERATORS_FEED_INTAKE_OPERATOR_DESCRIPTOR_CLASSLOADER_NOT_CONFIGURED,
+                    adaptorLibraryName, feedId.getDataverse());
+            LOGGER.severe(err.getMessage());
+            throw err;
         }
         return adapterFactory;
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/FeedIntakeOperatorNodePushable.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/FeedIntakeOperatorNodePushable.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/FeedIntakeOperatorNodePushable.java
index 6f7ee15..f58e9e5 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/FeedIntakeOperatorNodePushable.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/FeedIntakeOperatorNodePushable.java
@@ -23,6 +23,8 @@ import org.apache.asterix.active.ActiveRuntimeId;
 import org.apache.asterix.active.EntityId;
 import org.apache.asterix.active.message.ActivePartitionMessage;
 import org.apache.asterix.common.api.IAppRuntimeContext;
+import org.apache.asterix.common.exceptions.ErrorCode;
+import org.apache.asterix.common.exceptions.RuntimeDataException;
 import org.apache.asterix.external.api.IAdapterFactory;
 import org.apache.asterix.external.dataset.adapter.FeedAdapter;
 import org.apache.asterix.external.feed.dataflow.DistributeFeedFrameWriter;
@@ -95,7 +97,8 @@ public class FeedIntakeOperatorNodePushable extends AbstractUnaryOutputSourceOpe
             feedManager.deregisterRuntime(ingestionRuntime.getRuntimeId());
             // If there was a failure, we need to throw an exception
             if (adapterRuntimeManager.isFailed()) {
-                throw new HyracksDataException("Unable to ingest data");
+                throw new RuntimeDataException(
+                        ErrorCode.OPERATORS_FEED_INTAKE_OPERATOR_NODE_PUSHABLE_FAIL_AT_INGESTION);
             }
         } catch (Throwable ie) {
             /*

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/FeedMessageOperatorNodePushable.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/FeedMessageOperatorNodePushable.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/FeedMessageOperatorNodePushable.java
index d1105b2..b273325 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/FeedMessageOperatorNodePushable.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/FeedMessageOperatorNodePushable.java
@@ -26,6 +26,8 @@ import org.apache.asterix.active.ActiveRuntimeId;
 import org.apache.asterix.active.EntityId;
 import org.apache.asterix.active.IActiveMessage;
 import org.apache.asterix.common.api.IAppRuntimeContext;
+import org.apache.asterix.common.exceptions.ErrorCode;
+import org.apache.asterix.common.exceptions.RuntimeDataException;
 import org.apache.asterix.external.feed.api.ISubscribableRuntime;
 import org.apache.asterix.external.feed.management.FeedConnectionId;
 import org.apache.asterix.external.feed.message.EndFeedMessage;
@@ -124,7 +126,9 @@ public class FeedMessageOperatorNodePushable extends AbstractUnaryOutputSourceOp
                     runtimeType = FeedRuntimeType.COMPUTE_COLLECT;
                     break;
                 default:
-                    throw new IllegalStateException("Invalid subscribable runtime type " + subscribableRuntimeType);
+                    throw new RuntimeDataException(
+                            ErrorCode.OPERATORS_FEED_MSG_OPERATOR_NODE_PUSHABLE_INVALID_SUBSCRIBABLE_RUNTIME,
+                            subscribableRuntimeType);
             }
 
             runtimeId = new ActiveRuntimeId(endFeedMessage.getSourceFeedId(), runtimeType.toString(), partition);
@@ -142,7 +146,9 @@ public class FeedMessageOperatorNodePushable extends AbstractUnaryOutputSourceOp
                 case INTAKE:
                     // illegal state as data hand-off from one feed to another does not happen at
                     // intake
-                    throw new IllegalStateException("Illegal State, invalid runtime type  " + subscribableRuntimeType);
+                    throw new RuntimeDataException(
+                            ErrorCode.OPERATORS_FEED_MSG_OPERATOR_NODE_PUSHABLE_INVALID_SUBSCRIBABLE_RUNTIME,
+                            subscribableRuntimeType);
                 case COMPUTE:
                     // feed could be primary or secondary, doesn't matter
                     ActiveRuntimeId feedSubscribableRuntimeId = new ActiveRuntimeId(connectionId.getFeedId(),

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/FeedMetaOperatorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/FeedMetaOperatorDescriptor.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/FeedMetaOperatorDescriptor.java
index 908601d..d0d9f7b 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/FeedMetaOperatorDescriptor.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/operators/FeedMetaOperatorDescriptor.java
@@ -20,6 +20,8 @@ package org.apache.asterix.external.operators;
 
 import java.util.Map;
 
+import org.apache.asterix.common.exceptions.ErrorCode;
+import org.apache.asterix.common.exceptions.RuntimeDataException;
 import org.apache.asterix.external.feed.management.FeedConnectionId;
 import org.apache.asterix.external.util.FeedUtils.FeedRuntimeType;
 import org.apache.hyracks.api.context.IHyracksTaskContext;
@@ -101,7 +103,8 @@ public class FeedMetaOperatorDescriptor extends AbstractSingleActivityOperatorDe
                         coreOperator, feedConnectionId, feedPolicyProperties, operandId, this);
                 break;
             default:
-                throw new HyracksDataException(new IllegalArgumentException("Invalid feed runtime: " + runtimeType));
+                throw new RuntimeDataException(ErrorCode.OPERATORS_FEED_META_OPERATOR_DESCRIPTOR_INVALID_RUNTIME,
+                        runtimeType);
         }
         return nodePushable;
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java
index 8fe11c8..d1a3ad1 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java
@@ -22,6 +22,7 @@ import java.io.DataOutput;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.Serializable;
 import java.util.BitSet;
 import java.util.List;
 
@@ -32,12 +33,12 @@ import org.apache.asterix.builders.ListBuilderFactory;
 import org.apache.asterix.builders.OrderedListBuilder;
 import org.apache.asterix.builders.RecordBuilderFactory;
 import org.apache.asterix.builders.UnorderedListBuilder;
+import org.apache.asterix.common.exceptions.ErrorCode;
 import org.apache.asterix.dataflow.data.nontagged.serde.APolygonSerializerDeserializer;
 import org.apache.asterix.external.api.IRawRecord;
 import org.apache.asterix.external.api.IRecordDataParser;
 import org.apache.asterix.external.api.IStreamDataParser;
 import org.apache.asterix.om.base.ABoolean;
-import org.apache.asterix.om.base.AMutableInterval;
 import org.apache.asterix.om.base.ANull;
 import org.apache.asterix.om.base.temporal.GregorianCalendarSystem;
 import org.apache.asterix.om.types.AOrderedListType;
@@ -84,6 +85,15 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
             super(message);
         }
 
+        public ParseException(int errorCode, Serializable... param) {
+            super(ErrorCode.ASTERIX, errorCode, ErrorCode.getErrorMessage(errorCode), param);
+        }
+
+        public ParseException(int errorCode, Throwable e, Serializable... param) {
+            super(ErrorCode.ASTERIX, errorCode, e, ErrorCode.getErrorMessage(errorCode), param);
+            addSuppressed(e);
+        }
+
         public ParseException(Throwable cause) {
             super(cause);
         }
@@ -133,7 +143,7 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
     }
 
     @Override
-    public boolean parse(DataOutput out) throws IOException {
+    public boolean parse(DataOutput out) throws HyracksDataException {
         try {
             resetPools();
             return parseAdmInstance(recordType, out);
@@ -146,7 +156,7 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
     }
 
     @Override
-    public void parse(IRawRecord<? extends char[]> record, DataOutput out) throws IOException {
+    public void parse(IRawRecord<? extends char[]> record, DataOutput out) throws HyracksDataException {
         try {
             resetPools();
             admLexer.setBuffer(record.get());
@@ -181,14 +191,15 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                 if (checkType(ATypeTag.NULL, objectType)) {
                     nullSerde.serialize(ANull.NULL, out);
                 } else {
-                    throw new ParseException("This field can not be null");
+                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_FIELD_NOT_NULL, "");
                 }
                 break;
             case AdmLexer.TOKEN_TRUE_LITERAL:
                 if (checkType(ATypeTag.BOOLEAN, objectType)) {
                     booleanSerde.serialize(ABoolean.TRUE, out);
                 } else {
-                    throw new ParseException(mismatchErrorMessage + objectType.getTypeName());
+                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_TYPE_MISMATCH,
+                            objectType.getTypeName());
                 }
                 break;
             case AdmLexer.TOKEN_BOOLEAN_CONS:
@@ -198,7 +209,8 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                 if (checkType(ATypeTag.BOOLEAN, objectType)) {
                     booleanSerde.serialize(ABoolean.FALSE, out);
                 } else {
-                    throw new ParseException(mismatchErrorMessage + objectType.getTypeName());
+                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_TYPE_MISMATCH,
+                            objectType.getTypeName());
                 }
                 break;
             case AdmLexer.TOKEN_DOUBLE_LITERAL:
@@ -255,7 +267,8 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                     aUUID.parseUUIDString(tokenImage);
                     uuidSerde.serialize(aUUID, out);
                 } else {
-                    throw new ParseException(mismatchErrorMessage + objectType.getTypeName());
+                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_TYPE_MISMATCH,
+                            objectType.getTypeName());
                 }
                 break;
             case AdmLexer.TOKEN_STRING_CONS:
@@ -273,7 +286,8 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                         }
                     }
                 }
-                throw new ParseException(mismatchErrorMessage + objectType.getTypeName());
+                throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_TYPE_MISMATCH,
+                        objectType.getTypeName());
             case AdmLexer.TOKEN_DATE_CONS:
                 parseConstructor(ATypeTag.DATE, objectType, out);
                 break;
@@ -288,7 +302,8 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                     objectType = getComplexType(objectType, ATypeTag.INTERVAL);
                     parseInterval(ATypeTag.INTERVAL, objectType, out);
                 } else {
-                    throw new ParseException(mismatchErrorMessage + objectType.getTypeName());
+                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_TYPE_MISMATCH,
+                            objectType.getTypeName());
                 }
                 break;
             case AdmLexer.TOKEN_DURATION_CONS:
@@ -323,7 +338,8 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                     objectType = getComplexType(objectType, ATypeTag.UNORDEREDLIST);
                     parseUnorderedList((AUnorderedListType) objectType, out);
                 } else {
-                    throw new ParseException(mismatchErrorMessage + objectType.getTypeName());
+                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_TYPE_MISMATCH,
+                            objectType.getTypeName());
                 }
                 break;
             case AdmLexer.TOKEN_START_ORDERED_LIST:
@@ -331,7 +347,8 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                     objectType = getComplexType(objectType, ATypeTag.ORDEREDLIST);
                     parseOrderedList((AOrderedListType) objectType, out);
                 } else {
-                    throw new ParseException(mismatchErrorMessage + objectType.getTypeName());
+                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_TYPE_MISMATCH,
+                            objectType.getTypeName());
                 }
                 break;
             case AdmLexer.TOKEN_START_RECORD:
@@ -339,7 +356,8 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                     objectType = getComplexType(objectType, ATypeTag.RECORD);
                     parseRecord((ARecordType) objectType, out);
                 } else {
-                    throw new ParseException(mismatchErrorMessage + objectType.getTypeName());
+                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_TYPE_MISMATCH,
+                            objectType.getTypeName());
                 }
                 break;
             case AdmLexer.TOKEN_UUID_CONS:
@@ -348,7 +366,8 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
             case AdmLexer.TOKEN_EOF:
                 break;
             default:
-                throw new ParseException("Unexpected ADM token kind: " + AdmLexer.tokenKindToString(token) + ".");
+                throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_UNEXPECTED_TOKEN_KIND,
+                        AdmLexer.tokenKindToString(token));
         }
 
     }
@@ -388,7 +407,8 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                         readpos += 4;
                         break;
                     default:
-                        throw new ParseException("Illegal escape '\\" + chars[readpos + 1] + "'");
+                        throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_ILLEGAL_ESCAPE,
+                                chars[readpos + 1]);
                 }
                 ++readpos;
                 movemarker = readpos + 1;
@@ -485,7 +505,7 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
             switch (token) {
                 case AdmLexer.TOKEN_END_RECORD:
                     if (expectingRecordField) {
-                        throw new ParseException("Found END_RECORD while expecting a record field.");
+                        throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_RECORD_END_UNEXPECTED);
                     }
                     inRecord = false;
                     break;
@@ -502,7 +522,7 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                         fieldId = recBuilder.getFieldId(fldName);
                         if ((fieldId < 0) && !recType.isOpen()) {
                             throw new ParseException(
-                                    "This record is closed, you can not add extra fields! new field name: " + fldName);
+                                    ErrorCode.PARSER_ADM_DATA_PARSER_EXTRA_FIELD_IN_CLOSED_RECORD, fldName);
                         } else if ((fieldId < 0) && recType.isOpen()) {
                             aStringFieldName.setValue(admLexer.getLastTokenImage().substring(1,
                                     admLexer.getLastTokenImage().length() - 1));
@@ -525,8 +545,9 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
 
                     token = admLexer.next();
                     if (token != AdmLexer.TOKEN_COLON) {
-                        throw new ParseException("Unexpected ADM token kind: " + AdmLexer.tokenKindToString(token)
-                                + " while expecting \":\".");
+                        throw new ParseException(
+                                ErrorCode.PARSER_ADM_DATA_PARSER_UNEXPECTED_TOKEN_WHEN_EXPECT_COMMA,
+                                AdmLexer.tokenKindToString(token));
                     }
 
                     token = admLexer.next();
@@ -540,16 +561,18 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                     break;
                 case AdmLexer.TOKEN_COMMA:
                     if (first) {
-                        throw new ParseException("Found COMMA before any record field.");
+                        throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_FOUND_COMMA_WHEN,
+                                "before any");
                     }
                     if (expectingRecordField) {
-                        throw new ParseException("Found COMMA while expecting a record field.");
+                        throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_FOUND_COMMA_WHEN,
+                                "expecting a");
                     }
                     expectingRecordField = true;
                     break;
                 default:
-                    throw new ParseException("Unexpected ADM token kind: " + AdmLexer.tokenKindToString(token)
-                            + " while parsing record fields.");
+                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_UNEXPECTED_TOKEN_KIND,
+                            AdmLexer.tokenKindToString(token));
             }
             first = false;
         } while (inRecord);
@@ -557,7 +580,8 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
         if (recType != null) {
             final int nullableFieldId = checkOptionalConstraints(recType, nulls);
             if (nullableFieldId != -1) {
-                throw new ParseException("Field: " + recType.getFieldNames()[nullableFieldId] + " can not be null");
+                throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_FIELD_NOT_NULL,
+                        recType.getFieldNames()[nullableFieldId]);
             }
         }
         recBuilder.write(out, true);
@@ -603,7 +627,8 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                     intervalType = ATypeTag.DATETIME;
                     break;
                 default:
-                    throw new ParseException("Unsupported interval type: " + AdmLexer.tokenKindToString(token) + ".");
+                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_UNSUPPORTED_INTERVAL_TYPE,
+                            AdmLexer.tokenKindToString(token));
             }
 
             // Interval
@@ -621,7 +646,7 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                 throw new ParseException(e);
             }
         } else {
-            throw new ParseException("Interval was not closed.");
+            throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_INTERVAL_NOT_CLOSED);
         }
         intervalSerde.serialize(aInterval, out);
     }
@@ -633,11 +658,11 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
             if (token == startToken) {
                 return parseIntervalArgument(parseType);
             } else {
-                throw new ParseException("The interval start and end point types do not match: "
-                        + AdmLexer.tokenKindToString(startToken) + " != " + AdmLexer.tokenKindToString(token));
+                throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_INTERVAL_BEGIN_END_POINT_MISMATCH,
+                        AdmLexer.tokenKindToString(startToken), AdmLexer.tokenKindToString(token));
             }
         } else {
-            throw new ParseException("Missing COMMA before interval end point.");
+            throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_INTERVAL_MISSING_COMMA);
         }
     }
 
@@ -659,15 +684,14 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                     case DATETIME:
                         int timeSeperatorOffsetInDatetimeString = arg.indexOf('T');
                         if (timeSeperatorOffsetInDatetimeString < 0) {
-                            throw new ParseException(
-                                    "This can not be an instance of interval: missing T for a datetime value.");
+                            throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_INTERVAL_INVALID_DATETIME);
                         }
                         chrononTimeInMs += parseDatePart(arg, 0, timeSeperatorOffsetInDatetimeString - 1);
                         chrononTimeInMs += parseTimePart(arg, timeSeperatorOffsetInDatetimeString + 1,
                                 arg.length() - 1);
                         break;
                     default:
-                        throw new ParseException("Unsupported interval type: " + tag.name() + ".");
+                        throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_INTERVAL_UNSUPPORTED_TYPE);
                 }
                 token = admLexer.next();
                 if (token == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
@@ -675,7 +699,7 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                 }
             }
         }
-        throw new ParseException("Interval argument not properly constructed.");
+        throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_INTERVAL_INTERVAL_ARGUMENT_ERROR);
     }
 
     private void parseOrderedList(AOrderedListType oltype, DataOutput out) throws IOException {
@@ -696,15 +720,15 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
             token = admLexer.next();
             if (token == AdmLexer.TOKEN_END_ORDERED_LIST) {
                 if (expectingListItem) {
-                    throw new ParseException("Found END_COLLECTION while expecting a list item.");
+                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_LIST_FOUND_END_COLLECTION);
                 }
                 inList = false;
             } else if (token == AdmLexer.TOKEN_COMMA) {
                 if (first) {
-                    throw new ParseException("Found COMMA before any list item.");
+                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_LIST_FOUND_COMMA_BEFORE_LIST);
                 }
                 if (expectingListItem) {
-                    throw new ParseException("Found COMMA while expecting a list item.");
+                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_LIST_FOUND_COMMA_EXPECTING_ITEM);
                 }
                 expectingListItem = true;
             } else {
@@ -739,19 +763,19 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
             if (token == AdmLexer.TOKEN_END_RECORD) {
                 if (admLexer.next() == AdmLexer.TOKEN_END_RECORD) {
                     if (expectingListItem) {
-                        throw new ParseException("Found END_COLLECTION while expecting a list item.");
+                        throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_LIST_FOUND_END_COLLECTION);
                     } else {
                         inList = false;
                     }
                 } else {
-                    throw new ParseException("Found END_RECORD while expecting a list item.");
+                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_LIST_FOUND_END_RECOD);
                 }
             } else if (token == AdmLexer.TOKEN_COMMA) {
                 if (first) {
-                    throw new ParseException("Found COMMA before any list item.");
+                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_LIST_FOUND_COMMA_BEFORE_LIST);
                 }
                 if (expectingListItem) {
-                    throw new ParseException("Found COMMA while expecting a list item.");
+                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_LIST_FOUND_COMMA_EXPECTING_ITEM);
                 }
                 expectingListItem = true;
             } else {
@@ -819,7 +843,7 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                 // can promote typeTag to targetTypeTag
                 ITypeConvertComputer promoteComputer = ATypeHierarchy.getTypePromoteComputer(typeTag, targetTypeTag);
                 if (promoteComputer == null) {
-                    throw new ParseException("Can't cast the " + typeTag + " type to the " + targetTypeTag + " type.");
+                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_CAST_ERROR, typeTag, targetTypeTag);
                 }
                 // do the promotion; note that the type tag field should be skipped
                 promoteComputer.convertType(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1,
@@ -828,7 +852,7 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                 // can demote source type to the target type
                 ITypeConvertComputer demoteComputer = ATypeHierarchy.getTypeDemoteComputer(typeTag, targetTypeTag);
                 if (demoteComputer == null) {
-                    throw new ParseException("Can't cast the " + typeTag + " type to the " + targetTypeTag + " type.");
+                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_CAST_ERROR, typeTag, targetTypeTag);
                 }
                 // do the demotion; note that the type tag field should be skipped
                 demoteComputer.convertType(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1,
@@ -852,8 +876,9 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                     String unquoted = admLexer.getLastTokenImage().substring(1,
                             admLexer.getLastTokenImage().length() - 1);
                     if (!parseValue(unquoted, typeTag, dataOutput)) {
-                        throw new ParseException("Missing deserializer method for constructor: "
-                                + AdmLexer.tokenKindToString(token) + ".");
+                        throw new ParseException(
+                                ErrorCode.PARSER_ADM_DATA_PARSER_CONSTRUCTOR_MISSING_DESERIALIZER,
+                                AdmLexer.tokenKindToString(token));
                     }
                     token = admLexer.next();
                     if (token == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
@@ -872,7 +897,9 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                 }
             }
         }
-        throw new ParseException(mismatchErrorMessage + objectType.getTypeName() + ". Got " + typeTag + " instead.");
+
+        throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_TYPE_MISMATCH,
+                objectType.getTypeName() + " got " + typeTag);
     }
 
     private boolean parseValue(String unquoted, ATypeTag typeTag, DataOutput out) throws HyracksDataException {
@@ -950,18 +977,16 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
     }
 
     private void parseBoolean(String bool, DataOutput out) throws HyracksDataException {
-        String errorMessage = "This can not be an instance of boolean";
         if (bool.equals("true")) {
             booleanSerde.serialize(ABoolean.TRUE, out);
         } else if (bool.equals("false")) {
             booleanSerde.serialize(ABoolean.FALSE, out);
         } else {
-            throw new ParseException(errorMessage);
+            throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_WRONG_INSTANCE, "boolean");
         }
     }
 
     private void parseInt8(String int8, DataOutput out) throws HyracksDataException {
-        String errorMessage = "This can not be an instance of int8";
         boolean positive = true;
         byte value = 0;
         int offset = 0;
@@ -979,11 +1004,11 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                     && ((offset + 2) == int8.length())) {
                 break;
             } else {
-                throw new ParseException(errorMessage);
+                throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_WRONG_INSTANCE, "int8");
             }
         }
         if (value < 0) {
-            throw new ParseException(errorMessage);
+            throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_WRONG_INSTANCE, "int8");
         }
         if ((value > 0) && !positive) {
             value *= -1;
@@ -993,7 +1018,6 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
     }
 
     private void parseInt16(String int16, DataOutput out) throws HyracksDataException {
-        String errorMessage = "This can not be an instance of int16";
         boolean positive = true;
         short value = 0;
         int offset = 0;
@@ -1011,11 +1035,11 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                     && (int16.charAt(offset + 2) == '6') && ((offset + 3) == int16.length())) {
                 break;
             } else {
-                throw new ParseException(errorMessage);
+                throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_WRONG_INSTANCE, "int16");
             }
         }
         if (value < 0) {
-            throw new ParseException(errorMessage);
+            throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_WRONG_INSTANCE, "int16");
         }
         if ((value > 0) && !positive) {
             value *= -1;
@@ -1025,7 +1049,6 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
     }
 
     private void parseInt32(String int32, DataOutput out) throws HyracksDataException {
-        String errorMessage = "This can not be an instance of int32";
         boolean positive = true;
         int value = 0;
         int offset = 0;
@@ -1043,11 +1066,11 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                     && (int32.charAt(offset + 2) == '2') && ((offset + 3) == int32.length())) {
                 break;
             } else {
-                throw new ParseException(errorMessage);
+                throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_WRONG_INSTANCE, "int32");
             }
         }
         if (value < 0) {
-            throw new ParseException(errorMessage);
+            throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_WRONG_INSTANCE, "int32");
         }
         if ((value > 0) && !positive) {
             value *= -1;
@@ -1058,7 +1081,6 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
     }
 
     private void parseInt64(String int64, DataOutput out) throws HyracksDataException {
-        String errorMessage = "This can not be an instance of int64";
         boolean positive = true;
         long value = 0;
         int offset = 0;
@@ -1076,11 +1098,11 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars
                     && (int64.charAt(offset + 2) == '4') && ((offset + 3) == int64.length())) {
                 break;
             } else {
-                throw new ParseException(errorMessage);
+                throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_WRONG_INSTANCE, "int64");
             }
         }
         if (value < 0) {
-            throw new ParseException(errorMessage);
+            throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_WRONG_INSTANCE, "int64");
         }
         if ((value > 0) && !positive) {
             value *= -1;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/DelimitedDataParser.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/DelimitedDataParser.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/DelimitedDataParser.java
index 28fd169..b14a2c4 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/DelimitedDataParser.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/DelimitedDataParser.java
@@ -25,10 +25,12 @@ import java.io.InputStreamReader;
 
 import org.apache.asterix.builders.IARecordBuilder;
 import org.apache.asterix.builders.RecordBuilder;
+import org.apache.asterix.common.exceptions.RuntimeDataException;
 import org.apache.asterix.external.api.IDataParser;
 import org.apache.asterix.external.api.IRawRecord;
 import org.apache.asterix.external.api.IRecordDataParser;
 import org.apache.asterix.external.api.IStreamDataParser;
+import org.apache.asterix.common.exceptions.ErrorCode;
 import org.apache.asterix.om.base.AMutableString;
 import org.apache.asterix.om.types.ARecordType;
 import org.apache.asterix.om.types.ATypeTag;
@@ -87,7 +89,7 @@ public class DelimitedDataParser extends AbstractDataParser implements IStreamDa
             fldIds[i] = recBuilder.getFieldId(name);
             if (fldIds[i] < 0) {
                 if (!recordType.isOpen()) {
-                    throw new HyracksDataException("Illegal field " + name + " in closed type " + recordType);
+                    throw new RuntimeDataException(ErrorCode.PARSER_DELIMITED_ILLEGAL_FIELD, name, recordType);
                 } else {
                     nameBuffers[i] = new ArrayBackedValueStorage();
                     str.setValue(name);
@@ -101,62 +103,78 @@ public class DelimitedDataParser extends AbstractDataParser implements IStreamDa
     }
 
     @Override
-    public boolean parse(DataOutput out) throws IOException {
-        while (cursor.nextRecord()) {
-            parseRecord(out);
-            if (!areAllNullFields) {
-                recBuilder.write(out, true);
-                return true;
+    public boolean parse(DataOutput out) throws HyracksDataException {
+        try {
+            while (cursor.nextRecord()) {
+                parseRecord();
+                if (!areAllNullFields) {
+                    recBuilder.write(out, true);
+                    return true;
+                }
             }
+            return false;
+        } catch (IOException e) {
+            throw new HyracksDataException(e);
         }
-        return false;
     }
 
-    private void parseRecord(DataOutput out) throws IOException {
+    private void parseRecord() throws HyracksDataException {
         recBuilder.reset(recordType);
         recBuilder.init();
         areAllNullFields = true;
 
         for (int i = 0; i < valueParsers.length; ++i) {
-            if (!cursor.nextField()) {
-                break;
+            try {
+                if (!cursor.nextField()) {
+                    break;
+                }
+            } catch (IOException e) {
+                throw new HyracksDataException(e);
             }
             fieldValueBuffer.reset();
 
-            if (cursor.fStart == cursor.fEnd && recordType.getFieldTypes()[i].getTypeTag() != ATypeTag.STRING
-                    && recordType.getFieldTypes()[i].getTypeTag() != ATypeTag.NULL) {
-                // if the field is empty and the type is optional, insert
-                // NULL. Note that string type can also process empty field as an
-                // empty string
-                if (!NonTaggedFormatUtil.isOptional(recordType.getFieldTypes()[i])) {
-                    throw new HyracksDataException("At record: " + cursor.recordCount + " - Field " + cursor.fieldCount
-                            + " is not an optional type so it cannot accept null value. ");
+            try {
+                if (cursor.fStart == cursor.fEnd && recordType.getFieldTypes()[i].getTypeTag() != ATypeTag.STRING
+                        && recordType.getFieldTypes()[i].getTypeTag() != ATypeTag.NULL) {
+                    // if the field is empty and the type is optional, insert
+                    // NULL. Note that string type can also process empty field as an
+                    // empty string
+                    if (!NonTaggedFormatUtil.isOptional(recordType.getFieldTypes()[i])) {
+                        throw new RuntimeDataException(ErrorCode.PARSER_DELIMITED_NONOPTIONAL_NULL,
+                                cursor.recordCount, cursor.fieldCount);
+                    }
+                    fieldValueBufferOutput.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
+                } else {
+                    fieldValueBufferOutput.writeByte(fieldTypeTags[i]);
+                    // Eliminate doule quotes in the field that we are going to parse
+                    if (cursor.isDoubleQuoteIncludedInThisField) {
+                        cursor.eliminateDoubleQuote(cursor.buffer, cursor.fStart, cursor.fEnd - cursor.fStart);
+                        cursor.fEnd -= cursor.doubleQuoteCount;
+                        cursor.isDoubleQuoteIncludedInThisField = false;
+                    }
+                    valueParsers[i]
+                            .parse(cursor.buffer, cursor.fStart, cursor.fEnd - cursor.fStart, fieldValueBufferOutput);
+                    areAllNullFields = false;
                 }
-                fieldValueBufferOutput.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
-            } else {
-                fieldValueBufferOutput.writeByte(fieldTypeTags[i]);
-                // Eliminate doule quotes in the field that we are going to parse
-                if (cursor.isDoubleQuoteIncludedInThisField) {
-                    cursor.eliminateDoubleQuote(cursor.buffer, cursor.fStart, cursor.fEnd - cursor.fStart);
-                    cursor.fEnd -= cursor.doubleQuoteCount;
-                    cursor.isDoubleQuoteIncludedInThisField = false;
+                if (fldIds[i] < 0) {
+                    recBuilder.addField(nameBuffers[i], fieldValueBuffer);
+                } else {
+                    recBuilder.addField(fldIds[i], fieldValueBuffer);
                 }
-                valueParsers[i].parse(cursor.buffer, cursor.fStart, cursor.fEnd - cursor.fStart,
-                        fieldValueBufferOutput);
-                areAllNullFields = false;
-            }
-            if (fldIds[i] < 0) {
-                recBuilder.addField(nameBuffers[i], fieldValueBuffer);
-            } else {
-                recBuilder.addField(fldIds[i], fieldValueBuffer);
+            } catch (IOException e) {
+                throw new HyracksDataException(e);
             }
         }
     }
 
     @Override
-    public void parse(IRawRecord<? extends char[]> record, DataOutput out) throws IOException {
-        cursor.nextRecord(record.get(), record.size());
-        parseRecord(out);
+    public void parse(IRawRecord<? extends char[]> record, DataOutput out) throws HyracksDataException {
+        try {
+            cursor.nextRecord(record.get(), record.size());
+        } catch (IOException e) {
+            throw new HyracksDataException(e);
+        }
+        parseRecord();
         if (!areAllNullFields) {
             recBuilder.write(out, true);
         }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/HiveRecordParser.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/HiveRecordParser.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/HiveRecordParser.java
index 9723461..fdcd4ff 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/HiveRecordParser.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/HiveRecordParser.java
@@ -27,6 +27,8 @@ import org.apache.asterix.builders.IARecordBuilder;
 import org.apache.asterix.builders.OrderedListBuilder;
 import org.apache.asterix.builders.RecordBuilder;
 import org.apache.asterix.builders.UnorderedListBuilder;
+import org.apache.asterix.common.exceptions.ErrorCode;
+import org.apache.asterix.common.exceptions.RuntimeDataException;
 import org.apache.asterix.external.api.IRawRecord;
 import org.apache.asterix.external.api.IRecordDataParser;
 import org.apache.asterix.om.base.temporal.GregorianCalendarSystem;
@@ -54,7 +56,6 @@ import org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspe
 import org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector;
 import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.mapred.JobConf;
-import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.util.string.UTF8StringWriter;
@@ -134,62 +135,66 @@ public class HiveRecordParser implements IRecordDataParser<Writable> {
     }
 
     private void parseItem(IAType itemType, Object value, ObjectInspector foi, DataOutput dataOutput,
-            boolean primitiveOnly) throws IOException {
-        switch (itemType.getTypeTag()) {
-            case BOOLEAN:
-                parseBoolean(value, (BooleanObjectInspector) foi, dataOutput);
-                break;
-            case TIME:
-                parseTime(value, (TimestampObjectInspector) foi, dataOutput);
-                break;
-            case DATE:
-                parseDate(value, (TimestampObjectInspector) foi, dataOutput);
-                break;
-            case DATETIME:
-                parseDateTime(value, (TimestampObjectInspector) foi, dataOutput);
-                break;
-            case DOUBLE:
-                parseDouble(value, (DoubleObjectInspector) foi, dataOutput);
-                break;
-            case FLOAT:
-                parseFloat(value, (FloatObjectInspector) foi, dataOutput);
-                break;
-            case INT8:
-                parseInt8(value, (ByteObjectInspector) foi, dataOutput);
-                break;
-            case INT16:
-                parseInt16(value, (ShortObjectInspector) foi, dataOutput);
-                break;
-            case INT32:
-                parseInt32(value, (IntObjectInspector) foi, dataOutput);
-                break;
-            case INT64:
-                parseInt64(value, (LongObjectInspector) foi, dataOutput);
-                break;
-            case STRING:
-                parseString(value, (StringObjectInspector) foi, dataOutput);
-                break;
-            case ORDEREDLIST:
-                if (primitiveOnly) {
-                    throw new HyracksDataException("doesn't support hive data with list of non-primitive types");
-                }
-                parseOrderedList((AOrderedListType) itemType, value, (ListObjectInspector) foi);
-                break;
-            case UNORDEREDLIST:
-                if (primitiveOnly) {
-                    throw new HyracksDataException("doesn't support hive data with list of non-primitive types");
-                }
-                parseUnorderedList((AUnorderedListType) itemType, value, (ListObjectInspector) foi);
-                break;
-            default:
-                throw new HyracksDataException("Can't get hive type for field of type " + itemType.getTypeTag());
+            boolean primitiveOnly) throws HyracksDataException {
+        try {
+            switch (itemType.getTypeTag()) {
+                case BOOLEAN:
+                    parseBoolean(value, (BooleanObjectInspector) foi, dataOutput);
+                    break;
+                case TIME:
+                    parseTime(value, (TimestampObjectInspector) foi, dataOutput);
+                    break;
+                case DATE:
+                    parseDate(value, (TimestampObjectInspector) foi, dataOutput);
+                    break;
+                case DATETIME:
+                    parseDateTime(value, (TimestampObjectInspector) foi, dataOutput);
+                    break;
+                case DOUBLE:
+                    parseDouble(value, (DoubleObjectInspector) foi, dataOutput);
+                    break;
+                case FLOAT:
+                    parseFloat(value, (FloatObjectInspector) foi, dataOutput);
+                    break;
+                case INT8:
+                    parseInt8(value, (ByteObjectInspector) foi, dataOutput);
+                    break;
+                case INT16:
+                    parseInt16(value, (ShortObjectInspector) foi, dataOutput);
+                    break;
+                case INT32:
+                    parseInt32(value, (IntObjectInspector) foi, dataOutput);
+                    break;
+                case INT64:
+                    parseInt64(value, (LongObjectInspector) foi, dataOutput);
+                    break;
+                case STRING:
+                    parseString(value, (StringObjectInspector) foi, dataOutput);
+                    break;
+                case ORDEREDLIST:
+                    if (primitiveOnly) {
+                        throw new RuntimeDataException(ErrorCode.PARSER_HIVE_NON_PRIMITIVE_LIST_NOT_SUPPORT);
+                    }
+                    parseOrderedList((AOrderedListType) itemType, value, (ListObjectInspector) foi);
+                    break;
+                case UNORDEREDLIST:
+                    if (primitiveOnly) {
+                        throw new RuntimeDataException(ErrorCode.PARSER_HIVE_NON_PRIMITIVE_LIST_NOT_SUPPORT);
+                    }
+                    parseUnorderedList((AUnorderedListType) itemType, value, (ListObjectInspector) foi);
+                    break;
+                default:
+                    throw new RuntimeDataException(ErrorCode.PARSER_HIVE_FIELD_TYPE, itemType.getTypeTag());
+            }
+        } catch (IOException e) {
+            throw new HyracksDataException(e);
         }
     }
 
-    private Object getColTypes(ARecordType record) throws Exception {
+    private Object getColTypes(ARecordType record) throws HyracksDataException {
         int n = record.getFieldTypes().length;
         if (n < 1) {
-            throw new HyracksDataException("Failed to get columns of record");
+            throw new RuntimeDataException(ErrorCode.PARSER_HIVE_GET_COLUMNS);
         }
         //First Column
         String cols = getHiveTypeString(record.getFieldTypes(), 0);
@@ -199,9 +204,9 @@ public class HiveRecordParser implements IRecordDataParser<Writable> {
         return cols;
     }
 
-    private String getCommaDelimitedColNames(ARecordType record) throws Exception {
+    private String getCommaDelimitedColNames(ARecordType record) throws HyracksDataException {
         if (record.getFieldNames().length < 1) {
-            throw new HyracksDataException("Can't deserialize hive records with no closed columns");
+            throw new RuntimeDataException(ErrorCode.PARSER_HIVE_NO_CLOSED_COLUMNS);
         }
 
         String cols = record.getFieldNames()[0];
@@ -211,17 +216,17 @@ public class HiveRecordParser implements IRecordDataParser<Writable> {
         return cols;
     }
 
-    private String getHiveTypeString(IAType[] types, int i) throws Exception {
+    private String getHiveTypeString(IAType[] types, int i) throws HyracksDataException {
         final IAType type = types[i];
         ATypeTag tag = type.getTypeTag();
         if (tag == ATypeTag.UNION) {
             if (NonTaggedFormatUtil.isOptional(type)) {
-                throw new NotImplementedException("Non-optional UNION type is not supported.");
+                throw new RuntimeDataException(ErrorCode.PARSER_HIVE_NOT_SUPPORT_NON_OP_UNION);
             }
             tag = ((AUnionType) type).getActualType().getTypeTag();
         }
         if (tag == null) {
-            throw new NotImplementedException("Failed to get the type information for field " + i + ".");
+            throw new RuntimeDataException(ErrorCode.PARSER_HIVE_MISSING_FIELD_TYPE_INFO, i);
         }
         switch (tag) {
             case BOOLEAN:
@@ -251,7 +256,7 @@ public class HiveRecordParser implements IRecordDataParser<Writable> {
             case UNORDEREDLIST:
                 return Constants.LIST_TYPE_NAME;
             default:
-                throw new HyracksDataException("Can't get hive type for field of type " + tag);
+                throw new RuntimeDataException(ErrorCode.PARSER_HIVE_FIELD_TYPE, tag);
         }
     }
 
@@ -261,7 +266,7 @@ public class HiveRecordParser implements IRecordDataParser<Writable> {
 
     private void parseInt32(Object obj, IntObjectInspector foi, DataOutput dataOutput) throws IOException {
         if (obj == null) {
-            throw new HyracksDataException("can't parse null field");
+            throw new RuntimeDataException(ErrorCode.PARSER_HIVE_NULL_FIELD);
         }
         dataOutput.writeInt(foi.get(obj));
     }
@@ -308,7 +313,7 @@ public class HiveRecordParser implements IRecordDataParser<Writable> {
     }
 
     private void parseOrderedList(AOrderedListType aOrderedListType, Object obj, ListObjectInspector foi)
-            throws IOException {
+            throws HyracksDataException {
         OrderedListBuilder orderedListBuilder = getOrderedListBuilder();
         IAType itemType = null;
         if (aOrderedListType != null)
@@ -320,7 +325,7 @@ public class HiveRecordParser implements IRecordDataParser<Writable> {
             Object element = foi.getListElement(obj, i);
             ObjectInspector eoi = foi.getListElementObjectInspector();
             if (element == null) {
-                throw new HyracksDataException("can't parse hive list with null values");
+                throw new RuntimeDataException(ErrorCode.PARSER_HIVE_NULL_VALUE_IN_LIST);
             }
             parseItem(itemType, element, eoi, listItemBuffer.getDataOutput(), true);
             orderedListBuilder.addItem(listItemBuffer);
@@ -341,7 +346,7 @@ public class HiveRecordParser implements IRecordDataParser<Writable> {
             Object element = oi.getListElement(obj, i);
             ObjectInspector eoi = oi.getListElementObjectInspector();
             if (element == null) {
-                throw new HyracksDataException("can't parse hive list with null values");
+                throw new RuntimeDataException(ErrorCode.PARSER_HIVE_NULL_VALUE_IN_LIST);
             }
             listItemBuffer.reset();
             final DataOutput dataOutput = listItemBuffer.getDataOutput();

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/RSSParser.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/RSSParser.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/RSSParser.java
index 5336c30..c2d6be8 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/RSSParser.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/RSSParser.java
@@ -30,6 +30,7 @@ import org.apache.asterix.om.base.AMutableString;
 import org.apache.asterix.om.types.ARecordType;
 
 import com.sun.syndication.feed.synd.SyndEntryImpl;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
 
 public class RSSParser implements IRecordDataParser<SyndEntryImpl> {
     private long id = 0;
@@ -49,7 +50,7 @@ public class RSSParser implements IRecordDataParser<SyndEntryImpl> {
     }
 
     @Override
-    public void parse(IRawRecord<? extends SyndEntryImpl> record, DataOutput out) throws IOException {
+    public void parse(IRawRecord<? extends SyndEntryImpl> record, DataOutput out) throws HyracksDataException {
         SyndEntryImpl entry = record.get();
         tupleFieldValues[0] = idPrefix + ":" + id;
         tupleFieldValues[1] = entry.getTitle();

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/RecordWithMetadataParser.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/RecordWithMetadataParser.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/RecordWithMetadataParser.java
index 2be9019..ed33401 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/RecordWithMetadataParser.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/RecordWithMetadataParser.java
@@ -107,7 +107,7 @@ public class RecordWithMetadataParser<T, O> implements IRecordWithMetadataParser
     }
 
     @Override
-    public void appendLastParsedPrimaryKeyToTuple(ArrayTupleBuilder tb) throws IOException {
+    public void appendLastParsedPrimaryKeyToTuple(ArrayTupleBuilder tb) throws HyracksDataException {
         rwm.appendPrimaryKeyToTuple(tb);
     }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/RecordWithPKDataParser.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/RecordWithPKDataParser.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/RecordWithPKDataParser.java
index b8c265c..1f9fef2 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/RecordWithPKDataParser.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/RecordWithPKDataParser.java
@@ -26,6 +26,7 @@ import org.apache.asterix.external.api.IRecordDataParser;
 import org.apache.asterix.external.api.IRecordWithPKDataParser;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder;
 
 public class RecordWithPKDataParser<T> implements IRecordWithPKDataParser<T> {
@@ -36,15 +37,20 @@ public class RecordWithPKDataParser<T> implements IRecordWithPKDataParser<T> {
     }
 
     @Override
-    public void parse(IRawRecord<? extends T> record, DataOutput out) throws IOException {
+    public void parse(IRawRecord<? extends T> record, DataOutput out) throws HyracksDataException {
         if (record.size() == 0) {
-            out.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
+            try {
+                out.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
+            } catch (IOException e) {
+                throw new HyracksDataException(e);
+            }
         } else {
             recordParser.parse(record, out);
         }
     }
 
     @Override
-    public void appendKeys(ArrayTupleBuilder tb, IRawRecord<? extends T> record) throws IOException {
+    public void appendKeys(ArrayTupleBuilder tb, IRawRecord<? extends T> record) throws HyracksDataException {
+        // do nothing.
     }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/TweetParser.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/TweetParser.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/TweetParser.java
index 95a5cd1..bb0b136 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/TweetParser.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/TweetParser.java
@@ -26,6 +26,8 @@ import org.apache.asterix.builders.IAsterixListBuilder;
 import org.apache.asterix.builders.ListBuilderFactory;
 import org.apache.asterix.builders.RecordBuilderFactory;
 import org.apache.asterix.builders.UnorderedListBuilder;
+import org.apache.asterix.common.exceptions.ErrorCode;
+import org.apache.asterix.common.exceptions.RuntimeDataException;
 import org.apache.asterix.external.api.IRawRecord;
 import org.apache.asterix.external.api.IRecordDataParser;
 import org.apache.asterix.om.base.AMutablePoint;
@@ -178,8 +180,8 @@ public class TweetParser extends AbstractDataParser implements IRecordDataParser
                 DataOutput fieldOutput = fieldValueBuffer.getDataOutput();
                 if (obj.get(curFNames[iter1]).isNull()) {
                     if (curRecType.isClosedField(curFNames[iter1])) {
-                        throw new HyracksDataException("Closed field " + curFNames[iter1] + " has null value.");
-                    } else {
+                        throw new RuntimeDataException(ErrorCode.PARSER_TWEET_PARSER_CLOSED_FIELD_NULL,
+                                curFNames[iter1]);                    } else {
                         continue;
                     }
                 } else {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/DelimitedDataParserFactory.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/DelimitedDataParserFactory.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/DelimitedDataParserFactory.java
index f724b48..786dac0 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/DelimitedDataParserFactory.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/DelimitedDataParserFactory.java
@@ -20,6 +20,8 @@ package org.apache.asterix.external.parser.factory;
 
 import java.util.Map;
 
+import org.apache.asterix.common.exceptions.ErrorCode;
+import org.apache.asterix.common.exceptions.RuntimeDataException;
 import org.apache.asterix.external.api.IExternalDataSourceFactory.DataSourceType;
 import org.apache.asterix.external.api.IRecordDataParser;
 import org.apache.asterix.external.api.IStreamDataParser;
@@ -66,8 +68,8 @@ public class DelimitedDataParserFactory extends AbstractRecordStreamParserFactor
         if (delimiterValue == null) {
             delimiterValue = ExternalDataConstants.DEFAULT_DELIMITER;
         } else if (delimiterValue.length() != 1) {
-            throw new HyracksDataException(
-                    "'" + delimiterValue + "' is not a valid delimiter. The length of a delimiter should be 1.");
+            throw new RuntimeDataException(
+                    ErrorCode.PARSER_FACTORY_DELIMITED_DATA_PARSER_FACTORY_NOT_VALID_DELIMITER, delimiterValue);
         }
         return delimiterValue.charAt(0);
     }
@@ -79,15 +81,16 @@ public class DelimitedDataParserFactory extends AbstractRecordStreamParserFactor
         if (quoteValue == null) {
             quoteValue = ExternalDataConstants.DEFAULT_QUOTE;
         } else if (quoteValue.length() != 1) {
-            throw new HyracksDataException(
-                    "'" + quoteValue + "' is not a valid quote. The length of a quote should be 1.");
+            throw new RuntimeDataException(ErrorCode.PARSER_FACTORY_DELIMITED_DATA_PARSER_FACTORY_NOT_VALID_QUOTE,
+                    quoteValue);
         }
 
         // Since delimiter (char type value) can't be null,
         // we only check whether delimiter and quote use the same character
         if (quoteValue.charAt(0) == delimiter) {
-            throw new HyracksDataException(
-                    "Quote '" + quoteValue + "' cannot be used with the delimiter '" + delimiter + "'. ");
+            throw new RuntimeDataException(
+                    ErrorCode.PARSER_FACTORY_DELIMITED_DATA_PARSER_FACTORY_QUOTE_DELIMITER_MISMATCH, quoteValue,
+                    delimiter);
         }
 
         return quoteValue.charAt(0);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/HiveDataParserFactory.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/HiveDataParserFactory.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/HiveDataParserFactory.java
index a4c8679..15ecbfd 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/HiveDataParserFactory.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/HiveDataParserFactory.java
@@ -20,6 +20,7 @@ package org.apache.asterix.external.parser.factory;
 
 import java.util.Map;
 
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.external.api.IExternalDataSourceFactory.DataSourceType;
 import org.apache.asterix.external.api.IRecordDataParser;
 import org.apache.asterix.external.api.IRecordDataParserFactory;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/RecordWithMetadataParserFactory.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/RecordWithMetadataParserFactory.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/RecordWithMetadataParserFactory.java
index 96c592a..484fafb 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/RecordWithMetadataParserFactory.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/RecordWithMetadataParserFactory.java
@@ -21,6 +21,7 @@ package org.apache.asterix.external.parser.factory;
 import java.util.Map;
 
 import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.ErrorCode;
 import org.apache.asterix.external.api.IRecordDataParser;
 import org.apache.asterix.external.api.IRecordDataParserFactory;
 import org.apache.asterix.external.input.record.RecordWithMetadataAndPK;
@@ -48,14 +49,13 @@ public class RecordWithMetadataParserFactory<I, O> implements IRecordDataParserF
         // validate first
         String recordFormat = configuration.get(ExternalDataConstants.KEY_RECORD_FORMAT);
         if (recordFormat == null) {
-            throw new AsterixException(
-                    "Unknown record format for a record with meta parser. Did you specify the parameter "
-                            + ExternalDataConstants.KEY_RECORD_FORMAT);
+            throw new AsterixException(ErrorCode.UNKNOWN_RECORD_FORMAT_FOR_META_PARSER,
+                    ExternalDataConstants.KEY_FORMAT);
         }
         String format = configuration.get(ExternalDataConstants.KEY_FORMAT);
         if (format == null) {
-            throw new AsterixException("Unknown format for a record with meta parser. Did you specify the parameter "
-                    + ExternalDataConstants.KEY_FORMAT);
+            throw new AsterixException(ErrorCode.UNKNOWN_RECORD_FORMAT_FOR_META_PARSER,
+                    ExternalDataConstants.KEY_FORMAT);
         }
         // Create Parser Factory
         recordParserFactory = (IRecordDataParserFactory<O>) ParserFactoryProvider.getDataParserFactory(recordFormat);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/provider/DataflowControllerProvider.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/provider/DataflowControllerProvider.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/provider/DataflowControllerProvider.java
index 98cb4b0..a369fe3 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/provider/DataflowControllerProvider.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/provider/DataflowControllerProvider.java
@@ -22,6 +22,8 @@ import java.io.IOException;
 import java.util.Map;
 
 import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.ErrorCode;
+import org.apache.asterix.common.exceptions.RuntimeDataException;
 import org.apache.asterix.external.api.AsterixInputStream;
 import org.apache.asterix.external.api.IDataFlowController;
 import org.apache.asterix.external.api.IDataParserFactory;
@@ -115,8 +117,8 @@ public class DataflowControllerProvider {
                                 streamParser);
                     }
                 default:
-                    throw new HyracksDataException(
-                            "Unknown data source type: " + dataSourceFactory.getDataSourceType());
+                    throw new RuntimeDataException(ErrorCode.PROVIDER_DATAFLOW_CONTROLLER_UNKNOWN_DATA_SOURCE,
+                            dataSourceFactory.getDataSourceType());
             }
         } catch (IOException | AsterixException e) {
             throw new HyracksDataException(e);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/024fafe2/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/provider/DatasourceFactoryProvider.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/provider/DatasourceFactoryProvider.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/provider/DatasourceFactoryProvider.java
index 73a5302..1428863 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/provider/DatasourceFactoryProvider.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/provider/DatasourceFactoryProvider.java
@@ -20,7 +20,8 @@ package org.apache.asterix.external.provider;
 
 import java.util.Map;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.ErrorCode;
+import org.apache.asterix.common.exceptions.RuntimeDataException;
 import org.apache.asterix.common.library.ILibraryManager;
 import org.apache.asterix.external.api.IExternalDataSourceFactory;
 import org.apache.asterix.external.api.IExternalDataSourceFactory.DataSourceType;
@@ -35,6 +36,8 @@ import org.apache.asterix.external.input.stream.factory.SocketClientInputStreamF
 import org.apache.asterix.external.input.stream.factory.SocketServerInputStreamFactory;
 import org.apache.asterix.external.util.ExternalDataConstants;
 import org.apache.asterix.external.util.ExternalDataUtils;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
 
 public class DatasourceFactoryProvider {
 
@@ -42,7 +45,7 @@ public class DatasourceFactoryProvider {
     }
 
     public static IExternalDataSourceFactory getExternalDataSourceFactory(ILibraryManager libraryManager,
-            Map<String, String> configuration) throws AsterixException {
+            Map<String, String> configuration) throws HyracksDataException {
         if (ExternalDataUtils.getDataSourceType(configuration).equals(DataSourceType.RECORDS)) {
             String reader = configuration.get(ExternalDataConstants.KEY_READER);
             return DatasourceFactoryProvider.getRecordReaderFactory(libraryManager, reader, configuration);
@@ -54,7 +57,7 @@ public class DatasourceFactoryProvider {
     }
 
     public static IInputStreamFactory getInputStreamFactory(ILibraryManager libraryManager, String streamSource,
-            Map<String, String> configuration) throws AsterixException {
+            Map<String, String> configuration) throws HyracksDataException {
         IInputStreamFactory streamSourceFactory;
         if (ExternalDataUtils.isExternal(streamSource)) {
             String dataverse = ExternalDataUtils.getDataverse(configuration);
@@ -76,7 +79,9 @@ public class DatasourceFactoryProvider {
                     try {
                         streamSourceFactory = (IInputStreamFactory) Class.forName(streamSource).newInstance();
                     } catch (Exception e) {
-                        throw new AsterixException("unknown input stream factory: " + streamSource, e);
+                        throw new RuntimeDataException(
+                                ErrorCode.PROVIDER_DATASOURCE_FACTORY_UNKNOWN_INPUT_STREAM_FACTORY, e,
+                                streamSource);
                     }
             }
         }
@@ -84,9 +89,14 @@ public class DatasourceFactoryProvider {
     }
 
     public static IRecordReaderFactory<?> getRecordReaderFactory(ILibraryManager libraryManager, String reader,
-            Map<String, String> configuration) throws AsterixException {
+            Map<String, String> configuration) throws HyracksDataException {
         if (reader.equals(ExternalDataConstants.EXTERNAL)) {
-            return ExternalDataUtils.createExternalRecordReaderFactory(libraryManager, configuration);
+            try {
+                return ExternalDataUtils.createExternalRecordReaderFactory(libraryManager, configuration);
+            } catch (AlgebricksException e) {
+                // Not sure whether this is the right way to handle AlgebricksException  (xikui)
+                throw new HyracksDataException(e);
+            }
         }
         switch (reader) {
             case ExternalDataConstants.READER_HDFS:
@@ -111,7 +121,7 @@ public class DatasourceFactoryProvider {
                     return (IRecordReaderFactory<?>) Class.forName(reader).newInstance();
                 } catch (IllegalAccessException | ClassNotFoundException | InstantiationException
                         | ClassCastException e) {
-                    throw new AsterixException("Unknown record reader factory: " + reader, e);
+                    throw new RuntimeDataException(ErrorCode.UNKNOWN_RECORD_READER_FACTORY, e,reader);
                 }
         }
     }


Mime
View raw message