Class SortedKeyValueFile.Reader<K,V>

java.lang.Object
org.apache.avro.hadoop.file.SortedKeyValueFile.Reader<K,V>
Type Parameters:
K - The key type.
V - The value type.
All Implemented Interfaces:
Closeable, AutoCloseable, 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.

  • Constructor Details

  • Method Details

    • 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<K>
      Returns:
      An iterator.
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException