mapreduce作业停留在map 100(使用元组值)

vmdwslir  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(333)

我不知道我的代码有什么问题。它卡在Map100%的输入:

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();  
  }
}
5fjcxozz

5fjcxozz1#

减速机启动了吗?日志中有错误吗?
只是一个想法:可能是readline()阻碍了你。。。我会尝试使用 writeString() 以及 readString() ,而不是 writeChars() 以及 readLine() 用于在可写实现中从writeableutils类写入/读取expr。重写方法也是一个好主意(至少在旧的api中是这样) get() 以及 set(Writable value) 在你的exprfit课上。
您还可以将计数器存储为vintwritable,而不是intwriteable,以节省一些空间(如果需要),甚至更短。
更多注解:在reducer中,我将在reduce()方法中初始化ef并删除count,因为它没有被使用。我不确定您是否需要此任务的map/reduce。

相关问题