public class PrimeMapper extends Mapper<LongWritable,IntWritable,IntWritable,NullWritable>
{
public void map(LongWritable k,IntWritable val,Context c) throws IOException, InterruptedException
{
int v=val.get();
int i=2;
if(v==1)
c.write(new IntWritable(v), NullWritable.get());
for(i=2;i<v;i++)
{
if(v%i==0)
break;
}
if(v==i)
c.write(new IntWritable(v),NullWritable.get());
}
}
当我尝试运行此代码时,我收到类型错误的错误。
答案 0 :(得分:0)
当您使用TextInputFormat(扩展FileInputFormat<LongWritable, Text>
)的默认输入格式时,映射器预期LongWritable
为key
,Text
为{{1} }}。如果您尚未在程序中明确更改此设置,则您的映射器定义不正确。
正确的实现看起来像这样:
value