Setup:
I have an HBase table, with 100M+ rows and 1 Million+ columns. Every row has data for only 2 to 5 columns. There is in just 1 Column Family.
Problem:
I want to find out all the distinct qualifiers
(columns) in this column family
. Is there a quick way to do that?
I can think of about scanning the whole table, then getting familyMap
for each row, get qualifier
and add it to a Set<>
. But that would be awfully slow, as there are 100M+ rows.
Can we do any better?
You can use a mapreduce for this. In this case you don't need to install a custom libs for hbase as in case for coprocessor. Below a code for creating a mapreduce task.
Job setup
Mapper
}
Reducer
HBase Coprocessors can be used for this scenario. You can write custom EndPoint implementation which works like Stored Procedures in RDBMS. It executes your code on server side and get distinct columns for each region. On client you can get the distinct columns across all regions.
Performance Benefit: All columns are not transferred to the client which results in reduced network calls.
HBase can be visualised as a distributed
NavigableMap<byte[], NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>>>
There is no "metadata" (say something centrally stored in the master node) about the list of all qualifiers that's available in all region servers.
So if you have a one-time use-case, the only way for you would be to scan through the entire table and add the qualifier names in a
Set<>
, like you mentioned.If this is a repeat use-case (plus if you have the discretion to add components to your tech stack), you may want to consider adding Redis. Set of qualifiers can be maintained in a distributed fashion using a Redis Set.