public int getNanos() { if (!timestampTZEmpty) { return timestampTZ.getNanos(); } else if (!bytesEmpty) { return hasDecimalOrSecondVInt(currentBytes[offset]) ? getNanos(currentBytes, offset + 4) : 0; } throw new IllegalStateException("Both timestamp and bytes are empty"); }
private void populateTimestampTZ() { if (timestampTZEmpty) { if (bytesEmpty) { throw new IllegalStateException("Bytes are empty"); } long seconds = getSeconds(currentBytes, offset); int nanos = hasDecimalOrSecondVInt(currentBytes[offset]) ? getNanos(currentBytes, offset + 4) : 0; timestampTZ.set(seconds, nanos, timeZone); timestampTZEmpty = false; } }
@Override public void readFields(DataInput dataInput) throws IOException { dataInput.readFully(internalBytes, 0, 4); if (hasDecimalOrSecondVInt(internalBytes[0])) { dataInput.readFully(internalBytes, 4, 1); int len = (byte) WritableUtils.decodeVIntSize(internalBytes[4]); if (len > 1) { dataInput.readFully(internalBytes, 5, len - 1); } long vlong = LazyBinaryUtils.readVLongFromByteArray(internalBytes, 4); Preconditions.checkState(vlong >= -1000000000 && vlong <= 999999999, "Invalid nanos value for a TimestampTZWritable: " + vlong + ", expected to be between -1000000000 and 999999999."); if (vlong < 0) { // This indicates there is a second VInt containing the additional bits of the seconds // field. dataInput.readFully(internalBytes, 4 + len, 1); int secondVIntLen = (byte) WritableUtils.decodeVIntSize(internalBytes[4 + len]); if (secondVIntLen > 1) { dataInput.readFully(internalBytes, 5 + len, secondVIntLen - 1); } } } currentBytes = internalBytes; offset = 0; timestampTZEmpty = true; bytesEmpty = false; }
public static void setTimestampTZ(TimestampTZ t, byte[] bytes, int offset, ZoneId timeZone) { long seconds = getSeconds(bytes, offset); int nanos = hasDecimalOrSecondVInt(bytes[offset]) ? getNanos(bytes, offset + 4) : 0; t.set(seconds, nanos, timeZone); }
public static int getTotalLength(byte[] bytes, int offset) { int len = 4; if (hasDecimalOrSecondVInt(bytes[offset])) { int firstVIntLen = WritableUtils.decodeVIntSize(bytes[offset + 4]); len += firstVIntLen; if (hasSecondVInt(bytes[offset + 4])) { len += WritableUtils.decodeVIntSize(bytes[offset + 4 + firstVIntLen]); } } return len; }
public int getNanos() { if (!timestampTZEmpty) { return timestampTZ.getNanos(); } else if (!bytesEmpty) { return hasDecimalOrSecondVInt(currentBytes[offset]) ? getNanos(currentBytes, offset + 4) : 0; } throw new IllegalStateException("Both timestamp and bytes are empty"); }
private void populateTimestampTZ() { if (timestampTZEmpty) { if (bytesEmpty) { throw new IllegalStateException("Bytes are empty"); } long seconds = getSeconds(currentBytes, offset); int nanos = hasDecimalOrSecondVInt(currentBytes[offset]) ? getNanos(currentBytes, offset + 4) : 0; timestampTZ.set(seconds, nanos, timeZone); timestampTZEmpty = false; } }
@Override public void readFields(DataInput dataInput) throws IOException { dataInput.readFully(internalBytes, 0, 4); if (hasDecimalOrSecondVInt(internalBytes[0])) { dataInput.readFully(internalBytes, 4, 1); int len = (byte) WritableUtils.decodeVIntSize(internalBytes[4]); if (len > 1) { dataInput.readFully(internalBytes, 5, len - 1); } long vlong = LazyBinaryUtils.readVLongFromByteArray(internalBytes, 4); Preconditions.checkState(vlong >= -1000000000 && vlong <= 999999999, "Invalid nanos value for a TimestampTZWritable: " + vlong + ", expected to be between -1000000000 and 999999999."); if (vlong < 0) { // This indicates there is a second VInt containing the additional bits of the seconds // field. dataInput.readFully(internalBytes, 4 + len, 1); int secondVIntLen = (byte) WritableUtils.decodeVIntSize(internalBytes[4 + len]); if (secondVIntLen > 1) { dataInput.readFully(internalBytes, 5 + len, secondVIntLen - 1); } } } currentBytes = internalBytes; offset = 0; timestampTZEmpty = true; bytesEmpty = false; }
public static void setTimestampTZ(TimestampTZ t, byte[] bytes, int offset, ZoneId timeZone) { long seconds = getSeconds(bytes, offset); int nanos = hasDecimalOrSecondVInt(bytes[offset]) ? getNanos(bytes, offset + 4) : 0; t.set(seconds, nanos, timeZone); }
public static int getTotalLength(byte[] bytes, int offset) { int len = 4; if (hasDecimalOrSecondVInt(bytes[offset])) { int firstVIntLen = WritableUtils.decodeVIntSize(bytes[offset + 4]); len += firstVIntLen; if (hasSecondVInt(bytes[offset + 4])) { len += WritableUtils.decodeVIntSize(bytes[offset + 4 + firstVIntLen]); } } return len; }