mapreduce作业卡在地图100(使用元组值)

时间:2014-02-20 07:29:56

标签: java hadoop

我不知道我的code.it卡在地图100%有什么问题 输入:

expression, number
1+2+3, 0.4

输出应为:

count   expression    number
1 1+2+3 0.4
2 3*4   0.8

这是map方法:

public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
    inputs = value.toString();  
    tokens = inputs.split(",");
    expr = new Text (tokens[0]);
    fit = new DoubleWritable(Double.parseDouble(tokens[1]));
    EF.setExpr(tokens[0]);
    EF.setFit(Double.parseDouble(tokens[1]));
    count++;
    context.write(new IntWritable(count),EF );    
}

和班级Reduce

public static class Reduce extends Reducer<IntWritable,exprfit,IntWritable,exprfit> {
  private exprfit EF = new exprfit();
  private int count;

  public void reduce(IntWritable key, Iterable<exprfit> values, Context context) throws IOException, InterruptedException {
    EF.setExpr(values.iterator().next().getExpr());
    EF.setFit(values.iterator().next().getFit());
    context.write(key, EF); 
  }
}

班级exprfit

public static class exprfit implements Writable {
  private String expr;
  private Double fit;// type of output value

  public String getExpr() {
    return expr;
  }

  public void setExpr(String expr) {
    this.expr = expr;
  }

  public double getFit() {
    return fit;
  }

  public void setFit(Double fit) {
    this.fit = fit;
  }

  @Override
  public void write(DataOutput out) throws IOException {
    out.writeChars(expr);
    out.writeDouble(fit);
  }

  @Override
  public String toString() {
    // TODO Auto-generated method stub
    return super.toString();
  }

  public void readFields(DataInput in) throws IOException {
    expr =in.readLine();
    fit = in.readDouble();  
  }
}

1 个答案:

答案 0 :(得分:0)

减速机启动了吗?日志中的任何错误?

只是一个想法: 它可能是readLine()阻止你...我会尝试使用writeString()readString()而不是writeChars()readLine()来写入/读取你的Writr中的expr实施,来自WritableUtils class。在exprfit类中重写方法get()set(Writable value)也是一个好主意(至少在旧API中)。

您还可以将计数器存储为VIntWritable,而不是IntWritable,以节省一些空间(如果需要),甚至可以缩短空间。

更多评论:在Reducer中,我会在reduce()方法中初始化EF并删除计数,因为它没有被使用。 我不确定你是否需要Map / Reduce来完成这项任务。

相关问题