gpt4 book ai didi

java - mapreduce作业卡在 map 100上(使用元组值)

转载 作者:行者123 更新时间:2023-12-02 21:49:57 27 4
gpt4 key购买 nike

我不知道我的代码有什么问题。它卡在 map 上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();
}
}

最佳答案

reducer 启动吗?日志中有任何错误?

只是一个想法:
可能是readLine()使您停滞了...我会尝试使用writeString()readString(),而不是writeChars()readLine()WritableUtils class编写/读取可写实现中的expr。 (至少在旧的API中)覆盖exprfit类中的get()set(Writable value)方法也是一个好主意。

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

更多注释:在Reducer中,我将在reduce()方法中初始化EF并删除计数,因为它没有使用。
我不确定您是否需要Map / Reduce来完成此任务。

关于java - mapreduce作业卡在 map 100上(使用元组值),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21901035/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com