Hadoop 如何操作reduce()输出并将其存储在另一个文件中?
我刚刚开始学习Hadoop。我想使用我的Hadoop 如何操作reduce()输出并将其存储在另一个文件中?,hadoop,Hadoop,我刚刚开始学习Hadoop。我想使用我的reduce()的输出并对其进行一些操作。我正在开发新的API,并尝试使用JobControl,但它似乎与新的API不兼容 有什么办法吗?在reducer中做任何你想做的事情,创建一个FSDataOutputStream并通过它写入输出 例如: public static class TokenCounterReducer extends Reducer<Text, IntWritable, Text, IntWritable
reduce()
的输出并对其进行一些操作。我正在开发新的API,并尝试使用JobControl
,但它似乎与新的API不兼容
有什么办法吗?在reducer中做任何你想做的事情,创建一个FSDataOutputStream并通过它写入输出 例如:
public static class TokenCounterReducer extends
Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterable<IntWritable> values,
Context context) throws IOException, InterruptedException {
FileSystem fs = FileSystem.get(context.getConfiguration());
FSDataOutputStream out = fs.create(new Path("/path/to/your/file"));
//do the manipulation and write it down to the file
out.write(......);
int sum = 0;
for (IntWritable value : values) {
sum += value.get();
}
context.write(key, new IntWritable(sum));
}
}
公共静态类令牌计数器扩展
减速器{
public void reduce(文本键、Iterable值、,
上下文)抛出IOException、InterruptedException{
FileSystem fs=FileSystem.get(context.getConfiguration());
FSDataOutputStream out=fs.create(新路径(“/Path/to/your/file”);
//执行操作并将其写入文件
写出(……);
整数和=0;
for(可写入值:值){
sum+=value.get();
}
write(key,newintwriteable(sum));
}
}
不确定您想做什么。是否要将不同类型的输出发送到不同的输出格式?如果要对贴图中的值进行过滤或操作,请使用reduce 您可以使用创建一个作业,其形式为[MAP+/REDUCE MAP*]
,即多个映射后跟一个减速机,然后是另一系列映射,从处理减速机的输出开始。最终输出是系列中最后一个映射器的输出
或者,您可以有多个按顺序启动的作业,前一个作业的减速器输出是下一个作业的输入。但是,如果您对中间输出不感兴趣,这会导致不必要的IO