Example #1
0
 /** @return nanoseconds in this TimestampWritable */
 public int getNanos() {
   if (!timestampEmpty) {
     return timestamp.getNanos();
   } else if (!bytesEmpty) {
     return hasDecimalOrSecondVInt() ? TimestampWritable.getNanos(currentBytes, offset + 4) : 0;
   } else {
     throw new IllegalStateException("Both timestamp and bytes are empty");
   }
 }
Example #2
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;
   }
 }
Example #3
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);
   }
 }