org.apache.hadoop.hive.ql.exec.persistence
Class HashMapWrapper<K,V>

java.lang.Object
  extended by org.apache.hadoop.hive.ql.exec.persistence.HashMapWrapper<K,V>

public class HashMapWrapper<K,V>
extends Object

Simple wrapper for persistent Hashmap implementing only the put/get/remove/clear interface. The main memory hash table acts as a cache and all put/get will operate on it first. If the size of the main memory hash table exceeds a certain threshold, new elements will go into the persistent hash table.


Field Summary
protected  org.apache.commons.logging.Log LOG
           
 
Constructor Summary
HashMapWrapper()
           
HashMapWrapper(int threshold)
          Constructor.
 
Method Summary
 int cacheSize()
          Get the main memory cache capacity.
 void clear()
          Clean up the hash table.
 void close()
          Close the persistent hash table and clean it up.
 V get(K key)
          Get the value based on the key.
 Set<K> keySet()
          Get a list of all keys in the hash map.
 void put(K key, V value)
          Put the key value pair in the hash table.
 void remove(Object key)
          Remove one key-value pairs from the hash table based on the given key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected org.apache.commons.logging.Log LOG
Constructor Detail

HashMapWrapper

public HashMapWrapper(int threshold)
Constructor.

Parameters:
threshold - User specified threshold to store new values into persistent storage.

HashMapWrapper

public HashMapWrapper()
Method Detail

get

public V get(K key)
      throws HiveException
Get the value based on the key. We try to get it from the main memory hash table first. If it is not there we will look up the persistent hash table. This function also guarantees if any item is found given a key, it is available in main memory HashMap. So mutating the returned value will be reflected (saved) in HashMapWrapper.

Parameters:
key -
Returns:
Value corresponding to the key. If the key is not found, return null.
Throws:
HiveException

put

public void put(K key,
                V value)
         throws HiveException
Put the key value pair in the hash table. It will first try to put it into the main memory hash table. If the size exceeds the threshold, it will put it into the persistent hash table.

Parameters:
key -
value -
Throws:
HiveException

clear

public void clear()
           throws HiveException
Clean up the hash table. All elements in the main memory hash table will be removed, and the persistent hash table will be destroyed (temporary file will be deleted).

Throws:
HiveException

remove

public void remove(Object key)
            throws HiveException
Remove one key-value pairs from the hash table based on the given key. If the pairs are removed from the main memory hash table, pairs in the persistent hash table will not be moved to the main memory hash table. Future inserted elements will go into the main memory hash table though.

Parameters:
key -
Throws:
HiveException

keySet

public Set<K> keySet()
Get a list of all keys in the hash map.

Returns:

cacheSize

public int cacheSize()
Get the main memory cache capacity.

Returns:
the maximum number of items can be put into main memory HashMap cache.

close

public void close()
           throws HiveException
Close the persistent hash table and clean it up.

Throws:
HiveException


Copyright © 2010 The Apache Software Foundation