Package org.apache.avro.hadoop.file
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A class to encapsulate the options of a Reader. -
Constructor Summary
-
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Reader
Constructs a reader.- Parameters:
options
- The options.- Throws:
IOException
- If there is an error.
-
-
Method Details
-
get
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
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.
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-