You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-user@hadoop.apache.org by Andy Sautins <an...@returnpath.net> on 2008/12/12 00:55:41 UTC

API Documentation question - WritableComparable

 

  I have a question regarding the Hadoop API documentation for .19.  The
question is in regard to:
http://hadoop.apache.org/core/docs/current/api/org/apache/hadoop/io/Writ
ableComparable.html.  The document shows the following for the compareTo
method:

 

       public int compareTo(MyWritableComparable w) {

         int thisValue = this.value;

         int thatValue = ((IntWritable)o).value;

         return (thisValue < thatValue ? -1 : (thisValue==thatValue ? 0
: 1));

       }

 

 

   Taking the full class example doesn't compile.  What I _think_ would
be right would be:

 

       public int compareTo(Object o) {

         int thisValue = this.value;

         int thatValue = ((MyWritableComparable)o).value;

         return (thisValue < thatValue ? -1 : (thisValue==thatValue ? 0
: 1));

       }

 

  But even at that it's unclear why the compareTo function is comparing
value ( which isn't a member of the class in the example ) and not the
counter and timestamp variables in the class.

 

   Am I understanding this right?  Is there something amiss with the
documentation?

 

   Thanks

 

   Andy

 

 


Re: API Documentation question - WritableComparable

Posted by Tom White <to...@gmail.com>.
I've opened https://issues.apache.org/jira/browse/HADOOP-4881 and
attached a patch to fix this.

Tom

On Fri, Dec 12, 2008 at 2:18 AM, Tarandeep Singh <ta...@gmail.com> wrote:
> The example is just to illustrate how one should implement one's own
> WritableComparable class and in the compreTo method, it is just showing how
> it works in case of IntWritable with "value" as its member variable.
>
> You are right the example's code is misleading. It should have used  either
> timestamp or counter or both and not "value".
>
> -Taran
>
> On Thu, Dec 11, 2008 at 3:55 PM, Andy Sautins
> <an...@returnpath.net>wrote:
>
>>
>>
>>  I have a question regarding the Hadoop API documentation for .19.  The
>> question is in regard to:
>> http://hadoop.apache.org/core/docs/current/api/org/apache/hadoop/io/Writ
>> ableComparable.html<http://hadoop.apache.org/core/docs/current/api/org/apache/hadoop/io/WritableComparable.html>.
>>  The document shows the following for the compareTo
>> method:
>>
>>
>>
>>       public int compareTo(MyWritableComparable w) {
>>
>>         int thisValue = this.value;
>>
>>         int thatValue = ((IntWritable)o).value;
>>
>>         return (thisValue < thatValue ? -1 : (thisValue==thatValue ? 0
>> : 1));
>>
>>       }
>>
>>
>>
>>
>>
>>   Taking the full class example doesn't compile.  What I _think_ would
>> be right would be:
>>
>>
>>
>>       public int compareTo(Object o) {
>>
>>         int thisValue = this.value;
>>
>>         int thatValue = ((MyWritableComparable)o).value;
>>
>>         return (thisValue < thatValue ? -1 : (thisValue==thatValue ? 0
>> : 1));
>>
>>       }
>>
>>
>>
>>  But even at that it's unclear why the compareTo function is comparing
>> value ( which isn't a member of the class in the example ) and not the
>> counter and timestamp variables in the class.
>>
>>
>>
>>   Am I understanding this right?  Is there something amiss with the
>> documentation?
>>
>>
>>
>>   Thanks
>>
>>
>>
>>   Andy
>>
>>
>>
>>
>>
>>
>

Re: API Documentation question - WritableComparable

Posted by Tarandeep Singh <ta...@gmail.com>.
The example is just to illustrate how one should implement one's own
WritableComparable class and in the compreTo method, it is just showing how
it works in case of IntWritable with "value" as its member variable.

You are right the example's code is misleading. It should have used  either
timestamp or counter or both and not "value".

-Taran

On Thu, Dec 11, 2008 at 3:55 PM, Andy Sautins
<an...@returnpath.net>wrote:

>
>
>  I have a question regarding the Hadoop API documentation for .19.  The
> question is in regard to:
> http://hadoop.apache.org/core/docs/current/api/org/apache/hadoop/io/Writ
> ableComparable.html<http://hadoop.apache.org/core/docs/current/api/org/apache/hadoop/io/WritableComparable.html>.
>  The document shows the following for the compareTo
> method:
>
>
>
>       public int compareTo(MyWritableComparable w) {
>
>         int thisValue = this.value;
>
>         int thatValue = ((IntWritable)o).value;
>
>         return (thisValue < thatValue ? -1 : (thisValue==thatValue ? 0
> : 1));
>
>       }
>
>
>
>
>
>   Taking the full class example doesn't compile.  What I _think_ would
> be right would be:
>
>
>
>       public int compareTo(Object o) {
>
>         int thisValue = this.value;
>
>         int thatValue = ((MyWritableComparable)o).value;
>
>         return (thisValue < thatValue ? -1 : (thisValue==thatValue ? 0
> : 1));
>
>       }
>
>
>
>  But even at that it's unclear why the compareTo function is comparing
> value ( which isn't a member of the class in the example ) and not the
> counter and timestamp variables in the class.
>
>
>
>   Am I understanding this right?  Is there something amiss with the
> documentation?
>
>
>
>   Thanks
>
>
>
>   Andy
>
>
>
>
>
>