Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
MapReduce >> mail # user >> ClassCastException


Copy link to this message
-
Re: ClassCastException
Since mFormatter.format() returns a String, you don't need to introduce
newline.
You can call paramOut.writeUTF() to save the String and call
paramIn.readUTF() to read it back.

The value class doesn't need to implement Comparable.

On Thu, Oct 7, 2010 at 6:58 AM, Johannes.Lichtenberger <
[EMAIL PROTECTED]> wrote:

> On 10/07/2010 06:46 AM, Anthony Urso wrote:
> >  Hadoop is attempting to cast a Date object to WritableComparable, which
> > Date does not implement, and is causing that exception.
> >
> > Your keys must implement WritableComparable and your values must
> > implement Comparable.
>
> The values have to implement only Comparable or Writable?
>
> So I'm currently not sure if this is right:
>
>    /** {@link DateFormat}. */
>    private final DateFormat mFormatter = new
> SimpleDateFormat("yyyy.MM.ddTHH.mm.ssZ", Locale.ENGLISH);
>
>    /** {@link Date} used as the key. */
>    private transient Date mTimestamp;
>
>    /** Set timestamp. */
>    public void setTimestamp(final Date paramTimestamp) {
>        mTimestamp = paramTimestamp;
>    }
>
>    @Override
>    public void readFields(final DataInput paramIn) throws IOException {
>        try {
>            mTimestamp = mFormatter.parse(paramIn.readLine());
>        } catch (final ParseException e) {
>            LOGWRAPPER.error(e.getMessage(), e);
>        }
>    }
>
>    @Override
>    public void write(final DataOutput paramOut) throws IOException {
>        paramOut.writeBytes(mFormatter.format(mTimestamp));
>    }
>
> Then I'm just storing a Date (timestamp) with setTimestamp(...), but I'm
> not sure if readFields(...) is implemented correctly (because of
> paramIn.readLine()). I assume I have to append a newline in write(...).
>
>    @Override
>    public void write(final DataOutput paramOut) throws IOException {
>
>  paramOut.writeBytes(mFormatter.format(mTimestamp)+System.getProperty("line.separator"));
>    }
>
> BTW: Why does a value have to implement Comparable? It's not used for
> sorting and grouping!?
>
> regards,
> Johannes
>