org.apache.hadoop.hive.serde2.lazybinary
Class LazyBinaryMap

java.lang.Object
  extended by org.apache.hadoop.hive.serde2.lazy.LazyObjectBase
      extended by org.apache.hadoop.hive.serde2.lazybinary.LazyBinaryObject<OI>
          extended by org.apache.hadoop.hive.serde2.lazybinary.LazyBinaryNonPrimitive<LazyBinaryMapObjectInspector>
              extended by org.apache.hadoop.hive.serde2.lazybinary.LazyBinaryMap

public class LazyBinaryMap
extends LazyBinaryNonPrimitive<LazyBinaryMapObjectInspector>

LazyBinaryMap is serialized as follows: start A b c b c b c end bytes[] -> |--------|---|---|---|---| ... |---|---| Section A is the null-bytes. Suppose the map has N key-value pairs, then there are (N*2+7)/8 bytes used as null-bytes. Each bit corresponds to a key or a value and it indicates whether that key or value is null (0) or not null (1). After A, all the bytes are actual serialized data of the map, which are key-value pairs. b represent the keys and c represent the values. Each of them is again a LazyBinaryObject.


Field Summary
 
Fields inherited from class org.apache.hadoop.hive.serde2.lazybinary.LazyBinaryNonPrimitive
bytes, length, start
 
Constructor Summary
protected LazyBinaryMap(LazyBinaryMapObjectInspector oi)
           
 
Method Summary
protected  void adjustArraySize(int newSize)
          Adjust the size of arrays: keyStart, keyLength valueStart, valueLength keyInited, keyIsNull valueInited, valueIsNull.
 Map<Object,Object> getMap()
          Return the map object representing this LazyBinaryMap.
 int getMapSize()
          Get the size of the map represented by this LazyBinaryMap.
 Object getMapValueElement(Object key)
          Get the value in the map for the key.
 void init(ByteArrayRef bytes, int start, int length)
          Set the row data for this LazyBinaryMap.
 
Methods inherited from class org.apache.hadoop.hive.serde2.lazybinary.LazyBinaryNonPrimitive
getObject, hashCode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LazyBinaryMap

protected LazyBinaryMap(LazyBinaryMapObjectInspector oi)
Method Detail

init

public void init(ByteArrayRef bytes,
                 int start,
                 int length)
Set the row data for this LazyBinaryMap.

Overrides:
init in class LazyBinaryNonPrimitive<LazyBinaryMapObjectInspector>
Parameters:
bytes - The wrapper of the byte[].
start - The start position inside the bytes.
length - The length of the data, starting from "start"
See Also:
LazyObjectBase.init(ByteArrayRef, int, int)

adjustArraySize

protected void adjustArraySize(int newSize)
Adjust the size of arrays: keyStart, keyLength valueStart, valueLength keyInited, keyIsNull valueInited, valueIsNull.


getMapValueElement

public Object getMapValueElement(Object key)
Get the value in the map for the key. If there are multiple matches (which is possible in the serialized format), only the first one is returned. The most efficient way to get the value for the key is to serialize the key and then try to find it in the array. We do linear search because in most cases, user only wants to get one or two values out of the map, and the cost of building up a HashMap is substantially higher.

Parameters:
key - The key object that we are looking for.
Returns:
The corresponding value object, or NULL if not found

getMap

public Map<Object,Object> getMap()
Return the map object representing this LazyBinaryMap. Note that the keyObjects will be Writable primitive objects.

Returns:
the map object

getMapSize

public int getMapSize()
Get the size of the map represented by this LazyBinaryMap.

Returns:
The size of the map


Copyright © 2013 The Apache Software Foundation