Hadoop throws a ClassCastException for the java.nio.ByteBuffer keyword

I am using "hadoop-0.20.203.0rc1.tar.gz" to configure my cluster. Whenever I installjob.setMapOutputKeyClass(ByteBuffer.class);

and run the task that I get after the exception:

    12/01/13 15:09:00 INFO mapred.JobClient: Task Id : attempt_201201131428_0005_m_000001_2, Status : FAILED
java.lang.ClassCastException: class java.nio.ByteBuffer
        at java.lang.Class.asSubclass(Class.java:3018)
        at org.apache.hadoop.mapred.JobConf.getOutputKeyComparator(JobConf.java:776)
        at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.<init>(MapTask.java:958)
        at org.apache.hadoop.mapred.MapTask$NewOutputCollector.<init>(MapTask.java:673)
        at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:755)
        at org.apache.hadoop.mapred.MapTask.run(MapTask.java:369)
        at org.apache.hadoop.mapred.Child$4.run(Child.java:259)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.security.auth.Subject.doAs(Subject.java:396)
        at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1059)
        at org.apache.hadoop.mapred.Child.main(Child.java:253)

I also noticed that ByteBuffer is comparable, not Writable - is it something like that? Let me know if any further information is needed.

+5
source share
1 answer

An exception is thrown here. Here is the code from SVN.

public RawComparator getOutputKeyComparator() {
    Class<? extends RawComparator> theClass = getClass("mapred.output.key.comparator.class",
        null, RawComparator.class);
    if (theClass != null)
        return ReflectionUtils.newInstance(theClass, this);
    return WritableComparator.get(getMapOutputKeyClass().asSubclass(WritableComparable.class));
}

If the property is mapred.output.key.comparator.classnot defined in JobConf, then the key must implement the WritableComparable interface. The ByteBuffer class does not implement the WritableComparable interface, therefore an exception.

BTW, WritableComparable - - Writable Comparable.

+5

All Articles