hadoop0.18.3を使用すると次のエラーが発生します
java.lang.ClassCastException:org.apache.hadoop.io.Textをorg.apache.hadoop.io.DoubleWritableにキャストできません
マッパーを次のように定義しました。
public class HadoopMapper extends MapReduceBase implements Mapper<Text,DoubleWritable,Text,DoubleWritable> {
// The Karmasphere Studio Workflow Log displays logging from Apache Commons Logging, for example:
// private static final Log LOG = LogFactory.getLog("HadoopMapper");
@Override
public void map(Text key, DoubleWritable value, OutputCollector<Text, DoubleWritable> output, Reporter reporter)
throws IOException {
// throw new UnsupportedOperationException("Not supported yet.");
Random generator = new Random();
int i;
final int iter = 100000;
for (i =0; i < iter; i++)
{
double x = generator.nextDouble();
double y = generator.nextDouble();
double z;
z = x*x + y*y;
if (z <= 1){
output.collect(new Text("VALUE"), new DoubleWritable(1));
}else{
output.collect(new Text ("VALUE"), new DoubleWritable(0));
}
}
}
}
およびレデューサークラスとして
public class HadoopReducer extends MapReduceBase implements Reducer<Text,DoubleWritable,Text,DoubleWritable> {
// The Karmasphere Studio Workflow Log displays logging from Apache Commons Logging, for example:
// private static final Log LOG = LogFactory.getLog("HadoopReducer");
@Override
public void reduce(Text key, Iterator<DoubleWritable> value, OutputCollector<Text, DoubleWritable> output, Reporter reporter)
throws IOException {
// TODO code reducer logic here
// throw new UnsupportedOperationException("Not supported yet.");
double pi = 0;
double inside = 0;
double outside = 0;
while (value.hasNext())
{
if (value.next().get() == (long)1)
inside++;
else
outside++;
}
pi = (4*inside)/(inside + outside);
output.collect(new Text ("pi"), new DoubleWritable(pi));
}
}
jobconfを次のように設定します。
public static void initJobConf(JobConf conf) {
// Generating code using Karmasphere Protocol for Hadoop 0.18
// CG_GLOBAL
// CG_INPUT_HIDDEN
conf.setInputFormat(KeyValueTextInputFormat.class);
// CG_MAPPER_HIDDEN
conf.setMapperClass(HadoopMapper.class);
// CG_MAPPER
// CG_PARTITIONER_HIDDEN
conf.setPartitionerClass(org.apache.hadoop.mapred.lib.HashPartitioner.class);
// CG_PARTITIONER
// CG_COMPARATOR_HIDDEN
conf.setOutputKeyComparatorClass(org.apache.hadoop.io.Text.Comparator.class);
// CG_COMPARATOR
// CG_COMBINER_HIDDEN
// CG_REDUCER_HIDDEN
conf.setReducerClass(HadoopReducer.class);
// CG_REDUCER
conf.setNumReduceTasks(1);
// CG_OUTPUT_HIDDEN
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(DoubleWritable.class);
// CG_OUTPUT
// Others
}
一致するInputformatが見つかりません。conf.setInputFormat(KeyValueTextInputFormat.class)のKeyValueTextInputFormat.classはですが、どのように処理しますか?サブクラス化できますか、例を教えていただけますか?ありがとう