Hadoop mapReduce How to store only values in HDFS(Hadoop mapReduce 如何在 HDFS 中仅存储值)
问题描述
我正在使用它来删除重复的行
I am using This for removing Duplicate lines
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));
}
}
}
我只需要在 hdfs 中存储密钥.
i have to store only Key in hdfs.
推荐答案
如果你不需要 reducer 的值,只需使用 NullWritable.
If you do not require value from your reducer, just use NullWritable.
你可以简单地说 context.write(key,NullWritable.get());
在你的驱动中,你也可以设置
In you driver, you could also set
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
&
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(NullWritable.class);
这篇关于Hadoop mapReduce 如何在 HDFS 中仅存储值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Hadoop mapReduce 如何在 HDFS 中仅存储值


基础教程推荐
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 降序排序:Java Map 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01