@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;
 }
예제 #2
0
  public static void printDayTimeDurationString(byte[] b, int s, int l, PrintStream ps)
      throws HyracksDataException {
    boolean positive = true;
    long milliseconds = AInt64SerializerDeserializer.getLong(b, s + 1);

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

    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 (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);
    }
  }
예제 #3
0
  public static void printDateTimeString(byte[] b, int s, int l, PrintStream ps)
      throws HyracksDataException {
    long chrononTime = AInt64SerializerDeserializer.getLong(b, s + 1);

    try {
      gCalInstance.getExtendStringRepUntilField(
          chrononTime,
          0,
          ps,
          GregorianCalendarSystem.Fields.YEAR,
          GregorianCalendarSystem.Fields.MILLISECOND,
          true);
    } catch (IOException e) {
      throw new HyracksDataException(e);
    }
  }
 protected void processPartialResults(IFrameTupleReference tuple) throws AlgebricksException {
   if (skipStep()) {
     return;
   }
   inputVal.reset();
   eval.evaluate(tuple);
   byte[] serBytes = inputVal.getByteArray();
   ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serBytes[0]);
   switch (typeTag) {
     case NULL:
       {
         processNull();
         break;
       }
     case SYSTEM_NULL:
       {
         // Ignore and return.
         break;
       }
     case RECORD:
       {
         // Expected.
         aggType = ATypeTag.DOUBLE;
         int nullBitmapSize = 0;
         int offset1 =
             ARecordSerializerDeserializer.getFieldOffsetById(
                 serBytes, SUM_FIELD_ID, nullBitmapSize, false);
         sum += ADoubleSerializerDeserializer.getDouble(serBytes, offset1);
         int offset2 =
             ARecordSerializerDeserializer.getFieldOffsetById(
                 serBytes, COUNT_FIELD_ID, nullBitmapSize, false);
         count += AInt64SerializerDeserializer.getLong(serBytes, offset2);
         break;
       }
     default:
       {
         throw new AlgebricksException(
             "Global-Avg is not defined for values of type "
                 + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serBytes[0]));
       }
   }
 }
 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();
 }