code reivew: related small changes for issue 29,55,134,166,201,205,208

git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization_printerfix_staging@970 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-external-data/src/main/java/edu/uci/ics/asterix/external/dataset/adapter/HDFSAdapter.java b/asterix-external-data/src/main/java/edu/uci/ics/asterix/external/dataset/adapter/HDFSAdapter.java
index f7a79cd..744683c 100644
--- a/asterix-external-data/src/main/java/edu/uci/ics/asterix/external/dataset/adapter/HDFSAdapter.java
+++ b/asterix-external-data/src/main/java/edu/uci/ics/asterix/external/dataset/adapter/HDFSAdapter.java
@@ -40,7 +40,7 @@
 import org.apache.hadoop.mapred.TextInputFormat;
 
 import edu.uci.ics.asterix.om.types.IAType;
-import edu.uci.ics.asterix.runtime.util.AsterixRuntimeUtil;
+import edu.uci.ics.asterix.om.util.AsterixRuntimeUtil;
 import edu.uci.ics.hyracks.algebricks.common.constraints.AlgebricksAbsolutePartitionConstraint;
 import edu.uci.ics.hyracks.algebricks.common.constraints.AlgebricksCountPartitionConstraint;
 import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
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 4c0a201..8bb4d49 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
@@ -5,12 +5,12 @@
 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.pointables.PointableAllocator;
+import edu.uci.ics.asterix.om.pointables.base.IVisitablePointable;
+import edu.uci.ics.asterix.om.pointables.cast.ACastVisitor;
 import edu.uci.ics.asterix.om.types.ARecordType;
 import edu.uci.ics.asterix.om.types.IAType;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import edu.uci.ics.asterix.runtime.pointables.PointableAllocator;
