public Job getJob() throws IOException { Configuration conf = getConf(); Job job = new Job(conf); conf = job.getConfiguration(); conf.set("mapreduce.job.tracker", "local"); job.setJobName("vertica test"); job.setOutputKeyClass(Text.class); job.setOutputValueClass(VerticaRecord.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(DoubleWritable.class); job.setInputFormatClass(VerticaInputFormat.class); job.setOutputFormatClass(VerticaOutputFormat.class); job.setJarByClass(VerticaExample.class); job.setMapperClass(Map.class); job.setReducerClass(Reduce.class); VerticaOutputFormat.setOutput( job, "mrtarget", true, "a int", "b boolean", "c char(1)", "d date", "f float", "t timestamp", "v varchar", "z varbinary"); return job; }
@SuppressWarnings("serial") @Override public int run(String[] args) throws Exception { Job job = getJob(); VerticaOutputFormat.setOutput( job, "mrtarget", true, "a int", "b boolean", "c char(1)", "d date", "f float", "t timestamp", "v varchar", "z varbinary"); VerticaInputFormat.setInput( job, "select * from allTypes where key = ?", "select distinct key from allTypes"); job.waitForCompletion(true); job = getJob(); Collection<List<Object>> params = new HashSet<List<Object>>() {}; List<Object> param = new ArrayList<Object>(); param.add(new Integer(0)); params.add(param); VerticaInputFormat.setInput(job, "select * from allTypes where key = ?", params); job.waitForCompletion(true); job = getJob(); VerticaInputFormat.setInput(job, "select * from allTypes where key = ?", "0", "1", "2"); job.waitForCompletion(true); return 0; }