@Override
 public IJObject access(IVisitablePointable pointable, IObjectPool<IJObject, IAType> objectPool)
     throws HyracksDataException {
   byte[] b = pointable.getByteArray();
   int s = pointable.getStartOffset();
   int v = ATimeSerializerDeserializer.getChronon(b, s);
   IJObject jObject = objectPool.allocate(BuiltinType.ATIME);
   ((JTime) jObject).setValue(v);
   return jObject;
 }
 @Override
 public IJObject access(IVisitablePointable pointable, IObjectPool<IJObject, IAType> objectPool)
     throws HyracksDataException {
   byte[] b = pointable.getByteArray();
   int s = pointable.getStartOffset();
   float v = AFloatSerializerDeserializer.getFloat(b, s + 1);
   IJObject jObject = objectPool.allocate(BuiltinType.AFLOAT);
   ((JFloat) jObject).setValue(v);
   return jObject;
 }
 @Override
 public IJObject access(IVisitablePointable pointable, IObjectPool<IJObject, IAType> objectPool)
     throws HyracksDataException {
   byte[] b = pointable.getByteArray();
   int s = pointable.getStartOffset();
   long v = AInt64SerializerDeserializer.getLong(b, s + 1);
   IJObject jObject = objectPool.allocate(BuiltinType.AINT64);
   ((JLong) jObject).setValue(v);
   return jObject;
 }
 @Override
 public IJObject access(IVisitablePointable pointable, IObjectPool<IJObject, IAType> objectPool)
     throws HyracksDataException {
   byte[] b = pointable.getByteArray();
   int s = pointable.getStartOffset();
   short i = AInt16SerializerDeserializer.getShort(b, s + 1);
   IJObject jObject = objectPool.allocate(BuiltinType.AINT16);
   ((JInt) jObject).setValue(i);
   return null;
 }
 @Override
 public IJObject access(IVisitablePointable pointable, IObjectPool<IJObject, IAType> objectPool)
     throws HyracksDataException {
   byte[] b = pointable.getByteArray();
   int s = pointable.getStartOffset();
   int l = pointable.getLength();
   ARectangle v =
       ARectangleSerializerDeserializer.INSTANCE.deserialize(
           new DataInputStream(new ByteArrayInputStream(b, s, l)));
   JRectangle jObject = (JRectangle) objectPool.allocate(BuiltinType.ARECTANGLE);
   jObject.setValue(v.getP1(), v.getP2());
   return jObject;
 }
 @Override
 public IJObject access(IVisitablePointable pointable, IObjectPool<IJObject, IAType> objectPool)
     throws HyracksDataException {
   byte[] b = pointable.getByteArray();
   int s = pointable.getStartOffset();
   int l = pointable.getLength();
   APolygon v =
       APolygonSerializerDeserializer.INSTANCE.deserialize(
           new DataInputStream(new ByteArrayInputStream(b, s, l)));
   JPolygon jObject = (JPolygon) objectPool.allocate(BuiltinType.APOLYGON);
   jObject.setValue(v.getPoints());
   return jObject;
 }
 @Override
 public IJObject access(IVisitablePointable pointable, IObjectPool<IJObject, IAType> objectPool)
     throws HyracksDataException {
   byte[] b = pointable.getByteArray();
   int s = pointable.getStartOffset();
   int l = pointable.getLength();
   ADuration duration =
       ADurationSerializerDeserializer.INSTANCE.deserialize(
           new DataInputStream(new ByteArrayInputStream(b, s, l)));
   IJObject jObject = objectPool.allocate(BuiltinType.ADURATION);
   ((JDuration) jObject).setValue(duration.getMonths(), duration.getMilliseconds());
   return jObject;
 }
 @Override
 public IJObject access(IVisitablePointable pointable, IObjectPool<IJObject, IAType> objectPool)
     throws HyracksDataException {
   byte[] b = pointable.getByteArray();
   int s = pointable.getStartOffset();
   int l = pointable.getLength();
   ACircle v =
       ACircleSerializerDeserializer.INSTANCE.deserialize(
           new DataInputStream(new ByteArrayInputStream(b, s, l)));
   JPoint jpoint = (JPoint) objectPool.allocate(BuiltinType.APOINT);
   jpoint.setValue(v.getP().getX(), v.getP().getY());
   IJObject jObject = objectPool.allocate(BuiltinType.ACIRCLE);
   ((JCircle) jObject).setValue(jpoint, v.getRadius());
   return jObject;
 }
 @Override
 public IJObject access(IVisitablePointable pointable, IObjectPool<IJObject, IAType> objectPool)
     throws HyracksDataException {
   byte[] b = pointable.getByteArray();
   int s = pointable.getStartOffset();
   long intervalStart = AIntervalSerializerDeserializer.getIntervalStart(b, s);
   long intervalEnd = AIntervalSerializerDeserializer.getIntervalEnd(b, s);
   byte intervalType = AIntervalSerializerDeserializer.getIntervalTimeType(b, s);
   IJObject jObject = objectPool.allocate(BuiltinType.AINTERVAL);
   try {
     ((JInterval) jObject).setValue(intervalStart, intervalEnd, intervalType);
   } catch (AlgebricksException e) {
     throw new HyracksDataException(e);
   }
   return jObject;
 }
    @Override
    public IJObject access(IVisitablePointable pointable, IObjectPool<IJObject, IAType> objectPool)
        throws HyracksDataException {
      IJObject jObject = objectPool.allocate(BuiltinType.ASTRING);

      try {
        byte byteArray[] = pointable.getByteArray();
        int len = pointable.getLength() - 3;
        int off = pointable.getStartOffset() + 3;
        baaos.reset();
        if (off >= 0 && off <= byteArray.length && len >= 0 && off + len - byteArray.length <= 0) {
          baaos.write(byteArray, off, len);
          ((JString) jObject).setValue(JObjectUtil.getNormalizedString(baaos.toString("UTF-8")));
        } else {
          ((JString) jObject).setValue("");
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
      return jObject;
    }
    @Override
    public IJObject access(
        AListVisitablePointable pointable,
        IObjectPool<IJObject, IAType> objectPool,
        IAType listType,
        JObjectPointableVisitor pointableVisitor)
        throws HyracksDataException {
      List<IVisitablePointable> items = pointable.getItems();
      List<IVisitablePointable> itemTags = pointable.getItemTags();
      JList list = pointable.ordered() ? new JOrderedList(listType) : new JUnorderedList(listType);
      IJObject listItem = null;
      int index = 0;
      try {

        for (IVisitablePointable itemPointable : items) {
          IVisitablePointable itemTagPointable = itemTags.get(index);
          ATypeTag itemTypeTag =
              EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(
                  itemTagPointable.getByteArray()[itemTagPointable.getStartOffset()]);
          typeInfo.reset(listType.getType(), listType.getTypeTag());
          switch (itemTypeTag) {
            case RECORD:
              listItem =
                  pointableVisitor.visit((ARecordVisitablePointable) itemPointable, typeInfo);
              break;
            case UNORDEREDLIST:
            case ORDEREDLIST:
              listItem = pointableVisitor.visit((AListVisitablePointable) itemPointable, typeInfo);
              break;
            case ANY:
              throw new IllegalArgumentException(
                  "Cannot parse list item of type " + listType.getTypeTag());
            default:
              IAType itemType = ((AbstractCollectionType) listType).getItemType();
              typeInfo.reset(itemType, itemType.getTypeTag());
              listItem = pointableVisitor.visit((AFlatValuePointable) itemPointable, typeInfo);
          }
          ATypeTag typeTag =
              EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(
                  itemPointable.getByteArray()[itemPointable.getStartOffset()]);

          list.add(listItem);
        }
      } catch (AsterixException exception) {
        throw new HyracksDataException(exception);
      }
      return list;
    }
    @Override
    public JRecord access(
        ARecordVisitablePointable pointable,
        IObjectPool<IJObject, IAType> objectPool,
        ARecordType recordType,
        JObjectPointableVisitor pointableVisitor)
        throws HyracksDataException {
      try {
        jRecord.reset();
      } catch (AlgebricksException e) {
        throw new HyracksDataException(e);
      }
      ARecordVisitablePointable recordPointable = (ARecordVisitablePointable) pointable;
      List<IVisitablePointable> fieldPointables = recordPointable.getFieldValues();
      List<IVisitablePointable> fieldTypeTags = recordPointable.getFieldTypeTags();
      List<IVisitablePointable> fieldNames = recordPointable.getFieldNames();
      int index = 0;
      boolean closedPart = true;
      try {
        IJObject fieldObject = null;
        for (IVisitablePointable fieldPointable : fieldPointables) {
          closedPart = index < recordType.getFieldTypes().length;
          IVisitablePointable tt = fieldTypeTags.get(index);
          IAType fieldType = closedPart ? recordType.getFieldTypes()[index] : null;
          ATypeTag typeTag =
              EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(
                  tt.getByteArray()[tt.getStartOffset()]);
          IVisitablePointable fieldName = fieldNames.get(index);
          typeInfo.reset(fieldType, typeTag);
          switch (typeTag) {
            case RECORD:
              fieldObject =
                  pointableVisitor.visit((ARecordVisitablePointable) fieldPointable, typeInfo);
              break;
            case ORDEREDLIST:
            case UNORDEREDLIST:
              if (fieldPointable instanceof AFlatValuePointable) {
                // value is null
                fieldObject = null;
              } else {
                fieldObject =
                    pointableVisitor.visit((AListVisitablePointable) fieldPointable, typeInfo);
              }
              break;
            case ANY:
              break;
            default:
              fieldObject = pointableVisitor.visit((AFlatValuePointable) fieldPointable, typeInfo);
          }
          if (closedPart) {
            jObjects[index] = fieldObject;
          } else {
            byte[] b = fieldName.getByteArray();
            int s = fieldName.getStartOffset();
            int l = fieldName.getLength();
            String v =
                AStringSerializerDeserializer.INSTANCE
                    .deserialize(new DataInputStream(new ByteArrayInputStream(b, s + 1, l - 1)))
                    .getStringValue();
            openFields.put(v, fieldObject);
          }
          index++;
          fieldObject = null;
        }

      } catch (Exception e) {
        e.printStackTrace();
        throw new HyracksDataException(e);
      }
      return jRecord;
    }