org.apache.hadoop.hive.serde2.io
Class TimestampWritable

java.lang.Object
  extended by org.apache.hadoop.hive.serde2.io.TimestampWritable
All Implemented Interfaces:
Comparable<TimestampWritable>, org.apache.hadoop.io.Writable, org.apache.hadoop.io.WritableComparable<TimestampWritable>

public class TimestampWritable
extends Object
implements org.apache.hadoop.io.WritableComparable<TimestampWritable>

TimestampWritable Writable equivalent of java.sq.Timestamp Timestamps are of the format YYYY-MM-DD HH:MM:SS.[fff...] We encode Unix timestamp in seconds in 4 bytes, using the MSB to signify whether the timestamp has a fractional portion. The fractional portion is reversed, and encoded as a VInt so timestamps with less precision use fewer bytes. 0.1 -> 1 0.01 -> 10 0.001 -> 100


Field Summary
static int BINARY_SORTABLE_LENGTH
           
static int MAX_BYTES
          The maximum number of bytes required for a TimestampWritable
static byte[] nullBytes
           
 
Constructor Summary
TimestampWritable()
           
TimestampWritable(byte[] bytes, int offset)
           
TimestampWritable(Timestamp t)
           
TimestampWritable(TimestampWritable t)
           
 
Method Summary
 int compareTo(TimestampWritable t)
           
static void convertTimestampToBytes(Timestamp t, byte[] b, int offset)
          Writes a Timestamp's serialized value to byte array b at the given offset
static Timestamp createTimestamp(byte[] bytes, int offset)
           
static Timestamp decimalToTimestamp(HiveDecimal d)
           
static Timestamp doubleToTimestamp(double f)
           
 boolean equals(Object o)
           
static Timestamp floatToTimestamp(float f)
          Interprets a float as a unix timestamp and returns a Timestamp object
 byte[] getBinarySortable()
           
 byte[] getBytes()
          Used to create copies of objects
 double getDouble()
           
 int getNanos()
           
static int getNanos(byte[] bytes, int offset)
           
 long getSeconds()
           
static long getSeconds(byte[] bytes, int offset)
          Gets seconds stored as integer at bytes[offset]
 Timestamp getTimestamp()
           
static int getTotalLength(byte[] bytes, int offset)
           
 boolean hasDecimal()
           
 int hashCode()
           
 void readFields(DataInput in)
           
 void set(byte[] bytes, int offset)
           
 void set(Timestamp t)
           
 void set(TimestampWritable t)
           
 void setBinarySortable(byte[] bytes, int binSortOffset)
          Given a byte[] that has binary sortable data, initialize the internal structures to hold that data
static void setTimestamp(Timestamp t, byte[] bytes, int offset)
           
 String toString()
           
 void write(DataOutput out)
           
 void write(OutputStream out)
           
 void writeToByteStream(ByteStream.Output byteStream)
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

nullBytes

public static final byte[] nullBytes

MAX_BYTES

public static final int MAX_BYTES
The maximum number of bytes required for a TimestampWritable

See Also:
Constant Field Values

BINARY_SORTABLE_LENGTH

public static final int BINARY_SORTABLE_LENGTH
See Also:
Constant Field Values
Constructor Detail

TimestampWritable

public TimestampWritable()

TimestampWritable

public TimestampWritable(byte[] bytes,
                         int offset)

TimestampWritable

public TimestampWritable(TimestampWritable t)

TimestampWritable

public TimestampWritable(Timestamp t)
Method Detail

set

public void set(byte[] bytes,
                int offset)

set

public void set(Timestamp t)

set

public void set(TimestampWritable t)

writeToByteStream

public void writeToByteStream(ByteStream.Output byteStream)

getSeconds

public long getSeconds()
Returns:
seconds corresponding to this TimestampWritable

getNanos

public int getNanos()
Returns:
nanoseconds in this TimestampWritable

getTotalLength

public static int getTotalLength(byte[] bytes,
                                 int offset)

getTimestamp

public Timestamp getTimestamp()

getBytes

public byte[] getBytes()
Used to create copies of objects

Returns:
a copy of the internal TimestampWritable byte[]

getBinarySortable

public byte[] getBinarySortable()
Returns:
byte[] representation of TimestampWritable that is binary sortable (7 bytes for seconds, 4 bytes for nanoseconds)

setBinarySortable

public void setBinarySortable(byte[] bytes,
                              int binSortOffset)
Given a byte[] that has binary sortable data, initialize the internal structures to hold that data

Parameters:
bytes - the byte array that holds the binary sortable representation
binSortOffset - offset of the binary-sortable representation within the buffer.

getDouble

public double getDouble()
Returns:
double representation of the timestamp, accurate to nanoseconds

readFields

public void readFields(DataInput in)
                throws IOException
Specified by:
readFields in interface org.apache.hadoop.io.Writable
Throws:
IOException

write

public void write(OutputStream out)
           throws IOException
Throws:
IOException

write

public void write(DataOutput out)
           throws IOException
Specified by:
write in interface org.apache.hadoop.io.Writable
Throws:
IOException

compareTo

public int compareTo(TimestampWritable t)
Specified by:
compareTo in interface Comparable<TimestampWritable>

equals

public boolean equals(Object o)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

getSeconds

public static long getSeconds(byte[] bytes,
                              int offset)
Gets seconds stored as integer at bytes[offset]

Parameters:
bytes -
offset -
Returns:
the number of seconds

getNanos

public static int getNanos(byte[] bytes,
                           int offset)

convertTimestampToBytes

public static void convertTimestampToBytes(Timestamp t,
                                           byte[] b,
                                           int offset)
Writes a Timestamp's serialized value to byte array b at the given offset

Parameters:
timestamp - to convert to bytes
b - destination byte array
offset - destination offset in the byte array

floatToTimestamp

public static Timestamp floatToTimestamp(float f)
Interprets a float as a unix timestamp and returns a Timestamp object

Parameters:
f -
Returns:
the equivalent Timestamp object

decimalToTimestamp

public static Timestamp decimalToTimestamp(HiveDecimal d)

doubleToTimestamp

public static Timestamp doubleToTimestamp(double f)

setTimestamp

public static void setTimestamp(Timestamp t,
                                byte[] bytes,
                                int offset)

createTimestamp

public static Timestamp createTimestamp(byte[] bytes,
                                        int offset)

hasDecimal

public final boolean hasDecimal()


Copyright © 2014 The Apache Software Foundation. All rights reserved.