Home | About | Sematext search-lucene.com search-hadoop.com
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB
 Search Hadoop and all its subprojects:

Switch to Threaded View
Hadoop >> mail # user >> implementing comparable


Copy link to this message
-
Re: implementing comparable
Hi,

Discussion, below.

On Sat, Oct 15, 2011 at 4:26 PM, Keith Thompson <[EMAIL PROTECTED]>wrote:

> Hello,
> I am trying to write my very first MapReduce code.  When I try to run the
> jar, I get this error:
>
> 11/10/15 17:17:30 INFO mapred.JobClient: Task Id :
> attempt_201110151636_0003_m_000001_2, Status : FAILED
> java.lang.ClassCastException: class edu.bing.vfi5.KeyList
> at java.lang.Class.asSubclass(Class.java:3018)
> at
> org.apache.hadoop.mapred.JobConf.getOutputKeyComparator(JobConf.java:599)
> at
> org.apache.hadoop.mapred.MapTask$MapOutputBuffer.<init>(MapTask.java:791)
> at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:350)
> at org.apache.hadoop.mapred.MapTask.run(MapTask.java:307)
> at org.apache.hadoop.mapred.Child.main(Child.java:170)
>
> I assume this means that it has something to do with my implementation of
> comparable.  KeyList is a class for a 3-tuple key.  The code is listed
> below.  Any hints would be greatly appreciated as I am trying to understand
> how comparable is supposed to work.  Also, do I need to implement Writable
> as well?  If so, should this be code for how the output is written to a
> file
> in HDFS?
>
> Thanks,
> Keith
>
> package edu.bing.vfi5;
>
> public class KeyList implements Comparable<KeyList> {
>

Key's need to be WritableComparable.
>
> private int[] keys;
>  public KeyList(int i, int j, int k) {
> keys = new int[3];
> keys[0] = i;
> keys[0] = j;
> keys[0] = k;
> }
>
> @Override
> public int compareTo(KeyList k) {
> // TODO Auto-generated method stub
> if(this.keys[0] == k.keys[0] && this.keys[1] == k.keys[1] && this.keys[2]
> => k.keys[2])
> return 0;
> else if((this.keys[0]>k.keys[0])
> ||(this.keys[0]==k.keys[0]&&this.keys[1]>k.keys[1])
>
> ||(this.keys[0]==k.keys[0]&&this.keys[1]==k.keys[1]&&this.keys[2]>k.keys[2]))
> return 1;
> else
> return -1;
> }
> }
>
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB