fix parsing and promotion of int[8|16|32|64] literals
change ITypePromoteComputer.promote to accept a DataOutput instead of an IMutableValueStorage
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/cast/ACastVisitor.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/cast/ACastVisitor.java
index a711eb9..e93048e 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/cast/ACastVisitor.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/cast/ACastVisitor.java
@@ -112,7 +112,7 @@
                 try {
                     // do the promotion; note that the type tag field should be skipped
                     promoteComputer.promote(accessor.getByteArray(), accessor.getStartOffset() + 1,
-                            accessor.getLength() - 1, castBuffer);
+                            accessor.getLength() - 1, castBuffer.getDataOutput());
                     arg.first.set(castBuffer);
                 } catch (IOException e) {
                     throw new AsterixException(e);
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/AbstractIntegerTypePromoteComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/AbstractIntegerTypePromoteComputer.java
index 7df6f43..e10e41a 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/AbstractIntegerTypePromoteComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/AbstractIntegerTypePromoteComputer.java
@@ -14,23 +14,23 @@
  */
 package edu.uci.ics.asterix.om.types.hierachy;
 
+import java.io.DataOutput;
 import java.io.IOException;
 
 import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.hyracks.data.std.api.IMutableValueStorage;
 
 public abstract class AbstractIntegerTypePromoteComputer implements ITypePromoteComputer {
 
-    public void promoteIntegerType(byte[] data, int start, int length, IMutableValueStorage storageForPromotedValue,
+    public void promoteIntegerType(byte[] data, int start, int length, DataOutput out,
             ATypeTag targetType, int targetTypeLength) throws IOException {
-        storageForPromotedValue.getDataOutput().writeByte(targetType.serialize());
+        out.writeByte(targetType.serialize());
         long num = 0;
         for (int i = start; i < start + length; i++) {
             num += (data[i] & 0xff) << ((length - 1 - (i - start)) * 8);
         }
 
         for (int i = targetTypeLength - 1; i >= 0; i--) {
-            storageForPromotedValue.getDataOutput().writeByte((byte) ((num >>> (i * 8)) & 0xFF));
+            out.writeByte((byte) ((num >>> (i * 8)) & 0xFF));
         }
     }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/FloatToDoubleTypePromoteComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/FloatToDoubleTypePromoteComputer.java
index a3cfbc8..70c6097 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/FloatToDoubleTypePromoteComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/FloatToDoubleTypePromoteComputer.java
@@ -14,10 +14,10 @@
  */
 package edu.uci.ics.asterix.om.types.hierachy;
 
+import java.io.DataOutput;
 import java.io.IOException;
 
 import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.hyracks.data.std.api.IMutableValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.marshalling.DoubleSerializerDeserializer;
 import edu.uci.ics.hyracks.dataflow.common.data.marshalling.FloatSerializerDeserializer;
 
@@ -33,11 +33,11 @@
      * @see edu.uci.ics.asterix.om.types.hierachy.ITypePromoteComputer#promote(byte[], int, int, edu.uci.ics.hyracks.data.std.api.IMutableValueStorage)
      */
     @Override
-    public void promote(byte[] data, int start, int length, IMutableValueStorage storageForPromotedValue)
+    public void promote(byte[] data, int start, int length, DataOutput out)
             throws IOException {
-        storageForPromotedValue.getDataOutput().writeByte(ATypeTag.DOUBLE.serialize());
+        out.writeByte(ATypeTag.DOUBLE.serialize());
         DoubleSerializerDeserializer.INSTANCE.serialize((double) (FloatSerializerDeserializer.getFloat(data, start)),
-                storageForPromotedValue.getDataOutput());
+                out);
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/ITypePromoteComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/ITypePromoteComputer.java
index e8612af..995b61a 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/ITypePromoteComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/ITypePromoteComputer.java
@@ -14,12 +14,11 @@
  */
 package edu.uci.ics.asterix.om.types.hierachy;
 
+import java.io.DataOutput;
 import java.io.IOException;
 
-import edu.uci.ics.hyracks.data.std.api.IMutableValueStorage;
-
 public interface ITypePromoteComputer {
 
-    void promote(byte[] data, int start, int length, IMutableValueStorage storageForPromotedValue) throws IOException;
+    void promote(byte[] data, int start, int length, DataOutput out) throws IOException;
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToDoubleTypePromoteComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToDoubleTypePromoteComputer.java
index dfd116e..4987b94 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToDoubleTypePromoteComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToDoubleTypePromoteComputer.java
@@ -14,10 +14,10 @@
  */
 package edu.uci.ics.asterix.om.types.hierachy;
 
+import java.io.DataOutput;
 import java.io.IOException;
 
 import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.hyracks.data.std.api.IMutableValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.marshalling.DoubleSerializerDeserializer;
 
 public class IntegerToDoubleTypePromoteComputer implements ITypePromoteComputer {
@@ -29,14 +29,14 @@
     }
 
     @Override
-    public void promote(byte[] data, int start, int length, IMutableValueStorage storageForPromotedValue)
+    public void promote(byte[] data, int start, int length, DataOutput out)
             throws IOException {
-        storageForPromotedValue.getDataOutput().writeByte(ATypeTag.DOUBLE.serialize());
+        out.writeByte(ATypeTag.DOUBLE.serialize());
         long val = 0L;
         for (int i = 0; i < length; i++) {
             val += ((long) (data[start + i] & 0xff)) << (8 * (length - 1 - i));
         }
-        DoubleSerializerDeserializer.INSTANCE.serialize(Double.valueOf(val), storageForPromotedValue.getDataOutput());
+        DoubleSerializerDeserializer.INSTANCE.serialize(Double.valueOf(val), out);
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToFloatTypePromoteComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToFloatTypePromoteComputer.java
index c1bd9e5..db8d59a 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToFloatTypePromoteComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToFloatTypePromoteComputer.java
@@ -14,10 +14,10 @@
  */
 package edu.uci.ics.asterix.om.types.hierachy;
 
+import java.io.DataOutput;
 import java.io.IOException;
 
 import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.hyracks.data.std.api.IMutableValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.marshalling.FloatSerializerDeserializer;
 
 public class IntegerToFloatTypePromoteComputer implements ITypePromoteComputer {
@@ -32,14 +32,14 @@
      * @see edu.uci.ics.asterix.om.types.hierachy.ITypePromoteComputer#promote(byte[], int, int, edu.uci.ics.hyracks.data.std.api.IMutableValueStorage)
      */
     @Override
-    public void promote(byte[] data, int start, int length, IMutableValueStorage storageForPromotedValue)
+    public void promote(byte[] data, int start, int length, DataOutput out)
             throws IOException {
-        storageForPromotedValue.getDataOutput().writeByte(ATypeTag.FLOAT.serialize());
+        out.writeByte(ATypeTag.FLOAT.serialize());
         float val = 0;
         for (int i = 0; i < length; i++) {
             val += (data[start + i] & 0xff) << (8 * (length - 1 - i));
         }
-        FloatSerializerDeserializer.INSTANCE.serialize(val, storageForPromotedValue.getDataOutput());
+        FloatSerializerDeserializer.INSTANCE.serialize(val, out);
 
     }
 
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt16TypePromoteComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt16TypePromoteComputer.java
index 8835a57..6731c8c 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt16TypePromoteComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt16TypePromoteComputer.java
@@ -14,10 +14,10 @@
  */
 package edu.uci.ics.asterix.om.types.hierachy;
 
+import java.io.DataOutput;
 import java.io.IOException;
 
 import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.hyracks.data.std.api.IMutableValueStorage;
 
 public class IntegerToInt16TypePromoteComputer extends AbstractIntegerTypePromoteComputer {
 
@@ -31,9 +31,9 @@
      * @see edu.uci.ics.asterix.om.types.hierachy.ITypePromoteComputer#promote(byte[], int, int, edu.uci.ics.hyracks.data.std.api.IMutableValueStorage)
      */
     @Override
-    public void promote(byte[] data, int start, int length, IMutableValueStorage storageForPromotedValue)
+    public void promote(byte[] data, int start, int length, DataOutput out)
             throws IOException {
-        promoteIntegerType(data, start, length, storageForPromotedValue, ATypeTag.INT16, 2);
+        promoteIntegerType(data, start, length, out, ATypeTag.INT16, 2);
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt32TypePromoteComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt32TypePromoteComputer.java
index 8a808bf..6e3978c 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt32TypePromoteComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt32TypePromoteComputer.java
@@ -14,10 +14,10 @@
  */
 package edu.uci.ics.asterix.om.types.hierachy;
 
+import java.io.DataOutput;
 import java.io.IOException;
 
 import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.hyracks.data.std.api.IMutableValueStorage;
 
 public class IntegerToInt32TypePromoteComputer extends AbstractIntegerTypePromoteComputer {
 
@@ -27,9 +27,9 @@
     }
 
     @Override
-    public void promote(byte[] data, int start, int length, IMutableValueStorage storageForPromotedValue)
+    public void promote(byte[] data, int start, int length, DataOutput out)
             throws IOException {
-        promoteIntegerType(data, start, length, storageForPromotedValue, ATypeTag.INT32, 4);
+        promoteIntegerType(data, start, length, out, ATypeTag.INT32, 4);
     }
 
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt64TypePromoteComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt64TypePromoteComputer.java
index b24604d..448dd8e 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt64TypePromoteComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/hierachy/IntegerToInt64TypePromoteComputer.java
@@ -14,10 +14,10 @@
  */
 package edu.uci.ics.asterix.om.types.hierachy;
 
+import java.io.DataOutput;
 import java.io.IOException;
 
 import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.hyracks.data.std.api.IMutableValueStorage;
 
 public class IntegerToInt64TypePromoteComputer extends AbstractIntegerTypePromoteComputer {
 
@@ -30,9 +30,9 @@
      * @see edu.uci.ics.asterix.om.types.hierachy.ITypePromoteComputer#promote(byte[], int, int, edu.uci.ics.hyracks.data.std.api.IMutableValueStorage)
      */
     @Override
-    public void promote(byte[] data, int start, int length, IMutableValueStorage storageForPromotedValue)
+    public void promote(byte[] data, int start, int length, DataOutput out)
             throws IOException {
-        promoteIntegerType(data, start, length, storageForPromotedValue, ATypeTag.INT64, 8);
+        promoteIntegerType(data, start, length, out, ATypeTag.INT64, 8);
     }
 
 }
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 29aba33..b961ef1 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
@@ -101,7 +101,7 @@
                     tempValForCasting.reset();
                     try {
                         tpc.promote(outputVal.getByteArray(), outputVal.getStartOffset() + 1,
-                                outputVal.getLength() - 1, tempValForCasting);
+                                outputVal.getLength() - 1, tempValForCasting.getDataOutput());
                     } catch (IOException e) {
                         throw new AlgebricksException(e);
                     }
@@ -119,7 +119,7 @@
                     tempValForCasting.reset();
                     try {
                         tpc.promote(inputVal.getByteArray(), inputVal.getStartOffset() + 1, inputVal.getLength() - 1,
-                                tempValForCasting);
+                                tempValForCasting.getDataOutput());
                     } catch (IOException e) {
                         throw new AlgebricksException(e);
                     }
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 755c0e0..26a6584 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
@@ -50,6 +50,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.util.NonTaggedFormatUtil;
 import edu.uci.ics.asterix.runtime.operators.file.adm.AdmLexer;
 import edu.uci.ics.asterix.runtime.operators.file.adm.AdmLexerException;
@@ -66,7 +67,8 @@
     protected boolean datasetRec;
 
     private int nullableFieldId = 0;
-
+    private ArrayBackedValueStorage castBuffer = new ArrayBackedValueStorage();
+    
     private Queue<ArrayBackedValueStorage> baaosPool = new ArrayDeque<ArrayBackedValueStorage>();
     private Queue<IARecordBuilder> recordBuilderPool = new ArrayDeque<IARecordBuilder>();
     private Queue<IAsterixListBuilder> orderedListBuilderPool = new ArrayDeque<IAsterixListBuilder>();
@@ -141,7 +143,7 @@
                 break;
             }
             case AdmLexer.TOKEN_DOUBLE_LITERAL: {
-                parseNumericLiteral(ATypeTag.DOUBLE, objectType, out);
+                parseToTarget(ATypeTag.DOUBLE, objectType, out);
                 break;
             }
             case AdmLexer.TOKEN_DOUBLE_CONS: {
@@ -149,7 +151,7 @@
                 break;
             }
             case AdmLexer.TOKEN_FLOAT_LITERAL: {
-                parseNumericLiteral(ATypeTag.FLOAT, objectType, out);
+                parseToTarget(ATypeTag.FLOAT, objectType, out);
                 break;
             }
             case AdmLexer.TOKEN_FLOAT_CONS: {
@@ -157,7 +159,7 @@
                 break;
             }
             case AdmLexer.TOKEN_INT8_LITERAL: {
-                parseNumericLiteral(ATypeTag.INT8, objectType, out);
+                parseAndCast(ATypeTag.INT8, objectType, out);
                 break;
             }
             case AdmLexer.TOKEN_INT8_CONS: {
@@ -165,16 +167,19 @@
                 break;
             }
             case AdmLexer.TOKEN_INT16_LITERAL: {
-                parseNumericLiteral(ATypeTag.INT16, objectType, out);
+                parseAndCast(ATypeTag.INT16, objectType, out);
                 break;
             }
             case AdmLexer.TOKEN_INT16_CONS: {
                 parseConstructor(ATypeTag.INT16, objectType, out);
                 break;
             }
-            case AdmLexer.TOKEN_INT_LITERAL:
+            case AdmLexer.TOKEN_INT_LITERAL:{
+                parseToTarget(ATypeTag.INT32, objectType, out);
+                break;
+            }
             case AdmLexer.TOKEN_INT32_LITERAL: {
-                parseNumericLiteral(ATypeTag.INT32, objectType, out);
+                parseAndCast(ATypeTag.INT32, objectType, out);
                 break;
             }
             case AdmLexer.TOKEN_INT32_CONS: {
@@ -182,7 +187,7 @@
                 break;
             }
             case AdmLexer.TOKEN_INT64_LITERAL: {
-                parseNumericLiteral(ATypeTag.INT64, objectType, out);
+                parseAndCast(ATypeTag.INT64, objectType, out);
                 break;
             }
             case AdmLexer.TOKEN_INT64_CONS: {
@@ -713,37 +718,66 @@
         baaosPool.add(tempBaaos);
     }
 
-    private void parseNumericLiteral(ATypeTag typeTag, IAType objectType, DataOutput out) throws AsterixException,
-            IOException {
-        final ATypeTag targetTypeTag = getTargetTypeTag(typeTag, objectType, out);
-        if (targetTypeTag != null) {
-            switch (targetTypeTag) {
-                case DOUBLE:
-                    aDouble.setValue(Double.parseDouble(admLexer.getLastTokenImage()));
-                    doubleSerde.serialize(aDouble, out);
-                    return;
-                case FLOAT:
-                    aFloat.setValue(Float.parseFloat(admLexer.getLastTokenImage()));
-                    floatSerde.serialize(aFloat, out);
-                    return;
-                case INT8:
-                    parseInt8(admLexer.getLastTokenImage(), out);
-                    return;
-                case INT16:
-                    parseInt16(admLexer.getLastTokenImage(), out);
-                    return;
-                case INT32:
-                    parseInt32(admLexer.getLastTokenImage(), out);
-                    return;
-                case INT64:
-                    parseInt64(admLexer.getLastTokenImage(), out);
-                    return;
-                default: // fall through
-            }
+    private boolean parseNumeric(final ATypeTag typeTag, DataOutput out) throws HyracksDataException,
+            AsterixException {
+        switch (typeTag) {
+            case DOUBLE:
+                aDouble.setValue(Double.parseDouble(admLexer.getLastTokenImage()));
+                doubleSerde.serialize(aDouble, out);
+                return true;
+            case FLOAT:
+                aFloat.setValue(Float.parseFloat(admLexer.getLastTokenImage()));
+                floatSerde.serialize(aFloat, out);
+                return true;
+            case INT8:
+                parseInt8(admLexer.getLastTokenImage(), out);
+                return true;
+            case INT16:
+                parseInt16(admLexer.getLastTokenImage(), out);
+                return true;
+            case INT32:
+                parseInt32(admLexer.getLastTokenImage(), out);
+                return true;
+            case INT64:
+                parseInt64(admLexer.getLastTokenImage(), out);
+                return true;
+            default: // fall through
         }
-        throw new AsterixException(mismatchErrorMessage + objectType.getTypeName() + mismatchErrorMessage2 + typeTag);
+        return false;
     }
 
+    private void parseToTarget(ATypeTag typeTag, IAType objectType, DataOutput out) throws AsterixException,
+            IOException {
+        final ATypeTag targetTypeTag = getTargetTypeTag(typeTag, objectType, out);
+        if (targetTypeTag == null || !parseNumeric(targetTypeTag, out)) {
+            throw new AsterixException(mismatchErrorMessage + objectType.getTypeName() + mismatchErrorMessage2
+                    + typeTag);
+        }
+    }
+    
+    private void parseAndCast(ATypeTag typeTag, IAType objectType, DataOutput out) throws AsterixException, IOException {
+        final ATypeTag targetTypeTag = getTargetTypeTag(typeTag, objectType, out);
+        DataOutput dataOutput = out;
+        if (targetTypeTag != typeTag) {
+            castBuffer.reset();
+            dataOutput = castBuffer.getDataOutput();
+        }
+
+        if (targetTypeTag == null || !parseNumeric(typeTag, dataOutput)) {
+            throw new AsterixException(mismatchErrorMessage + objectType.getTypeName() + mismatchErrorMessage2
+                    + typeTag);
+        }
+
+        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);
+        }
+    }
+    
     private void parseConstructor(ATypeTag typeTag, IAType objectType, DataOutput out) throws AsterixException {
         try {
             int token = admLexer.next();