mongodb - java.lang.ClassCastException even though I am casting it to the extended class -
i trying setup mongo-hadoop driver extensions hadoop streaming jobs have written python plugin dumbo.
the dumbo project needs me use typedbyteswritable class. made new inputformat & recordreader so:
package com.mongodb.hadoop; public class typedbytestableinputformat implements inputformat<typedbyteswritable, typedbyteswritable> { @override public recordreader<typedbyteswritable, typedbyteswritable> getrecordreader(inputsplit split, jobconf job, reporter reporter) { if (!(split instanceof mongoinputsplit)) throw new illegalstateexception("creation of new recordreader requires mongoinputsplit instance."); final mongoinputsplit mis = (mongoinputsplit) split; //**the following line throws error** return (recordreader<typedbyteswritable, typedbyteswritable>) new typedbytesmongorecordreader(mis); }
and here extended recordreader:
package com.mongodb.hadoop.input; ... ... import org.apache.hadoop.mapreduce.recordreader; ... ... public class typedbytesmongorecordreader extends recordreader<typedbyteswritable, typedbyteswritable> { public typedbytesmongorecordreader(mongoinputsplit mis) { _cursor = mis.getcursor(); } @override public void close() { if ( _cursor != null ) _cursor.close(); }
but when run job, throws error. not sure why, child of recordreader. doing wrong? here api doc recordreader class. thought doing correctly:
http://hadoop.apache.org/common/docs/current/api/org/apache/hadoop/mapreduce/recordreader.html
i warning on line being cast recordreader, no errors, , builds jar fine. warning:
type safety: unchecked cast typedbytesmongorecordreader recordreader<typedbyteswritable,typedbyteswritable>
try this:
public <t extends recordreader<typedbyteswritable, typedbyteswritable>> t getrecordreader(inputsplit split, jobconf job, reporter reporter) { if (!(split instanceof mongoinputsplit)) throw new illegalstateexception("creation of new recordreader requires mongoinputsplit instance."); final mongoinputsplit mis = (mongoinputsplit) split; return new typedbytesmongorecordreader(mis); // may need cast (t) - try without first }
Comments
Post a Comment