List of usage examples for org.apache.hadoop.mapreduce.lib.db DBConfiguration getInputOrderBy
public String getInputOrderBy()
From source file:net.mooncloud.mapreduce.lib.db.OracleDBRecordReader.java
License:Apache License
/** Returns the query for selecting the records from an Oracle DB. */ protected String getSelectQuery() { StringBuilder query = new StringBuilder(); DBConfiguration dbConf = getDBConf(); String conditions = getConditions(); String tableName = getTableName(); String[] fieldNames = getFieldNames(); // Oracle-specific codepath to use rownum instead of LIMIT/OFFSET. if (dbConf.getInputQuery() == null) { query.append("SELECT "); for (int i = 0; i < fieldNames.length; i++) { query.append(fieldNames[i]); if (i != fieldNames.length - 1) { query.append(", "); }// w ww .j a va 2 s. c om } query.append(" FROM ").append(tableName); if (conditions != null && conditions.length() > 0) query.append(" WHERE ").append(conditions); String orderBy = dbConf.getInputOrderBy(); if (orderBy != null && orderBy.length() > 0) { query.append(" ORDER BY ").append(orderBy); } } else { // PREBUILT QUERY query.append(dbConf.getInputQuery()); } try { DBInputFormat.DBInputSplit split = getSplit(); if (split.getLength() > 0 && split.getStart() > 0) { String querystring = query.toString(); query = new StringBuilder(); query.append("SELECT * FROM (SELECT a.*,ROWNUM dbif_rno FROM ( "); query.append(querystring); query.append(" ) a WHERE rownum <= ").append(split.getStart()); query.append(" + ").append(split.getLength()); query.append(" ) WHERE dbif_rno >= ").append(split.getStart()); } } catch (IOException ex) { // ignore, will not throw. } return query.toString(); }