<bdo id='1vYKd'></bdo><ul id='1vYKd'></ul>

    <small id='1vYKd'></small><noframes id='1vYKd'>

        <tfoot id='1vYKd'></tfoot>
        <i id='1vYKd'><tr id='1vYKd'><dt id='1vYKd'><q id='1vYKd'><span id='1vYKd'><b id='1vYKd'><form id='1vYKd'><ins id='1vYKd'></ins><ul id='1vYKd'></ul><sub id='1vYKd'></sub></form><legend id='1vYKd'></legend><bdo id='1vYKd'><pre id='1vYKd'><center id='1vYKd'></center></pre></bdo></b><th id='1vYKd'></th></span></q></dt></tr></i><div id='1vYKd'><tfoot id='1vYKd'></tfoot><dl id='1vYKd'><fieldset id='1vYKd'></fieldset></dl></div>
      1. <legend id='1vYKd'><style id='1vYKd'><dir id='1vYKd'><q id='1vYKd'></q></dir></style></legend>

        映射中键的类型不匹配:预期 org.apache.hadoop.io.Te

        时间:2023-09-26

              <bdo id='eNAHR'></bdo><ul id='eNAHR'></ul>
            • <legend id='eNAHR'><style id='eNAHR'><dir id='eNAHR'><q id='eNAHR'></q></dir></style></legend>
              <i id='eNAHR'><tr id='eNAHR'><dt id='eNAHR'><q id='eNAHR'><span id='eNAHR'><b id='eNAHR'><form id='eNAHR'><ins id='eNAHR'></ins><ul id='eNAHR'></ul><sub id='eNAHR'></sub></form><legend id='eNAHR'></legend><bdo id='eNAHR'><pre id='eNAHR'><center id='eNAHR'></center></pre></bdo></b><th id='eNAHR'></th></span></q></dt></tr></i><div id='eNAHR'><tfoot id='eNAHR'></tfoot><dl id='eNAHR'><fieldset id='eNAHR'></fieldset></dl></div>
            • <tfoot id='eNAHR'></tfoot>

                <tbody id='eNAHR'></tbody>

              1. <small id='eNAHR'></small><noframes id='eNAHR'>

                  本文介绍了映射中键的类型不匹配:预期 org.apache.hadoop.io.Text,收到 org.apache.hadoop.io.LongWritable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试在 java 中运行 map/reducer.以下是我的文件

                  I am trying to run a map/reducer in java. Below are my files

                  WordCount.java

                  WordCount.java

                  package counter;
                  
                  
                  public class WordCount extends Configured implements Tool {
                  
                  public int run(String[] arg0) throws Exception {
                      Configuration conf = new Configuration();
                  
                      Job job = new Job(conf, "wordcount");
                  
                      job.setOutputKeyClass(Text.class);
                      job.setOutputValueClass(IntWritable.class);
                  
                      job.setMapperClass(WordCountMapper.class);
                      job.setReducerClass(WordCountReducer.class);
                  
                      job.setInputFormatClass(TextInputFormat.class);
                      job.setOutputFormatClass(TextOutputFormat.class);
                  
                      FileInputFormat.addInputPath(job, new Path("counterinput"));
                      // Erase previous run output (if any)
                      FileSystem.get(conf).delete(new Path("counteroutput"), true);
                      FileOutputFormat.setOutputPath(job, new Path("counteroutput"));
                  
                      job.waitForCompletion(true);
                      return 0;
                  }   
                  
                  public static void main(String[] args) throws Exception {
                      int res = ToolRunner.run(new Configuration(), new WordCount(), args);
                      System.exit(res);
                  
                      }
                  }
                  

                  WordCountMapper.java

                  WordCountMapper.java

                  public class WordCountMapper extends
                  Mapper<LongWritable, Text, Text, IntWritable> {
                      private final static IntWritable one = new IntWritable(1);
                      private Text word = new Text();
                  
                      public void map(LongWritable key, Text value, OutputCollector<Text,IntWritable> output, Reporter reporter)
                      throws IOException, InterruptedException {
                          System.out.println("hi");
                      String line = value.toString();
                      StringTokenizer tokenizer = new StringTokenizer(line);
                      while (tokenizer.hasMoreTokens()) {
                          word.set(tokenizer.nextToken());
                          output.collect(word, one);
                          }
                      }
                  }
                  

                  WordCountReducer.java

                  WordCountReducer.java

                  public class WordCountReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
                      public void reduce(Text key, Iterator<IntWritable> values,
                          OutputCollector<Text,IntWritable> output, Reporter reporter) throws IOException, InterruptedException {
                          System.out.println("hello");
                          int sum = 0;
                          while (values.hasNext()) {
                              sum += values.next().get();
                          }
                          output.collect(key, new IntWritable(sum));
                      }
                  }
                  

                  我收到以下错误

                  13/06/23 23:13:25 INFO jvm.JvmMetrics: Initializing JVM Metrics with  
                  processName=JobTracker, sessionId=
                  
                  13/06/23 23:13:25 WARN mapred.JobClient: Use GenericOptionsParser for parsing the 
                  arguments. Applications should implement Tool for the same.
                  13/06/23 23:13:26 INFO input.FileInputFormat: Total input paths to process : 1
                  13/06/23 23:13:26 INFO mapred.JobClient: Running job: job_local_0001
                  13/06/23 23:13:26 INFO input.FileInputFormat: Total input paths to process : 1
                  13/06/23 23:13:26 INFO mapred.MapTask: io.sort.mb = 100
                  13/06/23 23:13:26 INFO mapred.MapTask: data buffer = 79691776/99614720
                  13/06/23 23:13:26 INFO mapred.MapTask: record buffer = 262144/327680
                  13/06/23 23:13:26 WARN mapred.LocalJobRunner: job_local_0001
                  java.io.IOException: Type mismatch in key from map: expected org.apache.hadoop.io.Text, 
                  recieved org.apache.hadoop.io.LongWritable
                  at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.collect(MapTask.java:845)
                  at org.apache.hadoop.mapred.MapTask$NewOutputCollector.write(MapTask.java:541)
                  at org.
                  apache.hadoop.mapreduce.TaskInputOutputContext.write(TaskInputOutputContext.java:80)
                  at org.apache.hadoop.mapreduce.Mapper.map(Mapper.java:124)
                  at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:144)
                  at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:621)
                  at org.apache.hadoop.mapred.MapTask.run(MapTask.java:305)
                  at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:177)
                  13/06/23 23:13:27 INFO mapred.JobClient:  map 0% reduce 0%
                  13/06/23 23:13:27 INFO mapred.JobClient: Job complete: job_local_0001
                  13/06/23 23:13:27 INFO mapred.JobClient: Counters: 0
                  

                  我认为它无法找到 Mapper 和 reducer 类.我已经在主类中编写了代码,它正在获取默认的 Mapper 和 reducer 类.

                  I think it is not able to find Mapper and reducer class. I have written the code in main class, It is getting default Mapper and reducer class.

                  推荐答案

                  在代码中添加这两行:

                  job.setMapOutputKeyClass(Text.class);
                  job.setMapOutputValueClass(IntWritable.class);
                  

                  您正在使用 TextOutputFormat 默认情况下发出 LongWritable 键和 Text 值,但您将 Text 作为键和 IntWritable 作为值发出.你需要把这件事告诉名人堂.

                  You are using TextOutputFormat which emits LongWritable key and Text value by default, but you are emitting Text as key and IntWritable as value. You need to tell this to the famework.

                  HTH

                  这篇关于映射中键的类型不匹配:预期 org.apache.hadoop.io.Text,收到 org.apache.hadoop.io.LongWritable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 Hadoop 伪分布式模式下充分利用所有内核 下一篇:Hadoop:java.lang.IncompatibleClassChangeError:找到接口 or

                  相关文章

                  最新文章

                • <tfoot id='UMm0a'></tfoot>

                    <i id='UMm0a'><tr id='UMm0a'><dt id='UMm0a'><q id='UMm0a'><span id='UMm0a'><b id='UMm0a'><form id='UMm0a'><ins id='UMm0a'></ins><ul id='UMm0a'></ul><sub id='UMm0a'></sub></form><legend id='UMm0a'></legend><bdo id='UMm0a'><pre id='UMm0a'><center id='UMm0a'></center></pre></bdo></b><th id='UMm0a'></th></span></q></dt></tr></i><div id='UMm0a'><tfoot id='UMm0a'></tfoot><dl id='UMm0a'><fieldset id='UMm0a'></fieldset></dl></div>

                      <bdo id='UMm0a'></bdo><ul id='UMm0a'></ul>

                    1. <legend id='UMm0a'><style id='UMm0a'><dir id='UMm0a'><q id='UMm0a'></q></dir></style></legend>

                      <small id='UMm0a'></small><noframes id='UMm0a'>