To get column qualifiers by column family we can use following code
1 2 3 4 5 6 7 8 |
Get get = new Get(Bytes.toBytes("rowA")); Table table = conn.getTable(TableName.valueOf("merchants")); Result result = table.get(get); Map<byte[], byte[]> familyMap = result.getFamilyMap(Bytes.toBytes("basicInfo")); for(Map.Entry<byte[], byte[]> entry:familyMap.entrySet()){ System.out.println(Bytes.toString(entry.getKey())); } |
Above code will outputs all column qualifer names of family map "basicInfo" in table "merchants".
And following code shows different ways to retrieve HBase cell value
1 2 3 4 5 6 7 8 9 10 11 12 |
private void getData() throws IOException { Get get = new Get(Bytes.toBytes("row1")); Table table = conn.getTable(TableName.valueOf("merchants")); Result result = table.get(get); byte[] value = result.getValue(Bytes.toBytes("merchantNo"), Bytes.toBytes("string")); System.out.println(Bytes.toString(value)); Map<byte[], byte[]> familyMap = result.getFamilyMap(Bytes.toBytes("merchantNo")); for(Map.Entry<byte[], byte[]> entry:familyMap.entrySet()){ System.out.println(Bytes.toString(entry.getKey()) + ", " + Bytes.toString(entry.getValue())); } } |
- Get Cell by Family Map and Column Qualifier
1 |
byte[] value = result.getValue(Bytes.toBytes("merchantNo"), Bytes.toBytes("string")); |
This line of code retrives cell value by family map "merchantNo" and column qualifier "string"
- Get All Cells by Faimily Map
1 2 3 4 |
Map<byte[], byte[]> familyMap = result.getFamilyMap(Bytes.toBytes("merchantNo")); for(Map.Entry<byte[], byte[]> entry:familyMap.entrySet()){ System.out.println(Bytes.toString(entry.getKey()) + ", " + Bytes.toString(entry.getValue())); } |
result.getFamilyMap(Bytes.toBytes("merchantNo")) will return column family map with name "merchantNo", it contains column qualifier name as key and cell value as value.
1 2 3 |
for(Map.Entry<byte[], byte[]> entry:familyMap.entrySet()){ System.out.println(Bytes.toString(entry.getKey()) + ", " + Bytes.toString(entry.getValue())); } |
Above code will iterate the column family map, and outputs each column qualifier and its corresponding cell value.