org.apache.hadoop.hbase.mapreduce
Class TableRecordReader

java.lang.Object
  extended by org.apache.hadoop.mapreduce.RecordReader<ImmutableBytesWritable,Result>
      extended by org.apache.hadoop.hbase.mapreduce.TableRecordReader
All Implemented Interfaces:
Closeable

public class TableRecordReader
extends org.apache.hadoop.mapreduce.RecordReader<ImmutableBytesWritable,Result>

Iterate over an HBase table data, return (ImmutableBytesWritable, Result) pairs.


Constructor Summary
TableRecordReader()
           
 
Method Summary
 void close()
          Closes the split.
 ImmutableBytesWritable getCurrentKey()
          Returns the current key.
 Result getCurrentValue()
          Returns the current value.
 float getProgress()
          The current progress of the record reader through its data.
 void init()
          Build the scanner.
 void initialize(org.apache.hadoop.mapreduce.InputSplit inputsplit, org.apache.hadoop.mapreduce.TaskAttemptContext context)
          Initializes the reader.
 boolean nextKeyValue()
          Positions the record reader to the next record.
 void restart(byte[] firstRow)
          Restart from survivable exceptions by creating a new scanner.
 void setHTable(HTable htable)
          Sets the HBase table.
 void setScan(Scan scan)
          Sets the scan defining the actual details like columns etc.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableRecordReader

public TableRecordReader()
Method Detail

restart

public void restart(byte[] firstRow)
             throws IOException
Restart from survivable exceptions by creating a new scanner.

Parameters:
firstRow - The first row to start at.
Throws:
IOException - When restarting fails.

init

public void init()
          throws IOException
Build the scanner. Not done in constructor to allow for extension.

Throws:
IOException - When restarting the scan fails.

setHTable

public void setHTable(HTable htable)
Sets the HBase table.

Parameters:
htable - The HTable to scan.

setScan

public void setScan(Scan scan)
Sets the scan defining the actual details like columns etc.

Parameters:
scan - The scan to set.

close

public void close()
Closes the split.

Specified by:
close in interface Closeable
Specified by:
close in class org.apache.hadoop.mapreduce.RecordReader<ImmutableBytesWritable,Result>
See Also:
RecordReader.close()

getCurrentKey

public ImmutableBytesWritable getCurrentKey()
                                     throws IOException,
                                            InterruptedException
Returns the current key.

Specified by:
getCurrentKey in class org.apache.hadoop.mapreduce.RecordReader<ImmutableBytesWritable,Result>
Returns:
The current key.
Throws:
IOException
InterruptedException - When the job is aborted.
See Also:
RecordReader.getCurrentKey()

getCurrentValue

public Result getCurrentValue()
                       throws IOException,
                              InterruptedException
Returns the current value.

Specified by:
getCurrentValue in class org.apache.hadoop.mapreduce.RecordReader<ImmutableBytesWritable,Result>
Returns:
The current value.
Throws:
IOException - When the value is faulty.
InterruptedException - When the job is aborted.
See Also:
RecordReader.getCurrentValue()

initialize

public void initialize(org.apache.hadoop.mapreduce.InputSplit inputsplit,
                       org.apache.hadoop.mapreduce.TaskAttemptContext context)
                throws IOException,
                       InterruptedException
Initializes the reader.

Specified by:
initialize in class org.apache.hadoop.mapreduce.RecordReader<ImmutableBytesWritable,Result>
Parameters:
inputsplit - The split to work with.
context - The current task context.
Throws:
IOException - When setting up the reader fails.
InterruptedException - When the job is aborted.
See Also:
RecordReader.initialize( org.apache.hadoop.mapreduce.InputSplit, org.apache.hadoop.mapreduce.TaskAttemptContext)

nextKeyValue

public boolean nextKeyValue()
                     throws IOException,
                            InterruptedException
Positions the record reader to the next record.

Specified by:
nextKeyValue in class org.apache.hadoop.mapreduce.RecordReader<ImmutableBytesWritable,Result>
Returns:
true if there was another record.
Throws:
IOException - When reading the record failed.
InterruptedException - When the job was aborted.
See Also:
RecordReader.nextKeyValue()

getProgress

public float getProgress()
The current progress of the record reader through its data.

Specified by:
getProgress in class org.apache.hadoop.mapreduce.RecordReader<ImmutableBytesWritable,Result>
Returns:
A number between 0.0 and 1.0, the fraction of the data read.
See Also:
RecordReader.getProgress()


Copyright © 2011 The Apache Software Foundation. All Rights Reserved.