hadoop-mapreduce-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Johannes.Lichtenberger" <Johannes.Lichtenber...@uni-konstanz.de>
Subject Re: ClassCastException
Date Thu, 07 Oct 2010 13:58:56 GMT
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

Mime
View raw message