在 hbase 中,我有列数:名称、城市……
并非所有列都有值(例如,某些行只能有“名称”)
我想提取行中的所有列+列的时间戳(按特定顺序),如果值为空,我想返回空字符串。
我面临的问题是,我必须Result
通过“family”和“qualifier”访问列(我无法通过索引访问,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...
}
Run Code Online (Sandbox Code Playgroud)
您可以尝试使用 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();
.....
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4720 次 |
最近记录: |