Package org.apache.hadoop.io
Class MapFile.Reader
java.lang.Object
org.apache.hadoop.io.MapFile.Reader
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
ArrayFile.Reader,BloomMapFile.Reader,SetFile.Reader
- Enclosing class:
- MapFile
Provide access to an existing map.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionReader(FileSystem fs, String dirName, Configuration conf) Deprecated.Reader(FileSystem fs, String dirName, WritableComparator comparator, Configuration conf) Deprecated.Reader(Path dir, Configuration conf, SequenceFile.Reader.Option... opts) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the map.static MapFile.Reader.Optioncomparator(WritableComparator value) protected SequenceFile.ReadercreateDataFileReader(Path dataFile, Configuration conf, SequenceFile.Reader.Option... options) Override this method to specialize the type ofSequenceFile.Readerreturned.voidReads the final key from the file.get(WritableComparable key, Writable val) Return the value for the named key, or null if none exists.getClosest(WritableComparable key, Writable val) Finds the record that is the closest match to the specified key.getClosest(WritableComparable key, Writable val, boolean before) Finds the record that is the closest match to the specified key.Class<?>Returns the class of keys in this file.Class<?>Returns the class of values in this file.midKey()Get the key at approximately the middle of the file.booleannext(WritableComparable key, Writable val) Read the next key/value pair in the map intokeyandval.protected voidopen(Path dir, WritableComparator comparator, Configuration conf, SequenceFile.Reader.Option... options) voidreset()Re-positions the reader before its first key.booleanseek(WritableComparable key) Positions the reader at the named key, or if none such exists, at the first entry after the named key.
-
Constructor Details
-
Reader
- Throws:
IOException
-
Reader
Deprecated.Construct a map reader for the named map.- Parameters:
fs- FileSystem.dirName- dirName.conf- configuration.- Throws:
IOException- raised on errors performing I/O.
-
Reader
@Deprecated public Reader(FileSystem fs, String dirName, WritableComparator comparator, Configuration conf) throws IOException Deprecated.Construct a map reader for the named map using the named comparator.- Parameters:
fs- FileSystem.dirName- dirName.comparator- WritableComparator.conf- Configuration.- Throws:
IOException- raised on errors performing I/O.
-
-
Method Details
-
getKeyClass
Returns the class of keys in this file.- Returns:
- keyClass.
-
getValueClass
Returns the class of values in this file.- Returns:
- Value Class.
-
comparator
-
open
protected void open(Path dir, WritableComparator comparator, Configuration conf, SequenceFile.Reader.Option... options) throws IOException - Throws:
IOException
-
createDataFileReader
protected SequenceFile.Reader createDataFileReader(Path dataFile, Configuration conf, SequenceFile.Reader.Option... options) throws IOException Override this method to specialize the type ofSequenceFile.Readerreturned.- Parameters:
dataFile- data file.conf- configuration.options- options.- Returns:
- SequenceFile.Reader.
- Throws:
IOException- raised on errors performing I/O.
-
reset
Re-positions the reader before its first key.- Throws:
IOException- raised on errors performing I/O.
-
midKey
Get the key at approximately the middle of the file. Or null if the file is empty.- Returns:
- WritableComparable.
- Throws:
IOException- raised on errors performing I/O.
-
finalKey
Reads the final key from the file.- Parameters:
key- key to read into- Throws:
IOException- raised on errors performing I/O.
-
seek
Positions the reader at the named key, or if none such exists, at the first entry after the named key. Returns true iff the named key exists in this map.- Parameters:
key- key.- Returns:
- if the named key exists in this map true, not false.
- Throws:
IOException- raised on errors performing I/O.
-
next
Read the next key/value pair in the map intokeyandval. Returns true if such a pair exists and false when at the end of the map.- Parameters:
key- WritableComparable.val- Writable.- Returns:
- if such a pair exists true,not false.
- Throws:
IOException- raised on errors performing I/O.
-
get
Return the value for the named key, or null if none exists.- Parameters:
key- key.val- val.- Returns:
- Writable if such a pair exists true,not false.
- Throws:
IOException- raised on errors performing I/O.
-
getClosest
Finds the record that is the closest match to the specified key. Returnskeyor if it does not exist, at the first entry after the named key.- Parameters:
key- key that we're trying to find.val- data value if key is found.- Returns:
- the key that was the closest match or null if eof.
- Throws:
IOException- raised on errors performing I/O.
-
getClosest
public WritableComparable getClosest(WritableComparable key, Writable val, boolean before) throws IOException Finds the record that is the closest match to the specified key.- Parameters:
key- - key that we're trying to findval- - data value if key is foundbefore- - IF true, andkeydoes not exist, return the first entry that falls just before thekey. Otherwise, return the record that sorts just after.- Returns:
- - the key that was the closest match or null if eof.
- Throws:
IOException- raised on errors performing I/O.
-
close
Close the map.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- raised on errors performing I/O.
-