Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Columns in a specific Column Family for a row HBase

Tags:

java

hadoop

hbase

I'm writing a application that shows data in a specific table in HBase by JSP. I want to get all columns in a specific column family for a row.

is there any way for do this?

like image 943
Mahdi Avatar asked Mar 17 '12 11:03

Mahdi


People also ask

What is the use of get () method in HBase?

You can retrieve data from the HBase table using the get() method of the HTable class. This method extracts a cell from a given row. It requires a Get class object as parameter.

What is the use of column family in HBase?

An HBase table is made of column families which are the logical and physical grouping of columns. The columns in one family are stored separately from the columns in another family. If you have data that is not often queried, assign that data to a separate column family.

What is column qualifier in HBase?

An HBase table contains column families , which are the logical and physical grouping of columns. There are column qualifiers inside of a column family, which are the columns. Column families contain columns with time stamped versions. Columns only exist when they are inserted, which makes HBase a sparse database.

How do I get all columns in HBase?

There is actually no way to find all the columns without scanning the file. The reason is that there is no globally defined schema for HBase tables. Each row knows what columns it has, but nothing else knows. As such, you have to scan the table to find the column names.


2 Answers

public String[] getColumnsInColumnFamily(Result r, String ColumnFamily)
{

      NavigableMap<byte[], byte[]> familyMap = r.getFamilyMap(Bytes.toBytes(ColumnFamily));
      String[] Quantifers = new String[familyMap.size()];

      int counter = 0;
      for(byte[] bQunitifer : familyMap.keySet())
      {
          Quantifers[counter++] = Bytes.toString(bQunitifer);

      }

      return Quantifers;
}

Result r is as a desirable row.

like image 62
Mahdi Avatar answered Sep 28 '22 06:09

Mahdi


If you are just interested in a single family you can set the scanner to fetch only that family

    Scan scan = new Scan(Bytes.toBytes(startKey),Bytes.toBytes(endKey);
    scan.addFamily(Bytes.toBytes(familyName));
like image 22
Arnon Rotem-Gal-Oz Avatar answered Sep 28 '22 06:09

Arnon Rotem-Gal-Oz