【发布时间】:2014-09-23 09:37:33
【问题描述】:
我在 Hadoop 中编写了一个 Map Reduce 程序,用于对文件的所有记录进行哈希处理,并将 hased 值作为附加属性附加到每个记录,然后输出到 Hadoop 文件系统 这是我写的代码
public class HashByMapReduce
{
public static class LineMapper extends Mapper<Text, Text, Text, Text>
{
private Text word = new Text();
public void map(Text key, Text value, Context context) throws IOException, InterruptedException
{
key.set("single")
String line = value.toString();
word.set(line);
context.write(key, line);
}
}
public static class LineReducer
extends Reducer<Text,Text,Text,Text>
{
private Text result = new Text();
public void reduce(Text key, Iterable<Text> values,
Context context
) throws IOException, InterruptedException
{
String translations = "";
for (Text val : values)
{
translations = val.toString()+","+String.valueOf(hash64(val.toString())); //Point of Error
result.set(translations);
context.write(key, result);
}
}
}
public static void main(String[] args) throws Exception
{
Configuration conf = new Configuration();
Job job = new Job(conf, "Hashing");
job.setJarByClass(HashByMapReduce.class);
job.setMapperClass(LineMapper.class);
job.setReducerClass(LineReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
job.setInputFormatClass(KeyValueTextInputFormat.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
我编写这段代码的逻辑是,每一行都由 Map 方法读取,该方法将所有值分配给单个键,然后传递给相同的 Reducer 方法。将每个值传递给 hash64() 函数。
但我看到它向哈希函数传递了一个空值(空值)。我不明白为什么?提前致谢
【问题讨论】:
-
你为什么用
org.w3c.dom.Text? -
对不起.. 不知道它是如何插入那里的@ThomasJungblut