我刚刚开始学习hadoop并遵循“hadoop-权威指南”。
我测试了第一种编写map和reduce类的方法,其中mapper和reducer是接口。代码运行良好。然后我开始编写代码,其中map和reduce是带有上下文类的抽象类。顺便说一句,我正在使用hadoop1.2.1我看到下面的错误
MaxTemperatureReducer.java:5: error: cannot find symbol
public class MaxTemperatureReducer extends Reducer<Text, IntWritable, Text, IntWritable>
^
symbol: class Reducer
MaxTemperatureReducer.java:7: error: cannot find symbol
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException,InterruptedException
^
symbol: class Context
location: class MaxTemperatureReducer
MaxTemperature.java:5: error: cannot find symbol
import org.apache.hadoop.mapreduce.FileInputFormat;
^
symbol: class FileInputFormat
location: package org.apache.hadoop.mapreduce
MaxTemperature.java:6: error: cannot find symbol
import org.apache.hadoop.mapreduce.FileOutputFormat;
^
symbol: class FileOutputFormat
location: package org.apache.hadoop.mapreduce
MaxTemperature.java:7: error: cannot find symbol
import org.apache.hadoop.mapreduce.JobClient;
我的mapper类看起来像
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
//import org.apache.hadoop.mapreduce.MapReduceBase;
import org.apache.hadoop.mapreduce.Mapper;
public class MaxTemperatureMapper extends Mapper<LongWritable, Text, Text, IntWritable>
{
private static final int MISSING = 9999;
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException
{
String line = value.toString();
String year = line.substring(0, 4);
int airTemperature;
if (line.charAt(4) == '+')
{
airTemperature = Integer.parseInt(line.substring(5, 10));
}
else
{
System.out.println( line );
airTemperature = Integer.parseInt(line.substring(4, 9));
}
System.out.println( "Mapper: " + year + ", " + airTemperature );
context.write(new Text(year), new IntWritable(airTemperature));
}
}
有人能帮忙吗?
2条答案
按热度按时间6jygbczu1#
问题似乎出在驱动程序类的import语句中,您试图使用错误的import语句
FileInputFormat
以及FileOutputFormat
. 使用这些import语句而不是FileInputFormat
&FileOutputFormat
在你的司机身上(MaxTemperature
)班级:使用此示例作为参考,以确保所有import语句都有效。
7gyucuyw2#
你的进口声明不正确。这些类文件在org.apache.hadoop.mapred包或org.apache.hadoop.mapreduce.lib.input中可用
fileoutputformat也有类似的问题