-import edu.uci.ics.asterix.runtime.pointables.base.IVisitablePointable;
-import edu.uci.ics.asterix.runtime.pointables.cast.ACastVisitor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.common.utils.Triple;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/AFlatValuePointable.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/AFlatValuePointable.java
deleted file mode 100644
index a3547a4..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/AFlatValuePointable.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright 2009-2010 by The Regents of the University of California
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package edu.uci.ics.asterix.runtime.pointables;
-
-import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.om.types.IAType;
-import edu.uci.ics.asterix.runtime.pointables.base.IVisitablePointable;
-import edu.uci.ics.asterix.runtime.pointables.visitor.IVisitablePointableVisitor;
-import edu.uci.ics.asterix.runtime.util.container.IObjectFactory;
-import edu.uci.ics.hyracks.data.std.api.IValueReference;
-
-/**
- * This class represents a flat field, e.g., int field, string field, and
- * so on, based on a binary representation.
- */
-public class AFlatValuePointable extends AbstractVisitablePointable {
-
-    /**
-     * DO NOT allow to create AFlatValuePointable object arbitrarily, force to
-     * use object pool based allocator. The factory is not public so that it
-     * cannot called in other places than PointableAllocator.
-     */
-    static IObjectFactory<IVisitablePointable, IAType> FACTORY = new IObjectFactory<IVisitablePointable, IAType>() {
-        public AFlatValuePointable create(IAType type) {
-            return new AFlatValuePointable();
-        }
-    };
-
-    /**
-     * private constructor, to prevent arbitrary creation
-     */
-    private AFlatValuePointable() {
-
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        if (!(o instanceof IValueReference))
-            return false;
-
-        // get right raw data
-        IValueReference ivf = (IValueReference) o;
-        byte[] odata = ivf.getByteArray();
-        int ostart = ivf.getStartOffset();
-        int olen = ivf.getLength();
-
-        // get left raw data
-        byte[] data = getByteArray();
-        int start = getStartOffset();
-        int len = getLength();
-
-        // bytes length should be equal
-        if (len != olen)
-            return false;
-
-        // check each byte
-        for (int i = 0; i < len; i++) {
-            if (data[start + i] != odata[ostart + i])
-                return false;
-        }
-        return true;
-    }
-
-    @Override
-    public <R, T> R accept(IVisitablePointableVisitor<R, T> vistor, T tag) throws AsterixException {
-        return vistor.visit(this, tag);
-    }
-}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/AListPointable.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/AListPointable.java
deleted file mode 100644
index 6f85694..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/AListPointable.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Copyright 2009-2010 by The Regents of the University of California
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package edu.uci.ics.asterix.runtime.pointables;
-
-import java.io.DataOutputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
-import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.asterix.om.types.AbstractCollectionType;
-import edu.uci.ics.asterix.om.types.EnumDeserializer;
-import edu.uci.ics.asterix.om.types.IAType;
-import edu.uci.ics.asterix.om.util.NonTaggedFormatUtil;
-import edu.uci.ics.asterix.runtime.pointables.base.IVisitablePointable;
-import edu.uci.ics.asterix.runtime.pointables.visitor.IVisitablePointableVisitor;
-import edu.uci.ics.asterix.runtime.util.ResettableByteArrayOutputStream;
-import edu.uci.ics.asterix.runtime.util.container.IObjectFactory;
-
-/**
- * This class interprets the binary data representation of a list, one can
- * call getItems and getItemTags to get pointable objects for items and item
- * type tags.
- * 
- */
-public class AListPointable extends AbstractVisitablePointable {
-
-    /**
-     * DO NOT allow to create AListPointable object arbitrarily, force to use
-     * object pool based allocator, in order to have object reuse.
-     */
-    static IObjectFactory<IVisitablePointable, IAType> FACTORY = new IObjectFactory<IVisitablePointable, IAType>() {
-        public IVisitablePointable create(IAType type) {
-            return new AListPointable((AbstractCollectionType) type);
-        }
-    };
-
-    private final List<IVisitablePointable> items = new ArrayList<IVisitablePointable>();
-    private final List<IVisitablePointable> itemTags = new ArrayList<IVisitablePointable>();
-    private final PointableAllocator allocator = new PointableAllocator();
-
-    private final ResettableByteArrayOutputStream dataBos = new ResettableByteArrayOutputStream();
-    private final DataOutputStream dataDos = new DataOutputStream(dataBos);
-
-    private IAType itemType;
-    private ATypeTag itemTag;
-    private boolean typedItemList = false;
-
-    /**
-     * private constructor, to prevent constructing it arbitrarily
-     * 
-     * @param inputType
-     */
-    private AListPointable(AbstractCollectionType inputType) {
-        if (inputType != null && inputType.getItemType() != null) {
-            itemType = inputType.getItemType();
-            if (itemType.getTypeTag() == ATypeTag.ANY) {
-                typedItemList = false;
-            } else {
-                typedItemList = true;
-                itemTag = inputType.getItemType().getTypeTag();
-            }
-        } else {
-            this.typedItemList = false;
-        }
-    }
-
-    private void reset() {
-        allocator.reset();
-        items.clear();
-        itemTags.clear();
-        dataBos.reset();
-    }
-
-    @Override
-    public void set(byte[] b, int s, int len) {
-        reset();
-
-        int numberOfitems = AInt32SerializerDeserializer.getInt(b, s + 6);
-        int itemOffset;
-        if (typedItemList) {
-            switch (itemTag) {
-                case STRING:
-                case RECORD:
-                case ORDEREDLIST:
-                case UNORDEREDLIST:
-                case ANY:
-                    itemOffset = s + 10 + (numberOfitems * 4);
-                    break;
-                default:
-                    itemOffset = s + 10;
-            }
-        } else {
-            itemOffset = s + 10 + (numberOfitems * 4);
-        }
-        int itemLength = 0;
-        try {
-            if (typedItemList) {
-                for (int i = 0; i < numberOfitems; i++) {
-                    itemLength = NonTaggedFormatUtil.getFieldValueLength(b, itemOffset, itemTag, false);
-                    IVisitablePointable tag = allocator.allocateEmpty();
-                    IVisitablePointable item = allocator.allocateFieldValue(itemType);
-
-                    // set item type tag
-                    int start = dataBos.size();
-                    dataDos.writeByte(itemTag.serialize());
-                    int end = dataBos.size();
-                    tag.set(dataBos.getByteArray(), start, end - start);
-                    itemTags.add(tag);
-
-                    // set item value
-                    start = dataBos.size();
-                    dataDos.writeByte(itemTag.serialize());
-                    dataDos.write(b, itemOffset, itemLength);
-                    end = dataBos.size();
-                    item.set(dataBos.getByteArray(), start, end - start);
-                    itemOffset += itemLength;
-                    items.add(item);
-                }
-            } else {
-                for (int i = 0; i < numberOfitems; i++) {
-                    itemTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(b[itemOffset]);
-                    itemLength = NonTaggedFormatUtil.getFieldValueLength(b, itemOffset, itemTag, true) + 1;
-                    IVisitablePointable tag = allocator.allocateEmpty();
-                    IVisitablePointable item = allocator.allocateFieldValue(itemType);
-
-                    // set item type tag
-                    int start = dataBos.size();
-                    dataDos.writeByte(itemTag.serialize());
-                    int end = dataBos.size();
-                    tag.set(dataBos.getByteArray(), start, end - start);
-                    itemTags.add(tag);
-
-                    // open part field already include the type tag
-                    item.set(b, itemOffset, itemLength);
-                    itemOffset += itemLength;
-                    items.add(item);
-                }
-            }
-        } catch (Exception e) {
-            throw new IllegalStateException(e);
-        }
-    }
-
-    @Override
-    public <R, T> R accept(IVisitablePointableVisitor<R, T> vistor, T tag) throws AsterixException {
-        return vistor.visit(this, tag);
-    }
-
-    public List<IVisitablePointable> getItems() {
-        return items;
-    }
-
-    public List<IVisitablePointable> getItemTags() {
-        return itemTags;
-    }
-}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/ARecordPointable.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/ARecordPointable.java
deleted file mode 100644
index 5904170..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/ARecordPointable.java
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- * Copyright 2009-2010 by The Regents of the University of California
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package edu.uci.ics.asterix.runtime.pointables;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.dataflow.data.nontagged.AqlNullWriterFactory;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
-import edu.uci.ics.asterix.om.types.ARecordType;
-import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.asterix.om.types.AUnionType;
-import edu.uci.ics.asterix.om.types.EnumDeserializer;
-import edu.uci.ics.asterix.om.types.IAType;
-import edu.uci.ics.asterix.om.util.NonTaggedFormatUtil;
-import edu.uci.ics.asterix.runtime.pointables.base.IVisitablePointable;
-import edu.uci.ics.asterix.runtime.pointables.visitor.IVisitablePointableVisitor;
-import edu.uci.ics.asterix.runtime.util.ResettableByteArrayOutputStream;
-import edu.uci.ics.asterix.runtime.util.container.IObjectFactory;
-import edu.uci.ics.hyracks.api.dataflow.value.INullWriter;
-
-/**
- * This class interprets the binary data representation of a record. One can
- * call getFieldNames, getFieldTypeTags and getFieldValues to get pointable
- * objects for field names, field type tags, and field values.
- * 
- */
-public class ARecordPointable extends AbstractVisitablePointable {
-
-    /**
-     * DO NOT allow to create ARecordPointable object arbitrarily, force to use
-     * object pool based allocator, in order to have object reuse
-     */
-    static IObjectFactory<IVisitablePointable, IAType> FACTORY = new IObjectFactory<IVisitablePointable, IAType>() {
-        public IVisitablePointable create(IAType type) {
-            return new ARecordPointable((ARecordType) type);
-        }
-    };
-
-    // access results: field names, field types, and field values
-    private final List<IVisitablePointable> fieldNames = new ArrayList<IVisitablePointable>();
-    private final List<IVisitablePointable> fieldTypeTags = new ArrayList<IVisitablePointable>();
-    private final List<IVisitablePointable> fieldValues = new ArrayList<IVisitablePointable>();
-
-    // pointable allocator
-    private final PointableAllocator allocator = new PointableAllocator();
-
-    private final ResettableByteArrayOutputStream typeBos = new ResettableByteArrayOutputStream();
-    private final DataOutputStream typeDos = new DataOutputStream(typeBos);
-
-    private final ResettableByteArrayOutputStream dataBos = new ResettableByteArrayOutputStream();
-    private final DataOutputStream dataDos = new DataOutputStream(dataBos);
-
-    private final ARecordType inputRecType;
-
-    private final int numberOfSchemaFields;
-    private final int[] fieldOffsets;
-    private final IVisitablePointable nullReference = AFlatValuePointable.FACTORY.create(null);
-
-    private int closedPartTypeInfoSize = 0;
-    private int offsetArrayOffset;
-    private ATypeTag typeTag;
-
-    /**
-     * private constructor, to prevent constructing it arbitrarily
-     * 
-     * @param inputType
-     */
-    private ARecordPointable(ARecordType inputType) {
-        this.inputRecType = inputType;
-        IAType[] fieldTypes = inputType.getFieldTypes();
-        String[] fieldNameStrs = inputType.getFieldNames();
-        numberOfSchemaFields = fieldTypes.length;
-
-        // initialize the buffer for closed parts(fieldName bytes+ type bytes) +
-        // constant(null bytes)
-        typeBos.reset();
-        try {
-            for (int i = 0; i < numberOfSchemaFields; i++) {
-                ATypeTag ftypeTag = fieldTypes[i].getTypeTag();
-
-                if (fieldTypes[i].getTypeTag() == ATypeTag.UNION
-                        && NonTaggedFormatUtil.isOptionalField((AUnionType) fieldTypes[i]))
-                    // optional field: add the embedded non-null type tag
-                    ftypeTag = ((AUnionType) fieldTypes[i]).getUnionList()
-                            .get(NonTaggedFormatUtil.OPTIONAL_TYPE_INDEX_IN_UNION_LIST).getTypeTag();
-
-                // add type tag Reference
-                int tagStart = typeBos.size();
-                typeDos.writeByte(ftypeTag.serialize());
-                int tagEnd = typeBos.size();
-                IVisitablePointable typeTagReference = AFlatValuePointable.FACTORY.create(null);
-                typeTagReference.set(typeBos.getByteArray(), tagStart, tagEnd - tagStart);
-                fieldTypeTags.add(typeTagReference);
-
-                // add type name Reference (including a astring type tag)
-                int nameStart = typeBos.size();
-                typeDos.writeByte(ATypeTag.STRING.serialize());
-                typeDos.writeUTF(fieldNameStrs[i]);
-                int nameEnd = typeBos.size();
-                IVisitablePointable typeNameReference = AFlatValuePointable.FACTORY.create(null);
-                typeNameReference.set(typeBos.getByteArray(), nameStart, nameEnd - nameStart);
-                fieldNames.add(typeNameReference);
-            }
-
-            // initialize a constant: null value bytes reference
-            int nullFieldStart = typeBos.size();
-            INullWriter nullWriter = AqlNullWriterFactory.INSTANCE.createNullWriter();
-            nullWriter.writeNull(typeDos);
-            int nullFieldEnd = typeBos.size();
-            nullReference.set(typeBos.getByteArray(), nullFieldStart, nullFieldEnd - nullFieldStart);
-        } catch (IOException e) {
-            throw new IllegalStateException(e);
-        }
-        closedPartTypeInfoSize = typeBos.size();
-        fieldOffsets = new int[numberOfSchemaFields];
-    }
-
-    private void reset() {
-        typeBos.reset(closedPartTypeInfoSize);
-        dataBos.reset(0);
-        // reset the allocator
-        allocator.reset();
-
-        // clean up the returned containers
-        for (int i = fieldNames.size() - 1; i >= numberOfSchemaFields; i--)
-            fieldNames.remove(i);
-        for (int i = fieldTypeTags.size() - 1; i >= numberOfSchemaFields; i--)
-            fieldTypeTags.remove(i);
-        fieldValues.clear();
-    }
-
-    @Override
-    public void set(byte[] b, int start, int len) {
-        // clear the previous states
-        reset();
-        super.set(b, start, len);
-
-        boolean isExpanded = false;
-        int openPartOffset = 0;
-        int s = start;
-        int recordOffset = s;
-        if (inputRecType == null) {
-            openPartOffset = s + AInt32SerializerDeserializer.getInt(b, s + 6);
-            s += 8;
-            isExpanded = true;
-        } else {
-            if (inputRecType.isOpen()) {
-                isExpanded = b[s + 5] == 1 ? true : false;
-                if (isExpanded) {
-                    openPartOffset = s + AInt32SerializerDeserializer.getInt(b, s + 6);
-                    s += 10;
-                } else {
-                    s += 6;
-                }
-            } else {
-                s += 5;
-            }
-        }
-        try {
-            if (numberOfSchemaFields > 0) {
-                s += 4;
-                int nullBitMapOffset = 0;
-                boolean hasNullableFields = NonTaggedFormatUtil.hasNullableField(inputRecType);
-                if (hasNullableFields) {
-                    nullBitMapOffset = s;
-                    offsetArrayOffset = s
-                            + (this.numberOfSchemaFields % 8 == 0 ? numberOfSchemaFields / 8
-                                    : numberOfSchemaFields / 8 + 1);
-                } else {
-                    offsetArrayOffset = s;
-                }
-                for (int i = 0; i < numberOfSchemaFields; i++) {
-                    fieldOffsets[i] = AInt32SerializerDeserializer.getInt(b, offsetArrayOffset) + recordOffset;
-                    offsetArrayOffset += 4;
-                }
-                for (int fieldNumber = 0; fieldNumber < numberOfSchemaFields; fieldNumber++) {
-                    if (hasNullableFields) {
-                        byte b1 = b[nullBitMapOffset + fieldNumber / 8];
-                        int p = 1 << (7 - (fieldNumber % 8));
-                        if ((b1 & p) == 0) {
-                            // set null value (including type tag inside)
-                            fieldValues.add(nullReference);
-                            continue;
-                        }
-                    }
-                    IAType[] fieldTypes = inputRecType.getFieldTypes();
-                    int fieldValueLength = 0;
-
-                    IAType fieldType = fieldTypes[fieldNumber];
-                    if (fieldTypes[fieldNumber].getTypeTag() == ATypeTag.UNION) {
-                        if (NonTaggedFormatUtil.isOptionalField((AUnionType) fieldTypes[fieldNumber])) {
-                            fieldType = ((AUnionType) fieldTypes[fieldNumber]).getUnionList().get(
-                                    NonTaggedFormatUtil.OPTIONAL_TYPE_INDEX_IN_UNION_LIST);
-                            typeTag = fieldType.getTypeTag();
-                            fieldValueLength = NonTaggedFormatUtil.getFieldValueLength(b, fieldOffsets[fieldNumber],
-                                    typeTag, false);
-                        }
-                    } else {
-                        typeTag = fieldTypes[fieldNumber].getTypeTag();
-                        fieldValueLength = NonTaggedFormatUtil.getFieldValueLength(b, fieldOffsets[fieldNumber],
-                                typeTag, false);
-                    }
-                    // set field value (including the type tag)
-                    int fstart = dataBos.size();
-                    dataDos.writeByte(typeTag.serialize());
-                    dataDos.write(b, fieldOffsets[fieldNumber], fieldValueLength);
-                    int fend = dataBos.size();
-                    IVisitablePointable fieldValue = allocator.allocateFieldValue(fieldType);
-                    fieldValue.set(dataBos.getByteArray(), fstart, fend - fstart);
-                    fieldValues.add(fieldValue);
-                }
-            }
-            if (isExpanded) {
-                int numberOfOpenFields = AInt32SerializerDeserializer.getInt(b, openPartOffset);
-                int fieldOffset = openPartOffset + 4 + (8 * numberOfOpenFields);
-                for (int i = 0; i < numberOfOpenFields; i++) {
-                    // set the field name (including a type tag, which is
-                    // astring)
-                    int fieldValueLength = NonTaggedFormatUtil.getFieldValueLength(b, fieldOffset, ATypeTag.STRING,
-                            false);
-                    int fnstart = dataBos.size();
-                    dataDos.writeByte(ATypeTag.STRING.serialize());
-                    dataDos.write(b, fieldOffset, fieldValueLength);
-                    int fnend = dataBos.size();
-                    IVisitablePointable fieldName = allocator.allocateEmpty();
-                    fieldName.set(dataBos.getByteArray(), fnstart, fnend - fnstart);
-                    fieldNames.add(fieldName);
-                    fieldOffset += fieldValueLength;
-
-                    // set the field type tag
-                    IVisitablePointable fieldTypeTag = allocator.allocateEmpty();
-                    fieldTypeTag.set(b, fieldOffset, 1);
-                    fieldTypeTags.add(fieldTypeTag);
-                    typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(b[fieldOffset]);
-
-                    // set the field value (already including type tag)
-                    fieldValueLength = NonTaggedFormatUtil.getFieldValueLength(b, fieldOffset, typeTag, true) + 1;
-
-                    // allocate
-                    IVisitablePointable fieldValueAccessor = allocator.allocateFieldValue(typeTag);
-                    fieldValueAccessor.set(b, fieldOffset, fieldValueLength);
-                    fieldValues.add(fieldValueAccessor);
-                    fieldOffset += fieldValueLength;
-                }
-            }
-        } catch (Exception e) {
-            throw new IllegalStateException(e);
-        }
-    }
-
-    public List<IVisitablePointable> getFieldNames() {
-        return fieldNames;
-    }
-
-    public List<IVisitablePointable> getFieldTypeTags() {
-        return fieldTypeTags;
-    }
-
-    public List<IVisitablePointable> getFieldValues() {
-        return fieldValues;
-    }
-
-    @Override
-    public <R, T> R accept(IVisitablePointableVisitor<R, T> vistor, T tag) throws AsterixException {
-        return vistor.visit(this, tag);
-    }
-
-}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/AbstractVisitablePointable.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/AbstractVisitablePointable.java
deleted file mode 100644
index 8cfe661..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/AbstractVisitablePointable.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2009-2010 by The Regents of the University of California
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package edu.uci.ics.asterix.runtime.pointables;
-
-import edu.uci.ics.asterix.runtime.pointables.base.IVisitablePointable;
-import edu.uci.ics.hyracks.data.std.api.IValueReference;
-
-/**
- * This class implements several "routine" methods in IVisitablePointable
- * interface, so that subclasses do not need to repeat the same code.
- * 
- */
-public abstract class AbstractVisitablePointable implements IVisitablePointable {
-
-    private byte[] data;
-    private int start;
-    private int len;
-
-    @Override
-    public byte[] getByteArray() {
-        return data;
-    }
-
-    @Override
-    public int getLength() {
-        return len;
-    }
-
-    @Override
-    public int getStartOffset() {
-        return start;
-    }
-
-    @Override
-    public void set(byte[] b, int start, int len) {
-        this.data = b;
-        this.start = start;
-        this.len = len;
-    }
-
-    @Override
-    public void set(IValueReference ivf) {
-        set(ivf.getByteArray(), ivf.getStartOffset(), ivf.getLength());
-    }
-
-}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/PointableAllocator.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/PointableAllocator.java
deleted file mode 100644
index b6116be..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/PointableAllocator.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright 2009-2010 by The Regents of the University of California
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package edu.uci.ics.asterix.runtime.pointables;
-
-import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.asterix.om.types.IAType;
-import edu.uci.ics.asterix.runtime.pointables.base.DefaultOpenFieldType;
-import edu.uci.ics.asterix.runtime.pointables.base.IVisitablePointable;
-import edu.uci.ics.asterix.runtime.util.container.IObjectPool;
-import edu.uci.ics.asterix.runtime.util.container.ListObjectPool;
-
-/**
- * This class is the ONLY place to create IVisitablePointable object instances,
- * to enforce use of an object pool.
- */
-public class PointableAllocator {
-
-    private IObjectPool<IVisitablePointable, IAType> flatValueAllocator = new ListObjectPool<IVisitablePointable, IAType>(
-            AFlatValuePointable.FACTORY);
-    private IObjectPool<IVisitablePointable, IAType> recordValueAllocator = new ListObjectPool<IVisitablePointable, IAType>(
-            ARecordPointable.FACTORY);
-    private IObjectPool<IVisitablePointable, IAType> listValueAllocator = new ListObjectPool<IVisitablePointable, IAType>(
-            AListPointable.FACTORY);
-
-    public IVisitablePointable allocateEmpty() {
-        return flatValueAllocator.allocate(null);
-    }
-
-    /**
-     * allocate closed part value pointable
-     * 
-     * @param type
-     * @return the pointable object
-     */
-    public IVisitablePointable allocateFieldValue(IAType type) {
-        if (type == null)
-            return flatValueAllocator.allocate(null);
-        else if (type.getTypeTag().equals(ATypeTag.RECORD))
-            return recordValueAllocator.allocate(type);
-        else if (type.getTypeTag().equals(ATypeTag.UNORDEREDLIST) || type.getTypeTag().equals(ATypeTag.ORDEREDLIST))
-            return listValueAllocator.allocate(type);
-        else
-            return flatValueAllocator.allocate(null);
-    }
-
-    /**
-     * allocate open part value pointable
-     * 
-     * @param typeTag
-     * @return the pointable object
-     */
-    public IVisitablePointable allocateFieldValue(ATypeTag typeTag) {
-        if (typeTag == null)
-            return flatValueAllocator.allocate(null);
-        else if (typeTag.equals(ATypeTag.RECORD))
-            return recordValueAllocator.allocate(DefaultOpenFieldType.NESTED_OPEN_RECORD_TYPE);
-        else if (typeTag.equals(ATypeTag.UNORDEREDLIST))
-            return listValueAllocator.allocate(DefaultOpenFieldType.NESTED_OPEN_AUNORDERED_LIST_TYPE);
-        else if (typeTag.equals(ATypeTag.ORDEREDLIST))
-            return listValueAllocator.allocate(DefaultOpenFieldType.NESTED_OPEN_AORDERED_LIST_TYPE);
-        else
-            return flatValueAllocator.allocate(null);
-    }
-
-    public IVisitablePointable allocateListValue(IAType type) {
-        return listValueAllocator.allocate(type);
-    }
-
-    public IVisitablePointable allocateRecordValue(IAType type) {
-        return recordValueAllocator.allocate(type);
-    }
-
-    public void reset() {
-        flatValueAllocator.reset();
-        recordValueAllocator.reset();
-        listValueAllocator.reset();
-    }
-}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/base/DefaultOpenFieldType.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/base/DefaultOpenFieldType.java
deleted file mode 100644
index 987ac02..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/base/DefaultOpenFieldType.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2009-2010 by The Regents of the University of California
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package edu.uci.ics.asterix.runtime.pointables.base;
-
-import edu.uci.ics.asterix.om.types.AOrderedListType;
-import edu.uci.ics.asterix.om.types.ARecordType;
-import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.asterix.om.types.AUnorderedListType;
-import edu.uci.ics.asterix.om.types.BuiltinType;
-import edu.uci.ics.asterix.om.types.IAType;
-
-/**
- * This class serves as the repository for the default record type and list type
- * fields in the open part, e.g., a "record" (nested) field in the open part is
- * always a fully open one, and a "list" field in the open part is always a list
- * of "ANY".
- * 
- */
-public class DefaultOpenFieldType {
-
-    // nested open field rec type
-    public static ARecordType NESTED_OPEN_RECORD_TYPE = new ARecordType("nested-open", new String[] {},
-            new IAType[] {}, true);
-
-    // nested open list type
-    public static AOrderedListType NESTED_OPEN_AORDERED_LIST_TYPE = new AOrderedListType(BuiltinType.ANY,
-            "nested-ordered-list");
-
-    // nested open list type
-    public static AUnorderedListType NESTED_OPEN_AUNORDERED_LIST_TYPE = new AUnorderedListType(BuiltinType.ANY,
-            "nested-unordered-list");
-
-    public static IAType getDefaultOpenFieldType(ATypeTag tag) {
-        if (tag.equals(ATypeTag.RECORD))
-            return NESTED_OPEN_RECORD_TYPE;
-        if (tag.equals(ATypeTag.ORDEREDLIST))
-            return NESTED_OPEN_AORDERED_LIST_TYPE;
-        if (tag.equals(ATypeTag.UNORDEREDLIST))
-            return NESTED_OPEN_AUNORDERED_LIST_TYPE;
-        else
-            return null;
-    }
-
-}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/base/IVisitablePointable.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/base/IVisitablePointable.java
deleted file mode 100644
index 28c61c2..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/base/IVisitablePointable.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright 2009-2010 by The Regents of the University of California
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package edu.uci.ics.asterix.runtime.pointables.base;
-
-import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.runtime.pointables.visitor.IVisitablePointableVisitor;
-import edu.uci.ics.hyracks.data.std.api.IPointable;
-
-/**
- * This interface extends IPointable with a visitor interface in order to ease
- * programming for recursive record structures.
- */
-public interface IVisitablePointable extends IPointable {
-
-    public <R, T> R accept(IVisitablePointableVisitor<R, T> vistor, T tag) throws AsterixException;
-}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/cast/ACastVisitor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/cast/ACastVisitor.java
deleted file mode 100644
index 822e37c..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/cast/ACastVisitor.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright 2009-2010 by The Regents of the University of California
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package edu.uci.ics.asterix.runtime.pointables.cast;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.om.types.ARecordType;
-import edu.uci.ics.asterix.om.types.AbstractCollectionType;
-import edu.uci.ics.asterix.om.types.IAType;
-import edu.uci.ics.asterix.runtime.pointables.AFlatValuePointable;
-import edu.uci.ics.asterix.runtime.pointables.AListPointable;
-import edu.uci.ics.asterix.runtime.pointables.ARecordPointable;
-import edu.uci.ics.asterix.runtime.pointables.base.IVisitablePointable;
-import edu.uci.ics.asterix.runtime.pointables.visitor.IVisitablePointableVisitor;
-import edu.uci.ics.hyracks.algebricks.common.utils.Triple;
-
-/**
- * This class is a IVisitablePointableVisitor implementation which recursively
- * visit a given record, list or flat value of a given type, and cast it to a
- * specified type. For example:
- * 
- * A record { "hobby": {{"music", "coding"}}, "id": "001", "name":
- * "Person Three"} which confirms to closed type ( id: string, name: string,
- * hobby: {{string}}? ) can be casted to a open type (id: string )
- * 
- * Since the open/closed part of a record has a completely different underlying
- * memory/storage layout, the visitor will change the layout as specified at
- * runtime.
- */
-public class ACastVisitor implements IVisitablePointableVisitor<Void, Triple<IVisitablePointable, IAType, Boolean>> {
-
-    private final Map<IVisitablePointable, ARecordCaster> raccessorToCaster = new HashMap<IVisitablePointable, ARecordCaster>();
-    private final Map<IVisitablePointable, AListCaster> laccessorToCaster = new HashMap<IVisitablePointable, AListCaster>();
-
-    @Override
-    public Void visit(AListPointable accessor, Triple<IVisitablePointable, IAType, Boolean> arg)
-            throws AsterixException {
-        AListCaster caster = laccessorToCaster.get(accessor);
-        if (caster == null) {
-            caster = new AListCaster();
-            laccessorToCaster.put(accessor, caster);
-        }
-        try {
-            caster.castList(accessor, arg.first, (AbstractCollectionType) arg.second, this);
-        } catch (Exception e) {
-            throw new AsterixException(e);
-        }
-        return null;
-    }
-
-    @Override
-    public Void visit(ARecordPointable accessor, Triple<IVisitablePointable, IAType, Boolean> arg)
-            throws AsterixException {
-        ARecordCaster caster = raccessorToCaster.get(accessor);
-        if (caster == null) {
-            caster = new ARecordCaster();
-            raccessorToCaster.put(accessor, caster);
-        }
-        try {
-            caster.castRecord(accessor, arg.first, (ARecordType) arg.second, this);
-        } catch (Exception e) {
-            throw new AsterixException(e);
-        }
-        return null;
-    }
-
-    @Override
-    public Void visit(AFlatValuePointable accessor, Triple<IVisitablePointable, IAType, Boolean> arg) {
-        // set the pointer for result
-        arg.first.set(accessor);
-        return null;
-    }
-
-}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/cast/AListCaster.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/cast/AListCaster.java
deleted file mode 100644
index e10fb72..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/cast/AListCaster.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright 2009-2010 by The Regents of the University of California
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package edu.uci.ics.asterix.runtime.pointables.cast;
-
-import java.io.DataOutput;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.List;
-
-import edu.uci.ics.asterix.builders.OrderedListBuilder;
-import edu.uci.ics.asterix.builders.UnorderedListBuilder;
-import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.om.types.AOrderedListType;
-import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.asterix.om.types.AUnorderedListType;
-import edu.uci.ics.asterix.om.types.AbstractCollectionType;
-import edu.uci.ics.asterix.om.types.EnumDeserializer;
-import edu.uci.ics.asterix.om.types.IAType;
-import edu.uci.ics.asterix.runtime.pointables.AListPointable;
-import edu.uci.ics.asterix.runtime.pointables.PointableAllocator;
-import edu.uci.ics.asterix.runtime.pointables.base.DefaultOpenFieldType;
-import edu.uci.ics.asterix.runtime.pointables.base.IVisitablePointable;
-import edu.uci.ics.asterix.runtime.util.ResettableByteArrayOutputStream;
-import edu.uci.ics.hyracks.algebricks.common.utils.Triple;
-
-/**
- * This class is to do the runtime type cast for a list. It is ONLY visible to
- * ACastVisitor.
- */
-class AListCaster {
-    // pointable allocator
-    private final PointableAllocator allocator = new PointableAllocator();
-
-    // for storing the cast result
-    private final IVisitablePointable itemTempReference = allocator.allocateEmpty();
-    private final Triple<IVisitablePointable, IAType, Boolean> itemVisitorArg = new Triple<IVisitablePointable, IAType, Boolean>(
-            itemTempReference, null, null);
-
-    private final UnorderedListBuilder unOrderedListBuilder = new UnorderedListBuilder();
-    private final OrderedListBuilder orderedListBuilder = new OrderedListBuilder();
-
-    private final ResettableByteArrayOutputStream dataBos = new ResettableByteArrayOutputStream();
-    private final DataOutput dataDos = new DataOutputStream(dataBos);
-    private IAType reqItemType;
-
-    public AListCaster() {
-
-    }
-
-    public void castList(AListPointable listAccessor, IVisitablePointable resultAccessor,
-            AbstractCollectionType reqType, ACastVisitor visitor) throws IOException, AsterixException {
-        if (reqType.getTypeTag().equals(ATypeTag.UNORDEREDLIST)) {
-            unOrderedListBuilder.reset((AUnorderedListType) reqType);
-        }
-        if (reqType.getTypeTag().equals(ATypeTag.ORDEREDLIST)) {
-            orderedListBuilder.reset((AOrderedListType) reqType);
-        }
-        dataBos.reset();
-
-        List<IVisitablePointable> itemTags = listAccessor.getItemTags();
-        List<IVisitablePointable> items = listAccessor.getItems();
-
-        int start = dataBos.size();
-        for (int i = 0; i < items.size(); i++) {
-            IVisitablePointable itemTypeTag = itemTags.get(i);
-            IVisitablePointable item = items.get(i);
-            ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(itemTypeTag.getByteArray()[itemTypeTag
-                    .getStartOffset()]);
-            if (reqItemType == null || reqItemType.getTypeTag().equals(ATypeTag.ANY)) {
-                itemVisitorArg.second = DefaultOpenFieldType.getDefaultOpenFieldType(typeTag);
-                item.accept(visitor, itemVisitorArg);
-            } else {
-                if (typeTag != reqItemType.getTypeTag())
-                    throw new AsterixException("mismatched item type");
-                itemVisitorArg.second = reqItemType;
-                item.accept(visitor, itemVisitorArg);
-            }
-            if (reqType.getTypeTag().equals(ATypeTag.ORDEREDLIST)) {
-                orderedListBuilder.addItem(itemVisitorArg.first);
-            }
-            if (reqType.getTypeTag().equals(ATypeTag.UNORDEREDLIST)) {
-                unOrderedListBuilder.addItem(itemVisitorArg.first);
-            }
-        }
-        if (reqType.getTypeTag().equals(ATypeTag.ORDEREDLIST)) {
-            orderedListBuilder.write(dataDos, true);
-        }
-        if (reqType.getTypeTag().equals(ATypeTag.UNORDEREDLIST)) {
-            unOrderedListBuilder.write(dataDos, true);
-        }
-        int end = dataBos.size();
-        resultAccessor.set(dataBos.getByteArray(), start, end - start);
-    }
-}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/cast/ARecordCaster.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/cast/ARecordCaster.java
deleted file mode 100644
index 8ef2ef0..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/cast/ARecordCaster.java
+++ /dev/null
@@ -1,318 +0,0 @@
-/*
- * Copyright 2009-2010 by The Regents of the University of California
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package edu.uci.ics.asterix.runtime.pointables.cast;
-
-import java.io.DataOutput;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import edu.uci.ics.asterix.builders.RecordBuilder;
-import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.dataflow.data.nontagged.AqlNullWriterFactory;
-import edu.uci.ics.asterix.om.types.ARecordType;
-import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.asterix.om.types.AUnionType;
-import edu.uci.ics.asterix.om.types.EnumDeserializer;
-import edu.uci.ics.asterix.om.types.IAType;
-import edu.uci.ics.asterix.om.util.NonTaggedFormatUtil;
-import edu.uci.ics.asterix.runtime.pointables.ARecordPointable;
-import edu.uci.ics.asterix.runtime.pointables.PointableAllocator;
-import edu.uci.ics.asterix.runtime.pointables.base.DefaultOpenFieldType;
-import edu.uci.ics.asterix.runtime.pointables.base.IVisitablePointable;
-import edu.uci.ics.asterix.runtime.util.ResettableByteArrayOutputStream;
-import edu.uci.ics.hyracks.algebricks.common.utils.Triple;
-import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparator;
-import edu.uci.ics.hyracks.api.dataflow.value.INullWriter;
-import edu.uci.ics.hyracks.data.std.accessors.PointableBinaryComparatorFactory;
-import edu.uci.ics.hyracks.data.std.api.IValueReference;
-import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
-import edu.uci.ics.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
-
-/**
- * This class is to do the runtime type cast for a record. It is ONLY visible to
- * ACastVisitor.
- */
-class ARecordCaster {
-
-    // pointable allocator
-    private final PointableAllocator allocator = new PointableAllocator();
-
-    private final List<IVisitablePointable> reqFieldNames = new ArrayList<IVisitablePointable>();
-    private final List<IVisitablePointable> reqFieldTypeTags = new ArrayList<IVisitablePointable>();
-    private ARecordType cachedReqType = null;
-
-    private final ResettableByteArrayOutputStream bos = new ResettableByteArrayOutputStream();
-    private final DataOutputStream dos = new DataOutputStream(bos);
-
-    private final RecordBuilder recBuilder = new RecordBuilder();
-    private final IVisitablePointable nullReference = allocator.allocateEmpty();
-    private final IVisitablePointable nullTypeTag = allocator.allocateEmpty();
-
-    private final IBinaryComparator fieldNameComparator = PointableBinaryComparatorFactory.of(
-            UTF8StringPointable.FACTORY).createBinaryComparator();
-
-    private final ByteArrayAccessibleOutputStream outputBos = new ByteArrayAccessibleOutputStream();
-    private final DataOutputStream outputDos = new DataOutputStream(outputBos);
-
-    private final IVisitablePointable fieldTempReference = allocator.allocateEmpty();
-    private final Triple<IVisitablePointable, IAType, Boolean> nestedVisitorArg = new Triple<IVisitablePointable, IAType, Boolean>(
-            fieldTempReference, null, null);
-
-    private int numInputFields = 0;
-
-    // describe closed fields in the required type
-    private int[] fieldPermutation;
-    private boolean[] optionalFields;
-
-    // describe fields (open or not) in the input records
-    private boolean[] openFields;
-    private int[] fieldNamesSortedIndex;
-    private int[] reqFieldNamesSortedIndex;
-
-    public ARecordCaster() {
-        try {
-            bos.reset();
-            int start = bos.size();
-            INullWriter nullWriter = AqlNullWriterFactory.INSTANCE.createNullWriter();
-            nullWriter.writeNull(dos);
-            int end = bos.size();
-            nullReference.set(bos.getByteArray(), start, end - start);
-            start = bos.size();
-            dos.write(ATypeTag.NULL.serialize());
-            end = bos.size();
-            nullTypeTag.set(bos.getByteArray(), start, end);
-        } catch (IOException e) {
-            throw new IllegalStateException(e);
-        }
-    }
-
-    public void castRecord(ARecordPointable recordAccessor, IVisitablePointable resultAccessor, ARecordType reqType,
-            ACastVisitor visitor) throws IOException, AsterixException {
-        List<IVisitablePointable> fieldNames = recordAccessor.getFieldNames();
-        List<IVisitablePointable> fieldTypeTags = recordAccessor.getFieldTypeTags();
-        List<IVisitablePointable> fieldValues = recordAccessor.getFieldValues();
-        numInputFields = fieldNames.size();
-
-        if (openFields == null || numInputFields > openFields.length) {
-            openFields = new boolean[numInputFields];
-            fieldNamesSortedIndex = new int[numInputFields];
-        }
-        if (cachedReqType == null || !reqType.equals(cachedReqType)) {
-            loadRequiredType(reqType);
-        }
-
-        // clear the previous states
-        reset();
-        matchClosedPart(fieldNames, fieldTypeTags, fieldValues);
-        writeOutput(fieldNames, fieldTypeTags, fieldValues, outputDos, visitor);
-        resultAccessor.set(outputBos.getByteArray(), 0, outputBos.size());
-    }
-
-    private void reset() {
-        for (int i = 0; i < numInputFields; i++)
-            openFields[i] = true;
-        for (int i = 0; i < fieldPermutation.length; i++)
-            fieldPermutation[i] = -1;
-        for (int i = 0; i < numInputFields; i++)
-            fieldNamesSortedIndex[i] = i;
-        outputBos.reset();
-    }
-
-    private void loadRequiredType(ARecordType reqType) throws IOException {
-        reqFieldNames.clear();
-        reqFieldTypeTags.clear();
-
-        cachedReqType = reqType;
-        int numSchemaFields = reqType.getFieldTypes().length;
-        IAType[] fieldTypes = reqType.getFieldTypes();
-        String[] fieldNames = reqType.getFieldNames();
-        fieldPermutation = new int[numSchemaFields];
-        optionalFields = new boolean[numSchemaFields];
-        for (int i = 0; i < optionalFields.length; i++)
-            optionalFields[i] = false;
-
-        bos.reset(nullReference.getStartOffset() + nullReference.getLength());
-        for (int i = 0; i < numSchemaFields; i++) {
-            ATypeTag ftypeTag = fieldTypes[i].getTypeTag();
-            String fname = fieldNames[i];
-
-            // add type tag pointable
-            if (fieldTypes[i].getTypeTag() == ATypeTag.UNION
-                    && NonTaggedFormatUtil.isOptionalField((AUnionType) fieldTypes[i])) {
-                // optional field: add the embedded non-null type tag
-                ftypeTag = ((AUnionType) fieldTypes[i]).getUnionList()
-                        .get(NonTaggedFormatUtil.OPTIONAL_TYPE_INDEX_IN_UNION_LIST).getTypeTag();
-                optionalFields[i] = true;
-            }
-            int tagStart = bos.size();
-            dos.writeByte(ftypeTag.serialize());
-            int tagEnd = bos.size();
-            IVisitablePointable typeTagPointable = allocator.allocateEmpty();
-            typeTagPointable.set(bos.getByteArray(), tagStart, tagEnd - tagStart);
-            reqFieldTypeTags.add(typeTagPointable);
-
-            // add type name pointable (including a string type tag)
-            int nameStart = bos.size();
-            dos.write(ATypeTag.STRING.serialize());
-            dos.writeUTF(fname);
-            int nameEnd = bos.size();
-            IVisitablePointable typeNamePointable = allocator.allocateEmpty();
-            typeNamePointable.set(bos.getByteArray(), nameStart, nameEnd - nameStart);
-            reqFieldNames.add(typeNamePointable);
-        }
-
-        reqFieldNamesSortedIndex = new int[reqFieldNames.size()];
-        for (int i = 0; i < reqFieldNamesSortedIndex.length; i++)
-            reqFieldNamesSortedIndex[i] = i;
-        // sort the field name index
-        quickSort(reqFieldNamesSortedIndex, reqFieldNames, 0, reqFieldNamesSortedIndex.length - 1);
-    }
-
-    private void matchClosedPart(List<IVisitablePointable> fieldNames, List<IVisitablePointable> fieldTypeTags,
-            List<IVisitablePointable> fieldValues) {
-        // sort-merge based match
-        quickSort(fieldNamesSortedIndex, fieldNames, 0, numInputFields - 1);
-        int fnStart = 0;
-        int reqFnStart = 0;
-        while (fnStart < numInputFields && reqFnStart < reqFieldNames.size()) {
-            int fnPos = fieldNamesSortedIndex[fnStart];
-            int reqFnPos = reqFieldNamesSortedIndex[reqFnStart];
-            int c = compare(fieldNames.get(fnPos), reqFieldNames.get(reqFnPos));
-            if (c == 0) {
-                IVisitablePointable fieldTypeTag = fieldTypeTags.get(fnPos);
-                IVisitablePointable reqFieldTypeTag = reqFieldTypeTags.get(reqFnPos);
-                if (fieldTypeTag.equals(reqFieldTypeTag) || (
-                // match the null type of optional field
-                        optionalFields[reqFnPos] && fieldTypeTag.equals(nullTypeTag))) {
-                    fieldPermutation[reqFnPos] = fnPos;
-                    openFields[fnPos] = false;
-                }
-                fnStart++;
-                reqFnStart++;
-            }
-            if (c > 0)
-                reqFnStart++;
-            if (c < 0)
-                fnStart++;
-        }
-
-        // check unmatched fields in the input type
-        for (int i = 0; i < openFields.length; i++) {
-            if (openFields[i] == true && !cachedReqType.isOpen())
-                throw new IllegalStateException("type mismatch: including extra closed fields");
-        }
-
-        // check unmatched fields in the required type
-        for (int i = 0; i < fieldPermutation.length; i++) {
-            if (fieldPermutation[i] < 0) {
-                IAType t = cachedReqType.getFieldTypes()[i];
-                if (!(t.getTypeTag() == ATypeTag.UNION && NonTaggedFormatUtil.isOptionalField((AUnionType) t))) {
-                    // no matched field in the input for a required closed field
-                    throw new IllegalStateException("type mismatch: miss a required closed field");
-                }
-            }
-        }
-    }
-
-    private void writeOutput(List<IVisitablePointable> fieldNames, List<IVisitablePointable> fieldTypeTags,
-            List<IVisitablePointable> fieldValues, DataOutput output, ACastVisitor visitor) throws IOException,
-            AsterixException {
-        // reset the states of the record builder
-        recBuilder.reset(cachedReqType);
-        recBuilder.init();
-
-        // write the closed part
-        for (int i = 0; i < fieldPermutation.length; i++) {
-            int pos = fieldPermutation[i];
-            IVisitablePointable field;
-            if (pos >= 0) {
-                field = fieldValues.get(pos);
-            } else {
-                field = nullReference;
-            }
-            IAType fType = cachedReqType.getFieldTypes()[i];
-            nestedVisitorArg.second = fType;
-
-            // recursively casting, the result of casting can always be thought
-            // as flat
-            if (optionalFields[i]) {
-                nestedVisitorArg.second = ((AUnionType) fType).getUnionList().get(
-                        NonTaggedFormatUtil.OPTIONAL_TYPE_INDEX_IN_UNION_LIST);
-            }
-            field.accept(visitor, nestedVisitorArg);
-            recBuilder.addField(i, nestedVisitorArg.first);
-        }
-
-        // write the open part
-        for (int i = 0; i < numInputFields; i++) {
-            if (openFields[i]) {
-                IVisitablePointable name = fieldNames.get(i);
-                IVisitablePointable field = fieldValues.get(i);
-                IVisitablePointable fieldTypeTag = fieldTypeTags.get(i);
-
-                ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER
-                        .deserialize(fieldTypeTag.getByteArray()[fieldTypeTag.getStartOffset()]);
-                nestedVisitorArg.second = DefaultOpenFieldType.getDefaultOpenFieldType(typeTag);
-                field.accept(visitor, nestedVisitorArg);
-                recBuilder.addField(name, nestedVisitorArg.first);
-            }
-        }
-        recBuilder.write(output, true);
-    }
-
-    private void quickSort(int[] index, List<IVisitablePointable> names, int start, int end) {
-        if (end <= start)
-            return;
-        int i = partition(index, names, start, end);
-        quickSort(index, names, start, i - 1);
-        quickSort(index, names, i + 1, end);
-    }
-
-    private int partition(int[] index, List<IVisitablePointable> names, int left, int right) {
-        int i = left - 1;
-        int j = right;
-        while (true) {
-            // grow from the left
-            while (compare(names.get(index[++i]), names.get(index[right])) < 0)
-                ;
-            // lower from the right
-            while (compare(names.get(index[right]), names.get(index[--j])) < 0)
-                if (j == left)
-                    break;
-            if (i >= j)
-                break;
-            // swap i and j
-            swap(index, i, j);
-        }
-        // swap i and right
-        swap(index, i, right); // swap with partition element
-        return i;
-    }
-
-    private void swap(int[] array, int i, int j) {
-        int temp = array[i];
-        array[i] = array[j];
-        array[j] = temp;
-    }
-
-    private int compare(IValueReference a, IValueReference b) {
-        // start+1 and len-1 due to the type tag
-        return fieldNameComparator.compare(a.getByteArray(), a.getStartOffset() + 1, a.getLength() - 1,
-                b.getByteArray(), b.getStartOffset() + 1, b.getLength() - 1);
-    }
-}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/visitor/IVisitablePointableVisitor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/visitor/IVisitablePointableVisitor.java
deleted file mode 100644
index 669e3fc..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/pointables/visitor/IVisitablePointableVisitor.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2009-2010 by The Regents of the University of California
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package edu.uci.ics.asterix.runtime.pointables.visitor;
-
-import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.runtime.pointables.AFlatValuePointable;
-import edu.uci.ics.asterix.runtime.pointables.AListPointable;
-import edu.uci.ics.asterix.runtime.pointables.ARecordPointable;
-
-/**
- * This interface is a visitor for all the three different IVisitablePointable
- * (Note that right now we have three pointable implementations for type
- * casting) implementations.
- */
-public interface IVisitablePointableVisitor<R, T> {
-
-    public R visit(AListPointable accessor, T arg) throws AsterixException;
-
-    public R visit(ARecordPointable accessor, T arg) throws AsterixException;
-
-    public R visit(AFlatValuePointable accessor, T arg) throws AsterixException;
-}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/util/AsterixRuntimeUtil.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/util/AsterixRuntimeUtil.java
deleted file mode 100644
index ab57288..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/util/AsterixRuntimeUtil.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.runtime.util;
-
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import edu.uci.ics.asterix.common.api.AsterixAppContextInfoImpl;
-import edu.uci.ics.asterix.common.exceptions.AsterixException;
-
-public class AsterixRuntimeUtil {
-
-    public static Set<String> getNodeControllersOnIP(String ipAddress) throws AsterixException {
-        Map<String, Set<String>> nodeControllerInfo = AsterixAppContextInfoImpl.getNodeControllerMap();
-        Set<String> nodeControllersAtLocation = nodeControllerInfo.get(ipAddress);
-        return nodeControllersAtLocation;
-    }
-
-    public static Set<String> getNodeControllersOnHostName(String hostName) throws UnknownHostException {
-        Map<String, Set<String>> nodeControllerInfo = AsterixAppContextInfoImpl.getNodeControllerMap();
-        String address;
-        address = InetAddress.getByName(hostName).getHostAddress();
-        if (address.equals("127.0.1.1")) {
-            address = "127.0.0.1";
-        }
-        Set<String> nodeControllersAtLocation = nodeControllerInfo.get(address);
-        return nodeControllersAtLocation;
-    }
-
-    public static List<String> getAllNodeControllers() {
-
-        Collection<Set<String>> nodeControllersCollection = AsterixAppContextInfoImpl.getNodeControllerMap().values();
-        List<String> nodeControllers = new ArrayList<String>();
-        for (Set<String> ncCollection : nodeControllersCollection) {
-            nodeControllers.addAll(ncCollection);
-        }
-        return nodeControllers;
-    }
-}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/util/ResettableByteArrayOutputStream.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/util/ResettableByteArrayOutputStream.java
deleted file mode 100644
index 968c3f2..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/util/ResettableByteArrayOutputStream.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package edu.uci.ics.asterix.runtime.util;
-
-import edu.uci.ics.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
-
-/**
- * This class extends ByteArrayAccessibleOutputStream to allow reset to a given
- * size.
- * 
- */
-public class ResettableByteArrayOutputStream extends ByteArrayAccessibleOutputStream {
-
-    public void reset(int size) {
-        count = size;
-    }
-}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/util/container/IObjectFactory.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/util/container/IObjectFactory.java
deleted file mode 100644
index 85f0fa3..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/util/container/IObjectFactory.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright 2009-2010 by The Regents of the University of California
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package edu.uci.ics.asterix.runtime.util.container;
-
-/**
- * A factory interface to create objects.
- */
-public interface IObjectFactory<E, T> {
-
-    /**
-     * create an element of type E
-     * 
-     * @param arg
-     * @return an E element
-     */
-    public E create(T arg);
-}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/util/container/IObjectPool.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/util/container/IObjectPool.java
deleted file mode 100644
index dd2c3bf..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/util/container/IObjectPool.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2009-2010 by The Regents of the University of California
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package edu.uci.ics.asterix.runtime.util.container;
-
-/**
- * A reusable object pool interface.
- */
-public interface IObjectPool<E, T> {
-
-    /**
-     * Give client an E instance
-     * 
-     * @param arg
-     *            the argument to create E
-     * @return an E instance
-     */
-    public E allocate(T arg);
-
-    /**
-     * Mark all instances in the pool as unused
-     */
-    public void reset();
-}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/util/container/ListObjectPool.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/util/container/ListObjectPool.java
deleted file mode 100644
index b8f8e3a..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/util/container/ListObjectPool.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright 2009-2010 by The Regents of the University of California
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package edu.uci.ics.asterix.runtime.util.container;
-
-import java.util.ArrayList;
-import java.util.BitSet;
-import java.util.List;
-
-/**
- * Object pool backed by a list.
- * 
- * The argument for creating E instances could be different. This class also
- * considers arguments in object reusing, e.g., it reuses an E instances ONLY
- * when the construction argument is "equal".
- */
-public class ListObjectPool<E, T> implements IObjectPool<E, T> {
-
-    private IObjectFactory<E, T> factory;
-
-    /**
-     * cache of objects
-     */
-    private List<E> pool = new ArrayList<E>();
-
-    /**
-     * args that are used to create each element in the pool
-     */
-    private List<T> args = new ArrayList<T>();
-
-    /**
-     * bits indicating which element is in use
-     */
-    private BitSet usedBits = new BitSet();
-
-    public ListObjectPool(IObjectFactory<E, T> factory) {
-        this.factory = factory;
-    }
-
-    @Override
-    public E allocate(T arg) {
-        int freeSlot = -1;
-        while (freeSlot + 1 < pool.size()) {
-            freeSlot = usedBits.nextClearBit(freeSlot + 1);
-            if (freeSlot >= pool.size())
-                break;
-
-            // the two cases where an element in the pool is a match
-            if ((arg == null && args.get(freeSlot) == null)
-                    || (arg != null && args.get(freeSlot) != null && arg.equals(args.get(freeSlot)))) {
-                // the element is not used and the arg is the same as
-                // input arg
-                usedBits.set(freeSlot);
-                return pool.get(freeSlot);
-            }
-        }
-
-        // if we do not find a reusable object, allocate a new one
-        E element = factory.create(arg);
-        pool.add(element);
-        args.add(arg);
-        usedBits.set(pool.size() - 1);
-        return element;
-    }
-
-    @Override
-    public void reset() {
-        usedBits.clear();
-    }
-}