Hadoop 2.2 MapFile创建失败

时间:2014-01-09 00:22:25

标签: hadoop

我使用Hadoop 2.2

我的代码创建了一个MapFile编写器,如下所示

Configuration conf = new Configuration();  
Path path = new Path(filename);  
writer = new MapFile.Writer(conf,path,  
    SequenceFile.Writer.keyClass(key.getClass()),
    SequenceFile.Writer.valueClass(value.getClass()),
    SequenceFile.Writer.compression(SequenceFile.CompressionType.NONE));

我的密钥类声明如下

public class ReportingKeyWritable extends BinaryComparable implements
        WritableComparable<BinaryComparable> {

值类声明如下

public class ReportingValueWritable implements Writable

构造函数失败,出现以下异常

java.lang.IllegalArgumentException: key class or comparator option must be set
        at org.apache.hadoop.io.MapFile$Writer.<init>(MapFile.java:246)
        at DataLoader.main(DataLoader.java:66)

1 个答案:

答案 0 :(得分:1)

它会正常工作:

writer = new MapFile.Writer(conf,path,  
MapFile.Writer.keyClass(key.getClass()),
MapFile.Writer.valueClass(value.getClass()),
MapFile.Writer.compression(SequenceFile.CompressionType.NONE));