use*_*736 5 java hadoop mapreduce
我正在使用它来删除重复行
public class DLines
{
public static class TokenCounterMapper extends Mapper<Object, Text, Text, IntWritable>
{
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
@Override
public void map(Object key, Text value, Context context) throws IOException, InterruptedException
{
String line=value.toString();
//int hash_code=line.hashCode();
context.write(value, one);
}
}
public static class TokenCounterReducer extends Reducer<Text, IntWritable, Text, IntWritable>
{
@Override
public void reduce(Text key, Iterable<IntWritable> values, Context context)throws IOException, InterruptedException
{
public void reduce(Text key, Iterable<IntWritable> values, Context context)throws IOException, InterruptedException
{
int sum = 0;
for (IntWritable value : values)
{
sum += value.get();
}
if (sum<2)
{
context.write(key,new IntWritable(sum));
}
}
}
Run Code Online (Sandbox Code Playgroud)
我必须只将密钥存储在 hdfs 中。
如果您不需要减速器的值,则只需使用NullWritable。
你可以简单地说context.write(key,NullWritable.get());
在你的驱动程序中,你还可以设置
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
Run Code Online (Sandbox Code Playgroud)
&
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(NullWritable.class);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3157 次 |
| 最近记录: |