Java hadoop在完成所有还原程序后给出输出
在代码的第一部分中,我设置了许多数组来跟踪一些值,如下所示:Java hadoop在完成所有还原程序后给出输出,java,hadoop,counter,cloudera,Java,Hadoop,Counter,Cloudera,在代码的第一部分中,我设置了许多数组来跟踪一些值,如下所示: @Override public void configure(JobConf conf){ top5=new String[5]; counttop5=new int[5] } 现在,在从reducer编写了一些代码之后,我想将top的内容输出到输出文件,但是,为了实现这一点,我创建了一个close()函数: @Override public void close(
@Override
public void configure(JobConf conf){
top5=new String[5];
counttop5=new int[5]
}
现在,在从reducer编写了一些代码之后,我想将top的内容输出到输出文件,但是,为了实现这一点,我创建了一个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 {
}
公共静态类映射扩展MapReduceBase实现映射器{
私有静态IntWritable one=新的IntWritable(1);
公共void映射(LongWritable键、文本值、OutputCollector输出、Reporter报告器)引发IOException{
公共静态类Reduce扩展MapReduceBase实现Reducer{
静态ArrayList文件;
静态字符串[]top5;
静态int[]counttop5;
int约化项;
公共void配置(JobConf conf){
files=newarraylist();
top5=新字符串[5];
简化项=0;
counttop5=新整数[5];
}
@凌驾
公众假期结束(){
//这里有什么?
}
公共void reduce(文本键、迭代器值、OutputCollector输出、Reporter报告器)引发IOException{
}
有人知道修复方法吗?这是一个使用
org.apache.hadoop.mapreduce
类的答案。API与您提供的代码有些不同,因为我们现在扩展了org.apache.hadoop.mapreduce.Reducer
基类,而不是实现org.apache.hadoop.mapred.Reducer
接口,但这里有一个简单的说明做你需要的事情的一种方式:
public static class Reduce extends Reducer<Text, Writable, Text, Writable> {
static ArrayList<String> files;
static String[] top5;
static int[] counttop5;
int reducedterms;
//setup method instead of configure
public void setup(Context context){
files= new ArrayList<String>();
top5=new String[5];
reducedterms=0;
counttop5=new int[5];
}
//In cleanup you may access the write method
@Override
public void cleanup(Context context){
// Use top5 and counttop5 the way you see fit
// Use context.write() to pass them ahead!
}
public void reduce(Text key, Iterator<Writable> values, Context context) throws IOException {
}
公共静态类Reduce扩展Reducer{
静态ArrayList文件;
静态字符串[]top5;
静态int[]counttop5;
int约化项;
//设置方法而不是配置
公共无效设置(上下文){
files=newarraylist();
top5=新字符串[5];
简化项=0;
counttop5=新整数[5];
}
//在“清理”中,您可以访问write方法
@凌驾
公共空间清理(上下文){
//按您认为合适的方式使用top5和counttop5
//使用context.write()提前传递它们!
}
公共void reduce(文本键、迭代器值、上下文)引发IOException{
}
这是一个使用org.apache.hadoop.mapreduce
类的答案。API与您提供的代码有点不同,因为我们现在扩展了org.apache.hadoop.mapreduce.Reducer
基类,而不是实现org.apache.hadoop.mapred.Reducer
接口,但这里是一个简单的方法你不需要:
public static class Reduce extends Reducer<Text, Writable, Text, Writable> {
static ArrayList<String> files;
static String[] top5;
static int[] counttop5;
int reducedterms;
//setup method instead of configure
public void setup(Context context){
files= new ArrayList<String>();
top5=new String[5];
reducedterms=0;
counttop5=new int[5];
}
//In cleanup you may access the write method
@Override
public void cleanup(Context context){
// Use top5 and counttop5 the way you see fit
// Use context.write() to pass them ahead!
}
public void reduce(Text key, Iterator<Writable> values, Context context) throws IOException {
}
公共静态类Reduce扩展Reducer{
静态ArrayList文件;
静态字符串[]top5;
静态int[]counttop5;
int约化项;
//设置方法而不是配置
公共无效设置(上下文){
files=newarraylist();
top5=新字符串[5];
简化项=0;
counttop5=新整数[5];
}
//在“清理”中,您可以访问write方法
@凌驾
公共空间清理(上下文){
//按您认为合适的方式使用top5和counttop5
//使用context.write()提前传递它们!
}
公共void reduce(文本键、迭代器值、上下文)引发IOException{
}
你说的“代码的第一部分”是指在映射器内部还是之前?我已经添加了函数的数据签名,但是文件太大了,我怀疑它是否合适。谢谢(很抱歉发出噪音)但是扩展org.apache.hadoop.mapreduce.Reducer
而不是实现org.apache.hadoop.mapred.Reducer
接口是不可能的吗?如果没有,我想我有一个答案。扩展而不是实现成功了,谢谢!@artemstikiridis应该写一个答案,然后你可以接受它,并奖励赏金“代码的第一部分”是指在映射器内部还是之前?我已经添加了函数的数据签名,但是文件太大了,我怀疑它是否适合。谢谢(很抱歉发出噪音)但是扩展org.apache.hadoop.mapreduce.Reducer
而不是实现org.apache.hadoop.mapred.Reducer
接口是不可能的吗?如果没有,我想我有一个答案。扩展而不是实现成功了,谢谢!@artemstikiridis应该写一个答案,你可以接受它,并奖励奖金。