Because the first bit of positive number is 0 while the first bit of
negative number is 1. Negative number is greater than positive number
according lexicographical order.


On Wed, Mar 19, 2014 at 7:37 PM, haosdent <[email protected]> wrote:

> For your scenario, I thinks this code snippet should work for you:
>
> *********************************************
>     int i = 40;
>     FilterList filters = new FilterList();
>     ValueFilter filter = new
> ValueFilter(CompareFilter.CompareOp.GREATER_OR_EQUAL,new
>             BinaryComparator(Bytes.toBytes(i)));
>     filters.addFilter(filter);
>     filter = new ValueFilter(CompareFilter.CompareOp.LESS,new
>             BinaryComparator(Bytes.toBytes(Integer.MIN_VALUE)));
>
>     scan.setFilter(filters);
> *********************************************
>
>
>
> On Wed, Mar 19, 2014 at 7:31 PM, ramkrishna vasudevan <
> [email protected]> wrote:
>
>> Which version you are using?
>> Any way you have guessed it correctly.  The best option is to write your
>> own BinaryComparator that compares negatives also.  As everything is
>> lexographically sorted you may end up in getting negatives as bigger
>> values.
>>
>> Regards
>> Ram
>>
>>
>> On Wed, Mar 19, 2014 at 4:49 PM, Chaitanya <[email protected]
>> >wrote:
>>
>> > Hi All,
>> >
>> > I have come across an issue while using filters to get a result.
>> >
>> > For eg.
>> > I have created a table and its specifications are as follows :
>> >
>> > table name --> test
>> > column family --> cf
>> > row keys --> rowKey1 - rowKey10 (10 different row keys)
>> > column qualifier --> integerData
>> >
>> > For different rowkeys, the qualifier 'integerData' contains either
>> positive
>> > or negative integer values (data loaded randomly).
>> >
>> > Now, while I am trying to retrieve the data from the table based on a
>> > filter
>> > condition, its failing to give the desired result.
>> >
>> > For eg. say,
>> > My table contains following data :
>> > [-50,-40,-30,-20,-10,10,20,30,40,50]
>> >
>> > I want to get only those values which are greater than or equal to 40.
>> > Following is the code for the filter set on scan :
>> >
>> > ********************************************
>> >   Scan scan = new Scan();
>> >   scan.addColumn(Bytes.toBytes("cf"), Bytes.toBytes(" integerData"));
>> >
>> >   int i = 40;
>> >   Filter filter = new ValueFilter(CompareOp.GREATER_OR_EQUAL,new
>> > BinaryComparator(Bytes.toBytes(i)));
>> >
>> >   scan.setFilter(filter);
>> > *********************************************
>> >
>> > The result should be : 40 and 50
>> > BUT, the actual result is : -50, -40, -30, -20, -10, 40, 50
>> >
>> > I have read few posts which addressed this issue, and few people
>> provided
>> > the solution as:
>> >
>> > 1) write a custom comparator, as BinaryComparator is not meant for
>> number
>> > comparison
>> > OR
>> > 2) retrieve all the values as integer and then compare
>> >
>> > BUT, I want to know if there is any other way to achieve this.
>> > Because this seems to be a very basic need, i.e. comparing numbers, and
>> I
>> > feel HBase should have something straight forward to deal with this.
>> > This comparison fails only when the negative numbers are involved.
>> >
>> > I am not able to get the right way to do it.
>> >
>> > Can anyone help me on this ?
>> >
>> >
>> >
>> > -----
>> > Regards,
>> > Chaitanya
>> > --
>> > View this message in context:
>> >
>> http://apache-hbase.679495.n3.nabble.com/Filters-failing-to-compare-negative-numbers-int-float-double-or-long-tp4057268.html
>> > Sent from the HBase User mailing list archive at Nabble.com.
>> >
>>
>
>
>
> --
> Best Regards,
> Haosdent Huang
>



-- 
Best Regards,
Haosdent Huang

Reply via email to