Reputation: 2184
In hbase I have number of columns: name, city,...
Not all columns have values ( some rows can have only 'name' for example)
I want to extract all columns in a row + timestamp of column (in specific order), in case value is null I want to return empty string.
The problem that I facing, I must access column in Result
by 'family' and 'qualifier' (I can't access by index of result.listCells().get(i)
because null values are skipped)
scan.addColumn(Bytes.toBytes("personal data"), Bytes.toBytes("name"));
scan.addColumn(Bytes.toBytes("personal data"), Bytes.toBytes("city"));
ResultScanner scanner = table.getScanner(scan);
for (Result result = scanner.next(); result != null; result = scanner.next()){
byte [] valCity = result.getValue("personal data", "city"); //can't get timestamp using this
//check if valCity null write ("") else write the value
//next column...
}
Upvotes: 5
Views: 4850
Reputation: 3112
You can try to use a CellScanner for this. See example below:
CellScanner cellScanner = result.cellScanner();
while (cellScanner.advance()) {
Cell cell = cellScanner.current();
byte[] columnName = Bytes.copy(cell.getQualifierArray(),
cell.getQualifierOffset(),
cell.getQualifierLength());
byte[] familyName = Bytes.copy(cell.getFamilyArray(),
cell.getFamilyOffset(),
cell.getFamilyLength());
long timestamp = cell.getTimestamp();
.....
}
Upvotes: 2