Class DBRecordReader<T extends DBWritable>
java.lang.Object
org.apache.hadoop.mapreduce.RecordReader<LongWritable,T>
org.apache.hadoop.mapreduce.lib.db.DBRecordReader<T>
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
DataDrivenDBRecordReader,MySQLDBRecordReader,OracleDBRecordReader
@Public
@Evolving
public class DBRecordReader<T extends DBWritable>
extends RecordReader<LongWritable,T>
A RecordReader that reads records from a SQL table.
Emits LongWritables containing the record number as
key and DBWritables as value.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDBRecordReader(org.apache.hadoop.mapreduce.lib.db.DBInputFormat.DBInputSplit split, Class<T> inputClass, Configuration conf, Connection conn, DBConfiguration dbConfig, String cond, String[] fields, String table) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the record reader.Deprecated.protected ResultSetexecuteQuery(String query) protected Stringprotected ConnectionGet the current keyGet the current value.protected DBConfigurationprotected String[]longgetPos()Deprecated.floatThe current progress of the record reader through its data.protected StringReturns the query for selecting the records, subclasses can override this for custom behaviour.protected org.apache.hadoop.mapreduce.lib.db.DBInputFormat.DBInputSplitgetSplit()protected PreparedStatementprotected Stringvoidinitialize(InputSplit split, TaskAttemptContext context) Called once at initialization.booleannext(LongWritable key, T value) Deprecated.booleanRead the next key, value pair.protected void
-
Field Details
-
statement
-
-
Constructor Details
-
DBRecordReader
public DBRecordReader(org.apache.hadoop.mapreduce.lib.db.DBInputFormat.DBInputSplit split, Class<T> inputClass, Configuration conf, Connection conn, DBConfiguration dbConfig, String cond, String[] fields, String table) throws SQLException - Parameters:
split- The InputSplit to read data for- Throws:
SQLException
-
-
Method Details
-
executeQuery
- Throws:
SQLException
-
getSelectQuery
Returns the query for selecting the records, subclasses can override this for custom behaviour. -
close
Close the record reader.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classRecordReader<LongWritable,T extends DBWritable> - Throws:
IOException
-
initialize
public void initialize(InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException Description copied from class:RecordReaderCalled once at initialization.- Specified by:
initializein classRecordReader<LongWritable,T extends DBWritable> - Parameters:
split- the split that defines the range of records to readcontext- the information about the task- Throws:
IOExceptionInterruptedException
-
getCurrentKey
Get the current key- Specified by:
getCurrentKeyin classRecordReader<LongWritable,T extends DBWritable> - Returns:
- the current key or null if there is no current key
-
getCurrentValue
Get the current value.- Specified by:
getCurrentValuein classRecordReader<LongWritable,T extends DBWritable> - Returns:
- the object that was read
-
createValue
Deprecated. -
getPos
Deprecated.- Throws:
IOException
-
next
Deprecated.UsenextKeyValue()- Throws:
IOException
-
getProgress
The current progress of the record reader through its data.- Specified by:
getProgressin classRecordReader<LongWritable,T extends DBWritable> - Returns:
- a number between 0.0 and 1.0 that is the fraction of the data read
- Throws:
IOException
-
nextKeyValue
Read the next key, value pair.- Specified by:
nextKeyValuein classRecordReader<LongWritable,T extends DBWritable> - Returns:
- true if a key/value pair was read
- Throws:
IOException
-
getSplit
protected org.apache.hadoop.mapreduce.lib.db.DBInputFormat.DBInputSplit getSplit() -
getFieldNames
-
getTableName
-
getConditions
-
getDBConf
-
getConnection
-
getStatement
-
setStatement
-
nextKeyValue()