【发布时间】:2015-07-17 19:38:58
【问题描述】:
我正在尝试编写一个程序,该程序需要一个庞大的数据集,然后使用mapreduce 对其运行一些查询。我有这样的代码:
public static class MRMapper
extends Mapper<LongWritable, Text, Text, IntWritable>{
String output2="hdfs://master:9000/user/xxxx/indexln.txt";
FileSystem Phdfs =FileSystem.get(new Configuration());
Path fname1=new Path(output2);
BufferedWriter out=new BufferedWriter(new OutputStreamWriter(Phdfs.create(fname1,true)));
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
long max=0;
public void map(LongWritable key, Text value, Context context
) throws IOException, InterruptedException {
String binln = Long.toBinaryString(0x8000000000000000L | key).substring(1);
out2.write(binln+"\n");
out2.flush();
String line = value.toString();
String [] ST = line.split(",");
long val=Math.abs(Long.parseLong(ST[2]));
if (max < val){
max= val;
}
else{
word.set(line);
context.write(word, val);
}
}
}
我想做的是在映射器中构建一个indexfile。映射器将使用它来访问输入文件的特定区域。映射器根据索引读取输入文件的一部分,然后将读取的部分和读取的行数打印到输出。我正在使用一个带有 9 个减速器的映射器。
我的问题是,是否可以在 map 函数中创建/写入与输出文件不同的文件,并且 reducer 是否可以读取在 mapper 中打开的文件?如果是,我是在正确的道路上还是完全错误的,或者
mapreduce不是这样的方式?如果这个问题听起来太菜鸟,我深表歉意,但我实际上是hadoop的菜鸟。努力学习。谢谢
【问题讨论】:
标签: java hadoop mapreduce hdfs reduce