asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From buyin...@apache.org
Subject [06/22] asterixdb git commit: Unify runtime type exceptions by using error code and message template.
Date Tue, 01 Nov 2016 03:08:15 GMT
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordAddFieldsDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordAddFieldsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordAddFieldsDescriptor.java
index 6565935..d9f3e68 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordAddFieldsDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordAddFieldsDescriptor.java
@@ -24,6 +24,8 @@ import java.util.List;
 
 import org.apache.asterix.builders.RecordBuilder;
 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.comparators.ListItemBinaryComparatorFactory;
 import org.apache.asterix.dataflow.data.nontagged.hash.ListItemBinaryHashFunctionFactory;
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
@@ -38,13 +40,13 @@ import org.apache.asterix.om.typecomputer.impl.TypeComputeUtils;
 import org.apache.asterix.om.types.AOrderedListType;
 import org.apache.asterix.om.types.ARecordType;
 import org.apache.asterix.om.types.ATypeTag;
-import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.om.types.IAType;
 import org.apache.asterix.om.types.runtime.RuntimeRecordTypeInfo;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.BinaryHashMap;
 import org.apache.asterix.runtime.evaluators.functions.PointableHelper;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.asterix.runtime.exceptions.InvalidDataFormatException;
+import org.apache.asterix.runtime.exceptions.TypeMismatchException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
@@ -82,14 +84,12 @@ public class RecordAddFieldsDescriptor extends AbstractScalarFunctionDynamicDesc
     }
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
-
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
                 final PointableAllocator allocator = new PointableAllocator();
                 final IVisitablePointable vp0 = allocator.allocateRecordValue(inRecType);
                 final IVisitablePointable vp1 = allocator.allocateListValue(inListType);
@@ -107,7 +107,7 @@ public class RecordAddFieldsDescriptor extends AbstractScalarFunctionDynamicDesc
                     pointableHelper.serializeString("field-name", fieldNamePointable, true);
                     pointableHelper.serializeString("field-value", fieldValuePointer, true);
                 } catch (AsterixException e) {
-                    throw new AlgebricksException(e);
+                    throw new HyracksDataException(e);
                 }
 
                 return new IScalarEvaluator() {
@@ -131,7 +131,7 @@ public class RecordAddFieldsDescriptor extends AbstractScalarFunctionDynamicDesc
                     private DataOutput out = resultStorage.getDataOutput();
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                         resultStorage.reset();
                         recordBuilder.reset(outRecType);
                         requiredRecordTypeInfo.reset(outRecType);
@@ -139,46 +139,42 @@ public class RecordAddFieldsDescriptor extends AbstractScalarFunctionDynamicDesc
                         eval1.evaluate(tuple, argPtr1);
 
                         // Make sure we get a valid record
-                        if (argPtr0.getByteArray()[argPtr0.getStartOffset()] != ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
-                            throw new AlgebricksException("Expected an ordederlist of type " + inRecType + " but "
-                                    + "got " + EnumDeserializer.ATYPETAGDESERIALIZER
-                                            .deserialize(argPtr0.getByteArray()[argPtr0.getStartOffset()]));
+                        byte typeTag0 = argPtr0.getByteArray()[argPtr0.getStartOffset()];
+                        if (typeTag0 != ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
+                            throw new TypeMismatchException(getIdentifier(), 0, typeTag0,
+                                    ATypeTag.SERIALIZED_RECORD_TYPE_TAG);
                         }
 
                         // Make sure we get a valid list
-                        if (argPtr1.getByteArray()[argPtr1
-                                .getStartOffset()] != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG) {
-                            throw new AlgebricksException("Expected an ordederlist of type " + inListType + " but "
-                                    + "got " + EnumDeserializer.ATYPETAGDESERIALIZER
-                                            .deserialize(argPtr1.getByteArray()[argPtr1.getStartOffset()]));
+                        byte typeTag1 = argPtr1.getByteArray()[argPtr1.getStartOffset()];
+                        if (typeTag1 != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG) {
+                            throw new TypeMismatchException(getIdentifier(), 1, typeTag1,
+                                    ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG);
                         }
 
                         vp0.set(argPtr0);
                         vp1.set(argPtr1);
 
-                        try {
-                            ARecordVisitablePointable recordPointable = (ARecordVisitablePointable) vp0;
-                            AListVisitablePointable listPointable = (AListVisitablePointable) vp1;
 
-                            // Initialize our hashmap
-                            int tableSize = recordPointable.getFieldNames().size() + listPointable.getItems().size();
-                            // Construct a new hash table only if table size is larger than the default
-                            // Thus avoiding unnecessary object construction
-                            if (hashMap == null || tableSize > TABLE_SIZE) {
-                                hashMap = new BinaryHashMap(tableSize, TABLE_FRAME_SIZE, putHashFunc, getHashFunc, cmp);
-                            } else {
-                                hashMap.clear();
-                            }
-                            addFields(recordPointable, listPointable);
-                            recordBuilder.write(out, true);
-                        } catch (HyracksDataException e) {
-                            throw new AlgebricksException(e);
+                        ARecordVisitablePointable recordPointable = (ARecordVisitablePointable) vp0;
+                        AListVisitablePointable listPointable = (AListVisitablePointable) vp1;
+
+                        // Initialize our hashmap
+                        int tableSize = recordPointable.getFieldNames().size() + listPointable.getItems().size();
+                        // Construct a new hash table only if table size is larger than the default
+                        // Thus avoiding unnecessary object construction
+                        if (hashMap == null || tableSize > TABLE_SIZE) {
+                            hashMap = new BinaryHashMap(tableSize, TABLE_FRAME_SIZE, putHashFunc, getHashFunc, cmp);
+                        } else {
+                            hashMap.clear();
                         }
+                        addFields(recordPointable, listPointable);
+                        recordBuilder.write(out, true);
                         result.set(resultStorage);
                     }
 
                     private void addFields(ARecordVisitablePointable inputRecordPointer,
-                            AListVisitablePointable listPointable) throws AlgebricksException {
+                            AListVisitablePointable listPointable) throws HyracksDataException {
                         List<IVisitablePointable> inputRecordFieldNames = inputRecordPointer.getFieldNames();
                         List<IVisitablePointable> inputRecordFieldValues = inputRecordPointer.getFieldValues();
                         List<IVisitablePointable> inputFields = listPointable.getItems();
@@ -228,7 +224,7 @@ public class RecordAddFieldsDescriptor extends AbstractScalarFunctionDynamicDesc
                                 }
 
                                 if (namePointable == null || valuePointable == null) {
-                                    throw new AlgebricksException("Trying to add a null field name or field value");
+                                    throw new InvalidDataFormatException(getIdentifier(), "fields to be added");
                                 }
 
                                 // Check that the field being added is a valid field
@@ -243,7 +239,8 @@ public class RecordAddFieldsDescriptor extends AbstractScalarFunctionDynamicDesc
                                     tempValReference.set(entry.buf, entry.off, entry.len);
                                     // If value is not equal throw conflicting duplicate field, otherwise ignore
                                     if (!PointableHelper.byteArrayEqual(valuePointable, tempValReference)) {
-                                        throw new AlgebricksException("Conflicting duplicate field found.");
+                                        throw new RuntimeDataException(ErrorCode.ERROR_DUPLICATE_FIELD,
+                                                getIdentifier());
                                     }
                                 } else {
                                     if (pos > -1) {
@@ -256,8 +253,8 @@ public class RecordAddFieldsDescriptor extends AbstractScalarFunctionDynamicDesc
                                     hashMap.put(keyEntry, valEntry);
                                 }
                             }
-                        } catch (AsterixException | HyracksDataException e) {
-                            throw new AlgebricksException(e);
+                        } catch (AsterixException e) {
+                            throw new HyracksDataException(e);
                         }
                     }
                 };

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordFieldsUtil.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordFieldsUtil.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordFieldsUtil.java
index 93c1f1b..b99b488 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordFieldsUtil.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordFieldsUtil.java
@@ -44,7 +44,6 @@ import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.om.types.IAType;
 import org.apache.asterix.om.util.container.IObjectPool;
 import org.apache.asterix.om.util.container.ListObjectPool;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.api.IMutableValueStorage;
