心心失意 发表于 2018-10-31 06:26:18

Hadoop的word co-occurrence实现

package wco;  

  
import org.apache.hadoop.fs.Path;
  
import org.apache.hadoop.io.IntWritable;
  
import org.apache.hadoop.io.Text;
  
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  
import org.apache.hadoop.mapreduce.Job;
  

  
import org.apache.hadoop.conf.Configured;
  
import org.apache.hadoop.conf.Configuration;
  
import org.apache.hadoop.util.Tool;
  
import org.apache.hadoop.util.ToolRunner;
  

  
public class WCo extends Configured implements Tool {
  

  
@Override
  
public int run(String[] args) throws Exception {
  

  
    if (args.length != 2) {
  
      System.out.printf("Usage: hadoop jar wco.WCo\n");
  
      return -1;
  
    }
  

  
    Job job = new Job(getConf());
  
    job.setJarByClass(WCo.class);
  
    job.setJobName("Word Co Occurrence");
  

  
    FileInputFormat.setInputPaths(job, new Path(args));
  
    FileOutputFormat.setOutputPath(job, new Path(args));
  

  
    job.setMapperClass(WCoMapper.class);
  
    job.setReducerClass(WCoReducer.class);
  

  
    job.setOutputKeyClass(Text.class);
  
    job.setOutputValueClass(IntWritable.class);
  

  
    boolean success = job.waitForCompletion(true);
  
    return success ? 0 : 1;
  
}
  

  
public static void main(String[] args) throws Exception {
  
    int exitCode = ToolRunner.run(new Configuration(), new WCo(), args);
  
    System.exit(exitCode);
  
}
  
}


页: [1]
查看完整版本: Hadoop的word co-occurrence实现