java - 在编写mapreduce类时

标签 java class hadoop mapreduce

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

      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));
        }                                             
          }

最佳答案

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

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

您使用的是 IntelliJ 或 Eclipse 等 IDE 吗?它可以帮助格式化您的代码,并在编译之前识别此类问题。

关于java - 在编写mapreduce类时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59062623/

相关文章:

java - 用一小段 Java 代码将 343 更改为 42

css - 区分 CSS 中的上下文相关类

c++ - CUDA 和类

Hadoop:数据节点未在从站上启动

java - 在 Hadoop 中映射和减少类属性

多维数组的Java序列化

java - 当我使用套接字通过本地网络传输文件时,如何防止文件损坏?

c# - 类型转换类和设置通用值

hadoop - 为 hdfs namenode 禁用 Web UI

java - 为什么java中一个类无法识别另一个类的getter方法?