- Fixed Type Casting issue
- Reorganized duplicated internal class in the DelimitedDataParser and DelimitedDataParserFactory
- Prevented a user from creating an inverted index on a dataset with a variable-length PK
- INT64 is now the default type
- Issue 852 fixed

Change-Id: I2d71e8a21da4f709c3259a3d3f678c640f9e1160
Reviewed-on: http://fulliautomatix.ics.uci.edu:8443/192
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <westmann@gmail.com>
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/AbstractSerializableAvgAggregateFunction.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/AbstractSerializableAvgAggregateFunction.java
index 8f99129..738918c 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/AbstractSerializableAvgAggregateFunction.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/AbstractSerializableAvgAggregateFunction.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -47,6 +47,7 @@
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopySerializableAggregateFunction;
 import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
@@ -179,7 +180,7 @@
             try {
                 recType = new ARecordType(null, new String[] { "sum", "count" }, new IAType[] { BuiltinType.ADOUBLE,
                         BuiltinType.AINT64 }, false);
-            } catch (AsterixException e) {
+            } catch (AsterixException | HyracksDataException e) {
                 throw new AlgebricksException(e);
             }
             recordEval = new ClosedRecordConstructorEval(recType, new ICopyEvaluator[] { evalSum, evalCount },
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/AbstractAvgAggregateFunction.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/AbstractAvgAggregateFunction.java
index f83f097..1b2caf6 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/AbstractAvgAggregateFunction.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/AbstractAvgAggregateFunction.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -47,6 +47,7 @@
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
@@ -95,7 +96,7 @@
         try {
             tmpRecType = new ARecordType(null, new String[] { "sum", "count" }, new IAType[] { BuiltinType.ADOUBLE,
                     BuiltinType.AINT64 }, false);
-        } catch (AsterixException e) {
+        } catch (AsterixException | HyracksDataException e) {
             throw new AlgebricksException(e);
         }
 
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/AbstractMinMaxAggregateFunction.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/AbstractMinMaxAggregateFunction.java
index b961ef1..bffa7b0 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/AbstractMinMaxAggregateFunction.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/AbstractMinMaxAggregateFunction.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,13 +21,14 @@
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.EnumDeserializer;
 import edu.uci.ics.asterix.om.types.hierachy.ATypeHierarchy;
-import edu.uci.ics.asterix.om.types.hierachy.ITypePromoteComputer;
+import edu.uci.ics.asterix.om.types.hierachy.ITypeConvertComputer;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyAggregateFunction;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparator;
 import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparatorFactory;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
@@ -40,7 +41,7 @@
     private ICopyEvaluator eval;
     protected ATypeTag aggType;
     private IBinaryComparator cmp;
-    private ITypePromoteComputer tpc;
+    private ITypeConvertComputer tpc;
     private final boolean isMin;
 
     public AbstractMinMaxAggregateFunction(ICopyEvaluatorFactory[] args, IDataOutputProvider provider, boolean isMin)
@@ -100,7 +101,7 @@
                 if (tpc != null) {
                     tempValForCasting.reset();
                     try {
-                        tpc.promote(outputVal.getByteArray(), outputVal.getStartOffset() + 1,
+                        tpc.convertType(outputVal.getByteArray(), outputVal.getStartOffset() + 1,
                                 outputVal.getLength() - 1, tempValForCasting.getDataOutput());
                     } catch (IOException e) {
                         throw new AlgebricksException(e);
@@ -108,9 +109,13 @@
                     outputVal.reset();
                     outputVal.assign(tempValForCasting);
                 }
-                if (cmp.compare(inputVal.getByteArray(), inputVal.getStartOffset(), inputVal.getLength(),
-                        outputVal.getByteArray(), outputVal.getStartOffset(), outputVal.getLength()) < 0) {
-                    outputVal.assign(inputVal);
+                try {
+                    if (cmp.compare(inputVal.getByteArray(), inputVal.getStartOffset(), inputVal.getLength(),
+                            outputVal.getByteArray(), outputVal.getStartOffset(), outputVal.getLength()) < 0) {
+                        outputVal.assign(inputVal);
+                    }
+                } catch (HyracksDataException e) {
+                    throw new AlgebricksException(e);
                 }
 
             } else {
@@ -118,20 +123,28 @@
                 if (tpc != null) {
                     tempValForCasting.reset();
                     try {
-                        tpc.promote(inputVal.getByteArray(), inputVal.getStartOffset() + 1, inputVal.getLength() - 1,
-                                tempValForCasting.getDataOutput());
+                        tpc.convertType(inputVal.getByteArray(), inputVal.getStartOffset() + 1,
+                                inputVal.getLength() - 1, tempValForCasting.getDataOutput());
                     } catch (IOException e) {
                         throw new AlgebricksException(e);
                     }
-                    if (cmp.compare(tempValForCasting.getByteArray(), tempValForCasting.getStartOffset(),
-                            tempValForCasting.getLength(), outputVal.getByteArray(), outputVal.getStartOffset(),
-                            outputVal.getLength()) < 0) {
-                        outputVal.assign(tempValForCasting);
+                    try {
+                        if (cmp.compare(tempValForCasting.getByteArray(), tempValForCasting.getStartOffset(),
+                                tempValForCasting.getLength(), outputVal.getByteArray(), outputVal.getStartOffset(),
+                                outputVal.getLength()) < 0) {
+                            outputVal.assign(tempValForCasting);
+                        }
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
                     }
                 } else {
-                    if (cmp.compare(inputVal.getByteArray(), inputVal.getStartOffset(), inputVal.getLength(),
-                            outputVal.getByteArray(), outputVal.getStartOffset(), outputVal.getLength()) < 0) {
-                        outputVal.assign(inputVal);
+                    try {
+                        if (cmp.compare(inputVal.getByteArray(), inputVal.getStartOffset(), inputVal.getLength(),
+                                outputVal.getByteArray(), outputVal.getStartOffset(), outputVal.getLength()) < 0) {
+                            outputVal.assign(inputVal);
+                        }
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
                     }
                 }
 
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalDayAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalDayAccessor.java
index 88285e4..fb9bf4c 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalDayAccessor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalDayAccessor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,8 +21,8 @@
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.AInt32;
-import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
 import edu.uci.ics.asterix.om.base.ANull;
 import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
@@ -83,9 +83,9 @@
 
                     // for output: type integer
                     @SuppressWarnings("unchecked")
-                    private ISerializerDeserializer<AInt32> intSerde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.AINT32);
-                    private AMutableInt32 aMutableInt32 = new AMutableInt32(0);
+                    private ISerializerDeserializer<AInt64> intSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AINT64);
+                    private AMutableInt64 aMutableInt64 = new AMutableInt64(0);
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
@@ -99,9 +99,9 @@
                         try {
 
                             if (bytes[0] == SER_DURATION_TYPE_TAG) {
-                                aMutableInt32.setValue(calSystem.getDurationDay(ADurationSerializerDeserializer
+                                aMutableInt64.setValue(calSystem.getDurationDay(ADurationSerializerDeserializer
                                         .getDayTime(bytes, 1)));
-                                intSerde.serialize(aMutableInt32, out);
+                                intSerde.serialize(aMutableInt64, out);
                                 return;
                             }
 
@@ -122,8 +122,8 @@
                             int month = calSystem.getMonthOfYear(chrononTimeInMs, year);
                             int day = calSystem.getDayOfMonthYear(chrononTimeInMs, year, month);
 
-                            aMutableInt32.setValue(day);
-                            intSerde.serialize(aMutableInt32, out);
+                            aMutableInt64.setValue(day);
+                            intSerde.serialize(aMutableInt64, out);
 
                         } catch (IOException e) {
                             throw new AlgebricksException(e);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalHourAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalHourAccessor.java
index dee5723..33dc9fd 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalHourAccessor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalHourAccessor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,8 +21,8 @@
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.AInt32;
-import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
 import edu.uci.ics.asterix.om.base.ANull;
 import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
@@ -84,9 +84,9 @@
 
                     // for output: type integer
                     @SuppressWarnings("unchecked")
-                    private ISerializerDeserializer<AInt32> intSerde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.AINT32);
-                    private AMutableInt32 aMutableInt32 = new AMutableInt32(0);
+                    private ISerializerDeserializer<AInt64> intSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AINT64);
+                    private AMutableInt64 aMutableInt64 = new AMutableInt64(0);
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
@@ -100,9 +100,9 @@
                         try {
 
                             if (bytes[0] == SER_DURATION_TYPE_TAG) {
-                                aMutableInt32.setValue(calSystem.getDurationHour(ADurationSerializerDeserializer
+                                aMutableInt64.setValue(calSystem.getDurationHour(ADurationSerializerDeserializer
                                         .getDayTime(bytes, 1)));
-                                intSerde.serialize(aMutableInt32, out);
+                                intSerde.serialize(aMutableInt64, out);
                                 return;
                             }
 
@@ -120,8 +120,8 @@
 
                             int hour = calSystem.getHourOfDay(chrononTimeInMs);
 
-                            aMutableInt32.setValue(hour);
-                            intSerde.serialize(aMutableInt32, out);
+                            aMutableInt64.setValue(hour);
+                            intSerde.serialize(aMutableInt64, out);
 
                         } catch (IOException e) {
                             throw new AlgebricksException(e);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMillisecondAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMillisecondAccessor.java
index f75f9f1..701ecd3 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMillisecondAccessor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMillisecondAccessor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,8 +21,8 @@
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.AInt32;
-import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
 import edu.uci.ics.asterix.om.base.ANull;
 import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
@@ -84,9 +84,9 @@
 
                     // for output: type integer
                     @SuppressWarnings("unchecked")
-                    private ISerializerDeserializer<AInt32> intSerde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.AINT32);
-                    private AMutableInt32 aMutableInt32 = new AMutableInt32(0);
+                    private ISerializerDeserializer<AInt64> intSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AINT64);
+                    private AMutableInt64 aMutableInt64 = new AMutableInt64(0);
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
@@ -100,9 +100,9 @@
                         try {
 
                             if (bytes[0] == SER_DURATION_TYPE_TAG) {
-                                aMutableInt32.setValue(calSystem.getDurationMillisecond(ADurationSerializerDeserializer
+                                aMutableInt64.setValue(calSystem.getDurationMillisecond(ADurationSerializerDeserializer
                                         .getDayTime(bytes, 1)));
-                                intSerde.serialize(aMutableInt32, out);
+                                intSerde.serialize(aMutableInt64, out);
                                 return;
                             }
 
@@ -120,8 +120,8 @@
 
                             int ms = calSystem.getMillisOfSec(chrononTimeInMs);
 
-                            aMutableInt32.setValue(ms);
-                            intSerde.serialize(aMutableInt32, out);
+                            aMutableInt64.setValue(ms);
+                            intSerde.serialize(aMutableInt64, out);
 
                         } catch (IOException e) {
                             throw new AlgebricksException(e);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMinuteAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMinuteAccessor.java
index eb09547..13c3213 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMinuteAccessor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMinuteAccessor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,8 +21,8 @@
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.AInt32;
-import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
 import edu.uci.ics.asterix.om.base.ANull;
 import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
@@ -84,9 +84,9 @@
 
                     // for output: type integer
                     @SuppressWarnings("unchecked")
-                    private ISerializerDeserializer<AInt32> intSerde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.AINT32);
-                    private AMutableInt32 aMutableInt32 = new AMutableInt32(0);
+                    private ISerializerDeserializer<AInt64> intSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AINT64);
+                    private AMutableInt64 aMutableInt64 = new AMutableInt64(0);
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
@@ -100,9 +100,9 @@
                         try {
 
                             if (bytes[0] == SER_DURATION_TYPE_TAG) {
-                                aMutableInt32.setValue(calSystem.getDurationMinute(ADurationSerializerDeserializer
+                                aMutableInt64.setValue(calSystem.getDurationMinute(ADurationSerializerDeserializer
                                         .getDayTime(bytes, 1)));
-                                intSerde.serialize(aMutableInt32, out);
+                                intSerde.serialize(aMutableInt64, out);
                                 return;
                             }
 
@@ -120,8 +120,8 @@
 
                             int min = calSystem.getMinOfHour(chrononTimeInMs);
 
-                            aMutableInt32.setValue(min);
-                            intSerde.serialize(aMutableInt32, out);
+                            aMutableInt64.setValue(min);
+                            intSerde.serialize(aMutableInt64, out);
 
                         } catch (IOException e) {
                             throw new AlgebricksException(e);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMonthAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMonthAccessor.java
index a1abbfc..85c6aee 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMonthAccessor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMonthAccessor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,8 +21,8 @@
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.AInt32;
-import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
 import edu.uci.ics.asterix.om.base.ANull;
 import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
@@ -84,9 +84,9 @@
 
                     // for output: type integer
                     @SuppressWarnings("unchecked")
-                    private ISerializerDeserializer<AInt32> intSerde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.AINT32);
-                    private AMutableInt32 aMutableInt32 = new AMutableInt32(0);
+                    private ISerializerDeserializer<AInt64> intSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AINT64);
+                    private AMutableInt64 aMutableInt64 = new AMutableInt64(0);
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
@@ -100,9 +100,9 @@
                         try {
 
                             if (bytes[0] == SER_DURATION_TYPE_TAG) {
-                                aMutableInt32.setValue(calSystem.getDurationMonth(ADurationSerializerDeserializer
+                                aMutableInt64.setValue(calSystem.getDurationMonth(ADurationSerializerDeserializer
                                         .getYearMonth(bytes, 1)));
-                                intSerde.serialize(aMutableInt32, out);
+                                intSerde.serialize(aMutableInt64, out);
                                 return;
                             }
 
@@ -122,8 +122,8 @@
                             int year = calSystem.getYear(chrononTimeInMs);
                             int month = calSystem.getMonthOfYear(chrononTimeInMs, year);
 
-                            aMutableInt32.setValue(month);
-                            intSerde.serialize(aMutableInt32, out);
+                            aMutableInt64.setValue(month);
+                            intSerde.serialize(aMutableInt64, out);
 
                         } catch (IOException e) {
                             throw new AlgebricksException(e);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalSecondAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalSecondAccessor.java
index 6c61935..25ebbbc 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalSecondAccessor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalSecondAccessor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,8 +21,8 @@
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.AInt32;
-import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
 import edu.uci.ics.asterix.om.base.ANull;
 import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
@@ -84,9 +84,9 @@
 
                     // for output: type integer
                     @SuppressWarnings("unchecked")
-                    private ISerializerDeserializer<AInt32> intSerde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.AINT32);
-                    private AMutableInt32 aMutableInt32 = new AMutableInt32(0);
+                    private ISerializerDeserializer<AInt64> intSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AINT64);
+                    private AMutableInt64 aMutableInt64 = new AMutableInt64(0);
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
@@ -100,9 +100,9 @@
                         try {
 
                             if (bytes[0] == SER_DURATION_TYPE_TAG) {
-                                aMutableInt32.setValue(calSystem.getDurationSecond(ADurationSerializerDeserializer
+                                aMutableInt64.setValue(calSystem.getDurationSecond(ADurationSerializerDeserializer
                                         .getDayTime(bytes, 1)));
-                                intSerde.serialize(aMutableInt32, out);
+                                intSerde.serialize(aMutableInt64, out);
                                 return;
                             }
 
@@ -120,8 +120,8 @@
 
                             int sec = calSystem.getSecOfMin(chrononTimeInMs);
 
-                            aMutableInt32.setValue(sec);
-                            intSerde.serialize(aMutableInt32, out);
+                            aMutableInt64.setValue(sec);
+                            intSerde.serialize(aMutableInt64, out);
 
                         } catch (IOException e) {
                             throw new AlgebricksException(e);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalYearAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalYearAccessor.java
index 852852b..b9520d9 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalYearAccessor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalYearAccessor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,8 +21,8 @@
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.AInt32;
-import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
 import edu.uci.ics.asterix.om.base.ANull;
 import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
@@ -82,9 +82,9 @@
 
                     // for output: type integer
                     @SuppressWarnings("unchecked")
-                    private ISerializerDeserializer<AInt32> intSerde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.AINT32);
-                    private AMutableInt32 aMutableInt32 = new AMutableInt32(0);
+                    private ISerializerDeserializer<AInt64> intSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AINT64);
+                    private AMutableInt64 aMutableInt64 = new AMutableInt64(0);
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
@@ -98,9 +98,9 @@
                         try {
 
                             if (bytes[0] == SER_DURATION_TYPE_TAG) {
-                                aMutableInt32.setValue(calSystem.getDurationYear(ADurationSerializerDeserializer
+                                aMutableInt64.setValue(calSystem.getDurationYear(ADurationSerializerDeserializer
                                         .getYearMonth(bytes, 1)));
-                                intSerde.serialize(aMutableInt32, out);
+                                intSerde.serialize(aMutableInt64, out);
                                 return;
                             }
 
@@ -128,8 +128,8 @@
                                             + (UTF8StringPointable.charAt(bytes, 5) - '0') * 10
                                             + (UTF8StringPointable.charAt(bytes, 6) - '0');
                                 }
-                                aMutableInt32.setValue(year);
-                                intSerde.serialize(aMutableInt32, out);
+                                aMutableInt64.setValue(year);
+                                intSerde.serialize(aMutableInt64, out);
                                 return;
                             } else {
                                 throw new AlgebricksException("Inapplicable input type: " + bytes[0]);
@@ -137,8 +137,8 @@
 
                             int year = calSystem.getYear(chrononTimeInMs);
 
-                            aMutableInt32.setValue(year);
-                            intSerde.serialize(aMutableInt32, out);
+                            aMutableInt64.setValue(year);
+                            intSerde.serialize(aMutableInt64, out);
 
                         } catch (IOException e) {
                             throw new AlgebricksException(e);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/AbstractAsterixListIterator.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/AbstractAsterixListIterator.java
index e95e9cb..7dad6ee 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/AbstractAsterixListIterator.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/AbstractAsterixListIterator.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,10 +17,11 @@
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.common.exceptions.AsterixRuntimeException;
 import edu.uci.ics.asterix.formats.nontagged.AqlBinaryComparatorFactoryProvider;
+import edu.uci.ics.asterix.fuzzyjoin.similarity.IListIterator;
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.EnumDeserializer;
-import edu.uci.ics.asterix.fuzzyjoin.similarity.IListIterator;
 import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparator;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 
 public abstract class AbstractAsterixListIterator implements IListIterator {
 
@@ -38,7 +39,7 @@
     protected final boolean ignoreCase = true;
 
     @Override
-    public int compare(IListIterator cmpIter) {
+    public int compare(IListIterator cmpIter) throws HyracksDataException {
         return cmp.compare(data, pos, -1, cmpIter.getData(), cmpIter.getPos(), -1);
     }
 
@@ -103,10 +104,22 @@
         this.listLength = getListLength(data, startOff);
         ATypeTag tag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data[startOff + 1]);
         switch (tag) {
+            case INT64: {
+                cmp = AqlBinaryComparatorFactoryProvider.LONG_POINTABLE_INSTANCE.createBinaryComparator();
+                break;
+            }
             case INT32: {
                 cmp = AqlBinaryComparatorFactoryProvider.INTEGER_POINTABLE_INSTANCE.createBinaryComparator();
                 break;
             }
+            case INT16: {
+                cmp = AqlBinaryComparatorFactoryProvider.SHORT_POINTABLE_INSTANCE.createBinaryComparator();
+                break;
+            }
+            case INT8: {
+                cmp = AqlBinaryComparatorFactoryProvider.BYTE_POINTABLE_INSTANCE.createBinaryComparator();
+                break;
+            }
             case FLOAT: {
                 cmp = AqlBinaryComparatorFactoryProvider.FLOAT_POINTABLE_INSTANCE.createBinaryComparator();
                 break;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/EditDistanceCheckEvaluator.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/EditDistanceCheckEvaluator.java
index 272b417..cd1c55f 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/EditDistanceCheckEvaluator.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/EditDistanceCheckEvaluator.java
@@ -23,20 +23,20 @@
 import edu.uci.ics.asterix.om.types.AOrderedListType;
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
-import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.om.types.hierachy.ATypeHierarchy;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
-import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
 public class EditDistanceCheckEvaluator extends EditDistanceEvaluator {
 
     protected final ICopyEvaluator edThreshEval;
-    protected int edThresh = -1;
+    protected long edThresh = -1;
     protected final OrderedListBuilder listBuilder;
     protected ArrayBackedValueStorage listItemVal;
     @SuppressWarnings("unchecked")
@@ -57,21 +57,21 @@
         super.runArgEvals(tuple);
         int edThreshStart = argOut.getLength();
         edThreshEval.evaluate(tuple);
-        if (argOut.getByteArray()[edThreshStart] != SER_INT32_TYPE_TAG) {
-            throw new AlgebricksException("Invalid threshold type, expected INT32 but got "
-                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[edThreshStart]) + ".");
+        try {
+            edThresh = ATypeHierarchy.getIntegerValue(argOut.getByteArray(), edThreshStart);
+        } catch (HyracksDataException e) {
+            throw new AlgebricksException(e);
         }
-        edThresh = IntegerPointable.getInteger(argOut.getByteArray(), edThreshStart + typeIndicatorSize);
     }
 
     @Override
     protected int computeResult(byte[] bytes, int firstStart, int secondStart, ATypeTag argType)
-            throws AlgebricksException {
+            throws AlgebricksException, HyracksDataException {
         switch (argType) {
 
             case STRING: {
-                return ed.UTF8StringEditDistance(bytes, firstStart + typeIndicatorSize, secondStart
-                        + typeIndicatorSize, edThresh);
+                return ed.UTF8StringEditDistance(bytes, firstStart + typeIndicatorSize,
+                        secondStart + typeIndicatorSize, (int) edThresh);
             }
 
             case ORDEREDLIST: {
@@ -98,8 +98,8 @@
         listBuilder.addItem(listItemVal);
 
         listItemVal.reset();
-        aInt32.setValue((matches) ? ed : Integer.MAX_VALUE);
-        int32Serde.serialize(aInt32, listItemVal.getDataOutput());
+        aInt64.setValue((matches) ? ed : Integer.MAX_VALUE);
+        int64Serde.serialize(aInt64, listItemVal.getDataOutput());
         listBuilder.addItem(listItemVal);
 
         listBuilder.write(out, true);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/EditDistanceContainsEvaluator.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/EditDistanceContainsEvaluator.java
index 1dac595..73da275 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/EditDistanceContainsEvaluator.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/EditDistanceContainsEvaluator.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,10 +18,11 @@
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
 
 public class EditDistanceContainsEvaluator extends EditDistanceCheckEvaluator {
-    
+
     public EditDistanceContainsEvaluator(ICopyEvaluatorFactory[] args, IDataOutputProvider output)
             throws AlgebricksException {
         super(args, output);
@@ -34,13 +35,17 @@
 
             case STRING: {
                 return ed.UTF8StringEditDistanceContains(argOut.getByteArray(), firstStart + typeIndicatorSize,
-                        secondStart + typeIndicatorSize, edThresh);
+                        secondStart + typeIndicatorSize, (int) edThresh);
             }
 
             case ORDEREDLIST: {
                 firstOrdListIter.reset(bytes, firstStart);
                 secondOrdListIter.reset(bytes, secondStart);
-                return ed.getSimilarityContains(firstOrdListIter, secondOrdListIter, edThresh);
+                try {
+                    return ed.getSimilarityContains(firstOrdListIter, secondOrdListIter, (int) edThresh);
+                } catch (HyracksDataException e) {
+                    throw new AlgebricksException(e);
+                }
             }
 
             default: {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/EditDistanceEvaluator.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/EditDistanceEvaluator.java
index 7ddd957..4268437 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/EditDistanceEvaluator.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/EditDistanceEvaluator.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,17 +18,18 @@
 import java.io.IOException;
 
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.AInt32;
-import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.fuzzyjoin.similarity.SimilarityMetricEditDistance;
+import edu.uci.ics.asterix.om.base.AInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
 import edu.uci.ics.asterix.om.base.ANull;
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.EnumDeserializer;
-import edu.uci.ics.asterix.fuzzyjoin.similarity.SimilarityMetricEditDistance;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
@@ -46,10 +47,10 @@
     protected final AsterixOrderedListIterator firstOrdListIter = new AsterixOrderedListIterator();
     protected final AsterixOrderedListIterator secondOrdListIter = new AsterixOrderedListIterator();
     protected int editDistance = 0;
-    protected final AMutableInt32 aInt32 = new AMutableInt32(-1);
+    protected final AMutableInt64 aInt64 = new AMutableInt64(-1);
     @SuppressWarnings("unchecked")
-    protected final ISerializerDeserializer<AInt32> int32Serde = AqlSerializerDeserializerProvider.INSTANCE
-            .getSerializerDeserializer(BuiltinType.AINT32);
+    protected final ISerializerDeserializer<AInt64> int64Serde = AqlSerializerDeserializerProvider.INSTANCE
+            .getSerializerDeserializer(BuiltinType.AINT64);
     @SuppressWarnings("unchecked")
     private final ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
             .getSerializerDeserializer(BuiltinType.ANULL);
@@ -82,7 +83,11 @@
         if (itemTypeTag == ATypeTag.ANY)
             throw new AlgebricksException("\n Edit Distance can only be called on homogenous lists");
 
-        editDistance = computeResult(argOut.getByteArray(), firstStart, secondStart, firstTypeTag);
+        try {
+            editDistance = computeResult(argOut.getByteArray(), firstStart, secondStart, firstTypeTag);
+        } catch (HyracksDataException e1) {
+            throw new AlgebricksException(e1);
+        }
 
         try {
             writeResult(editDistance);
@@ -104,7 +109,7 @@
     }
 
     protected int computeResult(byte[] bytes, int firstStart, int secondStart, ATypeTag argType)
-            throws AlgebricksException {
+            throws AlgebricksException, HyracksDataException {
         switch (argType) {
 
             case STRING: {
@@ -115,7 +120,11 @@
             case ORDEREDLIST: {
                 firstOrdListIter.reset(bytes, firstStart);
                 secondOrdListIter.reset(bytes, secondStart);
-                return (int) ed.getSimilarity(firstOrdListIter, secondOrdListIter);
+                try {
+                    return (int) ed.getSimilarity(firstOrdListIter, secondOrdListIter);
+                } catch (HyracksDataException e) {
+                    throw new AlgebricksException(e);
+                }
             }
 
             default: {
@@ -130,7 +139,7 @@
         // edit distance between null and anything else is undefined
         if (typeTag1 == ATypeTag.NULL || typeTag2 == ATypeTag.NULL) {
             try {
-               nullSerde.serialize(ANull.NULL, out);
+                nullSerde.serialize(ANull.NULL, out);
             } catch (IOException e) {
                 throw new AlgebricksException(e);
             }
@@ -146,7 +155,7 @@
     }
 
     protected void writeResult(int ed) throws IOException {
-        aInt32.setValue(ed);
-        int32Serde.serialize(aInt32, out);
+        aInt64.setValue(ed);
+        int64Serde.serialize(aInt64, out);
     }
 }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/GramTokensEvaluator.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/GramTokensEvaluator.java
index d96a268..7a11c04 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/GramTokensEvaluator.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/GramTokensEvaluator.java
@@ -20,12 +20,13 @@
 import edu.uci.ics.asterix.builders.OrderedListBuilder;
 import edu.uci.ics.asterix.om.types.AOrderedListType;
 import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.hierachy.ATypeHierarchy;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
 import edu.uci.ics.hyracks.data.std.primitive.BooleanPointable;
-import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 import edu.uci.ics.hyracks.storage.am.lsm.invertedindex.tokenizers.IBinaryTokenizer;
@@ -66,7 +67,14 @@
         prePostEval.evaluate(tuple);
 
         byte[] bytes = argOut.getByteArray();
-        int gramLength = IntegerPointable.getInteger(bytes, gramLengthOff + typeIndicatorSize);
+        int gramLength = 0;
+
+        try {
+            gramLength = ATypeHierarchy.getIntegerValue(bytes, gramLengthOff);
+        } catch (HyracksDataException e1) {
+            throw new AlgebricksException(e1);
+        }
+
         tokenizer.setGramlength(gramLength);
         boolean prePost = BooleanPointable.getBoolean(bytes, prePostOff + typeIndicatorSize);
         tokenizer.setPrePost(prePost);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/SimilarityJaccardCheckEvaluator.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/SimilarityJaccardCheckEvaluator.java
index d6fae85..84f8e6a 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/SimilarityJaccardCheckEvaluator.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/SimilarityJaccardCheckEvaluator.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,6 +27,7 @@
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
 import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
@@ -62,7 +63,8 @@
     }
 
     @Override
-    protected int probeHashMap(AbstractAsterixListIterator probeIter, int buildListSize, int probeListSize) {
+    protected int probeHashMap(AbstractAsterixListIterator probeIter, int buildListSize, int probeListSize)
+            throws HyracksDataException {
         // Apply length filter.
         int lengthLowerBound = (int) Math.ceil(jaccThresh * probeListSize);
         if ((lengthLowerBound > buildListSize) || (buildListSize > (int) Math.floor(1.0f / jaccThresh * probeListSize))) {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/SimilarityJaccardEvaluator.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/SimilarityJaccardEvaluator.java
index 77f758b..2546fd0 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/SimilarityJaccardEvaluator.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/SimilarityJaccardEvaluator.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -34,6 +34,7 @@
 import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparator;
 import edu.uci.ics.hyracks.api.dataflow.value.IBinaryHashFunction;
 import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
 import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
@@ -157,17 +158,21 @@
         ATypeTag probeItemTypeTag = (probeList == firstListIter) ? firstItemTypeTag : secondItemTypeTag;
 
         setHashMap(bytes, buildItemTypeTag, probeItemTypeTag);
-        buildHashMap(buildList);
-        int intersectionSize = probeHashMap(probeList, buildListSize, probeListSize);
-        // Special indicator for the "check" version of jaccard.
-        if (intersectionSize < 0) {
-            return -1;
+        try {
+            buildHashMap(buildList);
+            int intersectionSize = probeHashMap(probeList, buildListSize, probeListSize);
+            // Special indicator for the "check" version of jaccard.
+            if (intersectionSize < 0) {
+                return -1;
+            }
+            unionSize -= intersectionSize;
+            return (float) intersectionSize / (float) unionSize;
+        } catch (HyracksDataException e) {
+            throw new AlgebricksException(e);
         }
-        unionSize -= intersectionSize;
-        return (float) intersectionSize / (float) unionSize;
     }
 
-    protected void buildHashMap(AbstractAsterixListIterator buildIter) {
+    protected void buildHashMap(AbstractAsterixListIterator buildIter) throws HyracksDataException {
         // Build phase: Add items into hash map, starting with first list.
         // Value in map is a pair of integers. Set first integer to 1.
         IntegerPointable.setInteger(valEntry.buf, 0, 1);
@@ -186,7 +191,8 @@
         }
     }
 
-    protected int probeHashMap(AbstractAsterixListIterator probeIter, int probeListSize, int buildListSize) {
+    protected int probeHashMap(AbstractAsterixListIterator probeIter, int probeListSize, int buildListSize)
+            throws HyracksDataException {
         // Probe phase: Probe items from second list, and compute intersection size.
         int intersectionSize = 0;
         while (probeIter.hasNext()) {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/SimilarityJaccardPrefixEvaluator.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/SimilarityJaccardPrefixEvaluator.java
index a8dd3dd..e5c8571 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/SimilarityJaccardPrefixEvaluator.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/SimilarityJaccardPrefixEvaluator.java
@@ -31,12 +31,13 @@
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.om.types.hierachy.ATypeHierarchy;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
-import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -97,11 +98,23 @@
 
         inputVal.reset();
         evalLen1.evaluate(tuple);
-        int length1 = IntegerPointable.getInteger(inputVal.getByteArray(), 1);
+        int length1 = 0;
+
+        try {
+            length1 = ATypeHierarchy.getIntegerValue(inputVal.getByteArray(), 0);
+        } catch (HyracksDataException e1) {
+            throw new AlgebricksException(e1);
+        }
 
         inputVal.reset();
         evalLen2.evaluate(tuple);
-        int length2 = IntegerPointable.getInteger(inputVal.getByteArray(), 1);
+        int length2 = 0;
+
+        try {
+            length2 = ATypeHierarchy.getIntegerValue(inputVal.getByteArray(), 0);
+        } catch (HyracksDataException e1) {
+            throw new AlgebricksException(e1);
+        }
 
         //
         // -- - length filter - --
@@ -126,24 +139,39 @@
                 // read tokens
                 for (i = 0; i < lengthTokens1; i++) {
                     int itemOffset;
+                    int token;
                     try {
                         itemOffset = AOrderedListSerializerDeserializer.getItemOffset(serList, i);
                     } catch (AsterixException e) {
                         throw new AlgebricksException(e);
                     }
-                    tokens1.add(IntegerPointable.getInteger(serList, itemOffset));
+
+                    try {
+                        token = ATypeHierarchy.getIntegerValueWithDifferentTypeTagPosition(serList, itemOffset, 1);
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                    tokens1.add(token);
                 }
             } else {
                 lengthTokens1 = AUnorderedListSerializerDeserializer.getNumberOfItems(inputVal.getByteArray());
                 // read tokens
                 for (i = 0; i < lengthTokens1; i++) {
                     int itemOffset;
+                    int token;
+
                     try {
                         itemOffset = AUnorderedListSerializerDeserializer.getItemOffset(serList, i);
                     } catch (AsterixException e) {
                         throw new AlgebricksException(e);
                     }
-                    tokens1.add(IntegerPointable.getInteger(serList, itemOffset));
+
+                    try {
+                        token = ATypeHierarchy.getIntegerValueWithDifferentTypeTagPosition(serList, itemOffset, 1);
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                    tokens1.add(token);
                 }
             }
             // pad tokens
@@ -168,24 +196,40 @@
                 // read tokens
                 for (i = 0; i < lengthTokens2; i++) {
                     int itemOffset;
+                    int token;
+
                     try {
                         itemOffset = AOrderedListSerializerDeserializer.getItemOffset(serList, i);
                     } catch (AsterixException e) {
                         throw new AlgebricksException(e);
                     }
-                    tokens2.add(IntegerPointable.getInteger(serList, itemOffset));
+
+                    try {
+                        token = ATypeHierarchy.getIntegerValueWithDifferentTypeTagPosition(serList, itemOffset, 1);
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                    tokens2.add(token);
                 }
             } else {
                 lengthTokens2 = AUnorderedListSerializerDeserializer.getNumberOfItems(inputVal.getByteArray());
                 // read tokens
                 for (i = 0; i < lengthTokens2; i++) {
                     int itemOffset;
+                    int token;
+
                     try {
                         itemOffset = AUnorderedListSerializerDeserializer.getItemOffset(serList, i);
                     } catch (AsterixException e) {
                         throw new AlgebricksException(e);
                     }
-                    tokens2.add(IntegerPointable.getInteger(serList, itemOffset));
+
+                    try {
+                        token = ATypeHierarchy.getIntegerValueWithDifferentTypeTagPosition(serList, itemOffset, 1);
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                    tokens2.add(token);
                 }
             }
             // pad tokens
@@ -196,7 +240,14 @@
             // -- - token prefix - --
             inputVal.reset();
             evalTokenPrefix.evaluate(tuple);
-            int tokenPrefix = IntegerPointable.getInteger(inputVal.getByteArray(), 1);
+
+            int tokenPrefix = 0;
+
+            try {
+                tokenPrefix = ATypeHierarchy.getIntegerValue(inputVal.getByteArray(), 0);
+            } catch (HyracksDataException e) {
+                throw new AlgebricksException(e);
+            }
 
             //
             // -- - position filter - --
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/SimilarityJaccardSortedCheckEvaluator.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/SimilarityJaccardSortedCheckEvaluator.java
index 15f788c..26a82e9 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/SimilarityJaccardSortedCheckEvaluator.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/SimilarityJaccardSortedCheckEvaluator.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -14,10 +14,11 @@
  */
 package edu.uci.ics.asterix.runtime.evaluators.common;
 
-import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.fuzzyjoin.similarity.SimilarityMetricJaccard;
+import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
 
 public class SimilarityJaccardSortedCheckEvaluator extends SimilarityJaccardCheckEvaluator {
@@ -32,6 +33,10 @@
     @Override
     protected float computeResult(byte[] bytes, int firstStart, int secondStart, ATypeTag argType)
             throws AlgebricksException {
-        return jaccard.getSimilarity(firstListIter, secondListIter, jaccThresh);
+        try {
+            return jaccard.getSimilarity(firstListIter, secondListIter, jaccThresh);
+        } catch (HyracksDataException e) {
+            throw new AlgebricksException(e);
+        }
     }
 }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/SimilarityJaccardSortedEvaluator.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/SimilarityJaccardSortedEvaluator.java
index 079df7a..08a57c0 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/SimilarityJaccardSortedEvaluator.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/SimilarityJaccardSortedEvaluator.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -14,10 +14,11 @@
  */
 package edu.uci.ics.asterix.runtime.evaluators.common;
 
-import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.fuzzyjoin.similarity.SimilarityMetricJaccard;
+import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
 
 // Assumes that both arguments are sorted by the same ordering.
@@ -32,6 +33,10 @@
 
     protected float computeResult(byte[] bytes, int firstStart, int secondStart, ATypeTag argType)
             throws AlgebricksException {
-        return jaccard.getSimilarity(firstListIter, secondListIter);
+        try {
+            return jaccard.getSimilarity(firstListIter, secondListIter);
+        } catch (HyracksDataException e) {
+            throw new AlgebricksException(e);
+        }
     }
 }
\ No newline at end of file
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/comparisons/AbstractComparisonEvaluator.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/comparisons/AbstractComparisonEvaluator.java
index a6ec388..6cce1da 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/comparisons/AbstractComparisonEvaluator.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/comparisons/AbstractComparisonEvaluator.java
@@ -16,6 +16,7 @@
 
 import java.io.DataOutput;
 
+import edu.uci.ics.asterix.dataflow.data.nontagged.comparators.ABinaryComparator;
 import edu.uci.ics.asterix.dataflow.data.nontagged.comparators.ACirclePartialBinaryComparatorFactory;
 import edu.uci.ics.asterix.dataflow.data.nontagged.comparators.ADurationPartialBinaryComparatorFactory;
 import edu.uci.ics.asterix.dataflow.data.nontagged.comparators.AIntervalPartialBinaryComparatorFactory;
@@ -40,8 +41,10 @@
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.BinaryComparatorConstant.ComparableResultCode;
 import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparator;
 import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.accessors.PointableBinaryComparatorFactory;
 import edu.uci.ics.hyracks.data.std.primitive.ByteArrayPointable;
 import edu.uci.ics.hyracks.data.std.primitive.FloatPointable;
@@ -90,8 +93,7 @@
     protected IBinaryComparator rectangleBinaryComparator = ARectanglePartialBinaryComparatorFactory.INSTANCE
             .createBinaryComparator();
     protected final IBinaryComparator byteArrayComparator = new PointableBinaryComparatorFactory(
-            ByteArrayPointable.FACTORY)
-            .createBinaryComparator();
+            ByteArrayPointable.FACTORY).createBinaryComparator();
 
     public AbstractComparisonEvaluator(DataOutput out, ICopyEvaluatorFactory evalLeftFactory,
             ICopyEvaluatorFactory evalRightFactory) throws AlgebricksException {
@@ -107,7 +109,9 @@
         evalRight.evaluate(tuple);
     }
 
-    protected void checkComparable() throws AlgebricksException {
+    // checks whether we can apply >, >=, <, and <= operations to the given type since
+    // these operations can not be defined for certain types.
+    protected void checkTotallyOrderable() throws AlgebricksException {
         if (outLeft.getLength() != 0) {
             ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(outLeft.getByteArray()[0]);
             switch (typeTag) {
@@ -119,13 +123,20 @@
                 case POLYGON:
                 case CIRCLE:
                 case RECTANGLE:
-                    throw new AlgebricksException("Inequality comparison for " + typeTag + " is not defined.");
+                    throw new AlgebricksException("Comparison operations (GT, GE, LT, and LE) for the " + typeTag
+                            + " type are not defined.");
                 default:
                     return;
             }
         }
     }
 
+    // checks whether two types are comparable
+    protected ComparableResultCode comparabilityCheck() {
+        // just check TypeTags
+        return ABinaryComparator.isComparable(outLeft.getByteArray(), 0, 1, outRight.getByteArray(), 0, 1);
+    }
+
     protected ComparisonResult compareResults() throws AlgebricksException {
         boolean isLeftNull = false;
         boolean isRightNull = false;
@@ -192,56 +203,60 @@
                     + actualTypeTag + ".");
         }
         int result = 0;
-        switch (actualTypeTag) {
-            case YEARMONTHDURATION:
-            case TIME:
-            case DATE:
-                result = Integer.compare(AInt32SerializerDeserializer.getInt(outLeft.getByteArray(), 1),
-                        AInt32SerializerDeserializer.getInt(outRight.getByteArray(), 1));
-                break;
-            case DAYTIMEDURATION:
-            case DATETIME:
-                result = Long.compare(AInt64SerializerDeserializer.getLong(outLeft.getByteArray(), 1),
-                        AInt64SerializerDeserializer.getLong(outRight.getByteArray(), 1));
-                break;
-            case CIRCLE:
-                result = circleBinaryComp.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
-                        outRight.getByteArray(), 1, outRight.getLength() - 1);
-                break;
-            case LINE:
-                result = lineBinaryComparator.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
-                        outRight.getByteArray(), 1, outRight.getLength() - 1);
-                break;
-            case POINT:
-                result = pointBinaryComparator.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
-                        outRight.getByteArray(), 1, outRight.getLength() - 1);
-                break;
-            case POINT3D:
-                result = point3DBinaryComparator.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
-                        outRight.getByteArray(), 1, outRight.getLength() - 1);
-                break;
-            case POLYGON:
-                result = polygonBinaryComparator.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
-                        outRight.getByteArray(), 1, outRight.getLength() - 1);
-                break;
-            case DURATION:
-                result = durationBinaryComp.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
-                        outRight.getByteArray(), 1, outRight.getLength() - 1);
-                break;
-            case INTERVAL:
-                result = intervalBinaryComp.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
-                        outRight.getByteArray(), 1, outRight.getLength() - 1);
-                break;
-            case RECTANGLE:
-                result = rectangleBinaryComparator.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
-                        outRight.getByteArray(), 1, outRight.getLength() - 1);
-                break;
-            case BINARY:
-                result = byteArrayComparator.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
-                        outRight.getByteArray(), 1, outRight.getLength() - 1);
-                break;
-            default:
-                throw new AlgebricksException("Comparison for " + actualTypeTag + " is not supported.");
+        try {
+            switch (actualTypeTag) {
+                case YEARMONTHDURATION:
+                case TIME:
+                case DATE:
+                    result = Integer.compare(AInt32SerializerDeserializer.getInt(outLeft.getByteArray(), 1),
+                            AInt32SerializerDeserializer.getInt(outRight.getByteArray(), 1));
+                    break;
+                case DAYTIMEDURATION:
+                case DATETIME:
+                    result = Long.compare(AInt64SerializerDeserializer.getLong(outLeft.getByteArray(), 1),
+                            AInt64SerializerDeserializer.getLong(outRight.getByteArray(), 1));
+                    break;
+                case CIRCLE:
+                    result = circleBinaryComp.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
+                            outRight.getByteArray(), 1, outRight.getLength() - 1);
+                    break;
+                case LINE:
+                    result = lineBinaryComparator.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
+                            outRight.getByteArray(), 1, outRight.getLength() - 1);
+                    break;
+                case POINT:
+                    result = pointBinaryComparator.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
+                            outRight.getByteArray(), 1, outRight.getLength() - 1);
+                    break;
+                case POINT3D:
+                    result = point3DBinaryComparator.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
+                            outRight.getByteArray(), 1, outRight.getLength() - 1);
+                    break;
+                case POLYGON:
+                    result = polygonBinaryComparator.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
+                            outRight.getByteArray(), 1, outRight.getLength() - 1);
+                    break;
+                case DURATION:
+                    result = durationBinaryComp.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
+                            outRight.getByteArray(), 1, outRight.getLength() - 1);
+                    break;
+                case INTERVAL:
+                    result = intervalBinaryComp.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
+                            outRight.getByteArray(), 1, outRight.getLength() - 1);
+                    break;
+                case RECTANGLE:
+                    result = rectangleBinaryComparator.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
+                            outRight.getByteArray(), 1, outRight.getLength() - 1);
+                    break;
+                case BINARY:
+                    result = byteArrayComparator.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
+                            outRight.getByteArray(), 1, outRight.getLength() - 1);
+                    break;
+                default:
+                    throw new AlgebricksException("Comparison for " + actualTypeTag + " is not supported.");
+            }
+        } catch (HyracksDataException e) {
+            throw new AlgebricksException(e);
         }
         if (result == 0) {
             return ComparisonResult.EQUAL;
@@ -263,8 +278,13 @@
 
     private ComparisonResult compareStringWithArg(ATypeTag typeTag2) throws AlgebricksException {
         if (typeTag2 == ATypeTag.STRING) {
-            int result = strBinaryComp.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
-                    outRight.getByteArray(), 1, outRight.getLength() - 1);
+            int result;
+            try {
+                result = strBinaryComp.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
+                        outRight.getByteArray(), 1, outRight.getLength() - 1);
+            } catch (HyracksDataException e) {
+                throw new AlgebricksException(e);
+            }
             if (result == 0) {
                 return ComparisonResult.EQUAL;
             } else if (result < 0) {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/comparisons/ComparisonEvalFactory.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/comparisons/ComparisonEvalFactory.java
index d62db02..ad3d007 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/comparisons/ComparisonEvalFactory.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/comparisons/ComparisonEvalFactory.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -79,21 +79,41 @@
         @Override
         public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
             evalInputs(tuple);
-            ComparisonResult r = compareResults();
-            if (r == ComparisonResult.UNKNOWN) {
-                try {
-                    nullSerde.serialize(ANull.NULL, out);
-                    return;
-                } catch (HyracksDataException e) {
-                    throw new AlgebricksException(e);
-                }
+
+            // Checks whether two types are comparable
+            switch (comparabilityCheck()) {
+                case UNKNOWN:
+                    // result:UNKNOWN - NULL value found
+                    try {
+                        nullSerde.serialize(ANull.NULL, out);
+                        return;
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                case FALSE:
+                    // result:FALSE - two types cannot be compared. Thus we return FALSE since this is equality comparison
+                    ABoolean b = ABoolean.FALSE;
+                    try {
+                        serde.serialize(b, out);
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                    break;
+                case TRUE:
+                    // Two types can be compared
+                    ComparisonResult r = compareResults();
+                    ABoolean b1 = (r == ComparisonResult.EQUAL) ? ABoolean.TRUE : ABoolean.FALSE;
+                    try {
+                        serde.serialize(b1, out);
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                    break;
+                default:
+                    throw new AlgebricksException(
+                            "Equality Comparison cannot be processed. The return code from ComparabilityCheck is not correct.");
             }
-            ABoolean b = (r == ComparisonResult.EQUAL) ? ABoolean.TRUE : ABoolean.FALSE;
-            try {
-                serde.serialize(b, out);
-            } catch (HyracksDataException e) {
-                throw new AlgebricksException(e);
-            }
+
         }
 
     }
@@ -107,21 +127,41 @@
         @Override
         public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
             evalInputs(tuple);
-            ComparisonResult r = compareResults();
-            if (r == ComparisonResult.UNKNOWN) {
-                try {
-                    nullSerde.serialize(ANull.NULL, out);
-                    return;
-                } catch (HyracksDataException e) {
-                    throw new AlgebricksException(e);
-                }
+
+            // Checks whether two types are comparable
+            switch (comparabilityCheck()) {
+                case UNKNOWN:
+                    // result:UNKNOWN - NULL value found
+                    try {
+                        nullSerde.serialize(ANull.NULL, out);
+                        return;
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                case FALSE:
+                    // result:FALSE - two types cannot be compared. Thus we return TRUE since this is NOT EQ comparison.
+                    ABoolean b = ABoolean.TRUE;
+                    try {
+                        serde.serialize(b, out);
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                    break;
+                case TRUE:
+                    // Two types can be compared
+                    ComparisonResult r = compareResults();
+                    ABoolean b1 = (r != ComparisonResult.EQUAL) ? ABoolean.TRUE : ABoolean.FALSE;
+                    try {
+                        serde.serialize(b1, out);
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                    break;
+                default:
+                    throw new AlgebricksException(
+                            "Inequality Comparison cannot be processed. The return code from ComparabilityCheck is not correct.");
             }
-            ABoolean b = (r != ComparisonResult.EQUAL) ? ABoolean.TRUE : ABoolean.FALSE;
-            try {
-                serde.serialize(b, out);
-            } catch (HyracksDataException e) {
-                throw new AlgebricksException(e);
-            }
+
         }
 
     }
@@ -135,23 +175,46 @@
         @Override
         public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
             evalInputs(tuple);
-            checkComparable();
-            ComparisonResult r = compareResults();
-            if (r == ComparisonResult.UNKNOWN) {
-                try {
-                    nullSerde.serialize(ANull.NULL, out);
-                    return;
-                } catch (HyracksDataException e) {
-                    throw new AlgebricksException(e);
-                }
+
+            // checks whether we can apply >, >=, <, and <= to the given type since
+            // these operations cannot be defined for certain types.
+            checkTotallyOrderable();
+
+            // Checks whether two types are comparable
+            switch (comparabilityCheck()) {
+                case UNKNOWN:
+                    // result:UNKNOWN - NULL value found
+                    try {
+                        nullSerde.serialize(ANull.NULL, out);
+                        return;
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                case FALSE:
+                    // result:FALSE - two types cannot be compared. Thus we return FALSE since this is an inequality comparison.
+                    ABoolean b = ABoolean.FALSE;
+                    try {
+                        serde.serialize(b, out);
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                    break;
+                case TRUE:
+                    // Two types can be compared
+                    ComparisonResult r = compareResults();
+                    ABoolean b1 = (r == ComparisonResult.EQUAL || r == ComparisonResult.GREATER_THAN) ? ABoolean.TRUE
+                            : ABoolean.FALSE;
+                    try {
+                        serde.serialize(b1, out);
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                    break;
+                default:
+                    throw new AlgebricksException(
+                            "Inequality Comparison cannot be processed. The return code from ComparabilityCheck is not correct.");
             }
-            ABoolean b = (r == ComparisonResult.EQUAL || r == ComparisonResult.GREATER_THAN) ? ABoolean.TRUE
-                    : ABoolean.FALSE;
-            try {
-                serde.serialize(b, out);
-            } catch (HyracksDataException e) {
-                throw new AlgebricksException(e);
-            }
+
         }
 
     }
@@ -165,22 +228,45 @@
         @Override
         public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
             evalInputs(tuple);
-            checkComparable();
-            ComparisonResult r = compareResults();
-            if (r == ComparisonResult.UNKNOWN) {
-                try {
-                    nullSerde.serialize(ANull.NULL, out);
-                    return;
-                } catch (HyracksDataException e) {
-                    throw new AlgebricksException(e);
-                }
+
+            // checks whether we can apply >, >=, <, and <= to the given type since
+            // these operations cannot be defined for certain types.
+            checkTotallyOrderable();
+
+            // Checks whether two types are comparable
+            switch (comparabilityCheck()) {
+                case UNKNOWN:
+                    // result:UNKNOWN - NULL value found
+                    try {
+                        nullSerde.serialize(ANull.NULL, out);
+                        return;
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                case FALSE:
+                    // result:FALSE - two types cannot be compared. Thus we return FALSE since this is an inequality comparison.
+                    ABoolean b = ABoolean.FALSE;
+                    try {
+                        serde.serialize(b, out);
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                    break;
+                case TRUE:
+                    // Two types can be compared
+                    ComparisonResult r = compareResults();
+                    ABoolean b1 = (r == ComparisonResult.GREATER_THAN) ? ABoolean.TRUE : ABoolean.FALSE;
+                    try {
+                        serde.serialize(b1, out);
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                    break;
+                default:
+                    throw new AlgebricksException(
+                            "Inequality Comparison cannot be processed. The return code from ComparabilityCheck is not correct.");
             }
-            ABoolean b = (r == ComparisonResult.GREATER_THAN) ? ABoolean.TRUE : ABoolean.FALSE;
-            try {
-                serde.serialize(b, out);
-            } catch (HyracksDataException e) {
-                throw new AlgebricksException(e);
-            }
+
         }
 
     }
@@ -194,23 +280,46 @@
         @Override
         public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
             evalInputs(tuple);
-            checkComparable();
-            ComparisonResult r = compareResults();
-            if (r == ComparisonResult.UNKNOWN) {
-                try {
-                    nullSerde.serialize(ANull.NULL, out);
-                    return;
-                } catch (HyracksDataException e) {
-                    throw new AlgebricksException(e);
-                }
+
+            // checks whether we can apply >, >=, <, and <= to the given type since
+            // these operations cannot be defined for certain types.
+            checkTotallyOrderable();
+
+            // Checks whether two types are comparable
+            switch (comparabilityCheck()) {
+                case UNKNOWN:
+                    // result:UNKNOWN - NULL value found
+                    try {
+                        nullSerde.serialize(ANull.NULL, out);
+                        return;
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                case FALSE:
+                    // result:FALSE - two types cannot be compared. Thus we return FALSE since this is an inequality comparison.
+                    ABoolean b = ABoolean.FALSE;
+                    try {
+                        serde.serialize(b, out);
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                    break;
+                case TRUE:
+                    // Two types can be compared
+                    ComparisonResult r = compareResults();
+                    ABoolean b1 = (r == ComparisonResult.EQUAL || r == ComparisonResult.LESS_THAN) ? ABoolean.TRUE
+                            : ABoolean.FALSE;
+                    try {
+                        serde.serialize(b1, out);
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                    break;
+                default:
+                    throw new AlgebricksException(
+                            "Inequality Comparison cannot be processed. The return code from ComparabilityCheck is not correct.");
             }
-            ABoolean b = (r == ComparisonResult.EQUAL || r == ComparisonResult.LESS_THAN) ? ABoolean.TRUE
-                    : ABoolean.FALSE;
-            try {
-                serde.serialize(b, out);
-            } catch (HyracksDataException e) {
-                throw new AlgebricksException(e);
-            }
+
         }
 
     }
@@ -224,22 +333,45 @@
         @Override
         public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
             evalInputs(tuple);
-            checkComparable();
-            ComparisonResult r = compareResults();
-            if (r == ComparisonResult.UNKNOWN) {
-                try {
-                    nullSerde.serialize(ANull.NULL, out);
-                    return;
-                } catch (HyracksDataException e) {
-                    throw new AlgebricksException(e);
-                }
+
+            // checks whether we can apply >, >=, <, and <= to the given type since
+            // these operations cannot be defined for certain types.
+            checkTotallyOrderable();
+
+            // Checks whether two types are comparable
+            switch (comparabilityCheck()) {
+                case UNKNOWN:
+                    // result:UNKNOWN - NULL value found
+                    try {
+                        nullSerde.serialize(ANull.NULL, out);
+                        return;
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                case FALSE:
+                    // result:FALSE - two types cannot be compared. Thus we return FALSE since this is an inequality comparison.
+                    ABoolean b = ABoolean.FALSE;
+                    try {
+                        serde.serialize(b, out);
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                    break;
+                case TRUE:
+                    // Two types can be compared
+                    ComparisonResult r = compareResults();
+                    ABoolean b1 = (r == ComparisonResult.LESS_THAN) ? ABoolean.TRUE : ABoolean.FALSE;
+                    try {
+                        serde.serialize(b1, out);
+                    } catch (HyracksDataException e) {
+                        throw new AlgebricksException(e);
+                    }
+                    break;
+                default:
+                    throw new AlgebricksException(
+                            "Inequality Comparison cannot be processed. The return code from ComparabilityCheck is not correct.");
             }
-            ABoolean b = (r == ComparisonResult.LESS_THAN) ? ABoolean.TRUE : ABoolean.FALSE;
-            try {
-                serde.serialize(b, out);
-            } catch (HyracksDataException e) {
-                throw new AlgebricksException(e);
-            }
+
         }
 
     }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AStringConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AStringConstructorDescriptor.java
index 7cf588e..e860ef9 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AStringConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AStringConstructorDescriptor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -76,6 +76,7 @@
                         public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
                             try {
                                 outInput.reset();
+                                baaos.reset();
                                 eval.evaluate(tuple);
                                 byte[] serString = outInput.getByteArray();
 
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/BinaryHashMap.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/BinaryHashMap.java
index 7451ac3..bd056cf 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/BinaryHashMap.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/BinaryHashMap.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -91,27 +91,29 @@
     /**
      * Inserts key, value into the hash map. If key already exists, returns
      * existing entry. Otherwise, returns null.
-     * 
+     *
      * @param key
      * @param value
      * @return
+     * @throws HyracksDataException
      */
-    public BinaryEntry put(BinaryEntry key, BinaryEntry value) {
+    public BinaryEntry put(BinaryEntry key, BinaryEntry value) throws HyracksDataException {
         return getPutInternal(key, value, true);
     }
 
     /**
      * Retrieves value for given key. Returns null if key doesn't exist.
-     * 
+     *
      * @param key
      * @param value
      * @return
+     * @throws HyracksDataException
      */
-    public BinaryEntry get(BinaryEntry key) {
+    public BinaryEntry get(BinaryEntry key) throws HyracksDataException {
         return getPutInternal(key, null, false);
     }
 
-    private BinaryEntry getPutInternal(BinaryEntry key, BinaryEntry value, boolean put) {
+    private BinaryEntry getPutInternal(BinaryEntry key, BinaryEntry value, boolean put) throws HyracksDataException {
         int bucket;
         if (put) {
             bucket = Math.abs(putHashFunc.hash(key.buf, key.off, key.len) % listHeads.length);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CastRecordDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CastRecordDescriptor.java
index fbdbaf3..534dd58 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CastRecordDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CastRecordDescriptor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -31,6 +31,7 @@
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
@@ -73,7 +74,7 @@
                 try {
                     clonedRecType = new ARecordType(reqType.getTypeName(), reqType.getFieldNames(),
                             reqType.getFieldTypes(), reqType.isOpen());
-                } catch (AsterixException e) {
+                } catch (AsterixException | HyracksDataException e) {
                     throw new AlgebricksException(e);
                 }
 
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodePointToStringDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodePointToStringDescriptor.java
index 934810f..cb64c5d 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodePointToStringDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodePointToStringDescriptor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,13 +18,13 @@
 import java.io.IOException;
 
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AOrderedListSerializerDeserializer;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.om.types.hierachy.ATypeHierarchy;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
@@ -43,8 +43,6 @@
             return new CodePointToStringDescriptor();
         }
     };
-    private final static byte SER_ORDEREDLIST_TYPE_TAG = ATypeTag.ORDEREDLIST.serialize();
-    private final static byte SER_INT32_TYPE_TAG = ATypeTag.INT32.serialize();
 
     private final static byte[] currentUTF8 = new byte[6];
     private final byte stringTypeTag = ATypeTag.STRING.serialize();
@@ -108,20 +106,35 @@
                             outInputList.reset();
                             evalList.evaluate(tuple);
                             byte[] serOrderedList = outInputList.getByteArray();
-                            if (serOrderedList[0] != SER_ORDEREDLIST_TYPE_TAG
-                                    && serOrderedList[1] != SER_INT32_TYPE_TAG) {
-                                throw new AlgebricksException(AsterixBuiltinFunctions.CODEPOINT_TO_STRING.getName()
-                                        + ": expects input type ORDEREDLIST but got "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serOrderedList[0]));
+                            int size = 0;
+
+                            if (ATypeTag.VALUE_TYPE_MAPPING[serOrderedList[0]] != ATypeTag.ORDEREDLIST) {
+                                cannotProcessException(serOrderedList[0], serOrderedList[1]);
+                            } else {
+                                switch (ATypeTag.VALUE_TYPE_MAPPING[serOrderedList[1]]) {
+                                    case INT8:
+                                    case INT16:
+                                    case INT32:
+                                    case INT64:
+                                    case FLOAT:
+                                    case DOUBLE:
+                                    case ANY:
+                                        size = AOrderedListSerializerDeserializer.getNumberOfItems(serOrderedList);
+                                        break;
+                                    default:
+                                        cannotProcessException(serOrderedList[0], serOrderedList[1]);
+                                }
                             }
-                            int size = AOrderedListSerializerDeserializer.getNumberOfItems(serOrderedList);
+
                             try {
                                 // calculate length first
                                 int utf_8_len = 0;
                                 for (int i = 0; i < size; i++) {
                                     int itemOffset = AOrderedListSerializerDeserializer
                                             .getItemOffset(serOrderedList, i);
-                                    int codePoint = AInt32SerializerDeserializer.getInt(serOrderedList, itemOffset);
+                                    int codePoint = 0;
+                                    codePoint = ATypeHierarchy.getIntegerValueWithDifferentTypeTagPosition(
+                                            serOrderedList, itemOffset, 1);
                                     utf_8_len += codePointToUTF8(codePoint);
                                 }
                                 out.writeByte(stringTypeTag);
@@ -129,7 +142,9 @@
                                 for (int i = 0; i < size; i++) {
                                     int itemOffset = AOrderedListSerializerDeserializer
                                             .getItemOffset(serOrderedList, i);
-                                    int codePoint = AInt32SerializerDeserializer.getInt(serOrderedList, itemOffset);
+                                    int codePoint = 0;
+                                    codePoint = ATypeHierarchy.getIntegerValueWithDifferentTypeTagPosition(
+                                            serOrderedList, itemOffset, 1);
                                     utf_8_len = codePointToUTF8(codePoint);
                                     for (int j = 0; j < utf_8_len; j++) {
                                         out.writeByte(currentUTF8[j]);
@@ -151,4 +166,12 @@
     public FunctionIdentifier getIdentifier() {
         return AsterixBuiltinFunctions.CODEPOINT_TO_STRING;
     }
+
+    private void cannotProcessException(byte tag1, byte tag2) throws AlgebricksException {
+        throw new AlgebricksException(AsterixBuiltinFunctions.CODEPOINT_TO_STRING.getName()
+                + ": expects input type ORDEREDLIST/[INT8|INT16|INT32|INT64|FLOAT|DOUBLE] but got "
+                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(tag1) + "/"
+                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(tag2));
+    }
+
 }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceListIsFilterable.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceListIsFilterable.java
index e0383a5..4b892cf 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceListIsFilterable.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceListIsFilterable.java
@@ -26,14 +26,15 @@
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.om.types.hierachy.ATypeHierarchy;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
-import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -47,6 +48,7 @@
 public class EditDistanceListIsFilterable extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
+
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new EditDistanceListIsFilterable();
@@ -97,7 +99,7 @@
             argBuf.reset();
             listEval.evaluate(tuple);
             typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
-            int listLen = 0;
+            long listLen = 0;
             switch (typeTag) {
                 case UNORDEREDLIST: {
                     listLen = AUnorderedListSerializerDeserializer.getNumberOfItems(argBuf.getByteArray(), 0);
@@ -118,14 +120,16 @@
             argBuf.reset();
             edThreshEval.evaluate(tuple);
             typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
-            if (!typeTag.equals(ATypeTag.INT32)) {
-                throw new AlgebricksException(AsterixBuiltinFunctions.EDIT_DISTANCE_LIST_IS_FILTERABLE.getName()
-                        + ": expected type INT32 as the second argument, but got " + typeTag + ".");
+            long edThresh;
+
+            try {
+                edThresh = ATypeHierarchy.getIntegerValue(argBuf.getByteArray(), 0);
+            } catch (HyracksDataException e1) {
+                throw new AlgebricksException(e1);
             }
-            int edThresh = IntegerPointable.getInteger(argBuf.getByteArray(), 1);
 
             // Compute result.
-            int lowerBound = listLen - edThresh;
+            long lowerBound = listLen - edThresh;
             try {
                 if (lowerBound <= 0) {
                     booleanSerde.serialize(ABoolean.FALSE, output.getDataOutput());
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceStringIsFilterable.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceStringIsFilterable.java
index 33469e2..d5135db 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceStringIsFilterable.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceStringIsFilterable.java
@@ -24,15 +24,16 @@
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.om.types.hierachy.ATypeHierarchy;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
 import edu.uci.ics.hyracks.data.std.primitive.BooleanPointable;
-import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
 import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
@@ -107,7 +108,7 @@
             }
             int utf8Length = UTF8StringPointable.getUTFLength(argBuf.getByteArray(), 1);
             int pos = 3;
-            int strLen = 0;
+            long strLen = 0;
             int end = pos + utf8Length;
             while (pos < end) {
                 strLen++;
@@ -118,21 +119,26 @@
             argBuf.reset();
             edThreshEval.evaluate(tuple);
             typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
-            if (!typeTag.equals(ATypeTag.INT32)) {
-                throw new AlgebricksException(AsterixBuiltinFunctions.EDIT_DISTANCE_STRING_IS_FILTERABLE.getName()
-                        + ": expects input type INT32 as second argument, but got " + typeTag + ".");
+
+            long edThresh = 0;
+
+            try {
+                edThresh = ATypeHierarchy.getIntegerValue(argBuf.getByteArray(), 0);
+            } catch (HyracksDataException e1) {
+                throw new AlgebricksException(e1);
             }
-            int edThresh = IntegerPointable.getInteger(argBuf.getByteArray(), 1);
 
             // Check type and extract gram length.
             argBuf.reset();
             gramLenEval.evaluate(tuple);
             typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
-            if (!typeTag.equals(ATypeTag.INT32)) {
-                throw new AlgebricksException(AsterixBuiltinFunctions.EDIT_DISTANCE_STRING_IS_FILTERABLE.getName()
-                        + ": expects input type INT32 as third argument, but got " + typeTag + ".");
+
+            long gramLen = 0;
+            try {
+                gramLen = ATypeHierarchy.getIntegerValue(argBuf.getByteArray(), 0);
+            } catch (HyracksDataException e1) {
+                throw new AlgebricksException(e1);
             }
-            int gramLen = IntegerPointable.getInteger(argBuf.getByteArray(), 1);
 
             // Check type and extract usePrePost flag.
             argBuf.reset();
@@ -145,8 +151,8 @@
             boolean usePrePost = BooleanPointable.getBoolean(argBuf.getByteArray(), 1);
 
             // Compute result.
-            int numGrams = (usePrePost) ? strLen + gramLen - 1 : strLen - gramLen + 1;
-            int lowerBound = numGrams - edThresh * gramLen;
+            long numGrams = (usePrePost) ? strLen + gramLen - 1 : strLen - gramLen + 1;
+            long lowerBound = numGrams - edThresh * gramLen;
             try {
                 if (lowerBound <= 0 || strLen == 0) {
                     booleanSerde.serialize(ABoolean.FALSE, output.getDataOutput());
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/GetItemDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/GetItemDescriptor.java
index 8aea6c1..c1480f6 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/GetItemDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/GetItemDescriptor.java
@@ -27,6 +27,7 @@
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.om.types.hierachy.ATypeHierarchy;
 import edu.uci.ics.asterix.om.util.NonTaggedFormatUtil;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -35,7 +36,6 @@
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
-import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -66,7 +66,6 @@
         private ICopyEvaluatorFactory indexEvalFactory;
         private final static byte SER_ORDEREDLIST_TYPE_TAG = ATypeTag.ORDEREDLIST.serialize();
         private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
-        private final static byte SER_INT32_TYPE_TAG = ATypeTag.INT32.serialize();
         private byte serItemTypeTag;
         private ATypeTag itemTag;
         private boolean selfDescList = false;
@@ -107,16 +106,18 @@
                             return;
                         }
 
-                        if (serOrderedList[0] != SER_ORDEREDLIST_TYPE_TAG
-                                || outInputIdx.getByteArray()[0] != SER_INT32_TYPE_TAG) {
-                            throw new AlgebricksException(AsterixBuiltinFunctions.GET_ITEM.getName()
-                                    + ": expects input type (NULL/ORDEREDLIST, INT32), but got ("
-                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serOrderedList[0]) + ", "
-                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(outInputIdx.getByteArray()[0])
-                                    + ").");
+                        if (serOrderedList[0] == SER_ORDEREDLIST_TYPE_TAG) {
+                            itemIndex = ATypeHierarchy.getIntegerValue(outInputIdx.getByteArray(), 0);
+                        } else {
+                            throw new AlgebricksException(
+                                    AsterixBuiltinFunctions.GET_ITEM.getName()
+                                            + ": expects input type (NULL/ORDEREDLIST, [INT8/16/32/64/FLOAT/DOUBLE]), but got ("
+                                            + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serOrderedList[0])
+                                            + ", "
+                                            + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(outInputIdx
+                                                    .getByteArray()[0]) + ").");
                         }
 
-                        itemIndex = IntegerPointable.getInteger(outInputIdx.getByteArray(), 1);
                         if (itemIndex >= AOrderedListSerializerDeserializer.getNumberOfItems(serOrderedList)) {
                             out.writeByte(SER_NULL_TYPE_TAG);
                             return;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/LenDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/LenDescriptor.java
index 9ff22ce..df531f2 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/LenDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/LenDescriptor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,8 +20,8 @@
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AOrderedListSerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AUnorderedListSerializerDeserializer;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.AInt32;
-import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
 import edu.uci.ics.asterix.om.base.ANull;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
@@ -68,10 +68,10 @@
                     private final ICopyEvaluator evalList = args[0].createEvaluator(inputVal);
 
                     // result
-                    private final AMutableInt32 res = new AMutableInt32(0);
+                    private final AMutableInt64 res = new AMutableInt64(0);
                     @SuppressWarnings("unchecked")
-                    private final ISerializerDeserializer<AInt32> int32Serde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.AINT32);
+                    private final ISerializerDeserializer<AInt64> int64Serde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AINT64);
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
@@ -106,7 +106,7 @@
 
                         res.setValue(numberOfitems);
                         try {
-                            int32Serde.serialize(res, out);
+                            int64Serde.serialize(res, out);
                         } catch (IOException e) {
                             throw new AlgebricksException(e);
                         }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/PrefixLenJaccardDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/PrefixLenJaccardDescriptor.java
index 5886a1d..670375c 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/PrefixLenJaccardDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/PrefixLenJaccardDescriptor.java
@@ -28,14 +28,15 @@
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.om.types.hierachy.ATypeHierarchy;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
-import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -43,8 +44,6 @@
 
     private static final long serialVersionUID = 1L;
 
-    // allowed input types
-    private final static byte SER_INT32_TYPE_TAG = ATypeTag.INT32.serialize();
     private final static byte SER_FLOAT_TYPE_TAG = ATypeTag.FLOAT.serialize();
 
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
@@ -68,6 +67,7 @@
                     private final ArrayBackedValueStorage inputVal = new ArrayBackedValueStorage();
                     private final ICopyEvaluator evalLen = args[0].createEvaluator(inputVal);
                     private final ICopyEvaluator evalThreshold = args[1].createEvaluator(inputVal);
+                    private final ArrayBackedValueStorage castBuffer = new ArrayBackedValueStorage();
 
                     private float similarityThresholdCache;
                     private SimilarityFiltersJaccard similarityFilters;
@@ -83,12 +83,12 @@
                         // length
                         inputVal.reset();
                         evalLen.evaluate(tuple);
-                        if (inputVal.getByteArray()[0] != SER_INT32_TYPE_TAG) {
-                            throw new AlgebricksException(AsterixBuiltinFunctions.PREFIX_LEN_JACCARD.getName()
-                                    + ": expects type Int32 the first argument but got "
-                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(inputVal.getByteArray()[0]));
+                        int length = 0;
+                        try {
+                            length = ATypeHierarchy.getIntegerValue(inputVal.getByteArray(), 0);
+                        } catch (HyracksDataException e1) {
+                            throw new AlgebricksException(e1);
                         }
-                        int length = IntegerPointable.getInteger(inputVal.getByteArray(), 1);
 
                         // similarity threshold
                         inputVal.reset();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/RecordMergeDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/RecordMergeDescriptor.java
index 9aa6057..e956e14 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/RecordMergeDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/RecordMergeDescriptor.java
@@ -68,7 +68,7 @@
                 try {
                     recType = new ARecordType(outRecType.getTypeName(), outRecType.getFieldNames(),
                             outRecType.getFieldTypes(), outRecType.isOpen());
-                } catch (AsterixException e) {
+                } catch (AsterixException | HyracksDataException e) {
                     throw new IllegalStateException();
                 }
 
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringLengthDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringLengthDescriptor.java
index f58fbb5..b0471e0 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringLengthDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringLengthDescriptor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,8 +18,8 @@
 import java.io.IOException;
 
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.AInt32;
-import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
 import edu.uci.ics.asterix.om.base.ANull;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
@@ -57,7 +57,7 @@
             @Override
             public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
                 return new ICopyEvaluator() {
-                    private AMutableInt32 result = new AMutableInt32(0);
+                    private AMutableInt64 result = new AMutableInt64(0);
                     private DataOutput out = output.getDataOutput();
                     private ArrayBackedValueStorage outInput = new ArrayBackedValueStorage();
                     private ICopyEvaluator eval = args[0].createEvaluator(outInput);
@@ -65,8 +65,8 @@
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
                     @SuppressWarnings("unchecked")
-                    private ISerializerDeserializer<AInt32> intSerde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.AINT32);
+                    private ISerializerDeserializer<AInt64> int64Serde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AINT64);
 
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
@@ -77,8 +77,8 @@
                             byte[] serString = outInput.getByteArray();
                             if (serString[0] == SER_STRING_TYPE_TAG) {
                                 int len = UTF8StringPointable.getUTFLength(outInput.getByteArray(), 1);
-                                result.setValue(len);
-                                intSerde.serialize(result, out);
+                                result.setValue((long) len);
+                                int64Serde.serialize(result, out);
                             } else if (serString[0] == SER_NULL_TYPE_TAG)
                                 nullSerde.serialize(ANull.NULL, out);
                             else {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringToCodePointDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringToCodePointDescriptor.java
index bff90f6..1b1472e 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringToCodePointDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringToCodePointDescriptor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,8 +19,8 @@
 
 import edu.uci.ics.asterix.builders.OrderedListBuilder;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.AInt32;
-import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
@@ -61,15 +61,15 @@
                     protected final DataOutput out = output.getDataOutput();;
                     protected final ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
                     protected final ICopyEvaluator stringEval = args[0].createEvaluator(argOut);
-                    protected final AOrderedListType intListType = new AOrderedListType(BuiltinType.AINT32, null);
+                    protected final AOrderedListType intListType = new AOrderedListType(BuiltinType.AINT64, null);
 
                     private OrderedListBuilder listBuilder = new OrderedListBuilder();
                     private ArrayBackedValueStorage inputVal = new ArrayBackedValueStorage();
 
                     @SuppressWarnings("unchecked")
-                    private final ISerializerDeserializer<AInt32> int32Serde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.AINT32);
-                    private final AMutableInt32 aInt32 = new AMutableInt32(0);
+                    private final ISerializerDeserializer<AInt64> int64Serde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AINT64);
+                    private final AMutableInt64 aInt64 = new AMutableInt64(0);
 
                     int UTF8ToCodePoint(byte[] b, int s) {
                         if (b[s] >> 7 == 0) {
@@ -119,8 +119,8 @@
                                     pos += UTF8StringPointable.charSize(bytes, pos);
 
                                     inputVal.reset();
-                                    aInt32.setValue(codePoint);
-                                    int32Serde.serialize(aInt32, inputVal.getDataOutput());
+                                    aInt64.setValue(codePoint);
+                                    int64Serde.serialize(aInt64, inputVal.getDataOutput());
                                     listBuilder.addItem(inputVal);
 
                                 }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/Substring2Descriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/Substring2Descriptor.java
index 96fea1c..5b179ce 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/Substring2Descriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/Substring2Descriptor.java
@@ -22,13 +22,14 @@
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.om.types.hierachy.ATypeHierarchy;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
-import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
 import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
@@ -38,7 +39,6 @@
     private static final long serialVersionUID = 1L;
 
     // allowed input types
-    private static final byte SER_INT32_TYPE_TAG = ATypeTag.INT32.serialize();
     private static final byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
 
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
@@ -66,12 +66,13 @@
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
                         argOut.reset();
                         evalStart.evaluate(tuple);
-                        if (argOut.getByteArray()[0] != SER_INT32_TYPE_TAG) {
-                            throw new AlgebricksException(AsterixBuiltinFunctions.SUBSTRING2.getName()
-                                    + ": expects type INT32 for the second argument but got "
-                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[0]));
+                        int start = 0;
+
+                        try {
+                            start = ATypeHierarchy.getIntegerValue(argOut.getByteArray(), 0) - 1;
+                        } catch (HyracksDataException e1) {
+                            throw new AlgebricksException(e1);
                         }
-                        int start = IntegerPointable.getInteger(argOut.getByteArray(), 1) - 1;
                         argOut.reset();
                         evalString.evaluate(tuple);
 
@@ -85,6 +86,7 @@
                         int sStart = 3;
                         int c = 0;
                         int idxPos1 = 0;
+
                         // skip to start
                         while (idxPos1 < start && c < utflen) {
                             c += UTF8StringPointable.charSize(bytes, sStart + c);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringDescriptor.java
index 0c851c6..c7f6d5f 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringDescriptor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,27 +21,25 @@
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
 import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.asterix.om.types.EnumDeserializer;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
+import edu.uci.ics.hyracks.data.std.primitive.DoublePointable;
+import edu.uci.ics.hyracks.data.std.primitive.FloatPointable;
 import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
+import edu.uci.ics.hyracks.data.std.primitive.LongPointable;
+import edu.uci.ics.hyracks.data.std.primitive.ShortPointable;
 import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
-import edu.uci.ics.hyracks.dataflow.common.data.marshalling.IntegerSerializerDeserializer;
 
 public class SubstringDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
 
-    // allowed input types
-    private static final byte SER_INT32_TYPE_TAG = ATypeTag.INT32.serialize();
-    private static final byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
-
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SubstringDescriptor();
@@ -68,30 +66,75 @@
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
                         argOut.reset();
                         evalStart.evaluate(tuple);
-                        if (argOut.getByteArray()[0] != SER_INT32_TYPE_TAG) {
-                            throw new AlgebricksException(AsterixBuiltinFunctions.SUBSTRING.getName()
-                                    + ": expects type INT32 for the second argument but got "
-                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[0]));
+                        int start = 0;
+
+                        ATypeTag argOutTypeTag = ATypeTag.VALUE_TYPE_MAPPING[argOut.getByteArray()[0]];
+
+                        switch (argOutTypeTag) {
+                            case INT64:
+                                start = (int) LongPointable.getLong(argOut.getByteArray(), 1) - 1;
+                                break;
+                            case INT32:
+                                start = IntegerPointable.getInteger(argOut.getByteArray(), 1) - 1;
+                                break;
+                            case INT8:
+                                start = argOut.getByteArray()[1] - 1;
+                                break;
+                            case INT16:
+                                start = (int) ShortPointable.getShort(argOut.getByteArray(), 1) - 1;
+                                break;
+                            case FLOAT:
+                                start = (int) FloatPointable.getFloat(argOut.getByteArray(), 1) - 1;
+                                break;
+                            case DOUBLE:
+                                start = (int) DoublePointable.getDouble(argOut.getByteArray(), 1) - 1;
+                                break;
+                            default:
+                                throw new AlgebricksException(AsterixBuiltinFunctions.SUBSTRING.getName()
+                                        + ": expects type INT8/16/32/64/FLOAT/DOUBLE for the second argument but got "
+                                        + argOutTypeTag);
                         }
-                        int start = IntegerPointable.getInteger(argOut.getByteArray(), 1) - 1;
+
                         argOut.reset();
                         evalLen.evaluate(tuple);
-                        if (argOut.getByteArray()[0] != SER_INT32_TYPE_TAG) {
-                            throw new AlgebricksException(AsterixBuiltinFunctions.SUBSTRING.getName()
-                                    + ": expects type INT32 for the third argument but got "
-                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[0]));
+                        int len = 0;
+
+                        argOutTypeTag = ATypeTag.VALUE_TYPE_MAPPING[argOut.getByteArray()[0]];
+
+                        switch (argOutTypeTag) {
+                            case INT64:
+                                len = (int) LongPointable.getLong(argOut.getByteArray(), 1);
+                                break;
+                            case INT32:
+                                len = IntegerPointable.getInteger(argOut.getByteArray(), 1);
+                                break;
+                            case INT8:
+                                len = argOut.getByteArray()[1];
+                                break;
+                            case INT16:
+                                len = (int) ShortPointable.getShort(argOut.getByteArray(), 1);
+                                break;
+                            case FLOAT:
+                                len = (int) FloatPointable.getFloat(argOut.getByteArray(), 1);
+                                break;
+                            case DOUBLE:
+                                len = (int) DoublePointable.getDouble(argOut.getByteArray(), 1);
+                                break;
+                            default:
+                                throw new AlgebricksException(AsterixBuiltinFunctions.SUBSTRING.getName()
+                                        + ": expects type INT8/16/32/64/FLOAT/DOUBLE for the third argument but got "
+                                        + argOutTypeTag);
                         }
-                        int len = IntegerPointable.getInteger(argOut.getByteArray(), 1);
 
                         argOut.reset();
                         evalString.evaluate(tuple);
 
                         byte[] bytes = argOut.getByteArray();
+                        argOutTypeTag = ATypeTag.VALUE_TYPE_MAPPING[bytes[0]];
 
-                        if (bytes[0] != SER_STRING_TYPE_TAG) {
+                        if (argOutTypeTag != ATypeTag.STRING) {
                             throw new AlgebricksException(AsterixBuiltinFunctions.SUBSTRING.getName()
-                                    + ": expects type STRING for the first argument but got "
-                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[0]));
+                                    + ": expects type STRING for the first argument but got " + argOutTypeTag);
                         }
                         int utflen = UTF8StringPointable.getUTFLength(bytes, 1);
                         int sStart = 3;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/binary/AbstractCopyEvaluator.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/binary/AbstractCopyEvaluator.java
index 09dc82d..3c8013f 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/binary/AbstractCopyEvaluator.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/binary/AbstractCopyEvaluator.java
@@ -19,6 +19,7 @@
 import edu.uci.ics.asterix.om.base.ANull;
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.hierachy.ATypeHierarchy;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
@@ -92,8 +93,11 @@
             throws AlgebricksException {
         for (int i = 0; i < expected.length; i++) {
             if (expected[i] != actual[i]) {
-                throw new AlgebricksException(title +
-                        ": expects " + expected[i] + " at " + idToString(i + 1) + " argument, but got " + actual[i]);
+                if (!ATypeHierarchy.canPromote(actual[i], expected[i])
+                        && !ATypeHierarchy.canPromote(expected[i], actual[i])) {
+                    throw new AlgebricksException(title + ": expects " + expected[i] + " at " + idToString(i + 1)
+                            + " argument, but got " + actual[i]);
+                }
             }
         }
     }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/binary/BinaryLengthDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/binary/BinaryLengthDescriptor.java
index 1d4717e..3555d41 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/binary/BinaryLengthDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/binary/BinaryLengthDescriptor.java
@@ -16,8 +16,8 @@
 package edu.uci.ics.asterix.runtime.evaluators.functions.binary;
 
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.AInt32;
-import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
@@ -51,10 +51,10 @@
                     throws AlgebricksException {
                 return new AbstractCopyEvaluator(output, args) {
 
-                    private AMutableInt32 result = new AMutableInt32(0);
+                    private AMutableInt64 result = new AMutableInt64(0);
                     @SuppressWarnings("unchecked")
-                    private ISerializerDeserializer<AInt32> intSerde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.AINT32);
+                    private ISerializerDeserializer<AInt64> intSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AINT64);
 
                     @Override public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
                         ATypeTag tag = evaluateTuple(tuple, 0);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/binary/FindBinaryDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/binary/FindBinaryDescriptor.java
index 4ba91d9..028b145 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/binary/FindBinaryDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/binary/FindBinaryDescriptor.java
@@ -16,8 +16,8 @@
 package edu.uci.ics.asterix.runtime.evaluators.functions.binary;
 
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.AInt32;
-import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
@@ -71,11 +71,11 @@
         }
 
         protected String functionName;
-        protected AMutableInt32 result = new AMutableInt32(-1);
+        protected AMutableInt64 result = new AMutableInt64(-1);
 
         @SuppressWarnings("unchecked")
-        protected ISerializerDeserializer<AInt32> intSerde = AqlSerializerDeserializerProvider.INSTANCE
-                .getSerializerDeserializer(BuiltinType.AINT32);
+        protected ISerializerDeserializer<AInt64> intSerde = AqlSerializerDeserializerProvider.INSTANCE
+                .getSerializerDeserializer(BuiltinType.AINT64);
 
         @Override public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
             ATypeTag textTag = evaluateTuple(tuple, 0);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/binary/FindBinaryFromDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/binary/FindBinaryFromDescriptor.java
index 0ad806f..7b330ad 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/binary/FindBinaryFromDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/binary/FindBinaryFromDescriptor.java
@@ -19,38 +19,48 @@
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
 import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.hierachy.ATypeHierarchy;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
-import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
-public class FindBinaryFromDescriptor extends AbstractScalarFunctionDynamicDescriptor{
+public class FindBinaryFromDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
-        @Override public IFunctionDescriptor createFunctionDescriptor() {
+        @Override
+        public IFunctionDescriptor createFunctionDescriptor() {
             return new FindBinaryFromDescriptor();
         }
     };
 
-    @Override public FunctionIdentifier getIdentifier() {
+    @Override
+    public FunctionIdentifier getIdentifier() {
         return AsterixBuiltinFunctions.FIND_BINARY_FROM;
     }
 
-    @Override public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args)
-            throws AlgebricksException {
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
         return new ICopyEvaluatorFactory() {
-            @Override public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
                 return new FindBinaryDescriptor.AbstractFindBinaryCopyEvaluator(output, args, getIdentifier().getName()) {
-                    @Override protected int getFromOffset(IFrameTupleReference tuple) throws AlgebricksException {
+                    @Override
+                    protected int getFromOffset(IFrameTupleReference tuple) throws AlgebricksException {
                         ATypeTag offsetTag = evaluateTuple(tuple, 2);
-                        if (offsetTag != ATypeTag.INT32){
-                            throw new AlgebricksException(functionName + ":expects INT32 at 3rd arguments, but got " + offsetTag);
+
+                        int getFrom = 0;
+                        try {
+                            getFrom = ATypeHierarchy.getIntegerValue(storages[2].getByteArray(), 0);
+                        } catch (HyracksDataException e) {
+                            throw new AlgebricksException(e);
                         }
-                        return IntegerPointable.getInteger(storages[2].getByteArray(), 1);
+
+                        return getFrom;
                     }
                 };
             }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/binary/SubBinaryFromToDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/binary/SubBinaryFromToDescriptor.java
index b03a643..0b8675c 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/binary/SubBinaryFromToDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/binary/SubBinaryFromToDescriptor.java
@@ -21,6 +21,7 @@
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
 import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.hierachy.ATypeHierarchy;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
@@ -29,34 +30,39 @@
 import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
 import edu.uci.ics.hyracks.data.std.primitive.ByteArrayPointable;
-import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
 public class SubBinaryFromToDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
-        @Override public IFunctionDescriptor createFunctionDescriptor() {
+        @Override
+        public IFunctionDescriptor createFunctionDescriptor() {
             return new SubBinaryFromToDescriptor();
         }
     };
 
-    @Override public FunctionIdentifier getIdentifier() {
+    @Override
+    public FunctionIdentifier getIdentifier() {
         return AsterixBuiltinFunctions.SUBBINARY_FROM_TO;
     }
 
-    @Override public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args)
-            throws AlgebricksException {
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
         return new ICopyEvaluatorFactory() {
-            @Override public ICopyEvaluator createEvaluator(final IDataOutputProvider output)
-                    throws AlgebricksException {
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
                 return new AbstractSubBinaryCopyEvaluator(output, args, getIdentifier().getName()) {
-                    @Override protected int getSubLength(IFrameTupleReference tuple) throws AlgebricksException {
+                    @Override
+                    protected int getSubLength(IFrameTupleReference tuple) throws AlgebricksException {
                         ATypeTag tagSubLength = evaluateTuple(tuple, 2);
-                        if (tagSubLength != ATypeTag.INT32) {
-                            throw new AlgebricksException(
-                                    functionName + ":expects INT32 at 3rd arguments, but got " + tagSubLength);
+                        int subLength = 0;
+                        try {
+                            subLength = ATypeHierarchy.getIntegerValue(storages[2].getByteArray(), 0);
+                        } catch (HyracksDataException e) {
+                            throw new AlgebricksException(e);
                         }
-                        return IntegerPointable.getInteger(storages[2].getByteArray(), 1);
+
+                        return subLength;
                     }
                 };
             }
@@ -65,8 +71,7 @@
 
     static abstract class AbstractSubBinaryCopyEvaluator extends AbstractCopyEvaluator {
         public AbstractSubBinaryCopyEvaluator(IDataOutputProvider output,
-                ICopyEvaluatorFactory[] copyEvaluatorFactories, String functionName)
-                throws AlgebricksException {
+                ICopyEvaluatorFactory[] copyEvaluatorFactories, String functionName) throws AlgebricksException {
             super(output, copyEvaluatorFactories);
             this.functionName = functionName;
         }
@@ -75,7 +80,8 @@
 
         static final ATypeTag[] EXPECTED_INPUT_TAGS = { ATypeTag.BINARY, ATypeTag.INT32 };
 
-        @Override public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+        @Override
+        public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
 
             ATypeTag argTag0 = evaluateTuple(tuple, 0);
             ATypeTag argTag1 = evaluateTuple(tuple, 1);
@@ -84,13 +90,16 @@
                 if (serializeNullIfAnyNull(argTag0, argTag1)) {
                     return;
                 }
-                checkTypeMachingThrowsIfNot(functionName, EXPECTED_INPUT_TAGS, argTag0,
-                        argTag1);
+                checkTypeMachingThrowsIfNot(functionName, EXPECTED_INPUT_TAGS, argTag0, argTag1);
 
                 byte[] binaryBytes = storages[0].getByteArray();
                 byte[] startBytes = storages[1].getByteArray();
 
-                int start = IntegerPointable.getInteger(startBytes, 1) - 1; // strange SQL index convention
+                int start = 0;
+
+                // strange SQL index convention
+                start = ATypeHierarchy.getIntegerValue(startBytes, 0) - 1;
+
                 int totalLength = ByteArrayPointable.getLength(binaryBytes, 1);
                 int subLength = getSubLength(tuple);
 
@@ -106,8 +115,7 @@
 
                 dataOutput.write(ATypeTag.BINARY.serialize());
                 dataOutput.writeShort(subLength);
-                dataOutput
-                        .write(binaryBytes, 1 + ByteArrayPointable.SIZE_OF_LENGTH + start, subLength);
+                dataOutput.write(binaryBytes, 1 + ByteArrayPointable.SIZE_OF_LENGTH + start, subLength);
             } catch (HyracksDataException e) {
                 throw new AlgebricksException(e);
             } catch (IOException e) {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DateFromUnixTimeInDaysDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DateFromUnixTimeInDaysDescriptor.java
index 1adf8c2..4608b84 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DateFromUnixTimeInDaysDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DateFromUnixTimeInDaysDescriptor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,9 +16,6 @@
 
 import java.io.DataOutput;
 
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt8SerializerDeserializer;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import edu.uci.ics.asterix.om.base.ADate;
 import edu.uci.ics.asterix.om.base.AMutableDate;
@@ -28,7 +25,7 @@
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
-import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.om.types.hierachy.ATypeHierarchy;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
@@ -47,9 +44,6 @@
 
     // allowed input types
     private static final byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
-    private static final byte SER_INT8_TYPE_TAG = ATypeTag.INT8.serialize();
-    private static final byte SER_INT16_TYPE_TAG = ATypeTag.INT16.serialize();
-    private static final byte SER_INT32_TYPE_TAG = ATypeTag.INT32.serialize();
 
     public final static IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
 
@@ -91,19 +85,7 @@
                             if (argOut.getByteArray()[0] == SER_NULL_TYPE_TAG) {
                                 nullSerde.serialize(ANull.NULL, out);
                             } else {
-                                if (argOut.getByteArray()[0] == SER_INT8_TYPE_TAG) {
-                                    aDate.setValue(AInt8SerializerDeserializer.getByte(argOut.getByteArray(), 1));
-                                } else if (argOut.getByteArray()[0] == SER_INT16_TYPE_TAG) {
-                                    aDate.setValue(AInt16SerializerDeserializer.getShort(argOut.getByteArray(), 1));
-                                } else if (argOut.getByteArray()[0] == SER_INT32_TYPE_TAG) {
-                                    aDate.setValue(AInt32SerializerDeserializer.getInt(argOut.getByteArray(), 1));
-                                } else {
-                                    throw new AlgebricksException(
-                                            FID.getName()
-                                                    + ": expects type INT8/INT16/INT32/INT64/NULL but got "
-                                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut
-                                                            .getByteArray()[0]));
-                                }
+                                aDate.setValue(ATypeHierarchy.getIntegerValue(argOut.getByteArray(), 0));
                                 dateSerde.serialize(aDate, out);
                             }
                         } catch (HyracksDataException hex) {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DatetimeFromUnixTimeInMsDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DatetimeFromUnixTimeInMsDescriptor.java
index cf70d0a..0c742b7 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DatetimeFromUnixTimeInMsDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DatetimeFromUnixTimeInMsDescriptor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,7 +29,6 @@
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
-import edu.uci.ics.asterix.om.types.EnumDeserializer;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
@@ -46,13 +45,6 @@
     private final static long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = AsterixBuiltinFunctions.DATETIME_FROM_UNIX_TIME_IN_MS;
 
-    // allowed input types
-    private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
-    private final static byte SER_INT8_TYPE_TAG = ATypeTag.INT8.serialize();
-    private final static byte SER_INT16_TYPE_TAG = ATypeTag.INT16.serialize();
-    private final static byte SER_INT32_TYPE_TAG = ATypeTag.INT32.serialize();
-    private final static byte SER_INT64_TYPE_TAG = ATypeTag.INT64.serialize();
-
     public final static IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
 
         @Override
@@ -93,26 +85,36 @@
                         argOut.reset();
                         eval.evaluate(tuple);
                         try {
-                            if (argOut.getByteArray()[0] == SER_NULL_TYPE_TAG) {
+
+                            ATypeTag argOutTypeTag = ATypeTag.VALUE_TYPE_MAPPING[argOut.getByteArray()[0]];
+
+                            if (argOutTypeTag == ATypeTag.NULL) {
                                 nullSerde.serialize(ANull.NULL, out);
                             } else {
-                                if (argOut.getByteArray()[0] == SER_INT8_TYPE_TAG) {
-                                    aDatetime.setValue(AInt8SerializerDeserializer.getByte(argOut.getByteArray(), 1));
-                                } else if (argOut.getByteArray()[0] == SER_INT16_TYPE_TAG) {
-                                    aDatetime.setValue(AInt16SerializerDeserializer.getShort(argOut.getByteArray(), 1));
-                                } else if (argOut.getByteArray()[0] == SER_INT32_TYPE_TAG) {
-                                    aDatetime.setValue(AInt32SerializerDeserializer.getInt(argOut.getByteArray(), 1));
-                                } else if (argOut.getByteArray()[0] == SER_INT64_TYPE_TAG) {
-                                    aDatetime.setValue(AInt64SerializerDeserializer.getLong(argOut.getByteArray(), 1));
-                                } else {
-                                    throw new AlgebricksException(
-                                            FID.getName()
-                                                    + ": expects type INT8/INT16/INT32/INT64/NULL but got "
-                                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut
-                                                            .getByteArray()[0]));
+                                switch (argOutTypeTag) {
+                                    case INT8:
+                                        aDatetime
+                                                .setValue(AInt8SerializerDeserializer.getByte(argOut.getByteArray(), 1));
+                                        break;
+                                    case INT16:
+                                        aDatetime.setValue(AInt16SerializerDeserializer.getShort(argOut.getByteArray(),
+                                                1));
+                                        break;
+                                    case INT32:
+                                        aDatetime
+                                                .setValue(AInt32SerializerDeserializer.getInt(argOut.getByteArray(), 1));
+                                        break;
+                                    case INT64:
+                                        aDatetime.setValue(AInt64SerializerDeserializer.getLong(argOut.getByteArray(),
+                                                1));
+                                        break;
+                                    default:
+                                        throw new AlgebricksException(FID.getName()
+                                                + ": expects type INT8/INT16/INT32/INT64/NULL but got " + argOutTypeTag);
                                 }
                                 datetimeSerde.serialize(aDatetime, out);
                             }
+
                         } catch (HyracksDataException hex) {
                             throw new AlgebricksException(hex);
                         }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DatetimeFromUnixTimeInSecsDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DatetimeFromUnixTimeInSecsDescriptor.java
index f5c3afb..a0facc7 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DatetimeFromUnixTimeInSecsDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DatetimeFromUnixTimeInSecsDescriptor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,7 +29,6 @@
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
-import edu.uci.ics.asterix.om.types.EnumDeserializer;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
@@ -46,13 +45,6 @@
     private final static long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = AsterixBuiltinFunctions.DATETIME_FROM_UNIX_TIME_IN_SECS;
 
-    // allowed input types
-    private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
-    private final static byte SER_INT8_TYPE_TAG = ATypeTag.INT8.serialize();
-    private final static byte SER_INT16_TYPE_TAG = ATypeTag.INT16.serialize();
-    private final static byte SER_INT32_TYPE_TAG = ATypeTag.INT32.serialize();
-    private final static byte SER_INT64_TYPE_TAG = ATypeTag.INT64.serialize();
-
     public final static IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
 
         @Override
@@ -93,29 +85,40 @@
                         argOut.reset();
                         eval.evaluate(tuple);
                         try {
-                            if (argOut.getByteArray()[0] == SER_NULL_TYPE_TAG) {
+
+                            ATypeTag argOutTypeTag = ATypeTag.VALUE_TYPE_MAPPING[argOut.getByteArray()[0]];
+
+                            if (argOutTypeTag == ATypeTag.NULL) {
                                 nullSerde.serialize(ANull.NULL, out);
                             } else {
-                                if (argOut.getByteArray()[0] == SER_INT8_TYPE_TAG) {
-                                    aDatetime.setValue((AInt8SerializerDeserializer.getByte(argOut.getByteArray(), 1)*1000l));
-                                } else if (argOut.getByteArray()[0] == SER_INT16_TYPE_TAG) {
-                                    aDatetime.setValue((AInt16SerializerDeserializer.getShort(argOut.getByteArray(), 1)*1000l));
-                                } else if (argOut.getByteArray()[0] == SER_INT32_TYPE_TAG) {
-                                    aDatetime.setValue((AInt32SerializerDeserializer.getInt(argOut.getByteArray(), 1)*1000l));
-                                } else if (argOut.getByteArray()[0] == SER_INT64_TYPE_TAG) {
-                                    aDatetime.setValue((AInt64SerializerDeserializer.getLong(argOut.getByteArray(), 1)*1000l));
-                                } else {
-                                    throw new AlgebricksException(
-                                            FID.getName()
-                                                    + ": expects type INT8/INT16/INT32/INT64/NULL but got "
-                                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut
-                                                            .getByteArray()[0]));
+                                switch (argOutTypeTag) {
+                                    case INT8:
+                                        aDatetime.setValue((AInt8SerializerDeserializer.getByte(argOut.getByteArray(),
+                                                1) * 1000l));
+                                        break;
+                                    case INT16:
+                                        aDatetime.setValue((AInt16SerializerDeserializer.getShort(
+                                                argOut.getByteArray(), 1) * 1000l));
+                                        break;
+                                    case INT32:
+                                        aDatetime.setValue((AInt32SerializerDeserializer.getInt(argOut.getByteArray(),
+                                                1) * 1000l));
+                                        break;
+                                    case INT64:
+                                        aDatetime.setValue((AInt64SerializerDeserializer.getLong(argOut.getByteArray(),
+                                                1) * 1000l));
+                                        break;
+                                    default:
+                                        throw new AlgebricksException(FID.getName()
+                                                + ": expects type INT8/INT16/INT32/INT64/NULL but got " + argOutTypeTag);
                                 }
                                 datetimeSerde.serialize(aDatetime, out);
                             }
+
                         } catch (HyracksDataException hex) {
                             throw new AlgebricksException(hex);
                         }
+
                     }
                 };
             }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DayOfWeekDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DayOfWeekDescriptor.java
index 11ba264..dd062fb 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DayOfWeekDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DayOfWeekDescriptor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,8 +19,8 @@
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADateSerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADateTimeSerializerDeserializer;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.AInt32;
-import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
 import edu.uci.ics.asterix.om.base.ANull;
 import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
@@ -78,9 +78,9 @@
 
                     // possible returning types
                     @SuppressWarnings("unchecked")
-                    private ISerializerDeserializer<AInt32> int32Serde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.AINT32);
-                    private AMutableInt32 aInt32 = new AMutableInt32(0);
+                    private ISerializerDeserializer<AInt64> int64Serde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AINT64);
+                    private AMutableInt64 aInt64 = new AMutableInt64(0);
 
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
@@ -116,7 +116,7 @@
                                     daysSinceAnchor -= 1;
                                 }
 
-                                // compute the weekday (0-based, and 0 = Sunday). Adjustment is needed as the anchor day is Thursday 
+                                // compute the weekday (0-based, and 0 = Sunday). Adjustment is needed as the anchor day is Thursday
                                 int weekday = (daysSinceAnchor + ANCHOR_WEEKDAY) % 7;
 
                                 // handle the negative weekday
@@ -129,9 +129,9 @@
                                     weekday = 7;
                                 }
 
-                                aInt32.setValue(weekday);
+                                aInt64.setValue(weekday);
 
-                                int32Serde.serialize(aInt32, out);
+                                int64Serde.serialize(aInt64, out);
                             }
                         } catch (HyracksDataException hex) {
                             throw new AlgebricksException(hex);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DurationFromMillisecondsDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DurationFromMillisecondsDescriptor.java
index 267f4a7..a3762cf 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DurationFromMillisecondsDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DurationFromMillisecondsDescriptor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,7 +29,6 @@
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
-import edu.uci.ics.asterix.om.types.EnumDeserializer;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
@@ -46,13 +45,6 @@
     private final static long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = AsterixBuiltinFunctions.DURATION_FROM_MILLISECONDS;
 
-    // allowed input types
-    private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
-    private final static byte SER_INT8_TYPE_TAG = ATypeTag.INT8.serialize();
-    private final static byte SER_INT16_TYPE_TAG = ATypeTag.INT16.serialize();
-    private final static byte SER_INT32_TYPE_TAG = ATypeTag.INT32.serialize();
-    private final static byte SER_INT64_TYPE_TAG = ATypeTag.INT64.serialize();
-
     public final static IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
 
         @Override
@@ -91,30 +83,40 @@
                         eval0.evaluate(tuple);
 
                         try {
-                            if (argOut0.getByteArray()[0] == SER_NULL_TYPE_TAG) {
+
+                            ATypeTag argOutTypeTag = ATypeTag.VALUE_TYPE_MAPPING[argOut0.getByteArray()[0]];
+
+                            if (argOutTypeTag == ATypeTag.NULL) {
                                 nullSerde.serialize(ANull.NULL, out);
-                                return;
-                            }
-
-                            if (argOut0.getByteArray()[0] == SER_INT8_TYPE_TAG) {
-                                aDuration.setValue(0, AInt8SerializerDeserializer.getByte(argOut0.getByteArray(), 1));
-                            } else if (argOut0.getByteArray()[0] == SER_INT16_TYPE_TAG) {
-                                aDuration.setValue(0, AInt16SerializerDeserializer.getShort(argOut0.getByteArray(), 1));
-                            } else if (argOut0.getByteArray()[0] == SER_INT32_TYPE_TAG) {
-                                aDuration.setValue(0, AInt32SerializerDeserializer.getInt(argOut0.getByteArray(), 1));
-                            } else if (argOut0.getByteArray()[0] == SER_INT64_TYPE_TAG) {
-                                aDuration.setValue(0, AInt64SerializerDeserializer.getLong(argOut0.getByteArray(), 1));
                             } else {
-                                throw new AlgebricksException(FID.getName()
-                                        + ": expects NULL/INT8/INT16/INT32/INT64, but got "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut0.getByteArray()[0]));
+                                switch (argOutTypeTag) {
+                                    case INT8:
+                                        aDuration.setValue(0,
+                                                AInt8SerializerDeserializer.getByte(argOut0.getByteArray(), 1));
+                                        break;
+                                    case INT16:
+                                        aDuration.setValue(0,
+                                                AInt16SerializerDeserializer.getShort(argOut0.getByteArray(), 1));
+                                        break;
+                                    case INT32:
+                                        aDuration.setValue(0,
+                                                AInt32SerializerDeserializer.getInt(argOut0.getByteArray(), 1));
+                                        break;
+                                    case INT64:
+                                        aDuration.setValue(0,
+                                                AInt64SerializerDeserializer.getLong(argOut0.getByteArray(), 1));
+                                        break;
+                                    default:
+                                        throw new AlgebricksException(FID.getName()
+                                                + ": expects type INT8/INT16/INT32/INT64/NULL but got " + argOutTypeTag);
+                                }
+                                durationSerde.serialize(aDuration, out);
                             }
 
-                            durationSerde.serialize(aDuration, out);
-
                         } catch (HyracksDataException hex) {
                             throw new AlgebricksException(hex);
                         }
+
                     }
                 };
             }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DurationFromMonthsDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DurationFromMonthsDescriptor.java
index f8b7a3e..75795cf 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DurationFromMonthsDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DurationFromMonthsDescriptor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,9 +16,6 @@
 
 import java.io.DataOutput;
 
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt8SerializerDeserializer;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import edu.uci.ics.asterix.om.base.ADuration;
 import edu.uci.ics.asterix.om.base.AMutableDuration;
@@ -28,7 +25,7 @@
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
-import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.om.types.hierachy.ATypeHierarchy;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
@@ -47,9 +44,6 @@
 
     // allowed input types
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
-    private final static byte SER_INT8_TYPE_TAG = ATypeTag.INT8.serialize();
-    private final static byte SER_INT16_TYPE_TAG = ATypeTag.INT16.serialize();
-    private final static byte SER_INT32_TYPE_TAG = ATypeTag.INT32.serialize();
 
     public final static IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
 
@@ -94,18 +88,7 @@
                                 return;
                             }
 
-                            if (argOut0.getByteArray()[0] == SER_INT8_TYPE_TAG) {
-                                aDuration.setValue(AInt8SerializerDeserializer.getByte(argOut0.getByteArray(), 1), 0);
-                            } else if (argOut0.getByteArray()[0] == SER_INT16_TYPE_TAG) {
-                                aDuration.setValue(AInt16SerializerDeserializer.getShort(argOut0.getByteArray(), 1), 0);
-                            } else if (argOut0.getByteArray()[0] == SER_INT32_TYPE_TAG) {
-                                aDuration.setValue(AInt32SerializerDeserializer.getInt(argOut0.getByteArray(), 1), 0);
-                            } else {
-                                throw new AlgebricksException(FID.getName()
-                                        + ": expects NULL/INT8/INT16/INT32, but got "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut0.getByteArray()[0]));
-                            }
-
+                            aDuration.setValue(ATypeHierarchy.getIntegerValue(argOut0.getByteArray(), 0), 0);
                             durationSerde.serialize(aDuration, out);
 
                         } catch (HyracksDataException hex) {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/MonthsFromYearMonthDurationDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/MonthsFromYearMonthDurationDescriptor.java
index d2f2b07..59d2855 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/MonthsFromYearMonthDurationDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/MonthsFromYearMonthDurationDescriptor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,8 +18,8 @@
 
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AYearMonthDurationSerializerDeserializer;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.AInt32;
-import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
 import edu.uci.ics.asterix.om.base.ANull;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
@@ -74,10 +74,10 @@
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
                     @SuppressWarnings("unchecked")
-                    private ISerializerDeserializer<AInt32> int32Serde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.AINT32);
+                    private ISerializerDeserializer<AInt64> int64Serde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AINT64);
 
-                    AMutableInt32 aInt32 = new AMutableInt32(0);
+                    AMutableInt64 aInt64 = new AMutableInt64(0);
 
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
@@ -96,10 +96,10 @@
                                         + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut0.getByteArray()[0]));
                             }
 
-                            aInt32.setValue(AYearMonthDurationSerializerDeserializer.getYearMonth(
+                            aInt64.setValue(AYearMonthDurationSerializerDeserializer.getYearMonth(
                                     argOut0.getByteArray(), 1));
 
-                            int32Serde.serialize(aInt32, out);
+                            int64Serde.serialize(aInt64, out);
 
                         } catch (HyracksDataException hex) {
                             throw new AlgebricksException(hex);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/TimeFromUnixTimeInMsDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/TimeFromUnixTimeInMsDescriptor.java
index 0f8cfe8..40d7739 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/TimeFromUnixTimeInMsDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/TimeFromUnixTimeInMsDescriptor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,9 +16,6 @@
 
 import java.io.DataOutput;
 
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt8SerializerDeserializer;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import edu.uci.ics.asterix.om.base.AMutableTime;
 import edu.uci.ics.asterix.om.base.ANull;
@@ -28,7 +25,7 @@
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
-import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.om.types.hierachy.ATypeHierarchy;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
@@ -47,9 +44,6 @@
 
     // allowed input types
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
-    private final static byte SER_INT8_TYPE_TAG = ATypeTag.INT8.serialize();
-    private final static byte SER_INT16_TYPE_TAG = ATypeTag.INT16.serialize();
-    private final static byte SER_INT32_TYPE_TAG = ATypeTag.INT32.serialize();
 
     public final static IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
 
@@ -94,19 +88,7 @@
                             if (argOut.getByteArray()[0] == SER_NULL_TYPE_TAG) {
                                 nullSerde.serialize(ANull.NULL, out);
                             } else {
-                                if (argOut.getByteArray()[0] == SER_INT8_TYPE_TAG) {
-                                    aTime.setValue(AInt8SerializerDeserializer.getByte(argOut.getByteArray(), 1));
-                                } else if (argOut.getByteArray()[0] == SER_INT16_TYPE_TAG) {
-                                    aTime.setValue(AInt16SerializerDeserializer.getShort(argOut.getByteArray(), 1));
-                                } else if (argOut.getByteArray()[0] == SER_INT32_TYPE_TAG) {
-                                    aTime.setValue(AInt32SerializerDeserializer.getInt(argOut.getByteArray(), 1));
-                                } else {
-                                    throw new AlgebricksException(
-                                            FID.getName()
-                                                    + ": expects input type INT8/INT16/INT32/NULL but got "
-                                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut
-                                                            .getByteArray()[0]));
-                                }
+                                aTime.setValue(ATypeHierarchy.getIntegerValue(argOut.getByteArray(), 0));
                                 timeSerde.serialize(aTime, out);
                             }
                         } catch (HyracksDataException hex) {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/ADMDataParser.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/ADMDataParser.java
index a6419fe..31a1319 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/ADMDataParser.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/ADMDataParser.java
@@ -39,7 +39,7 @@
 import edu.uci.ics.asterix.om.types.AUnorderedListType;
 import edu.uci.ics.asterix.om.types.IAType;
 import edu.uci.ics.asterix.om.types.hierachy.ATypeHierarchy;
-import edu.uci.ics.asterix.om.types.hierachy.ITypePromoteComputer;
+import edu.uci.ics.asterix.om.types.hierachy.ITypeConvertComputer;
 import edu.uci.ics.asterix.om.util.NonTaggedFormatUtil;
 import edu.uci.ics.asterix.runtime.operators.file.adm.AdmLexer;
 import edu.uci.ics.asterix.runtime.operators.file.adm.AdmLexerException;
@@ -122,8 +122,8 @@
     }
 
     // Constructor for dealing with auto-generated PK
-    public ADMDataParser(String filename, boolean isPKAutoGenerated,
-            int primaryKeyPosition, ARecordType origRecTypeForAutoGeneratedPK) {
+    public ADMDataParser(String filename, boolean isPKAutoGenerated, int primaryKeyPosition,
+            ARecordType origRecTypeForAutoGeneratedPK) {
         this.filename = filename;
         this.isPKAutoGenerated = isPKAutoGenerated;
         this.primaryKeyPosition = primaryKeyPosition;
@@ -237,7 +237,8 @@
                 break;
             }
             case AdmLexer.TOKEN_INT_LITERAL: {
-                parseToNumericTarget(ATypeTag.INT32, objectType, out);
+                // For an INT value without any suffix, we return it as INT64 type value since it is the default integer type.
+                parseAndCastNumeric(ATypeTag.INT64, objectType, out);
                 break;
             }
             case AdmLexer.TOKEN_INT32_LITERAL: {
@@ -505,12 +506,19 @@
         }
         if (aObjectType.getTypeTag() != ATypeTag.UNION) {
             final ATypeTag typeTag = aObjectType.getTypeTag();
-            return ATypeHierarchy.canPromote(expectedTypeTag, typeTag) ? typeTag : null;
+            if (ATypeHierarchy.canPromote(expectedTypeTag, typeTag)
+                    || ATypeHierarchy.canDemote(expectedTypeTag, typeTag)) {
+                return typeTag;
+            } else {
+                return null;
+            }
+            //            return ATypeHierarchy.canPromote(expectedTypeTag, typeTag) ? typeTag : null;
         } else { // union
             List<IAType> unionList = ((AUnionType) aObjectType).getUnionList();
             for (IAType t : unionList) {
                 final ATypeTag typeTag = t.getTypeTag();
-                if (ATypeHierarchy.canPromote(expectedTypeTag, typeTag)) {
+                if (ATypeHierarchy.canPromote(expectedTypeTag, typeTag)
+                        || ATypeHierarchy.canDemote(expectedTypeTag, typeTag)) {
                     return typeTag;
                 }
             }
@@ -649,10 +657,10 @@
                 fieldValueBuffer.reset();
                 aUUID.nextUUID();
                 fieldValueBuffer.getDataOutput().writeByte(AUUIDTag);
-                Integer64SerializerDeserializer.INSTANCE
-                        .serialize(aUUID.getMostSignificantBits(), fieldValueBuffer.getDataOutput());
-                Integer64SerializerDeserializer.INSTANCE
-                        .serialize(aUUID.getLeastSignificantBits(), fieldValueBuffer.getDataOutput());
+                Integer64SerializerDeserializer.INSTANCE.serialize(aUUID.getMostSignificantBits(),
+                        fieldValueBuffer.getDataOutput());
+                Integer64SerializerDeserializer.INSTANCE.serialize(aUUID.getLeastSignificantBits(),
+                        fieldValueBuffer.getDataOutput());
                 recBuilder.addField(primaryKeyPosition, fieldValueBuffer);
                 insertedAutoGeneratedPK = true;
                 nulls.set(nullableFieldId);
@@ -844,8 +852,8 @@
         baaosPool.add(tempBaaos);
     }
 
-    private void parseToBinaryTarget(int lexerToken, String tokenImage, DataOutput out)
-            throws ParseException, HyracksDataException {
+    private void parseToBinaryTarget(int lexerToken, String tokenImage, DataOutput out) throws ParseException,
+            HyracksDataException {
         switch (lexerToken) {
             case AdmLexer.TOKEN_HEX_CONS: {
                 parseHexBinaryString(tokenImage.toCharArray(), 1, tokenImage.length() - 2, out);
@@ -879,13 +887,27 @@
             throw new ParseException(mismatchErrorMessage + objectType.getTypeName() + mismatchErrorMessage2 + typeTag);
         }
 
+        // If two type tags are not the same, either we try to promote or demote source type to the target type
         if (targetTypeTag != typeTag) {
-            ITypePromoteComputer promoteComputer = ATypeHierarchy.getTypePromoteComputer(typeTag, targetTypeTag);
-            // the availability if the promote computer should be consistent with the availability of a target type
-            assert promoteComputer != null;
-            // do the promotion; note that the type tag field should be skipped
-            promoteComputer.promote(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1,
-                    castBuffer.getLength() - 1, out);
+            if (ATypeHierarchy.canPromote(typeTag, targetTypeTag)) {
+                // can promote typeTag to targetTypeTag
+                ITypeConvertComputer promoteComputer = ATypeHierarchy.getTypePromoteComputer(typeTag, targetTypeTag);
+                if (promoteComputer == null) {
+                    throw new AsterixException("Can't cast the " + typeTag + " type to the " + targetTypeTag + " type.");
+                }
+                // do the promotion; note that the type tag field should be skipped
+                promoteComputer.convertType(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1,
+                        castBuffer.getLength() - 1, out);
+            } else if (ATypeHierarchy.canDemote(typeTag, targetTypeTag)) {
+                //can demote source type to the target type
+                ITypeConvertComputer demoteComputer = ATypeHierarchy.getTypeDemoteComputer(typeTag, targetTypeTag);
+                if (demoteComputer == null) {
+                    throw new AsterixException("Can't cast the " + typeTag + " type to the " + targetTypeTag + " type.");
+                }
+                // do the demotion; note that the type tag field should be skipped
+                demoteComputer.convertType(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1,
+                        castBuffer.getLength() - 1, out);
+            }
         }
     }
 
@@ -911,12 +933,12 @@
                     token = admLexer.next();
                     if (token == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
                         if (targetTypeTag != typeTag) {
-                            ITypePromoteComputer promoteComputer = ATypeHierarchy.getTypePromoteComputer(typeTag,
+                            ITypeConvertComputer promoteComputer = ATypeHierarchy.getTypePromoteComputer(typeTag,
                                     targetTypeTag);
                             // the availability if the promote computer should be consistent with the availability of a target type
                             assert promoteComputer != null;
                             // do the promotion; note that the type tag field should be skipped
-                            promoteComputer.promote(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1,
+                            promoteComputer.convertType(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1,
                                     castBuffer.getLength() - 1, out);
                         }
                         return;
@@ -1059,8 +1081,8 @@
         for (; offset < int16.length(); offset++) {
             if (int16.charAt(offset) >= '0' && int16.charAt(offset) <= '9') {
                 value = (short) (value * 10 + int16.charAt(offset) - '0');
-            } else if (int16.charAt(offset) == 'i' && int16.charAt(offset + 1) == '1' && int16.charAt(offset + 2) == '6'
-                    && offset + 3 == int16.length()) {
+            } else if (int16.charAt(offset) == 'i' && int16.charAt(offset + 1) == '1'
+                    && int16.charAt(offset + 2) == '6' && offset + 3 == int16.length()) {
                 break;
             } else {
                 throw new ParseException(errorMessage);
@@ -1091,8 +1113,8 @@
         for (; offset < int32.length(); offset++) {
             if (int32.charAt(offset) >= '0' && int32.charAt(offset) <= '9') {
                 value = (value * 10 + int32.charAt(offset) - '0');
-            } else if (int32.charAt(offset) == 'i' && int32.charAt(offset + 1) == '3' && int32.charAt(offset + 2) == '2'
-                    && offset + 3 == int32.length()) {
+            } else if (int32.charAt(offset) == 'i' && int32.charAt(offset + 1) == '3'
+                    && int32.charAt(offset + 2) == '2' && offset + 3 == int32.length()) {
                 break;
             } else {
                 throw new ParseException(errorMessage);
@@ -1124,8 +1146,8 @@
         for (; offset < int64.length(); offset++) {
             if (int64.charAt(offset) >= '0' && int64.charAt(offset) <= '9') {
                 value = (value * 10 + int64.charAt(offset) - '0');
-            } else if (int64.charAt(offset) == 'i' && int64.charAt(offset + 1) == '6' && int64.charAt(offset + 2) == '4'
-                    && offset + 3 == int64.length()) {
+            } else if (int64.charAt(offset) == 'i' && int64.charAt(offset + 1) == '6'
+                    && int64.charAt(offset + 2) == '4' && offset + 3 == int64.length()) {
                 break;
             } else {
                 throw new ParseException(errorMessage);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/DelimitedDataParser.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/DelimitedDataParser.java
index c3ddde6..41cc7cf 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/DelimitedDataParser.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/DelimitedDataParser.java
@@ -18,8 +18,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.Reader;
-import java.util.Arrays;
 
 import edu.uci.ics.asterix.builders.IARecordBuilder;
 import edu.uci.ics.asterix.builders.RecordBuilder;
@@ -36,6 +34,7 @@
 import edu.uci.ics.hyracks.dataflow.common.data.marshalling.Integer64SerializerDeserializer;
 import edu.uci.ics.hyracks.dataflow.common.data.parsers.IValueParser;
 import edu.uci.ics.hyracks.dataflow.common.data.parsers.IValueParserFactory;
+import edu.uci.ics.hyracks.dataflow.std.file.FieldCursorForDelimitedDataParser;
 
 public class DelimitedDataParser extends AbstractDataParser implements IDataParser {
 
@@ -49,7 +48,7 @@
     private ArrayBackedValueStorage fieldValueBuffer;
     private DataOutput fieldValueBufferOutput;
     private IValueParser[] valueParsers;
-    private FieldCursor cursor;
+    private FieldCursorForDelimitedDataParser cursor;
     private byte[] fieldTypeTags;
     private int[] fldIds;
     private ArrayBackedValueStorage[] nameBuffers;
@@ -61,20 +60,16 @@
     private final ARecordType origRecordTypeForAutoGeneratedPK;
 
     private boolean areAllNullFields;
-    private boolean isDoubleQuoteIncludedInThisField;
-    private int doubleQuoteCount;
-
-    private int lineCount;
     private int fieldCount;
 
     public DelimitedDataParser(ARecordType recordType, IValueParserFactory[] valueParserFactories, char fieldDelimter,
-                               char quote, boolean hasHeader) {
+            char quote, boolean hasHeader) {
         this(recordType, valueParserFactories, fieldDelimter, quote, hasHeader, false, -1, null);
     }
 
     public DelimitedDataParser(ARecordType recordType, IValueParserFactory[] valueParserFactories, char fieldDelimter,
-                               char quote, boolean hasHeader, boolean isPKAutoGenerated, int primaryKeyPosition,
-                               ARecordType origRecordTypeForAutoGeneratedPK) {
+            char quote, boolean hasHeader, boolean isPKAutoGenerated, int primaryKeyPosition,
+            ARecordType origRecordTypeForAutoGeneratedPK) {
         this.recordType = recordType;
         this.valueParserFactories = valueParserFactories;
         this.fieldDelimiter = fieldDelimter;
@@ -95,15 +90,11 @@
         else
             recordTypeToApply = recordType;
 
-        lineCount = 1;
-
         valueParsers = new IValueParser[valueParserFactories.length];
         for (int i = 0; i < valueParserFactories.length; ++i) {
             valueParsers[i] = valueParserFactories[i].createValueParser();
         }
 
-        isDoubleQuoteIncludedInThisField = false;
-
         fieldValueBuffer = new ArrayBackedValueStorage();
         fieldValueBufferOutput = fieldValueBuffer.getDataOutput();
 
@@ -136,15 +127,15 @@
             }
         }
 
-        cursor = new FieldCursor(new InputStreamReader(in));
+        cursor = new FieldCursorForDelimitedDataParser(new InputStreamReader(in), fieldDelimiter, quote);
     }
 
     @Override
     public boolean parse(DataOutput out) throws AsterixException, IOException {
-        if (hasHeader && lineCount == 1) {
+        if (hasHeader && cursor.lineCount == 1) {
             // Consume all fields of first record
             cursor.nextRecord();
-            while (cursor.nextField());
+            while (cursor.nextField(fieldCount));
         }
         while (cursor.nextRecord()) {
             // If PK is auto-generated, then we need to use the recordType that
@@ -160,7 +151,7 @@
             fieldCount = 0;
 
             for (int i = 0; i < valueParsers.length; ++i) {
-                if (!cursor.nextField()) {
+                if (!cursor.nextField(fieldCount)) {
                     break;
                 }
                 fieldValueBuffer.reset();
@@ -172,7 +163,7 @@
                     // empty string
                     if (recordType.getFieldTypes()[i].getTypeTag() != ATypeTag.UNION
                             || !NonTaggedFormatUtil.isOptionalField((AUnionType) recordType.getFieldTypes()[i])) {
-                        throw new AsterixException("At line: " + lineCount + " - Field " + i
+                        throw new AsterixException("At line: " + cursor.lineCount + " - Field " + i
                                 + " is not an optional type so it cannot accept null value. ");
                     }
                     fieldValueBufferOutput.writeByte(ATypeTag.NULL.serialize());
@@ -180,10 +171,10 @@
                 } else {
                     fieldValueBufferOutput.writeByte(fieldTypeTags[i]);
                     // Eliminate doule quotes in the field that we are going to parse
-                    if (isDoubleQuoteIncludedInThisField) {
-                        eliminateDoubleQuote(cursor.buffer, cursor.fStart, cursor.fEnd - cursor.fStart);
-                        cursor.fEnd -= doubleQuoteCount;
-                        isDoubleQuoteIncludedInThisField = false;
+                    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);
@@ -215,7 +206,7 @@
             } else if (isPKAutoGenerated && fieldCount >= origRecordTypeForAutoGeneratedPK.getFieldTypes().length) {
                 // If we have all fields in the file including auto-generated PK,
                 // throw an exception
-                throw new AsterixException("At line: " + lineCount
+                throw new AsterixException("At line: " + cursor.lineCount
                         + " - check number of fields. Auto-generated PK field should not exist in the input data.");
             }
 
@@ -239,329 +230,4 @@
         }
     }
 
-    protected enum State {
-        INIT,
-        IN_RECORD,
-        EOR,
-        CR,
-        EOF
-    }
-
-    protected class FieldCursor {
-        private static final int INITIAL_BUFFER_SIZE = 4096;
-        private static final int INCREMENT = 4096;
-
-        private final Reader in;
-
-        private char[] buffer;
-        private int start;
-        private int end;
-        private State state;
-
-        private int fStart;
-        private int fEnd;
-
-        private int lastQuotePosition;
-        private int lastDoubleQuotePosition;
-        private int lastDelimiterPosition;
-        private int quoteCount;
-        private boolean startedQuote;
-
-        public FieldCursor(Reader in) {
-            this.in = in;
-            buffer = new char[INITIAL_BUFFER_SIZE];
-            start = 0;
-            end = 0;
-            state = State.INIT;
-            lastDelimiterPosition = -99;
-            lastQuotePosition = -99;
-            lastDoubleQuotePosition = -99;
-            quoteCount = 0;
-            startedQuote = false;
-        }
-
-        public boolean nextRecord() throws IOException {
-            while (true) {
-                switch (state) {
-                    case INIT:
-                        boolean eof = !readMore();
-                        if (eof) {
-                            state = State.EOF;
-                            return false;
-                        } else {
-                            state = State.IN_RECORD;
-                            return true;
-                        }
-
-                    case IN_RECORD:
-                        int p = start;
-                        while (true) {
-                            if (p >= end) {
-                                int s = start;
-                                eof = !readMore();
-                                if (eof) {
-                                    state = State.EOF;
-                                    return start < end;
-                                }
-                                p -= (s - start);
-                                lastQuotePosition -= (s - start);
-                                lastDoubleQuotePosition -= (s - start);
-                                lastDelimiterPosition -= (s - start);
-                            }
-                            char ch = buffer[p];
-                            // We perform rough format correctness (delimiter, quote) check here
-                            // to set the starting position of a record.
-                            // In the field level, more checking will be conducted.
-                            if (ch == quote) {
-                                startedQuote = true;
-                                // check two quotes in a row - "". This is an escaped quote
-                                if (lastQuotePosition == p - 1 && start != p - 1 && lastDoubleQuotePosition != p - 1) {
-                                    lastDoubleQuotePosition = p;
-                                }
-                                lastQuotePosition = p;
-                            } else if (ch == fieldDelimiter) {
-                                if (startedQuote && lastQuotePosition == p - 1 && lastDoubleQuotePosition != p - 1) {
-                                    startedQuote = false;
-                                    lastDelimiterPosition = p;
-                                }
-                            } else if (ch == '\n' && !startedQuote) {
-                                start = p + 1;
-                                state = State.EOR;
-                                lineCount++;
-                                lastDelimiterPosition = p;
-                                break;
-                            } else if (ch == '\r' && !startedQuote) {
-                                start = p + 1;
-                                state = State.CR;
-                                break;
-                            }
-                            ++p;
-                        }
-                        break;
-
-                    case CR:
-                        if (start >= end) {
-                            eof = !readMore();
-                            if (eof) {
-                                state = State.EOF;
-                                return false;
-                            }
-                        }
-                        char ch = buffer[start];
-                        if (ch == '\n' && !startedQuote) {
-                            ++start;
-                            state = State.EOR;
-                            lineCount++;
-                        } else {
-                            state = State.IN_RECORD;
-                            return true;
-                        }
-
-                    case EOR:
-                        if (start >= end) {
-                            eof = !readMore();
-                            if (eof) {
-                                state = State.EOF;
-                                return false;
-                            }
-                        }
-                        state = State.IN_RECORD;
-                        lastDelimiterPosition = start;
-                        return start < end;
-
-                    case EOF:
-                        return false;
-                }
-            }
-        }
-
-        public boolean nextField() throws IOException {
-            switch (state) {
-                case INIT:
-                case EOR:
-                case EOF:
-                case CR:
-                    return false;
-
-                case IN_RECORD:
-                    boolean eof;
-                    // reset quote related values
-                    startedQuote = false;
-                    isDoubleQuoteIncludedInThisField = false;
-                    lastQuotePosition = -99;
-                    lastDoubleQuotePosition = -99;
-                    quoteCount = 0;
-                    doubleQuoteCount = 0;
-
-                    int p = start;
-                    while (true) {
-                        if (p >= end) {
-                            int s = start;
-                            eof = !readMore();
-                            p -= (s - start);
-                            lastQuotePosition -= (s - start);
-                            lastDoubleQuotePosition -= (s - start);
-                            lastDelimiterPosition -= (s - start);
-                            if (eof) {
-                                state = State.EOF;
-                                if (startedQuote && lastQuotePosition == p - 1 && lastDoubleQuotePosition != p - 1
-                                        && quoteCount == doubleQuoteCount * 2 + 2) {
-                                    // set the position of fStart to +1, fEnd to -1 to remove quote character
-                                    fStart = start + 1;
-                                    fEnd = p - 1;
-                                } else {
-                                    fStart = start;
-                                    fEnd = p;
-                                }
-                                return true;
-                            }
-                        }
-                        char ch = buffer[p];
-                        if (ch == quote) {
-                            // If this is first quote in the field, then it needs to be placed in the beginning.
-                            if (!startedQuote) {
-                                if (lastDelimiterPosition == p - 1 || lastDelimiterPosition == -99) {
-                                    startedQuote = true;
-                                } else {
-                                    // In this case, we don't have a quote in the beginning of a field.
-                                    throw new IOException(
-                                            "At line: "
-                                                    + lineCount
-                                                    + ", field#: "
-                                                    + (fieldCount+1)
-                                                    + " - a quote enclosing a field needs to be placed in the beginning of that field.");
-                                }
-                            }
-                            // Check double quotes - "". We check [start != p-2]
-                            // to avoid false positive where there is no value in a field,
-                            // since it looks like a double quote. However, it's not a double quote.
-                            // (e.g. if field2 has no value:
-                            //       field1,"",field3 ... )
-                            if (lastQuotePosition == p - 1 && lastDelimiterPosition != p - 2
-                                    && lastDoubleQuotePosition != p - 1) {
-                                isDoubleQuoteIncludedInThisField = true;
-                                doubleQuoteCount++;
-                                lastDoubleQuotePosition = p;
-                            }
-                            lastQuotePosition = p;
-                            quoteCount++;
-                        } else if (ch == fieldDelimiter) {
-                            // If there was no quote in the field,
-                            // then we assume that the field contains a valid string.
-                            if (!startedQuote) {
-                                fStart = start;
-                                fEnd = p;
-                                start = p + 1;
-                                lastDelimiterPosition = p;
-                                return true;
-                            } else if (startedQuote) {
-                                if (lastQuotePosition == p - 1 && lastDoubleQuotePosition != p - 1) {
-                                    // There is a quote right before the delimiter (e.g. ",)  and it is not two quote,
-                                    // then the field contains a valid string.
-                                    // We set the position of fStart to +1, fEnd to -1 to remove quote character
-                                    fStart = start + 1;
-                                    fEnd = p - 1;
-                                    start = p + 1;
-                                    lastDelimiterPosition = p;
-                                    return true;
-                                } else if (lastQuotePosition < p - 1 && lastQuotePosition != lastDoubleQuotePosition
-                                        && quoteCount == doubleQuoteCount * 2 + 2) {
-                                    // There is a quote before the delimiter, however it is not directly placed before the delimiter.
-                                    // In this case, we throw an exception.
-                                    // quoteCount == doubleQuoteCount * 2 + 2 : only true when we have two quotes except double-quotes.
-                                    throw new IOException("At line: " + lineCount + ", field#: " + (fieldCount+1)
-                                            + " -  A quote enclosing a field needs to be followed by the delimiter.");
-                                }
-                            }
-                            // If the control flow reaches here: we have a delimiter in this field and
-                            // there should be a quote in the beginning and the end of
-                            // this field. So, just continue reading next character
-                        } else if (ch == '\n') {
-                            if (!startedQuote) {
-                                fStart = start;
-                                fEnd = p;
-                                start = p + 1;
-                                state = State.EOR;
-                                lineCount++;
-                                lastDelimiterPosition = p;
-                                return true;
-                            } else if (startedQuote && lastQuotePosition == p - 1 && lastDoubleQuotePosition != p - 1
-                                    && quoteCount == doubleQuoteCount * 2 + 2) {
-                                // set the position of fStart to +1, fEnd to -1 to remove quote character
-                                fStart = start + 1;
-                                fEnd = p - 1;
-                                lastDelimiterPosition = p;
-                                start = p + 1;
-                                state = State.EOR;
-                                lineCount++;
-                                return true;
-                            }
-                        } else if (ch == '\r') {
-                            if (!startedQuote) {
-                                fStart = start;
-                                fEnd = p;
-                                start = p + 1;
-                                state = State.CR;
-                                lastDelimiterPosition = p;
-                                return true;
-                            } else if (startedQuote && lastQuotePosition == p - 1 && lastDoubleQuotePosition != p - 1
-                                    && quoteCount == doubleQuoteCount * 2 + 2) {
-                                // set the position of fStart to +1, fEnd to -1 to remove quote character
-                                fStart = start + 1;
-                                fEnd = p - 1;
-                                lastDelimiterPosition = p;
-                                start = p + 1;
-                                state = State.CR;
-                                startedQuote = false;
-                                return true;
-                            }
-                        }
-                        ++p;
-                    }
-            }
-            throw new IllegalStateException();
-        }
-
-        protected boolean readMore() throws IOException {
-            if (start > 0) {
-                System.arraycopy(buffer, start, buffer, 0, end - start);
-            }
-            end -= start;
-            start = 0;
-
-            if (end == buffer.length) {
-                buffer = Arrays.copyOf(buffer, buffer.length + INCREMENT);
-            }
-
-            int n = in.read(buffer, end, buffer.length - end);
-            if (n < 0) {
-                return false;
-            }
-            end += n;
-            return true;
-        }
-
-    }
-
-    // Eliminate escaped double quotes("") in a field
-    protected void eliminateDoubleQuote(char[] buffer, int start, int length) {
-        int lastDoubleQuotePosition = -99;
-        int writepos = start;
-        int readpos = start;
-        // Find positions where double quotes appear
-        for (int i = 0; i < length; i++) {
-            // Skip double quotes
-            if (buffer[readpos] == quote && lastDoubleQuotePosition != readpos - 1) {
-                lastDoubleQuotePosition = readpos;
-                readpos++;
-            } else {
-                // Moving characters except double quote to the front
-                if (writepos != readpos) {
-                    buffer[writepos] = buffer[readpos];
-                }
-                writepos++;
-                readpos++;
-            }
-        }
-    }
 }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/runningaggregates/std/TidRunningAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/runningaggregates/std/TidRunningAggregateDescriptor.java
index a199f2d..f904601 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/runningaggregates/std/TidRunningAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/runningaggregates/std/TidRunningAggregateDescriptor.java
@@ -3,9 +3,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,8 +17,8 @@
 import java.io.DataOutput;
 
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.AInt32;
-import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
@@ -62,9 +62,9 @@
                 return new ICopyRunningAggregateFunction() {
 
                     int cnt;
-                    ISerializerDeserializer<AInt32> serde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.AINT32);
-                    AMutableInt32 m = new AMutableInt32(0);
+                    ISerializerDeserializer<AInt64> serde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AINT64);
+                    AMutableInt64 m = new AMutableInt64(0);
 
                     @Override
                     public void step(IFrameTupleReference tuple) throws AlgebricksException {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/unnestingfunctions/std/RangeDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/unnestingfunctions/std/RangeDescriptor.java
index 1c32442..431ba85 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/unnestingfunctions/std/RangeDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/unnestingfunctions/std/RangeDescriptor.java
@@ -17,11 +17,12 @@
 import java.io.DataOutput;
 
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
 import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.hierachy.ATypeHierarchy;
 import edu.uci.ics.asterix.runtime.unnestingfunctions.base.AbstractUnnestingFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
@@ -32,7 +33,6 @@
 import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
 import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
-import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -66,22 +66,30 @@
                     private DataOutput out = provider.getDataOutput();
                     @SuppressWarnings("rawtypes")
                     private ISerializerDeserializer serde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.AINT32);
+                            .getSerializerDeserializer(BuiltinType.AINT64);
                     private ArrayBackedValueStorage inputVal = new ArrayBackedValueStorage();
                     private ICopyEvaluator eval0 = args[0].createEvaluator(inputVal);
                     private ICopyEvaluator eval1 = args[1].createEvaluator(inputVal);
-                    private AMutableInt32 aInt32 = new AMutableInt32(0);
-                    private int current;
-                    private int max;
+                    private AMutableInt64 aInt64 = new AMutableInt64(0);
+                    private long current;
+                    private long max;
 
                     @Override
                     public void init(IFrameTupleReference tuple) throws AlgebricksException {
                         inputVal.reset();
                         eval0.evaluate(tuple);
-                        current = IntegerPointable.getInteger(inputVal.getByteArray(), 1);
+                        try {
+                            current = ATypeHierarchy.getLongValue(inputVal.getByteArray(), 0);
+                        } catch (HyracksDataException e) {
+                            throw new AlgebricksException(e);
+                        }
                         inputVal.reset();
                         eval1.evaluate(tuple);
-                        max = IntegerPointable.getInteger(inputVal.getByteArray(), 1);
+                        try {
+                            max = ATypeHierarchy.getLongValue(inputVal.getByteArray(), 0);
+                        } catch (HyracksDataException e) {
+                            throw new AlgebricksException(e);
+                        }
                     }
 
                     @SuppressWarnings("unchecked")
@@ -90,9 +98,9 @@
                         if (current > max) {
                             return false;
                         }
-                        aInt32.setValue(current);
+                        aInt64.setValue(current);
                         try {
-                            serde.serialize(aInt32, out);
+                            serde.serialize(aInt64, out);
                         } catch (HyracksDataException e) {
                             throw new AlgebricksException(e);
                         }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/unnestingfunctions/std/SubsetCollectionDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/unnestingfunctions/std/SubsetCollectionDescriptor.java
index 84a528f..20ffbc7 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/unnestingfunctions/std/SubsetCollectionDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/unnestingfunctions/std/SubsetCollectionDescriptor.java
@@ -28,6 +28,7 @@
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.om.types.hierachy.ATypeHierarchy;
 import edu.uci.ics.asterix.om.util.NonTaggedFormatUtil;
 import edu.uci.ics.asterix.runtime.unnestingfunctions.base.AbstractUnnestingFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -38,7 +39,6 @@
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyUnnestingFunctionFactory;
 import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
-import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -88,11 +88,13 @@
                         try {
                             inputVal.reset();
                             evalStart.evaluate(tuple);
-                            posStart = IntegerPointable.getInteger(inputVal.getByteArray(), 1);
+
+                            posStart = ATypeHierarchy.getIntegerValue(inputVal.getByteArray(), 0);
 
                             inputVal.reset();
                             evalLen.evaluate(tuple);
-                            numItems = IntegerPointable.getInteger(inputVal.getByteArray(), 1);
+
+                            numItems = ATypeHierarchy.getIntegerValue(inputVal.getByteArray(), 0);
 
                             inputVal.reset();
                             evalList.evaluate(tuple);
diff --git a/asterix-runtime/src/main/resources/adm.grammar b/asterix-runtime/src/main/resources/adm.grammar
index b0ca26f..2446e48 100644
--- a/asterix-runtime/src/main/resources/adm.grammar
+++ b/asterix-runtime/src/main/resources/adm.grammar
@@ -13,6 +13,7 @@
 INT16_CONS     = string(int16)
 INT32_CONS     = string(int32)
 INT64_CONS     = string(int64)
+INT64_CONS     = string(int)
 FLOAT_CONS     = string(float)
 DOUBLE_CONS    = string(double)
 DATE_CONS      = string(date)