简体   繁体   中英

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. It produces a navigablemap with byte[] as key and value.But when i try to do entries.getValue(), i donot get any data.

    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 . And indeed, you won't have a key in byteMap that corresponds to that value. All you need to log is:

logger.debug("Value:: "+Bytes.toString(value));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM