版本:

$ 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 May  7 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);
	}
}

 

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