[英]Getting all the column values for a particular row in Hbase
I wanted to get all the columns under the different columnfamily in hbase for a particular row and the below is the code that i tried to implement using getFamilyMap.我想为特定行获取 hbase 中不同列族下的所有列,下面是我尝试使用 getFamilyMap 实现的代码。 It produces a navigablemap with byte[] as key and value.But when i try to do entries.getValue(), i donot get any data.
它生成一个以 byte[] 作为键和值的 navigablemap。但是当我尝试执行 entry.getValue() 时,我没有得到任何数据。
Table table = connection.getTable(TableName.valueOf(tableName));
Get getVal = new Get(Bytes.toBytes(input));
// Reading the data
Result result = table.get(getVal);
NavigableMap<byte[], byte[]> byteMap = result.getFamilyMap(cfName.getBytes());
for(Map.Entry<byte[],byte[]> entries: byteMap.entrySet()){
byte[] temp = entries.getKey();
byte[] value = entries.getValue();
logger.debug("key:: "+Bytes.toString(temp));
logger.debug("Value:: "+Bytes.toString(byteMap.get(value)));
}
But the below code if i provide, i do get the key and the value.但是如果我提供下面的代码,我确实得到了键和值。 Please let me know whats the difference between these two code and how does the value of the map is affected?
请让我知道这两个代码之间的区别是什么以及地图的值如何受到影响?
for(byte[] map : byteMap.keySet()){
logger.debug("key:: "+Bytes.toString(map));
logger.debug("Value:: "+Bytes.toString(byteMap.get(map)));
}
Looking at these lines of the failing example:查看失败示例的这些行:
byte[] value = entries.getValue();
logger.debug("Value:: "+Bytes.toString(byteMap.get(value)));
You've already got the value as byte[]
, so you don't need to retrieve anything from the byteMap
.您已经获得了
byte[]
的值,因此您不需要从byteMap
检索任何byteMap
。 And indeed, you won't have a key in byteMap
that corresponds to that value.实际上,您在
byteMap
中不会有对应于该值的键。 All you need to log is:您只需要登录:
logger.debug("Value:: "+Bytes.toString(value));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.