@@ -83,7 +82,7 @@ public class RecordFieldsUtil {
     private final static ARecordType openType = DefaultOpenFieldType.NESTED_OPEN_RECORD_TYPE;
 
     public void processRecord(ARecordPointable recordAccessor, ARecordType recType, DataOutput out, int level)
-            throws IOException, AsterixException, AlgebricksException {
+            throws IOException, AsterixException {
         if (level == 0) {
             // Resets pools for recycling objects before processing a top-level record.
             resetPools();
@@ -221,7 +220,7 @@ public class RecordFieldsUtil {
     }
 
     public void addListField(IValueReference listArg, IAType fieldType, IARecordBuilder fieldRecordBuilder, int level)
-            throws AsterixException, IOException, AlgebricksException {
+            throws AsterixException, IOException {
         ArrayBackedValueStorage fieldAbvs = getTempBuffer();
         ArrayBackedValueStorage valueAbvs = getTempBuffer();
 
@@ -235,7 +234,7 @@ public class RecordFieldsUtil {
     }
 
     public void addNestedField(IValueReference recordArg, IAType fieldType, IARecordBuilder fieldRecordBuilder,
-            int level) throws HyracksDataException, AlgebricksException, IOException, AsterixException {
+            int level) throws IOException, AsterixException {
         ArrayBackedValueStorage fieldAbvs = getTempBuffer();
         ArrayBackedValueStorage valueAbvs = getTempBuffer();
 
@@ -257,7 +256,7 @@ public class RecordFieldsUtil {
     }
 
     public void processListValue(IValueReference listArg, IAType fieldType, DataOutput out, int level)
-            throws AsterixException, IOException, AlgebricksException {
+            throws AsterixException, IOException {
         ArrayBackedValueStorage itemValue = getTempBuffer();
         IARecordBuilder listRecordBuilder = getRecordBuilder();
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeDescriptor.java
index 2f54c9e..8e0d7ce 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeDescriptor.java
@@ -25,6 +25,8 @@ import java.util.List;
 
 import org.apache.asterix.builders.RecordBuilder;
 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.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
@@ -40,11 +42,11 @@ import org.apache.asterix.om.types.runtime.RuntimeRecordTypeInfo;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.asterix.runtime.evaluators.comparisons.DeepEqualAssessor;
 import org.apache.asterix.runtime.evaluators.functions.PointableHelper;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
 import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.api.IPointable;
 import org.apache.hyracks.data.std.primitive.VoidPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
@@ -79,14 +81,12 @@ public class RecordMergeDescriptor extends AbstractScalarFunctionDynamicDescript
     }
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
-
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
                 final PointableAllocator pa = new PointableAllocator();
                 final IVisitablePointable vp0 = pa.allocateRecordValue(inRecType0);
                 final IVisitablePointable vp1 = pa.allocateRecordValue(inRecType1);
@@ -109,7 +109,7 @@ public class RecordMergeDescriptor extends AbstractScalarFunctionDynamicDescript
                     private DataOutput out = resultStorage.getDataOutput();
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                         resultStorage.reset();
                         eval0.evaluate(tuple, argPtr0);
                         eval1.evaluate(tuple, argPtr1);
@@ -124,14 +124,14 @@ public class RecordMergeDescriptor extends AbstractScalarFunctionDynamicDescript
                             mergeFields(outRecType, rp0, rp1, true, 0);
                             rbStack.get(0).write(out, true);
                         } catch (IOException | AsterixException e) {
-                            throw new AlgebricksException(e);
+                            throw new HyracksDataException(e);
                         }
                         result.set(resultStorage);
                     }
 
                     private void mergeFields(ARecordType combinedType, ARecordVisitablePointable leftRecord,
                             ARecordVisitablePointable rightRecord, boolean openFromParent, int nestedLevel)
-                            throws IOException, AsterixException, AlgebricksException {
+                            throws IOException, AsterixException, HyracksDataException {
                         if (rbStack.size() < (nestedLevel + 1)) {
                             rbStack.add(new RecordBuilder());
                         }
@@ -160,7 +160,8 @@ public class RecordMergeDescriptor extends AbstractScalarFunctionDynamicDescript
                                                 openFromParent, nestedLevel);
                                         foundMatch = true;
                                     } else {
-                                        throw new AlgebricksException("Duplicate field found");
+                                        throw new RuntimeDataException(ErrorCode.ERROR_DUPLICATE_FIELD,
+                                                getIdentifier());
                                     }
                                 }
                             }
@@ -197,7 +198,7 @@ public class RecordMergeDescriptor extends AbstractScalarFunctionDynamicDescript
                      */
                     private void addFieldToSubRecord(ARecordType combinedType, IVisitablePointable fieldNamePointable,
                             IVisitablePointable leftValue, IVisitablePointable rightValue, boolean openFromParent,
-                            int nestedLevel) throws IOException, AsterixException, AlgebricksException {
+                            int nestedLevel) throws IOException, AsterixException, HyracksDataException {
 
                         runtimeRecordTypeInfo.reset(combinedType);
                         int pos = runtimeRecordTypeInfo.getFieldIndex(fieldNamePointable.getByteArray(),

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordPairsDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordPairsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordPairsDescriptor.java
index b6aedb4..f8904df 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordPairsDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordPairsDescriptor.java
@@ -26,6 +26,7 @@ import org.apache.asterix.builders.OrderedListBuilder;
 import org.apache.asterix.builders.RecordBuilder;
 import org.apache.asterix.dataflow.data.nontagged.serde.AObjectSerializerDeserializer;
 import org.apache.asterix.om.base.AString;
+import org.apache.asterix.runtime.exceptions.TypeMismatchException;
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
@@ -34,9 +35,7 @@ import org.apache.asterix.om.pointables.base.IVisitablePointable;
 import org.apache.asterix.om.types.AOrderedListType;
 import org.apache.asterix.om.types.ARecordType;
 import org.apache.asterix.om.types.ATypeTag;
-import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
@@ -74,7 +73,7 @@ public class RecordPairsDescriptor extends AbstractScalarFunctionDynamicDescript
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
                 // For writing each individual output record.
                 final ArrayBackedValueStorage itemStorage = new ArrayBackedValueStorage();
                 final DataOutput itemOutput = itemStorage.getDataOutput();
@@ -94,7 +93,7 @@ public class RecordPairsDescriptor extends AbstractScalarFunctionDynamicDescript
                     serde.serialize(new AString("name"), nameStorage.getDataOutput());
                     serde.serialize(new AString("value"), valueStorage.getDataOutput());
                 } catch (IOException e) {
-                    throw new AlgebricksException(e);
+                    throw new HyracksDataException(e);
                 }
 
                 return new IScalarEvaluator() {
@@ -104,41 +103,36 @@ public class RecordPairsDescriptor extends AbstractScalarFunctionDynamicDescript
                             recType);
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
-                        try {
-                            // Resets the result storage.
-                            resultStorage.reset();
-
-                            // Gets the input record.
-                            argEvaluator.evaluate(tuple, argPtr);
-                            byte inputTypeTag = argPtr.getByteArray()[argPtr.getStartOffset()];
-                            if (inputTypeTag != ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
-                                throw new AlgebricksException("Function " + RecordPairsDescriptor.this.getIdentifier()
-                                        + " expects a record as the input, " + "but get a "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(inputTypeTag));
-                            }
-                            recordVisitablePointable.set(argPtr);
-
-                            listBuilder.reset(AOrderedListType.FULL_OPEN_ORDEREDLIST_TYPE);
-                            List<IVisitablePointable> fieldNames = recordVisitablePointable.getFieldNames();
-                            List<IVisitablePointable> fieldValues = recordVisitablePointable.getFieldValues();
-                            // Adds each field of the input record as a key-value pair into the result.
-                            int numFields = recordVisitablePointable.getFieldNames().size();
-                            for (int fieldIndex = 0; fieldIndex < numFields; ++fieldIndex) {
-                                itemStorage.reset();
-                                recBuilder.init();
-                                recBuilder.addField(nameStorage, fieldNames.get(fieldIndex));
-                                recBuilder.addField(valueStorage, fieldValues.get(fieldIndex));
-                                recBuilder.write(itemOutput, true);
-                                listBuilder.addItem(itemStorage);
-                            }
-
-                            // Writes the result and sets the result pointable.
-                            listBuilder.write(resultOut, true);
-                            result.set(resultStorage);
-                        } catch (HyracksDataException e) {
-                            throw new AlgebricksException(e);
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
+                        // Resets the result storage.
+                        resultStorage.reset();
+
+                        // Gets the input record.
+                        argEvaluator.evaluate(tuple, argPtr);
+                        byte inputTypeTag = argPtr.getByteArray()[argPtr.getStartOffset()];
+                        if (inputTypeTag != ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
+                            throw new TypeMismatchException(getIdentifier(), 0, inputTypeTag,
+                                    ATypeTag.SERIALIZED_RECORD_TYPE_TAG);
                         }
+                        recordVisitablePointable.set(argPtr);
+
+                        listBuilder.reset(AOrderedListType.FULL_OPEN_ORDEREDLIST_TYPE);
+                        List<IVisitablePointable> fieldNames = recordVisitablePointable.getFieldNames();
+                        List<IVisitablePointable> fieldValues = recordVisitablePointable.getFieldValues();
+                        // Adds each field of the input record as a key-value pair into the result.
+                        int numFields = recordVisitablePointable.getFieldNames().size();
+                        for (int fieldIndex = 0; fieldIndex < numFields; ++fieldIndex) {
+                            itemStorage.reset();
+                            recBuilder.init();
+                            recBuilder.addField(nameStorage, fieldNames.get(fieldIndex));
+                            recBuilder.addField(valueStorage, fieldValues.get(fieldIndex));
+                            recBuilder.write(itemOutput, true);
+                            listBuilder.addItem(itemStorage);
+                        }
+
+                        // Writes the result and sets the result pointable.
+                        listBuilder.write(resultOut, true);
+                        result.set(resultStorage);
                     }
                 };
             }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveFieldsDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveFieldsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveFieldsDescriptor.java
index b7e719d..593d684 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveFieldsDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveFieldsDescriptor.java
@@ -25,7 +25,6 @@ import org.apache.asterix.om.types.AOrderedListType;
 import org.apache.asterix.om.types.ARecordType;
 import org.apache.asterix.om.types.IAType;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
 
@@ -52,8 +51,7 @@ public class RecordRemoveFieldsDescriptor extends AbstractScalarFunctionDynamicD
     }
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new RecordRemoveFieldsEvalFactory(args[0], args[1], outputRecordType, inputRecType, inputListType);
     }
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveFieldsEvalFactory.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveFieldsEvalFactory.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveFieldsEvalFactory.java
index 68865c3..57b8c12 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveFieldsEvalFactory.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveFieldsEvalFactory.java
@@ -28,6 +28,7 @@ import java.util.List;
 
 import org.apache.asterix.builders.RecordBuilder;
 import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.runtime.exceptions.TypeMismatchException;
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.pointables.AListVisitablePointable;
 import org.apache.asterix.om.pointables.ARecordVisitablePointable;
@@ -37,10 +38,8 @@ import org.apache.asterix.om.pointables.base.IVisitablePointable;
 import org.apache.asterix.om.types.AOrderedListType;
 import org.apache.asterix.om.types.ARecordType;
 import org.apache.asterix.om.types.ATypeTag;
-import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.om.types.runtime.RuntimeRecordTypeInfo;
 import org.apache.asterix.runtime.evaluators.functions.PointableHelper;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
 import org.apache.hyracks.api.context.IHyracksTaskContext;
@@ -70,7 +69,7 @@ class RecordRemoveFieldsEvalFactory implements IScalarEvaluatorFactory {
     }
 
     @Override
-    public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+    public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
 
         final PointableAllocator pa = new PointableAllocator();
         final IVisitablePointable vp0 = pa.allocateRecordValue(inputRecType);
@@ -91,23 +90,21 @@ class RecordRemoveFieldsEvalFactory implements IScalarEvaluatorFactory {
             private DataOutput out = resultStorage.getDataOutput();
 
             @Override
-            public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+            public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                 resultStorage.reset();
                 eval0.evaluate(tuple, inputArg0);
                 eval1.evaluate(tuple, inputArg1);
 
-                if (inputArg0.getByteArray()[inputArg0.getStartOffset()] != ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
-                    throw new AlgebricksException(
-                            AsterixBuiltinFunctions.REMOVE_FIELDS.getName() + ": expects input type " + inputRecType
-                                    + ", but got " + EnumDeserializer.ATYPETAGDESERIALIZER
-                                            .deserialize(inputArg0.getByteArray()[inputArg0.getStartOffset()]));
+                byte inputTypeTag0 = inputArg0.getByteArray()[inputArg0.getStartOffset()];
+                if (inputTypeTag0 != ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
+                    throw new TypeMismatchException(AsterixBuiltinFunctions.REMOVE_FIELDS, 0, inputTypeTag0,
+                            ATypeTag.SERIALIZED_INT32_TYPE_TAG);
                 }
 
-                if (inputArg1.getByteArray()[inputArg1.getStartOffset()] != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG) {
-                    throw new AlgebricksException(
-                            AsterixBuiltinFunctions.REMOVE_FIELDS.getName() + ": expects input type " + inputListType
-                                    + ", but got " + EnumDeserializer.ATYPETAGDESERIALIZER
-                                            .deserialize(inputArg1.getByteArray()[inputArg1.getStartOffset()]));
+                byte inputTypeTag1 = inputArg1.getByteArray()[inputArg1.getStartOffset()];
+                if (inputTypeTag1 != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG) {
+                    throw new TypeMismatchException(AsterixBuiltinFunctions.REMOVE_FIELDS, 1, inputTypeTag1,
+                            ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG);
                 }
 
                 vp0.set(inputArg0);
@@ -122,14 +119,14 @@ class RecordRemoveFieldsEvalFactory implements IScalarEvaluatorFactory {
                     processRecord(requiredRecType, recordPointable, listPointable, 0);
                     rbStack.get(0).write(out, true);
                 } catch (IOException | AsterixException e) {
-                    throw new AlgebricksException(e);
+                    throw new HyracksDataException(e);
                 }
                 result.set(resultStorage);
             }
 
             private void processRecord(ARecordType requiredType, ARecordVisitablePointable srp,
                     AListVisitablePointable inputList, int nestedLevel)
-                    throws IOException, AsterixException, AlgebricksException {
+                    throws IOException, AsterixException, HyracksDataException {
                 if (rbStack.size() < (nestedLevel + 1)) {
                     rbStack.add(new RecordBuilder());
                 }
@@ -160,7 +157,7 @@ class RecordRemoveFieldsEvalFactory implements IScalarEvaluatorFactory {
             private void addKeptFieldToSubRecord(ARecordType requiredType, IVisitablePointable fieldNamePointable,
                     IVisitablePointable fieldValuePointable, IVisitablePointable fieldTypePointable,
                     AListVisitablePointable inputList, int nestedLevel)
-                    throws IOException, AsterixException, AlgebricksException {
+                    throws IOException, AsterixException, HyracksDataException {
 
                 runtimeRecordTypeInfo.reset(requiredType);
                 int pos = runtimeRecordTypeInfo.getFieldIndex(fieldNamePointable.getByteArray(),

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/temporal/AbstractIntervalLogicFuncDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/temporal/AbstractIntervalLogicFuncDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/temporal/AbstractIntervalLogicFuncDescriptor.java
index b016fac..f782602 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/temporal/AbstractIntervalLogicFuncDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/temporal/AbstractIntervalLogicFuncDescriptor.java
@@ -22,12 +22,12 @@ import java.io.DataOutput;
 
 import org.apache.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import org.apache.asterix.om.base.ABoolean;
+import org.apache.asterix.runtime.exceptions.IncompatibleTypeException;
+import org.apache.asterix.runtime.exceptions.TypeMismatchException;
 import org.apache.asterix.om.pointables.nonvisitor.AIntervalPointable;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.BuiltinType;
-import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
 import org.apache.hyracks.api.context.IHyracksTaskContext;
@@ -42,14 +42,12 @@ public abstract class AbstractIntervalLogicFuncDescriptor extends AbstractScalar
     private static final long serialVersionUID = 1L;
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
-
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
 
                 return new IScalarEvaluator() {
 
@@ -73,34 +71,31 @@ public abstract class AbstractIntervalLogicFuncDescriptor extends AbstractScalar
                             .getSerializerDeserializer(BuiltinType.ABOOLEAN);
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                         resultStorage.reset();
                         eval0.evaluate(tuple, argPtr0);
                         eval1.evaluate(tuple, argPtr1);
 
-                        try {
-                            if (argPtr0.getTag() != ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG
-                                    || argPtr1.getTag() != ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG) {
-                                throw new AlgebricksException(getIdentifier().getName()
-                                        + ": expects input type (INTERVAL, INTERVAL) but got ("
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argPtr0.getTag()) + ", "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argPtr1.getTag()) + ")");
-                            }
-
-                            argPtr0.getValue(interval0);
-                            argPtr1.getValue(interval1);
-
-                            if (interval0.getType() != interval1.getType()) {
-                                throw new AlgebricksException(getIdentifier().getName()
-                                        + ": failed to compare intervals with different internal time type.");
-                            }
+                        byte typeTag0 = argPtr0.getTag();
+                        if (typeTag0 != ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG) {
+                            throw new TypeMismatchException(getIdentifier(), 0, typeTag0,
+                                    ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG);
+                        }
+                        byte typeTag1 = argPtr0.getTag();
+                        if (typeTag1 != ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG) {
+                            throw new TypeMismatchException(getIdentifier(), 1, typeTag1,
+                                    ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG);
+                        }
 
-                            ABoolean res = compareIntervals(il, interval0, interval1) ? ABoolean.TRUE : ABoolean.FALSE;
+                        argPtr0.getValue(interval0);
+                        argPtr1.getValue(interval1);
 
-                            booleanSerde.serialize(res, out);
-                        } catch (HyracksDataException hex) {
-                            throw new AlgebricksException(hex);
+                        if (typeTag0 != typeTag1) {
+                            throw new IncompatibleTypeException(getIdentifier(), typeTag0, typeTag1);
                         }
+
+                        ABoolean res = compareIntervals(il, interval0, interval1) ? ABoolean.TRUE : ABoolean.FALSE;
+                        booleanSerde.serialize(res, out);
                         result.set(resultStorage);
                     }
                 };

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/temporal/AdjustDateTimeForTimeZoneDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/temporal/AdjustDateTimeForTimeZoneDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/temporal/AdjustDateTimeForTimeZoneDescriptor.java
index 1ce0c9c..a01d7a8 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/temporal/AdjustDateTimeForTimeZoneDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/temporal/AdjustDateTimeForTimeZoneDescriptor.java
@@ -19,22 +19,24 @@
 package org.apache.asterix.runtime.evaluators.functions.temporal;
 
 import java.io.DataOutput;
+import java.io.IOException;
 
 import org.apache.asterix.dataflow.data.nontagged.serde.ADateTimeSerializerDeserializer;
 import org.apache.asterix.om.base.temporal.ATimeParserFactory;
 import org.apache.asterix.om.base.temporal.GregorianCalendarSystem;
 import org.apache.asterix.om.base.temporal.GregorianCalendarSystem.Fields;
+import org.apache.asterix.runtime.exceptions.InvalidDataFormatException;
+import org.apache.asterix.runtime.exceptions.TypeMismatchException;
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.om.types.ATypeTag;
-import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
 import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.api.IPointable;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.primitive.VoidPointable;
@@ -58,14 +60,12 @@ public class AdjustDateTimeForTimeZoneDescriptor extends AbstractScalarFunctionD
      * @see org.apache.asterix.runtime.base.IScalarFunctionDynamicDescriptor#createEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory[])
      */
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
-
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
                 return new IScalarEvaluator() {
 
                     private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
@@ -82,7 +82,7 @@ public class AdjustDateTimeForTimeZoneDescriptor extends AbstractScalarFunctionD
                     private final UTF8StringWriter utf8Writer = new UTF8StringWriter();
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                         resultStorage.reset();
                         eval0.evaluate(tuple, argPtr0);
                         eval1.evaluate(tuple, argPtr1);
@@ -95,15 +95,13 @@ public class AdjustDateTimeForTimeZoneDescriptor extends AbstractScalarFunctionD
 
                         try {
                             if (bytes0[offset0] != ATypeTag.SERIALIZED_DATETIME_TYPE_TAG) {
-                                throw new AlgebricksException(
-                                        FID.getName() + ": expects type DATETIME/NULL for parameter 0 but got "
-                                                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes0[offset0]));
+                                throw new TypeMismatchException(getIdentifier(), 0, bytes0[offset0],
+                                        ATypeTag.SERIALIZED_DATETIME_TYPE_TAG);
                             }
 
                             if (bytes1[offset1] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
-                                throw new AlgebricksException(
-                                        FID.getName() + ": expects type STRING/NULL for parameter 1 but got "
-                                                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes1[offset1]));
+                                throw new TypeMismatchException(getIdentifier(), 1, bytes1[offset1],
+                                        ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                             }
 
                             utf8Ptr.set(bytes1, offset1 + 1, len1 - 1);
@@ -111,7 +109,7 @@ public class AdjustDateTimeForTimeZoneDescriptor extends AbstractScalarFunctionD
                                     utf8Ptr.getCharStartOffset());
 
                             if (!calInstance.validateTimeZone(timezone)) {
-                                throw new AlgebricksException(FID.getName() + ": wrong format for a time zone string!");
+                                throw new InvalidDataFormatException(getIdentifier(), "timezone");
                             }
 
                             long chronon = ADateTimeSerializerDeserializer.getChronon(bytes0, offset0 + 1);
@@ -124,8 +122,8 @@ public class AdjustDateTimeForTimeZoneDescriptor extends AbstractScalarFunctionD
 
                             out.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                             utf8Writer.writeUTF8(sbder.toString(), out);
-                        } catch (Exception e1) {
-                            throw new AlgebricksException(e1);
+                        } catch (IOException e1) {
+                            throw new HyracksDataException(e1);
                         }
                         result.set(resultStorage);
                     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/temporal/AdjustTimeForTimeZoneDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/temporal/AdjustTimeForTimeZoneDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/temporal/AdjustTimeForTimeZoneDescriptor.java
index bab00bd..9a2e91f 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/temporal/AdjustTimeForTimeZoneDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/temporal/AdjustTimeForTimeZoneDescriptor.java
@@ -19,6 +19,7 @@
 package org.apache.asterix.runtime.evaluators.functions.temporal;
 
 import java.io.DataOutput;
+import java.io.IOException;
 
 import org.apache.asterix.dataflow.data.nontagged.serde.ATimeSerializerDeserializer;
 import org.apache.asterix.om.base.temporal.ATimeParserFactory;
@@ -28,13 +29,14 @@ import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.om.types.ATypeTag;
-import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.asterix.runtime.exceptions.InvalidDataFormatException;
+import org.apache.asterix.runtime.exceptions.TypeMismatchException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
 import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.api.IPointable;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.primitive.VoidPointable;
@@ -57,14 +59,13 @@ public class AdjustTimeForTimeZoneDescriptor extends AbstractScalarFunctionDynam
      * @see org.apache.asterix.runtime.base.IScalarFunctionDynamicDescriptor#createEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory[])
      */
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
 
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
                 return new IScalarEvaluator() {
 
                     private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
@@ -79,7 +80,7 @@ public class AdjustTimeForTimeZoneDescriptor extends AbstractScalarFunctionDynam
                     private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                         resultStorage.reset();
                         eval0.evaluate(tuple, argPtr0);
                         eval1.evaluate(tuple, argPtr1);
@@ -92,22 +93,20 @@ public class AdjustTimeForTimeZoneDescriptor extends AbstractScalarFunctionDynam
 
                         try {
                             if (bytes0[offset0] != ATypeTag.SERIALIZED_TIME_TYPE_TAG) {
-                                throw new AlgebricksException(
-                                        FID.getName() + ": expects type TIME/NULL for parameter 0 but got "
-                                                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes0[offset0]));
+                                throw new TypeMismatchException(getIdentifier(), 0, bytes0[offset0],
+                                        ATypeTag.SERIALIZED_TIME_TYPE_TAG);
                             }
 
                             if (bytes1[offset1] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
-                                throw new AlgebricksException(
-                                        FID.getName() + ": expects type STRING/NULL for parameter 1 but got "
-                                                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes1[offset1]));
+                                throw new TypeMismatchException(getIdentifier(), 1, bytes1[offset1],
+                                        ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                             }
 
                             utf8Ptr.set(argPtr1.getByteArray(), offset1 + 1, len1 - 1);
                             int timezone = ATimeParserFactory.parseTimezonePart(bytes1, utf8Ptr.getCharStartOffset());
 
                             if (!calInstance.validateTimeZone(timezone)) {
-                                throw new AlgebricksException(FID.getName() + ": wrong format for a time zone string!");
+                                throw new InvalidDataFormatException(getIdentifier(), "timezone");
                             }
 
                             int chronon = ATimeSerializerDeserializer.getChronon(bytes0, offset0 + 1);
@@ -121,9 +120,8 @@ public class AdjustTimeForTimeZoneDescriptor extends AbstractScalarFunctionDynam
 
                             out.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                             writer.writeUTF8(sbder.toString(), out);
-
-                        } catch (Exception e1) {
-                            throw new AlgebricksException(e1);
+                        } catch (IOException e1) {
+                            throw new HyracksDataException(e1);
                         }
                         result.set(resultStorage);
                     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/temporal/CalendarDuartionFromDateDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/temporal/CalendarDuartionFromDateDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/temporal/CalendarDuartionFromDateDescriptor.java
index e38da7e..985fd53 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/temporal/CalendarDuartionFromDateDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/temporal/CalendarDuartionFromDateDescriptor.java
@@ -32,9 +32,8 @@ import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.BuiltinType;
-import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.asterix.runtime.exceptions.TypeMismatchException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
@@ -57,18 +56,14 @@ public class CalendarDuartionFromDateDescriptor extends AbstractScalarFunctionDy
         }
     };
 
-    /* (non-Javadoc)
-     * @see org.apache.asterix.runtime.base.IScalarFunctionDynamicDescriptor#createEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory[])
-     */
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
 
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
 
                 return new IScalarEvaluator() {
 
@@ -80,15 +75,15 @@ public class CalendarDuartionFromDateDescriptor extends AbstractScalarFunctionDy
                     private IScalarEvaluator eval1 = args[1].createScalarEvaluator(ctx);
 
                     @SuppressWarnings("unchecked")
-                    private ISerializerDeserializer<ADuration> durationSerde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.ADURATION);
+                    private ISerializerDeserializer<ADuration> durationSerde = AqlSerializerDeserializerProvider.
+                            INSTANCE.getSerializerDeserializer(BuiltinType.ADURATION);
 
                     private AMutableDuration aDuration = new AMutableDuration(0, 0);
 
                     private GregorianCalendarSystem calInstanct = GregorianCalendarSystem.getInstance();
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                         resultStorage.reset();
                         eval0.evaluate(tuple, argPtr0);
                         eval1.evaluate(tuple, argPtr1);
@@ -98,119 +93,114 @@ public class CalendarDuartionFromDateDescriptor extends AbstractScalarFunctionDy
                         byte[] bytes1 = argPtr1.getByteArray();
                         int offset1 = argPtr1.getStartOffset();
 
-                        try {
-                            if (bytes0[offset0] != ATypeTag.SERIALIZED_DATE_TYPE_TAG) {
-                                throw new AlgebricksException(
-                                        FID.getName() + ": expects type DATE/NULL for parameter 0 but got "
-                                                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes0[offset0]));
-                            }
+                        if (bytes0[offset0] != ATypeTag.SERIALIZED_DATE_TYPE_TAG) {
+                            throw new TypeMismatchException(getIdentifier(), 0, bytes0[offset0],
+                                    ATypeTag.SERIALIZED_DATE_TYPE_TAG);
+                        }
+
+                        if (bytes1[offset1] != ATypeTag.SERIALIZED_DURATION_TYPE_TAG) {
+                            throw new TypeMismatchException(getIdentifier(), 1, bytes1[offset1],
+                                    ATypeTag.SERIALIZED_DURATION_TYPE_TAG);
+                        }
+
+                        int yearMonthDurationInMonths = ADurationSerializerDeserializer.getYearMonth(bytes1,
+                                offset1 + 1);
+                        long dayTimeDurationInMs = ADurationSerializerDeserializer.getDayTime(bytes1, offset1 + 1);
+
+                        long startingTimePoint = ADateSerializerDeserializer.getChronon(bytes0, offset0 + 1)
+                                * GregorianCalendarSystem.CHRONON_OF_DAY;
+
+                        long endingTimePoint = DurationArithmeticOperations.addDuration(startingTimePoint,
+                                yearMonthDurationInMonths, dayTimeDurationInMs, false);
+
+                        if (startingTimePoint == endingTimePoint) {
+                            aDuration.setValue(0, 0);
+                        } else {
 
-                            if (bytes1[offset1] != ATypeTag.SERIALIZED_DURATION_TYPE_TAG) {
-                                throw new AlgebricksException(
-                                        FID.getName() + ": expects type DURATION/NULL for parameter 1 but got "
-                                                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes1[offset1]));
+                            boolean negative = false;
+
+                            if (endingTimePoint < startingTimePoint) {
+                                negative = true;
+                                // swap the starting and ending time, so that ending time is always larger than the
+                                // starting time.
+                                long tmpTime = endingTimePoint;
+                                endingTimePoint = startingTimePoint;
+                                startingTimePoint = tmpTime;
                             }
 
-                            int yearMonthDurationInMonths = ADurationSerializerDeserializer.getYearMonth(bytes1,
-                                    offset1 + 1);
-                            long dayTimeDurationInMs = ADurationSerializerDeserializer.getDayTime(bytes1, offset1 + 1);
+                            int year0 = calInstanct.getYear(startingTimePoint);
+                            int month0 = calInstanct.getMonthOfYear(startingTimePoint, year0);
+
+                            int year1 = calInstanct.getYear(endingTimePoint);
+                            int month1 = calInstanct.getMonthOfYear(endingTimePoint, year1);
+
+                            int year = year1 - year0;
+                            int month = month1 - month0;
+                            int day = calInstanct.getDayOfMonthYear(endingTimePoint, year1, month1)
+                                    - calInstanct.getDayOfMonthYear(startingTimePoint, year0, month0);
+                            int hour = calInstanct.getHourOfDay(endingTimePoint)
+                                    - calInstanct.getHourOfDay(startingTimePoint);
+                            int min = calInstanct.getMinOfHour(endingTimePoint)
+                                    - calInstanct.getMinOfHour(startingTimePoint);
+                            int sec = calInstanct.getSecOfMin(endingTimePoint)
+                                    - calInstanct.getSecOfMin(startingTimePoint);
+                            int ms = calInstanct.getMillisOfSec(endingTimePoint)
+                                    - calInstanct.getMillisOfSec(startingTimePoint);
+
+                            if (ms < 0) {
+                                ms += GregorianCalendarSystem.CHRONON_OF_SECOND;
+                                sec -= 1;
+                            }
 
-                            long startingTimePoint = ADateSerializerDeserializer.getChronon(bytes0, offset0 + 1)
-                                    * GregorianCalendarSystem.CHRONON_OF_DAY;
+                            if (sec < 0) {
+                                sec += GregorianCalendarSystem.CHRONON_OF_MINUTE
+                                        / GregorianCalendarSystem.CHRONON_OF_SECOND;
+                                min -= 1;
+                            }
 
-                            long endingTimePoint = DurationArithmeticOperations.addDuration(startingTimePoint,
-                                    yearMonthDurationInMonths, dayTimeDurationInMs, false);
+                            if (min < 0) {
+                                min += GregorianCalendarSystem.CHRONON_OF_HOUR
+                                        / GregorianCalendarSystem.CHRONON_OF_MINUTE;
+                                hour -= 1;
+                            }
 
-                            if (startingTimePoint == endingTimePoint) {
-                                aDuration.setValue(0, 0);
-                            } else {
+                            if (hour < 0) {
+                                hour += GregorianCalendarSystem.CHRONON_OF_DAY
+                                        / GregorianCalendarSystem.CHRONON_OF_HOUR;
+                                day -= 1;
+                            }
 
-                                boolean negative = false;
-
-                                if (endingTimePoint < startingTimePoint) {
-                                    negative = true;
-                                    // swap the starting and ending time, so that ending time is always larger than the starting time.
-                                    long tmpTime = endingTimePoint;
-                                    endingTimePoint = startingTimePoint;
-                                    startingTimePoint = tmpTime;
-                                }
-
-                                int year0 = calInstanct.getYear(startingTimePoint);
-                                int month0 = calInstanct.getMonthOfYear(startingTimePoint, year0);
-
-                                int year1 = calInstanct.getYear(endingTimePoint);
-                                int month1 = calInstanct.getMonthOfYear(endingTimePoint, year1);
-
-                                int year = year1 - year0;
-                                int month = month1 - month0;
-                                int day = calInstanct.getDayOfMonthYear(endingTimePoint, year1, month1)
-                                        - calInstanct.getDayOfMonthYear(startingTimePoint, year0, month0);
-                                int hour = calInstanct.getHourOfDay(endingTimePoint)
-                                        - calInstanct.getHourOfDay(startingTimePoint);
-                                int min = calInstanct.getMinOfHour(endingTimePoint)
-                                        - calInstanct.getMinOfHour(startingTimePoint);
-                                int sec = calInstanct.getSecOfMin(endingTimePoint)
-                                        - calInstanct.getSecOfMin(startingTimePoint);
-                                int ms = calInstanct.getMillisOfSec(endingTimePoint)
-                                        - calInstanct.getMillisOfSec(startingTimePoint);
-
-                                if (ms < 0) {
-                                    ms += GregorianCalendarSystem.CHRONON_OF_SECOND;
-                                    sec -= 1;
-                                }
-
-                                if (sec < 0) {
-                                    sec += GregorianCalendarSystem.CHRONON_OF_MINUTE
-                                            / GregorianCalendarSystem.CHRONON_OF_SECOND;
-                                    min -= 1;
-                                }
-
-                                if (min < 0) {
-                                    min += GregorianCalendarSystem.CHRONON_OF_HOUR
-                                            / GregorianCalendarSystem.CHRONON_OF_MINUTE;
-                                    hour -= 1;
-                                }
-
-                                if (hour < 0) {
-                                    hour += GregorianCalendarSystem.CHRONON_OF_DAY
-                                            / GregorianCalendarSystem.CHRONON_OF_HOUR;
-                                    day -= 1;
-                                }
-
-                                if (day < 0) {
-                                    boolean isLeapYear = calInstanct.isLeapYear(year1);
-                                    // need to "borrow" the days in previous month to make the day positive; when month is 1 (Jan), Dec will be borrowed
-                                    day += (isLeapYear)
-                                            ? (GregorianCalendarSystem.DAYS_OF_MONTH_LEAP[(12 + month1 - 2) % 12])
-                                            : (GregorianCalendarSystem.DAYS_OF_MONTH_ORDI[(12 + month1 - 2) % 12]);
-                                    month -= 1;
-                                }
-
-                                if (month < 0) {
-                                    month += GregorianCalendarSystem.MONTHS_IN_A_YEAR;
-                                    year -= 1;
-                                }
-
-                                if (negative) {
-                                    aDuration.setValue(-1 * (year * GregorianCalendarSystem.MONTHS_IN_A_YEAR + month),
-                                            -1 * (day * GregorianCalendarSystem.CHRONON_OF_DAY
-                                                    + hour * GregorianCalendarSystem.CHRONON_OF_HOUR
-                                                    + min * GregorianCalendarSystem.CHRONON_OF_MINUTE
-                                                    + sec * GregorianCalendarSystem.CHRONON_OF_SECOND + ms));
-                                } else {
-                                    aDuration.setValue(year * GregorianCalendarSystem.MONTHS_IN_A_YEAR + month,
-                                            day * GregorianCalendarSystem.CHRONON_OF_DAY
-                                                    + hour * GregorianCalendarSystem.CHRONON_OF_HOUR
-                                                    + min * GregorianCalendarSystem.CHRONON_OF_MINUTE
-                                                    + sec * GregorianCalendarSystem.CHRONON_OF_SECOND + ms);
-                                }
+                            if (day < 0) {
+                                boolean isLeapYear = calInstanct.isLeapYear(year1);
+                                // need to "borrow" the days in previous month to make the day positive; when month is
+                                // 1 (Jan), Dec will be borrowed
+                                day += isLeapYear
+                                        ? (GregorianCalendarSystem.DAYS_OF_MONTH_LEAP[(12 + month1 - 2) % 12])
+                                        : (GregorianCalendarSystem.DAYS_OF_MONTH_ORDI[(12 + month1 - 2) % 12]);
+                                month -= 1;
                             }
 
-                            durationSerde.serialize(aDuration, out);
+                            if (month < 0) {
+                                month += GregorianCalendarSystem.MONTHS_IN_A_YEAR;
+                                year -= 1;
+                            }
 
-                        } catch (HyracksDataException hex) {
-                            throw new AlgebricksException(hex);
+                            if (negative) {
+                                aDuration.setValue(-1 * (year * GregorianCalendarSystem.MONTHS_IN_A_YEAR + month),
+                                        -1 * (day * GregorianCalendarSystem.CHRONON_OF_DAY
+                                                + hour * GregorianCalendarSystem.CHRONON_OF_HOUR
+                                                + min * GregorianCalendarSystem.CHRONON_OF_MINUTE
+                                                + sec * GregorianCalendarSystem.CHRONON_OF_SECOND + ms));
+                            } else {
+                                aDuration.setValue(year * GregorianCalendarSystem.MONTHS_IN_A_YEAR + month,
+                                        day * GregorianCalendarSystem.CHRONON_OF_DAY
+                                                + hour * GregorianCalendarSystem.CHRONON_OF_HOUR
+                                                + min * GregorianCalendarSystem.CHRONON_OF_MINUTE
+                                                + sec * GregorianCalendarSystem.CHRONON_OF_SECOND + ms);
+                            }
                         }
+
+                        durationSerde.serialize(aDuration, out);
                         result.set(resultStorage);
                     }
                 };


Mime
View raw message