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?
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.
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.
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.
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.
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.
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With