我正在尝试分析一个大型犯罪统计数据集,该文件约为 2 GB,CSV 格式。大约有 20 列,但我只对其中的一个子集感兴趣:Crime_Type 和 Crime_in_Year。例如,“入室盗窃”犯罪类型,从2001年到2013年,每年都会发生。我想要一个统计每年入室盗窃发生次数的结果。
所以我正在考虑有一个 key ,而 value 将是它在 2003 年出现的总和。在 hadoop/mapreduce 中是否可以有一对 value 作为 key ?
A Key
可以是任何东西,只要它实现Writable
。您可以很容易地编写自己的自定义密钥,如图所示here http://hadoop.apache.org/docs/current/api/org/apache/hadoop/io/Writable.html.
因此,借用文档,一种实现可能是
public class CrimeWritable implements Writable {
private int year;
private String type;
public void write(DataOutput out) throws IOException {
out.writeInt(year);
out.writeBytes(type);
}
public void readFields(DataInput in) throws IOException {
year = in.readInt();
type = in.readBytes();
}
public static CrimeWritable read(DataInput in) throws IOException {
CrimeWritable w = new CrimeWritable();
w.readFields(in);
return w;
}
}
在相关说明中,您可能需要考虑使用比 map-reduce 更高级别的抽象,例如级联 http://www.cascading.org/ or 阿帕奇火花 http://spark.incubator.apache.org/.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)