Exemplo n.º 1
0
 /**
  * Convert from Timestamp to an integer. This is called for CAST(... AS INT)
  *
  * @param i The Timestamp value to convert
  * @return IntWritable
  */
 public IntWritable evaluate(TimestampWritable i) {
   if (i == null) {
     return null;
   } else {
     intWritable.set(i.getSeconds());
     return intWritable;
   }
 }
 private LongWritable getLongWritable(TimestampWritable i) {
   LongWritable result = new LongWritable();
   if (i == null) {
     return null;
   } else {
     result.set(i.getSeconds());
     return result;
   }
 }
Exemplo n.º 3
0
 /** @return seconds corresponding to this TimestampWritable */
 public long getSeconds() {
   if (!timestampEmpty) {
     return millisToSeconds(timestamp.getTime());
   } else if (!bytesEmpty) {
     return TimestampWritable.getSeconds(currentBytes, offset);
   } else {
     throw new IllegalStateException("Both timestamp and bytes are empty");
   }
 }
Exemplo n.º 4
0
 public int compareTo(TimestampWritable t) {
   checkBytes();
   long s1 = this.getSeconds();
   long s2 = t.getSeconds();
   if (s1 == s2) {
     int n1 = this.getNanos();
     int n2 = t.getNanos();
     if (n1 == n2) {
       return 0;
     }
     return n1 - n2;
   } else {
     return s1 < s2 ? -1 : 1;
   }
 }
Exemplo n.º 5
0
 public static void setTimestamp(Timestamp t, byte[] bytes, int offset) {
   boolean hasDecimalOrSecondVInt = hasDecimalOrSecondVInt(bytes[offset]);
   long seconds = (long) TimestampWritable.getSeconds(bytes, offset);
   int nanos = 0;
   if (hasDecimalOrSecondVInt) {
     nanos = TimestampWritable.getNanos(bytes, offset + 4);
     if (hasSecondVInt(bytes[offset + 4])) {
       seconds +=
           LazyBinaryUtils.readVLongFromByteArray(
               bytes, offset + 4 + WritableUtils.decodeVIntSize(bytes[offset + 4]));
     }
   }
   t.setTime(seconds * 1000);
   if (nanos != 0) {
     t.setNanos(nanos);
   }
 }