在hbase中我有多列:名称,城市,...
并非所有列都具有值(例如,某些行只能包含“名称”)
我想提取一行中的所有列+列的时间戳(按特定顺序),以防值为null我想返回空字符串。
我遇到的问题是,我必须通过'family'和'qualifier'访问Result
中的列(我无法通过result.listCells().get(i)
的索引访问,因为会跳过空值)
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...
}
答案 0 :(得分:1)
您可以尝试使用CellScanner。见下面的例子:
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();
.....
}