/** * Fill all the vector entries with a HiveIntervalDayTime. * @param intervalDayTime */ public void fill(HiveIntervalDayTime intervalDayTime) { isRepeating = true; isNull[0] = false; totalSeconds[0] = intervalDayTime.getTotalSeconds(); nanos[0] = intervalDayTime.getNanos(); }
/** * Set a field from the current value in the scratch interval day time. * * This is a FAST version that assumes the caller has checked to make sure the scratch interval * day time is valid and elementNum is correctly adjusted for isRepeating. And, that the isNull * entry has been set. Only the output entry fields will be set by this method. * * @param elementNum */ public void setFromScratchIntervalDayTime(int elementNum) { this.totalSeconds[elementNum] = scratchIntervalDayTime.getTotalSeconds(); this.nanos[elementNum] = scratchIntervalDayTime.getNanos(); }
/** * Set a field from a HiveIntervalDayTime. * * This is a FAST version that assumes the caller has checked to make sure the sourceBuf * is not null and elementNum is correctly adjusted for isRepeating. And, that the isNull entry * has been set. Only the output entry fields will be set by this method. * * @param elementNum * @param intervalDayTime */ public void set(int elementNum, HiveIntervalDayTime intervalDayTime) { this.totalSeconds[elementNum] = intervalDayTime.getTotalSeconds(); this.nanos[elementNum] = intervalDayTime.getNanos(); }
public static long getIntervalDayTimeTotalNanos(HiveIntervalDayTime intervalDayTime) { return intervalDayTime.getTotalSeconds() * NANOS_PER_SEC + intervalDayTime.getNanos(); }
@Deprecated public boolean add(java.sql.Timestamp ts, HiveIntervalDayTime interval, java.sql.Timestamp result) { if (ts == null || interval == null) { return false; } nanosResult.addNanos(ts.getNanos(), interval.getNanos()); long newMillis = ts.getTime() + TimeUnit.SECONDS.toMillis(interval.getTotalSeconds() + nanosResult.seconds); result.setTime(newMillis); result.setNanos(nanosResult.nanos); return true; }
@Deprecated public boolean add(HiveIntervalDayTime interval, java.sql.Timestamp ts, java.sql.Timestamp result) { if (ts == null || interval == null) { return false; } nanosResult.addNanos(ts.getNanos(), interval.getNanos()); long newMillis = ts.getTime() + TimeUnit.SECONDS.toMillis(interval.getTotalSeconds() + nanosResult.seconds); result.setTime(newMillis); result.setNanos(nanosResult.nanos); return true; }
@Override public String toString() { // If normalize() was used, then day-hour-minute-second-nanos should have the same sign. // This is currently working with that assumption. boolean isNegative = (totalSeconds < 0 || nanos < 0); String daySecondSignStr = isNegative ? "-" : ""; return String.format("%s%d %02d:%02d:%02d.%09d", daySecondSignStr, Math.abs(getDays()), Math.abs(getHours()), Math.abs(getMinutes()), Math.abs(getSeconds()), Math.abs(getNanos())); }
public boolean add(Timestamp ts, HiveIntervalDayTime interval, Timestamp result) { if (ts == null || interval == null) { return false; } nanosResult.addNanos(ts.getNanos(), interval.getNanos()); long newMillis = ts.getTime() + TimeUnit.SECONDS.toMillis(interval.getTotalSeconds() + nanosResult.seconds); result.setTime(newMillis); result.setNanos(nanosResult.nanos); return true; }
public boolean add(HiveIntervalDayTime interval, Timestamp ts, Timestamp result) { if (ts == null || interval == null) { return false; } nanosResult.addNanos(ts.getNanos(), interval.getNanos()); long newMillis = ts.getTime() + TimeUnit.SECONDS.toMillis(interval.getTotalSeconds() + nanosResult.seconds); result.setTime(newMillis); result.setNanos(nanosResult.nanos); return true; }
public boolean add(HiveIntervalDayTime left, HiveIntervalDayTime right, HiveIntervalDayTime result) { if (left == null || right == null) { return false; } nanosResult.addNanos(left.getNanos(), right.getNanos()); long totalSeconds = left.getTotalSeconds() + right.getTotalSeconds() + nanosResult.seconds; result.set(totalSeconds, nanosResult.nanos); return true; }
public void set(HiveIntervalDayTime other) { set(other.getTotalSeconds(), other.getNanos()); }
public HiveIntervalDayTime negate() { return new HiveIntervalDayTime(-getTotalSeconds(), -getNanos()); }
public boolean add(HiveIntervalDayTime left, HiveIntervalDayTime right, HiveIntervalDayTime result) { if (left == null || right == null) { return false; } nanosResult.addNanos(left.getNanos(), right.getNanos()); long totalSeconds = left.getTotalSeconds() + right.getTotalSeconds() + nanosResult.seconds; result.set(totalSeconds, nanosResult.nanos); return true; }
public static void serializeHiveIntervalDayTime(ByteStream.Output buffer, HiveIntervalDayTime intervalDayTime, boolean invert) { long totalSecs = intervalDayTime.getTotalSeconds(); int nanos = intervalDayTime.getNanos(); serializeLong(buffer, totalSecs, invert); serializeInt(buffer, nanos, invert); }
@Override public void write(DataOutput out) throws IOException { // write totalSeconds, nanos to DataOutput WritableUtils.writeVLong(out, intervalValue.getTotalSeconds()); WritableUtils.writeVInt(out, intervalValue.getNanos()); }
public void writeToByteStream(RandomAccessOutput byteStream) { LazyBinaryUtils.writeVLong(byteStream, intervalValue.getTotalSeconds()); LazyBinaryUtils.writeVInt(byteStream, intervalValue.getNanos()); }
public boolean add(HiveIntervalDayTime interval, Timestamp ts, Timestamp result) { if (ts == null || interval == null) { return false; } nanosResult.addNanos(ts.getNanos(), interval.getNanos()); long newMillis = ts.toEpochMilli() + TimeUnit.SECONDS.toMillis(interval.getTotalSeconds() + nanosResult.seconds); result.setTimeInMillis(newMillis, nanosResult.nanos); return true; }
public boolean add(Timestamp ts, HiveIntervalDayTime interval, Timestamp result) { if (ts == null || interval == null) { return false; } nanosResult.addNanos(ts.getNanos(), interval.getNanos()); long newMillis = ts.toEpochMilli() + TimeUnit.SECONDS.toMillis(interval.getTotalSeconds() + nanosResult.seconds); result.setTimeInMillis(newMillis, nanosResult.nanos); return true; }
private long truncate(Timestamp ts, HiveIntervalDayTime idt, Timestamp origin) { long intervalDurationMs = idt.getTotalSeconds() * 1000L + idt.getNanos() / 1000L; long offset = ts.toEpochMilli() % intervalDurationMs - origin.toEpochMilli() % intervalDurationMs; if (offset < 0) { offset += intervalDurationMs; } return ts.toEpochMilli() - offset; }
@Test @Concurrent(count=4) @Repeating(repetition=100) public void testGetters() throws Exception { HiveIntervalDayTime i1 = new HiveIntervalDayTime(3, 4, 5, 6, 7); assertEquals(3, i1.getDays()); assertEquals(4, i1.getHours()); assertEquals(5, i1.getMinutes()); assertEquals(6, i1.getSeconds()); assertEquals(7, i1.getNanos()); }