Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

group by bit

group by bit

Contributor

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

4 REPLIES 4

ImRe: group by bit

Master Collaborator

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.

Re: ImRe: group by bit

Master Collaborator

I just realized we have a getbit() function that may be more convenient.

Highlighted

Re: ImRe: group by bit

Contributor

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

Re: ImRe: group by bit

Master Collaborator

Thanks for clarifying. Your approach sounds reasonable.

Don't have an account?
Coming from Hortonworks? Activate your account here