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

public static class MapFile.Reader extends Object implements Closeable
Provide access to an existing map.
  • Constructor Details

  • Method Details

    • getKeyClass

      public Class<?> getKeyClass()
      Returns the class of keys in this file.
      Returns:
      keyClass.
    • getValueClass

      public Class<?> getValueClass()
      Returns the class of values in this file.
      Returns:
      Value Class.
    • comparator

      public static MapFile.Reader.Option comparator(WritableComparator value)
    • 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 of SequenceFile.Reader returned.
      Parameters:
      dataFile - data file.
      conf - configuration.
      options - options.
      Returns:
      SequenceFile.Reader.
      Throws:
      IOException - raised on errors performing I/O.
    • reset

      public void reset() throws IOException
      Re-positions the reader before its first key.
      Throws:
      IOException - raised on errors performing I/O.
    • midKey

      public WritableComparable midKey() throws IOException
      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

      public void finalKey(WritableComparable key) throws IOException
      Reads the final key from the file.
      Parameters:
      key - key to read into
      Throws:
      IOException - raised on errors performing I/O.
    • seek

      public boolean seek(WritableComparable key) throws IOException
      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

      public boolean next(WritableComparable key, Writable val) throws IOException
      Read the next key/value pair in the map into key and val. 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

      public Writable get(WritableComparable key, Writable val) throws IOException
      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

      public WritableComparable getClosest(WritableComparable key, Writable val) throws IOException
      Finds the record that is the closest match to the specified key. Returns key or 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 find
      val - - data value if key is found
      before - - IF true, and key does not exist, return the first entry that falls just before the key. 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

      public void close() throws IOException
      Close the map.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - raised on errors performing I/O.