/** * @param binaryTimeStampValue * hive, impala timestamp values with nanoseconds precision * are stored in parquet Binary as INT96 (12 constant bytes) * * @return Unix Timestamp - the number of milliseconds since January 1, 1970, 00:00:00 GMT * represented by @param binaryTimeStampValue . */ public static long getDateTimeValueFromBinary(Binary binaryTimeStampValue) { // This method represents binaryTimeStampValue as ByteBuffer, where timestamp is stored as sum of // julian day number (32-bit) and nanos of day (64-bit) NanoTime nt = NanoTime.fromBinary(binaryTimeStampValue); int julianDay = nt.getJulianDay(); long nanosOfDay = nt.getTimeOfDayNanos(); return (julianDay - JULIAN_DAY_NUMBER_FOR_UNIX_EPOCH) * DateTimeConstants.MILLIS_PER_DAY + nanosOfDay / NANOS_PER_MILLISECOND; } }
public NanoTime getTimeNanos(int fieldIndex, int index) { return NanoTime.fromInt96((Int96Value)getValue(fieldIndex, index)); }
@Override public void writeValue(RecordConsumer recordConsumer) { recordConsumer.addBinary(toBinary()); }
public static NanoTime fromInt96(Int96Value int96) { ByteBuffer buf = int96.getInt96().toByteBuffer(); return new NanoTime(buf.getInt(), buf.getLong()); }
@Override public void add(int fieldIndex, NanoTime value) { add(fieldIndex, value.toInt96()); }
public static NanoTime fromInt96(Int96Value int96) { ByteBuffer buf = int96.getInt96().toByteBuffer(); return new NanoTime(buf.getInt(), buf.getLong()); }
@Override public void add(int fieldIndex, NanoTime value) { add(fieldIndex, value.toInt96()); }
/** * @param binaryTimeStampValue * hive, impala timestamp values with nanoseconds precision * are stored in parquet Binary as INT96 (12 constant bytes) * @param retainLocalTimezone * parquet files don't keep local timeZone according to the * <a href="https://github.com/Parquet/parquet-format/blob/master/LogicalTypes.md#timestamp">Parquet spec</a>, * but some tools (hive, for example) retain local timezone for parquet files by default * Note: Impala doesn't retain local timezone by default * @return Timestamp in milliseconds - the number of milliseconds since January 1, 1970, 00:00:00 GMT * represented by @param binaryTimeStampValue. * The nanos precision is cut to millis. Therefore the length of single timestamp value is * {@value org.apache.drill.exec.expr.holders.NullableTimeStampHolder#WIDTH} bytes instead of 12 bytes. */ public static long getDateTimeValueFromBinary(Binary binaryTimeStampValue, boolean retainLocalTimezone) { // This method represents binaryTimeStampValue as ByteBuffer, where timestamp is stored as sum of // julian day number (4 bytes) and nanos of day (8 bytes) NanoTime nt = NanoTime.fromBinary(binaryTimeStampValue); int julianDay = nt.getJulianDay(); long nanosOfDay = nt.getTimeOfDayNanos(); long dateTime = (julianDay - JULIAN_DAY_NUMBER_FOR_UNIX_EPOCH) * DateTimeConstants.MILLIS_PER_DAY + nanosOfDay / NANOS_PER_MILLISECOND; if (retainLocalTimezone) { return DateTimeZone.getDefault().convertUTCToLocal(dateTime); } else { return dateTime; } } }
public static NanoTime fromBinary(Binary bytes) { Preconditions.checkArgument(bytes.length() == 12, "Must be 12 bytes"); ByteBuffer buf = bytes.toByteBuffer(); buf.order(ByteOrder.LITTLE_ENDIAN); long timeOfDayNanos = buf.getLong(); int julianDay = buf.getInt(); return new NanoTime(julianDay, timeOfDayNanos); }
@Override public void writeValue(RecordConsumer recordConsumer) { recordConsumer.addBinary(toBinary()); }
public NanoTime getTimeNanos(int fieldIndex, int index) { return NanoTime.fromInt96((Int96Value)getValue(fieldIndex, index)); }
NanoTime nt = NanoTime.fromBinary(val); int julianDay = nt.getJulianDay(); long nanosOfDay = nt.getTimeOfDayNanos(); long epochSeconds = (julianDay - JULIAN_DAY_NUMBER_FOR_UNIX_EPOCH) * 24 * 60 * 60; Instant inst = Instant.ofEpochSecond(epochSeconds, nanosOfDay);
public static NanoTime fromBinary(Binary bytes) { Preconditions.checkArgument(bytes.length() == 12, "Must be 12 bytes"); ByteBuffer buf = bytes.toByteBuffer(); buf.order(ByteOrder.LITTLE_ENDIAN); long timeOfDayNanos = buf.getLong(); int julianDay = buf.getInt(); return new NanoTime(julianDay, timeOfDayNanos); }
public Int96Value toInt96() { return new Int96Value(toBinary()); }
public Int96Value toInt96() { return new Int96Value(toBinary()); }