Package co.nubetech.hiho.mapreduce.lib.db.apache

Examples of co.nubetech.hiho.mapreduce.lib.db.apache.DBConfiguration


  @SuppressWarnings("unchecked")
  public static String getSelectQuery(Configuration conf, String dbProductName)
      throws HIHOException {

    StringBuilder query = new StringBuilder();
    DBConfiguration dbConf = new DBConfiguration(conf);
    String[] fieldNames = dbConf.getInputFieldNames();
    String tableName = dbConf.getInputTableName();
    String conditions = dbConf.getInputConditions();
    StringBuilder conditionClauses = new StringBuilder();

    if (dbConf.getInputQuery() == null) {
      // We need to generate the entire query.
      query.append("SELECT ");

      for (int i = 0; i < fieldNames.length; i++) {
        query.append(fieldNames[i]);
        if (i != fieldNames.length - 1) {
          query.append(", ");
        }
      }

      query.append(" FROM ").append(tableName);
      if (!dbProductName.startsWith("ORACLE")) {
        // Seems to be necessary for hsqldb? Oracle explicitly does
        // *not*
        // use this clause.
        query.append(" AS ").append(tableName);
      }

    } else {
      // User provided the query. We replace the special token with our
      // WHERE clause.
      String inputQuery = dbConf.getInputQuery();
      if (inputQuery.indexOf(DataDrivenDBInputFormat.SUBSTITUTE_TOKEN) == -1) {
        logger.error("Could not find the clause substitution token "
            + DataDrivenDBInputFormat.SUBSTITUTE_TOKEN
            + " in the query: [" + inputQuery
            + "]. Parallel splits may not work correctly.");
View Full Code Here


  @Override
  protected RecordReader<LongWritable, GenericDBWritable> createDBRecordReader(
      DBInputSplit split, Configuration conf) throws IOException {

    DBConfiguration dbConf = getDBConf();
    @SuppressWarnings("unchecked")
    // Class<T> inputClass = (Class<T>) (dbConf.getInputClass());
    String dbProductName = getDBProductName();

    logger.debug("Creating db record reader for db product: "
        + dbProductName);
    ArrayList params = null;
    try {
      if (conf.get(HIHOConf.QUERY_PARAMS) != null) {
        logger.debug("creating stringifier in DBQueryInputFormat");
        DefaultStringifier<ArrayList> stringifier = new DefaultStringifier<ArrayList>(
            conf, ArrayList.class);
        logger.debug("created stringifier");

        params = stringifier
            .fromString(conf.get(HIHOConf.QUERY_PARAMS));
        logger.debug("created params");
      }
      // use database product name to determine appropriate record reader.
      if (dbProductName.startsWith("MYSQL")) {
        // use MySQL-specific db reader.
        return new MySQLQueryRecordReader(split, conf, getConnection(),
            dbConf, dbConf.getInputConditions(),
            dbConf.getInputFieldNames(),
            dbConf.getInputTableName(), params);
      } else {
        // Generic reader.
        return new DBQueryRecordReader(split, conf, getConnection(),
            dbConf, dbConf.getInputConditions(),
            dbConf.getInputFieldNames(),
            dbConf.getInputTableName(), dbProductName, params);
      }
    } catch (SQLException ex) {
      throw new IOException(ex.getMessage());
    }
  }
View Full Code Here

  }

  public static void setOutput(Job job, String tableName, String columnNames)
      throws IOException{
    job.setOutputFormatClass(GenericDBOutputFormat.class);
    DBConfiguration dbConf = new DBConfiguration(job.getConfiguration());
    dbConf.setOutputTableName(tableName);
    dbConf.setOutputFieldNames(columnNames);

    String dbDriver = job.getConfiguration().get(
        DBConfiguration.DRIVER_CLASS_PROPERTY);
    String connString = job.getConfiguration().get(
        DBConfiguration.URL_PROPERTY);
View Full Code Here

TOP

Related Classes of co.nubetech.hiho.mapreduce.lib.db.apache.DBConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.