9
votes

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?

2
I reach to a answer, if you have another solution, please advice me. for (Result rr = scanner.next() ; rr != null; rr = scanner.next()) { NavigableMap familyMap = rr.getFamilyMap(Bytes.toBytes("Info")); byte[] y = (byte[])familyMap.firstEntry().getKey(); System.out.println(Bytes.toString(y)); }Mahdi

2 Answers

12
votes
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.

9
votes

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));