복붙노트

[HADOOP] HADOOP - 1.2.1 Stable의 단어 수 계산 예

HADOOP

HADOOP - 1.2.1 Stable의 단어 수 계산 예

hadoop 1.2.1의 단어 수를 계산하고 있습니다. 그러나 무언가가 변했을 것입니다. 왜냐하면 나는 그것을 작동시키지 않는 것 같기 때문입니다.

다음은 Reduce 클래스입니다.

public static class Reduce extends Reducer<WritableComparable, Writable, WritableComparable, Writable> {

    public void reduce(WritableComparable key,
                       Iterator<Writable> values,
                       OutputCollector<WritableComparable, NullWritable> output,
                       Reporter reporter) throws IOException {

        output.collect(key, NullWritable.get());

    }

}

그리고 내 주요 기능 :

public static void main(String[] args) throws Exception {

    JobConf jobConf = new JobConf(MapDemo.class);

    jobConf.setNumMapTasks(10);
    jobConf.setNumReduceTasks(1);

    jobConf.setJobName("MapDemo");

    jobConf.setOutputKeyClass(Text.class);
    jobConf.setOutputValueClass(NullWritable.class);

    jobConf.setMapperClass(Map.class);
    jobConf.setReducerClass(Reduce.class);

    jobConf.setInputFormat(TextInputFormat.class);
    jobConf.setOutputFormat(TextOutputFormat.class);

    FileInputFormat.setInputPaths(jobConf, new Path(args[0]));
    FileOutputFormat.setOutputPath(jobConf, new Path(args[1]));

    JobClient.runJob(jobConf);
}

내 IDE에서 Maven에 의해 뒷받침되는 오류가 있음을 알립니다.

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] com/example/mapreduce/MapDemo.java:[71,16] method setReducerClass in class org.apache.hadoop.mapred.JobConf cannot be applied to given types;
required: java.lang.Class<? extends org.apache.hadoop.mapred.Reducer>
found: java.lang.Class<com.example.mapreduce.MapDemo.Reduce>
reason: actual argument java.lang.Class<com.example.mapreduce.MapDemo.Reduce> cannot be converted to java.lang.Class<? extends org.apache.hadoop.mapred.Reducer> by method invocation conversion
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.679s
[INFO] Finished at: Mon Sep 16 09:23:08 PDT 2013
[INFO] Final Memory: 17M/202M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project inventory: Compilation failure
[ERROR] com/example/mapreduce/MapDemo.java:[71,16] method setReducerClass in class org.apache.hadoop.mapred.JobConf cannot be applied to given types;
[ERROR] required: java.lang.Class<? extends org.apache.hadoop.mapred.Reducer>
[ERROR] found: java.lang.Class<com.example.mapreduce.MapDemo.Reduce>

나는 단어 수를 예를 들어 온라인으로 1.2.1에 대해 구식이라고 믿는다. 이 문제를 어떻게 해결할 수 있습니까? 누구든지 작동하는 1.2.1 단어 개수의 자바 소스에 대한 링크가 있습니까?

해결법

  1. ==============================

    1.어떤 링크를 따라 왔습니까? 나는 이런 종류의 화장실을 본 적이 없다. 그러나 오래된 API를 사용하고 있기 때문에 당신이 따라온 것은 무엇이든 오래되었습니다. 그리고 네가 제대로 따라 왔는지 의심 스럽다.

    어떤 링크를 따라 왔습니까? 나는 이런 종류의 화장실을 본 적이 없다. 그러나 오래된 API를 사용하고 있기 때문에 당신이 따라온 것은 무엇이든 오래되었습니다. 그리고 네가 제대로 따라 왔는지 의심 스럽다.

    이것은 작동해야합니다 :

    public class WordCount {
        /**
         * The map class of WordCount.
         */
        public static class TokenCounterMapper extends
                Mapper<Object, Text, Text, IntWritable> {
    
            private final static IntWritable one = new IntWritable(1);
            private Text word = new Text();
    
            public void map(Object key, Text value, Context context)
                    throws IOException, InterruptedException {              
    
                StringTokenizer itr = new StringTokenizer(value.toString());
                while (itr.hasMoreTokens()) {
                    word.set(itr.nextToken());
                    context.write(word, one);
                }
            }
        }
    
        /**
         * The reducer class of WordCount
         */
        public static class TokenCounterReducer extends
                Reducer<Text, IntWritable, Text, IntWritable> {
            public void reduce(Text key, Iterable<IntWritable> values,
                    Context context) throws IOException, InterruptedException {
                int sum = 0;
                for (IntWritable value : values) {
                    sum += value.get();
                }
                context.write(key, new IntWritable(sum));
            }
        }
    
        /**
         * The main entry point.
         */
        public static void main(String[] args) throws Exception {
            Configuration conf = new Configuration();
            conf.addResource(new Path("/Users/miqbal1/hadoop-eco/hadoop-1.1.2/conf/core-site.xml"));
            conf.addResource(new Path("/Users/miqbal1/hadoop-eco/hadoop-1.1.2/conf/hdfs-site.xml"));
            conf.set("fs.default.name", "hdfs://localhost:9000");
            conf.set("mapred.job.tracker", "localhost:9001");
            Job job = new Job(conf, "WordCount");
            job.setJarByClass(WordCount.class);
            job.setMapperClass(TokenCounterMapper.class);
            job.setReducerClass(TokenCounterReducer.class);
            job.setNumReduceTasks(2);
            job.setOutputKeyClass(Text.class);
            job.setOutputValueClass(IntWritable.class);
            FileInputFormat.addInputPath(job, new Path("/inputs/demo.txt"));
            FileOutputFormat.setOutputPath(job, new Path("/outputs/1111223"));
            System.exit(job.waitForCompletion(true) ? 0 : 1);
        }
    }
    

    몇 가지 관찰 결과 :

  2. ==============================

    2.이 라인은 Hadoop의 mapred 및 mapreduce API 버전을 믹싱 할 것을 제안합니다.

    이 라인은 Hadoop의 mapred 및 mapreduce API 버전을 믹싱 할 것을 제안합니다.

    actual argument java.lang.Class<com.example.mapreduce.MapDemo.Reduce> cannot be converted to java.lang.Class<? extends org.apache.hadoop.mapred.Reducer> by method invocation conversion
    

    mapred 또는 mapreduce API를 사용하십시오.

  3. from https://stackoverflow.com/questions/18832949/hadoop-word-count-example-for-1-2-1-stable by cc-by-sa and MIT license