Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HBase: Filters not working for negative integers

We have implemented QualifierFilter as well as ValueFilter (using BinaryComparator) of Hbase successfully and they are working fine for most of our cases. However they are failing in cases like number > -10 or number < -10

Please note that number = -10 is working perfectly fine. Also, number > 10 and number < 10 are also working fine.

If you want to see the code, please check following links:
1. QualifierFilter - Relevant lines are 126-142
2. Value Filter - Relevant lines are 107-128

As per this blog, this can be an issue with serialization if we want to store negative values for rowkeys and we should write our own serializers for comparison.
So we wanted to know:
1. Is it really necessary to write our own serializer in this case?
2. If yes, how? Any example would be great help.

like image 313
Easility Avatar asked Oct 22 '22 07:10

Easility


1 Answers

Since, Hbase has only BinaryComparators and not other 'typed' comparators, it fails to filter on Negative integers as it stores the 2's compliment of the negative number. Further, the binary representation of a negative 2’s Complement Integer would be lexicographically after the largest positive number and that's why it was not working.

The workaround is to change the signed bit of the number. Things are working fine after that. Please note that this is required only for integers and not for float types.

like image 121
Easility Avatar answered Oct 31 '22 14:10

Easility