@Override
 public IJObject access(IVisitablePointable pointable, IObjectPool<IJObject, IAType> objectPool)
     throws HyracksDataException {
   byte[] b = pointable.getByteArray();
   int s = pointable.getStartOffset();
   int i = AInt32SerializerDeserializer.getInt(b, s + 1);
   IJObject jObject = objectPool.allocate(BuiltinType.AINT32);
   ((JInt) jObject).setValue(i);
   return jObject;
 }
 @Override
 public void print(byte[] b, int s, int l, PrintStream ps) throws HyracksDataException {
   int d = AInt32SerializerDeserializer.getInt(b, s + 1);
   try {
     WriteValueTools.writeInt(d, ps);
     WriteValueTools.writeUTF8StringNoQuotes(SUFFIX_STRING, ps);
   } catch (IOException e) {
     throw new HyracksDataException(e);
   }
 }
  public static void printDateString(byte[] b, int s, int l, PrintStream ps)
      throws HyracksDataException {
    long chrononTime = AInt32SerializerDeserializer.getInt(b, s + 1) * CHRONON_OF_DAY;

    try {
      gCalInstance.getExtendStringRepUntilField(
          chrononTime,
          0,
          ps,
          GregorianCalendarSystem.Fields.YEAR,
          GregorianCalendarSystem.Fields.DAY,
          false);
    } catch (IOException e) {
      throw new HyracksDataException(e);
    }
  }
  public static void printTimeString(byte[] b, int s, int l, PrintStream ps)
      throws HyracksDataException {
    int time = AInt32SerializerDeserializer.getInt(b, s + 1);

    try {
      gCalInstance.getExtendStringRepUntilField(
          time,
          0,
          ps,
          GregorianCalendarSystem.Fields.HOUR,
          GregorianCalendarSystem.Fields.MILLISECOND,
          true);
    } catch (IOException e) {
      throw new HyracksDataException(e);
    }
  }
 protected void processDataValues(IFrameTupleReference tuple) throws AlgebricksException {
   if (skipStep()) {
     return;
   }
   inputVal.reset();
   eval.evaluate(tuple);
   ATypeTag typeTag =
       EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(inputVal.getByteArray()[0]);
   if (typeTag == ATypeTag.NULL) {
     processNull();
     return;
   } else if (aggType == ATypeTag.SYSTEM_NULL) {
     aggType = typeTag;
   } else if (typeTag != ATypeTag.SYSTEM_NULL && !ATypeHierarchy.isCompatible(typeTag, aggType)) {
     throw new AlgebricksException(
         "Unexpected type "
             + typeTag
             + " in aggregation input stream. Expected type "
             + aggType
             + ".");
   } else if (ATypeHierarchy.canPromote(aggType, typeTag)) {
     aggType = typeTag;
   }
   ++count;
   switch (typeTag) {
     case INT8:
       {
         byte val = AInt8SerializerDeserializer.getByte(inputVal.getByteArray(), 1);
         sum += val;
         break;
       }
     case INT16:
       {
         short val = AInt16SerializerDeserializer.getShort(inputVal.getByteArray(), 1);
         sum += val;
         break;
       }
     case INT32:
       {
         int val = AInt32SerializerDeserializer.getInt(inputVal.getByteArray(), 1);
         sum += val;
         break;
       }
     case INT64:
       {
         long val = AInt64SerializerDeserializer.getLong(inputVal.getByteArray(), 1);
         sum += val;
         break;
       }
     case FLOAT:
       {
         float val = AFloatSerializerDeserializer.getFloat(inputVal.getByteArray(), 1);
         sum += val;
         break;
       }
     case DOUBLE:
       {
         double val = ADoubleSerializerDeserializer.getDouble(inputVal.getByteArray(), 1);
         sum += val;
         break;
       }
     default:
       {
         throw new NotImplementedException("Cannot compute AVG for values of type " + typeTag);
       }
   }
   inputVal.reset();
 }
  public static void printDurationString(byte[] b, int s, int l, PrintStream ps)
      throws HyracksDataException {
    boolean positive = true;
    int months = AInt32SerializerDeserializer.getInt(b, s + 1);
    long milliseconds = AInt64SerializerDeserializer.getLong(b, s + 5);

    // set the negative flag. "||" is necessary in case that months field is not there (so it is 0)
    if (months < 0 || milliseconds < 0) {
      months *= -1;
      milliseconds *= -1;
      positive = false;
    }

    int month = gCalInstance.getDurationMonth(months);
    int year = gCalInstance.getDurationYear(months);
    int millisecond = gCalInstance.getDurationMillisecond(milliseconds);
    int second = gCalInstance.getDurationSecond(milliseconds);
    int minute = gCalInstance.getDurationMinute(milliseconds);
    int hour = gCalInstance.getDurationHour(milliseconds);
    int day = gCalInstance.getDurationDay(milliseconds);

    if (!positive) {
      ps.print("-");
    }
    try {
      ps.print("P");
      if (year != 0) {
        WriteValueTools.writeInt(year, ps);
        ps.print("Y");
      }
      if (month != 0) {
        WriteValueTools.writeInt(month, ps);
        ps.print("M");
      }
      if (day != 0) {
        WriteValueTools.writeInt(day, ps);
        ps.print("D");
      }
      if (hour != 0 || minute != 0 || second != 0 || millisecond != 0) {
        ps.print("T");
      }
      if (hour != 0) {
        WriteValueTools.writeInt(hour, ps);
        ps.print("H");
      }
      if (minute != 0) {
        WriteValueTools.writeInt(minute, ps);
        ps.print("M");
      }
      if (second != 0 || millisecond != 0) {
        WriteValueTools.writeInt(second, ps);
      }
      if (millisecond > 0) {
        ps.print(".");
        WriteValueTools.writeInt(millisecond, ps);
      }
      if (second != 0 || millisecond != 0) {
        ps.print("S");
      }
    } catch (IOException e) {
      throw new HyracksDataException(e);
    }
  }