[编写mapreduce类时

问题描述 投票:1回答:1

我在编译平均温度代码时遇到此错误。它给了我以下错误。

      hduser@ubuntu:/home/sara/Desktop/MaxTemp$ javac -classpath 
      $HADOOP_HOME/share/hadoop/common/hadoop-common- 
     2.7.2.jar:$HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-client- 
    core-2.7.2.jar:$HADOOP_HOME/share/hadoop/common/lib/commons-cli-1.2.jar 
    -d '/home/sara/Desktop/MaxTemp' *.java 
      AverageDriver.java:17: error: error while writing AvgMaxTemp: 
      /home/sara/Desktop/MaxTemp/AverageDriver$AvgMaxTemp.class
      public static class AvgMaxTemp extends Mapper<Object, Text, Text, 
          IntWritable>{
          ^
        1 error

我正在使用的CSV文件

enter image description here

代码是

       public class AverageDriver {
     public static class AvgMaxTempM extends Mapper<Object, Text, Text, 
      IntWritable>{

       private IntWritable TmaxValue = new IntWritable();
        private Text Value = new Text();

      public void map(Object key, Text value, Context con) throws 
      IOException, InterruptedException
        {
     String line = value.toString();
     String[] words = line.split(",");
      TmaxValue.set(Integer.parseInt(words[2]));
      Value.set(words[3]);
       if(words[2].equals("TMAX")){  

       for(String word: words )
      {
    con.write( Value , TmaxValue );
       }


      } } }
   public class AveragemaxTempR extends Reducer< Text, IntWritable,Text, 
   IntWritable >
    {
          public void reduce(Text key,  Iterable<IntWritable> values, 
        Context 
        context) throws IOException,                                                       
      InterruptedException
        {          
        int max_temp = 0; 
        int count = 0;
        for (IntWritable value : values)
                    {
                                max_temp += value.get();     
                                count+=1;
                    }
        context.write(key, new IntWritable(max_temp/count));
        }                                             
          }
java class hadoop mapreduce
1个回答
0
投票

您的驱动程序类中有一个静态类,它会引发编译错误:

 public class AverageDriver {
 public static class AvgMaxTempM extends Mapper<Object, Text, Text, 
  IntWritable>{

您是否正在使用像IntelliJ或Eclipse这样的IDE?它可以帮助格式化代码并在编译之前识别类似问题。

© www.soinside.com 2019 - 2024. All rights reserved.