Search in sources :

Example 1 with DBInputSplit

use of org.apache.hadoop.mapreduce.lib.db.DBInputFormat.DBInputSplit in project hadoop by apache.

the class TestDbClasses method testOracleDBRecordReader.

/**
   * test generate sql script for OracleDBRecordReader.
   */
@Test(timeout = 20000)
public void testOracleDBRecordReader() throws Exception {
    DBInputSplit splitter = new DBInputSplit(1, 10);
    Configuration configuration = new Configuration();
    Connection connect = DriverForTest.getConnection();
    DBConfiguration dbConfiguration = new DBConfiguration(configuration);
    dbConfiguration.setInputOrderBy("Order");
    String[] fields = { "f1", "f2" };
    OracleDBRecordReader<NullDBWritable> recorder = new OracleDBRecordReader<NullDBWritable>(splitter, NullDBWritable.class, configuration, connect, dbConfiguration, "condition", fields, "table");
    assertEquals("SELECT * FROM (SELECT a.*,ROWNUM dbif_rno FROM ( SELECT f1, f2 FROM table WHERE condition ORDER BY Order ) a WHERE rownum <= 10 ) WHERE dbif_rno > 1", recorder.getSelectQuery());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) NullDBWritable(org.apache.hadoop.mapreduce.lib.db.DBInputFormat.NullDBWritable) Connection(java.sql.Connection) DBInputSplit(org.apache.hadoop.mapreduce.lib.db.DBInputFormat.DBInputSplit) DataDrivenDBInputSplit(org.apache.hadoop.mapreduce.lib.db.DataDrivenDBInputFormat.DataDrivenDBInputSplit) Test(org.junit.Test)

Aggregations

Connection (java.sql.Connection)1 Configuration (org.apache.hadoop.conf.Configuration)1 DBInputSplit (org.apache.hadoop.mapreduce.lib.db.DBInputFormat.DBInputSplit)1 NullDBWritable (org.apache.hadoop.mapreduce.lib.db.DBInputFormat.NullDBWritable)1 DataDrivenDBInputSplit (org.apache.hadoop.mapreduce.lib.db.DataDrivenDBInputFormat.DataDrivenDBInputSplit)1 Test (org.junit.Test)1