【发布时间】:2013-12-02 11:38:25
【问题描述】:
在代码的第一部分,我设置了一些数组来跟踪一些值,如下所示:
@Override
public void configure(JobConf conf){
top5=new String[5];
counttop5=new int[5]
}
现在在 reducer 的一些代码之后,我想将顶部的内容输出到输出文件,但是,为了做到这一点,我创建了一个 close() 函数:
@Override
public void close(){
//what goes here?
}
但是,正如您所见,没有什么可以调用的,因为输出是在 reducer 方法中定义的。 虽然代码本身很长,但这里是方法的数据签名:
public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, Writable> {
private static IntWritable one = new IntWritable(1);
public void map(LongWritable key, Text value, OutputCollector<Text, Writable> output, Reporter reporter) throws IOException {
public static class Reduce extends MapReduceBase implements Reducer<Text, Writable, Text, Writable> {
static ArrayList<String> files;
static String[] top5;
static int[] counttop5;
int reducedterms;
public void configure(JobConf conf){
files= new ArrayList<String>();
top5=new String[5];
reducedterms=0;
counttop5=new int[5];
}
@Override
public void close(){
//what goes here?
}
public void reduce(Text key, Iterator<Writable> values, OutputCollector<Text, Writable> output, Reporter reporter) throws IOException {
}
有人知道解决办法吗?
【问题讨论】:
-
“代码的第一部分”是指在映射器内部还是之前?
-
我已经添加了函数的数据签名,但是文件很大,我怀疑它是否适合。
-
谢谢(并对噪音感到抱歉)但是扩展
org.apache.hadoop.mapreduce.Reducer而不是实现org.apache.hadoop.mapred.Reducer接口是不可能的?如果没有,我想我有一个答案。 -
扩展而不是实施,谢谢!
-
@ArtemTsikiridis 应该写一个答案,你可以接受它,并奖励赏金。
标签: java hadoop counter cloudera