13916729435 发表于 2016-12-5 11:53:16

Hadoop工具类之WritableUtils

  版本:

$ hadoop version
Hadoop 0.20.2-cdh3u4
Subversion git://ubuntu-slave01/var/lib/jenkins/workspace/CDH3u4-Full-RC/build/cdh3/hadoop20/0.20.2-cdh3u4/source -r 214dd731e3bdb687cb55988d3f47dd9e248c5690
Compiled by jenkins on Mon May7 13:01:39 PDT 2012
From source with checksum a60c9795e41a3248b212344fb131c12c
  工具:

org.apache.hadoop.io.WritableUtils
  用途:
  1.字节流读写
  2.Writable子类克隆
  3.Writable子类序列化
  使用:
  克隆 

protected void reduce(Text key, Iterable<VectorWritable> values, Context context)
throws IOException, InterruptedException {
CosineDistanceMeasure cdm = new CosineDistanceMeasure();
Map<String, VectorWritable> map = new HashMap<String, VectorWritable>();
for (VectorWritable vectorWritable : values) {
VectorWritable vw = WritableUtils.clone(vectorWritable, context.getConfiguration());
}
}
  序列化

protected void reduce(Text key, Iterable<VectorWritable> values, Context context)
throws IOException, InterruptedException {
CosineDistanceMeasure cdm = new CosineDistanceMeasure();
Map<String, VectorWritable> map = new HashMap<String, VectorWritable>();
for (VectorWritable vectorWritable : values) {
VectorWritable vw = WritableUtils.clone(vectorWritable, context.getConfiguration());
WritableUtils.toByteArray(vw);
}
}
页: [1]
查看完整版本: Hadoop工具类之WritableUtils