我正在尝试使用 SequenceFile 在两个 mapReduce 程序之间传递数据。我要传递的数据格式为 >. 由于某种原因,地图中的某些条目似乎没有从一个程序传递到另一个程序。这是我的代码,首先是生成 de SequenceFileOutput 的 reducer,然后是从中读取的映射器。
公共静态类 IntSumReducer 扩展 Reducer {
public void reduce(Text key, Iterable<Text> values,
Context context
) throws IOException, InterruptedException {
MapWritable vector = new MapWritable() ;
for (Text val : values){
if(vector.containsKey(val)){
vector.put(val , new IntWritable(((IntWritable)vector.get(val)).get() + 1));
}
else
vector.put(val , new IntWritable(1));
}
context.write(key, vector);
}
}
和映射器:
公共静态类 TokenizerMapper 扩展 Mapper{
private final static int cota = 100;
private final static double ady = 0.25;
public void map(Text key, MapWritable value, Context context
) throws IOException, InterruptedException {
IntWritable tot = (IntWritable)value.get(key);
int total = tot.get();
if(total > cota){
MapWritable vector = new MapWritable() ;
Set<Writable> keys = value.keySet();
Iterator<Writable> iterator = keys.iterator();
while(iterator.hasNext()){
Text llave = (Text) iterator.next();
if(!llave.equals(key)){
IntWritable cant = (IntWritable) value.get(llave);
double rel = (((double)cant.get())/(double)total);
if(cant.get() > cota && rel > ady ){
vector.put(llave, new DoubleWritable(rel));
}
}
}
context.write(key,vector);
}
}
}