Example usage for org.apache.hadoop.mapreduce.lib.db MySQLDataDrivenDBRecordReader MySQLDataDrivenDBRecordReader

List of usage examples for org.apache.hadoop.mapreduce.lib.db MySQLDataDrivenDBRecordReader MySQLDataDrivenDBRecordReader

Introduction

In this page you can find the example usage for org.apache.hadoop.mapreduce.lib.db MySQLDataDrivenDBRecordReader MySQLDataDrivenDBRecordReader.

Prototype

public MySQLDataDrivenDBRecordReader(DBInputFormat.DBInputSplit split, Class<T> inputClass, Configuration conf,
            Connection conn, DBConfiguration dbConfig, String cond, String[] fields, String table)
            throws SQLException 

Source Link

Usage

From source file:co.nubetech.apache.hadoop.mapred.DataDrivenDBInputFormat.java

License:Apache License

protected RecordReader<LongWritable, T> createDBRecordReader(
        org.apache.hadoop.mapreduce.lib.db.DBInputFormat.DBInputSplit split, Configuration conf)
        throws IOException {

    org.apache.hadoop.mapreduce.lib.db.DBConfiguration dbConf = getDBConf();
    @SuppressWarnings("unchecked")
    Class<T> inputClass = (Class<T>) (dbConf.getInputClass());
    String dbProductName = getDBProductName();

    LOG.debug("Creating db record reader for db product: " + dbProductName);

    try {//from   w  ww  .  j ava2  s. c o  m
        // use database product name to determine appropriate record reader.
        if (dbProductName.startsWith("MYSQL")) {
            // use MySQL-specific db reader.
            return new MySQLDataDrivenDBRecordReader<T>(split, inputClass, conf, getConnection(), dbConf,
                    dbConf.getInputConditions(), dbConf.getInputFieldNames(), dbConf.getInputTableName());
        } else {
            // Generic reader.
            return new DataDrivenDBRecordReader<T>(split, inputClass, conf, getConnection(), dbConf,
                    dbConf.getInputConditions(), dbConf.getInputFieldNames(), dbConf.getInputTableName(),
                    dbProductName);
        }
    } catch (SQLException ex) {
        throw new IOException(ex.getMessage());
    }
}