HadoopツールクラスのWritableUtils

1601 ワード

バージョン:
$ 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);
	}
}