Java tutorial
/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package com.avira.couchdoop.demo; import com.avira.couchdoop.imp.CouchbaseViewInputFormat; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; /** * Very simple driver for a Couchdoop import. */ public class ImportDriver extends Configured implements Tool { public static void main(String args[]) { int exitCode; try { exitCode = ToolRunner.run(new ImportDriver(), args); } catch (Exception e) { throw new RuntimeException(e); } System.exit(exitCode); } @Override public int run(String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: <output_path>"); return 1; } String output = args[0]; Job job = Job.getInstance(getConf()); job.setJarByClass(this.getClass()); // User classpath takes precedence in favor of Hadoop classpath. // This is because the Couchbase client requires a newer version of // org.apache.httpcomponents:httpcore. job.setUserClassesTakesPrecedence(true); // Input job.setInputFormatClass(CouchbaseViewInputFormat.class); // Mapper job.setMapperClass(ImportMapper.class); // Reducer job.setNumReduceTasks(0); // Output job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); FileOutputFormat.setOutputPath(job, new Path(output)); if (!job.waitForCompletion(true)) { return 2; } return 0; } }