Created 12-01-2016 09:03 PM
Hi,
I have a table with two fields : "user","some_integer"
And I was wondering if there is a way of doing something like:
select count(distinct("user")), "bit" from random_table group by bit(some_number);
Thanks
Created 12-01-2016 10:11 PM
Impala has bitwise AND/OR/XOR. For example, you can:
select count(distinct("user")), some_number & mask as bit from random_table group by bit;
You construct 'mask' to zero out all bits except the one you want.
Created 12-01-2016 11:09 PM
I just realized we have a getbit() function that may be more convenient.
Created on 12-02-2016 02:04 PM - edited 12-02-2016 02:08 PM
Thanks for you answer!
I actualy want to group by all the possible mask of a single 1 bit.
thanks to you I think I have a solution:
I will first construct a table with all my masks (1,2,4,8,...) and then do a join with my table with an "and" operator. That should "epxlode" my rows to have all possible groups filtering all "bit"=0 to only have the valid groups.
Not exactly sure about how my query will look like yet... But i think it should be possible that way
thanks
Created 12-02-2016 10:40 PM
Thanks for clarifying. Your approach sounds reasonable.