我想在eclipse中使用hadoopmapreduce而不需要输入文件,基本上我有一个对象列表,我想用这个列表来创建我需要的所有东西(键和值),我怎么做?我做了一些研究,但所有的输入格式似乎与一个输入文件
目前我有这个:
import java.io.IOException;
import java.util.List;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.RecordReader;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
public class SolverInputFormatClass extends RecordReader<Text,PropNogood>{
private Integer key=null;
private PropNogood value=null;
private List<PropNogood> list=null;
private int p=0;
@Override
public void close() throws IOException {
// TODO Auto-generated method stub
if(!list.iterator().hasNext()){
list=null;
}
key=null;
value=null;
}
@Override
public Text getCurrentKey() throws IOException, InterruptedException {
// TODO Auto-generated method stub
return new Text(this.key+value.varstoString());
}
@Override
public PropNogood getCurrentValue() throws IOException, InterruptedException {
// TODO Auto-generated method stub
return this.value;
}
@Override
public float getProgress() throws IOException, InterruptedException {
// TODO Auto-generated method stub
return this.list.indexOf(value)/this.list.size();
}
@Override
public void initialize(InputSplit split, TaskAttemptContext context)throws IOException, InterruptedException {
// TODO Auto-generated method stub
}
@Override
public boolean nextKeyValue() throws IOException, InterruptedException {
// TODO Auto-generated method stub
if(p<list.size()){
value=list.get(p);
key=value.cardinality();
p++;
return true;
}
else{
return false;
}
}
}
但我不知道如何初始化列表。谢谢!
暂无答案!
目前还没有任何答案,快来回答吧!