alibaba / wasp

megastore-like system
http://alibaba.github.io/wasp/
Apache License 2.0
189 stars 80 forks source link

condition won't work on negative number #11

Closed colorant closed 11 years ago

colorant commented 11 years ago

I can see that when stored in index table, the negative number is stored as it is. (say with the flip flag solution, thus the bytes representation of negative number is large than the positive number)

Thus, hbase will sort the row - key with positive number ahead of negative number

And I not yet read code to find out how you fetch index out of index table, but assuming that you will use hbase's row order directly, under this condition, the condition clause won't work right. e.g.

wasp(main):055:0> query "select * from Photo where user_id=-2" +----------+-----------+------------+-----------+----------------+-------+ | user_id | photo_id | time | full_url | thumbnail_url | tag | +----------+-----------+------------+-----------+----------------+-------+ | -2 | -502 | -20130728 | fullurl2 | thumburl2 | tag2 | +----------+-----------+------------+-----------+----------------+-------+

wasp(main):054:0> query "select * from Photo where user_id<5" +--+ | | +--+ +--+

jaywong85 commented 11 years ago

use_id is a primary key or index?

colorant commented 11 years ago

part of primary key, and I create index for it too.

colorant commented 11 years ago

And it doesn't matter that it is PK or not. I think it is just relate to the negative number 's format. same on time filed which is not PK but index

wasp(main):004:0> query "select * from Photo where time=-20130728" +----------+-----------+------------+-----------+----------------+-------+ | user_id | photo_id | time | full_url | thumbnail_url | tag | +----------+-----------+------------+-----------+----------------+-------+ | -2 | -502 | -20130728 | fullurl2 | thumburl2 | tag2 | +----------+-----------+------------+-----------+----------------+-------+

wasp(main):002:0> query "select * from Photo where time<5" +--+ | | +--+ +--+

colorant commented 11 years ago

You can see that on Phoenix https://github.com/forcedotcom/phoenix, the number is stored in a format that the flag bit is flipped in order to do sort correctly.

jaywong85 commented 11 years ago

OK. it's a bug.... thx for your great report. :+1:

jaywong85 commented 11 years ago

the bug fixed. please pull the newest code