Package test

Source Code of test.InfiniDBOutputDriver

package test;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.*;
import java.util.Date;
import java.util.Formatter;
import java.io.IOException;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.lib.db.*;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.*;
import org.apache.hadoop.mapreduce.lib.output.*;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.TextInputFormat;
import org.apache.hadoop.mapred.SequenceFileInputFormat;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.util.*;
import org.apache.hadoop.*;
import idb_hadoop.*;

public class InfiniDBOutputDriver extends Configured implements Tool
{
  public int run (String[] args) throws Exception
 
    Configuration conf = new Configuration();
    JobConf jobconf = new JobConf(conf, InfiniDoopDriver.class);
    DBConfiguration.configureDB(jobconf,
             "com.mysql.jdbc.Driver",
             "jdbc:mysql://srvswint4/tpch1","root", "");
    String [] fields = { "n_nationkey", "n_name" };
    String [] outFields = {"id", "name"};
    jobconf.setInputFormat(IDBFileInputFormat.class);
    jobconf.setOutputFormat(InfiniDBOutputFormat.class);
    //Class.forName(jobconf.get(DBConfiguration.DRIVER_CLASS_PROPERTY));
    //Connection connection = DriverManager.getConnection("jdbc:mysql://srvswint4/tpch1?user=root");
   
        //Job job = new Job(jobconf, "infinidb_driver");
        //jobconf.setOutputKeyClass(InfiniDoopRecord.class);
    jobconf.setOutputKeyClass(NullWritable.class);
        jobconf.setOutputValueClass(Text.class);
        //jobconf.setMapOutputKeyClass(InfiniDoopRecord.class);
        //jobconf.setMapOutputValueClass(LongWritable.class);
       
        //InfiniDBInputFormat.setInput(jobconf, InfiniDoopRecord.class, "nation",
     //      null,  "n_nationkey", fields);
        InfiniDBOutputFormat.setOutput(jobconf, "zz1", outFields);
        //InfiniDBInputFormat.setInput(jobconf, InfiniDBRecord.class, "select * from nation", "select count(*) from nation");
    Job job = new Job(jobconf);
    jobconf.set("mapred.input.dir", "output1");
    jobconf.set("mapred.output.dir", "output");
   
        jobconf.setMapperClass(InfiniDoopMapper.class);
        jobconf.setNumMapTasks(1);
        jobconf.setNumReduceTasks(2);
        JobClient client = new JobClient();
        //System.out.println(jobconf.getUser());
        //System.out.println(FileOutputFormat.getOutputPath(jobconf));
        jobconf.setInt("mapred.min.split.size", 2147483647);

        //int i = (job.waitForCompletion(true)? 1: 0);
        //return i;
        client.setConf(jobconf);
    try {
      JobClient.runJob(jobconf);
    } catch (Exception e) {
      e.printStackTrace();
    }
   
    return 0;
}
  public static void main(String [] args) throws Exception
  {
    int ret = ToolRunner.run(new InfiniDBOutputDriver(), args);
    System.exit(ret);
  }

}
TOP

Related Classes of test.InfiniDBOutputDriver

TOP
Copyright © 2018 www.massapi.com. 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.