我想在没有输入文件的情况下在eclipse中使用Hadoop mapreduce,基本上我有一个对象列表,我想使用该列表创建我需要的一切(键和值)我该怎么做?我已经做了一些研究但是所有的InputFormat似乎都适用于输入文件
目前我有这个:
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;
}
}
}
但我不确定如何初始化列表。 谢谢!