[英]The method raw() from the type Result is deprecated
在我们最新的CDH集群升级中,我们已经讨论了许多被弃用的方法和类。
一个这样的例子是方法raw(),我用它来从我们的Hbase表记录中获取epochTimestamp,如下所示:
String epochTimestamp = String.valueOf(values.raw()[0].getTimestamp());
我的PM要求我摆脱所有这些已弃用的功能,并用最新的功能替换掉。
来自https://hbase.apache.org/apidocs/org/apache/hadoop/hbase/client/Result.html我发现listCells相当于raw(),但任何人都可以帮助我如何从中获取epochTimestamp使用listCells的HBase记录?
替代
raw()
可能是迭代:
result.listCells()
哪个给你一个单元格,然后获取值,使用:
CellUtil.cloneValue(cell)
查看文档:
https://hbase.apache.org/apidocs/org/apache/hadoop/hbase/CellUtil.html
例:
for (Cell cell : result.listCells()) {
String row = new String(CellUtil.cloneRow(cell));
String family = new String(CellUtil.cloneFamily(cell));
String column = new String(CellUtil.cloneQualifier(cell));
String value = new String(CellUtil.cloneValue(cell));
long timestamp = cell.getTimestamp();
System.out.printf("%-20s column=%s:%s, timestamp=%s,
value=%s\n", row, family, column, timestamp, value);
}
根据文件 :
公共列表listCells()
在此结果中创建单元格的排序列表。 由于HBase 0.20.5,这相当于raw()。
因此,您的代码应该是:
String epochTimestamp = String.valueOf(values.listCells().get(0).getTimestamp());
要获取所有列和值,您可以使用如下的CellUtil:
List<Cell> cells = listCells();
Map<String, String> result = new HashMap<>();
for (Cell c : cells) {
result.put(Bytes.toString(CellUtil.cloneQualifier(c)),Bytes.toString(CellUtil.cloneValue(c)));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.