org.apache.avro.hadoop.file
Class SortedKeyValueFile.Reader<K,V>

java.lang.Object
  extended by org.apache.avro.hadoop.file.SortedKeyValueFile.Reader<K,V>
Type Parameters:
K - The key type.
V - The value type.
All Implemented Interfaces:
Closeable, Iterable<AvroKeyValue<K,V>>
Enclosing class:
SortedKeyValueFile

public static class SortedKeyValueFile.Reader<K,V>
extends Object
implements Closeable, Iterable<AvroKeyValue<K,V>>

Reads a SortedKeyValueFile by loading the key index into memory.

When doing a lookup, this reader finds the correct block in the data file using the key index. It performs a single disk seek to the block and loads the entire block into memory. The block is scanned until the key is found or is determined not to exist.


Nested Class Summary
static class SortedKeyValueFile.Reader.Options
          A class to encapsulate the options of a Reader.
 
Constructor Summary
SortedKeyValueFile.Reader(SortedKeyValueFile.Reader.Options options)
          Constructs a reader.
 
Method Summary
 void close()
          
 V get(K key)
          Gets the first value associated with a given key, or null if it is not found.
 Iterator<AvroKeyValue<K,V>> iterator()
          Returns an iterator starting at the current position in the file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SortedKeyValueFile.Reader

public SortedKeyValueFile.Reader(SortedKeyValueFile.Reader.Options options)
                          throws IOException
Constructs a reader.

Parameters:
options - The options.
Throws:
IOException - If there is an error.
Method Detail

get

public V get(K key)
      throws IOException
Gets the first value associated with a given key, or null if it is not found.

This method will move the current position in the file to the record immediately following the requested key.

Parameters:
key - The key to look up.
Returns:
The value associated with the key, or null if not found.
Throws:
IOException - If there is an error.

iterator

public Iterator<AvroKeyValue<K,V>> iterator()
Returns an iterator starting at the current position in the file.

Use the get() method to move the current position.

Note that this iterator is shared with other clients of the file; it does not contain a separate pointer into the file.

Specified by:
iterator in interface Iterable<AvroKeyValue<K,V>>
Returns:
An iterator.

close

public void close()
           throws IOException

Specified by:
close in interface Closeable
Throws:
IOException


Copyright © 2009-2013 The Apache Software Foundation. All Rights Reserved.