简体   繁体   中英

How to read a string from HBase result?

I am using HBase MapReduce ( docs ) to read strings from HBase table. Here is part of the code:

public void map(ImmutableBytesWritable row, Result values, Context context) throws IOException {

    String testing = values.getValue(Bytes.toBytes("data"),Bytes.toBytes("lastLine")).toString();

        try {
            context.write(new ImmutableBytesWritable(Bytes.toBytes(testing)), new IntWritable(1));
        } catch (InterruptedException e) {
            throw new IOException(e);
        }

    }
}

There is a reducer to output the string to another HBase table, which works fine when I try testing it with some hard code strings from mapper. I have checked from HBase shell that the string to be read is set correctly.

However, when I try to input that into another table in HBase as row id, it becomes unknown string like the following:

[B@fe2851
column=result:count, timestamp=1415868730030, value=\\x00\\x00\\x00\\x01
[B@fe331c
column=result:count, timestamp=1415868730030, value=\\x00\\x00\\x00\\x01
[B@fe6526
column=result:count, timestamp=1415868730030, value=\\x00\\x00\\x00\\x01
[B@fe7a98
column=result:count, timestamp=1415868730030, value=\\x00\\x00\\x00\\x01

The following is the expected result:

apple
column=result:count, timestamp=1415868730030, value=\\x00\\x00\\x00\\x01
orange
column=result:count, timestamp=1415868730030, value=\\x00\\x00\\x00\\x01
banana
column=result:count, timestamp=1415868730030, value=\\x00\\x00\\x00\\x01
pineapple
column=result:count, timestamp=1415868730030, value=\\x00\\x00\\x00\\x01

Any clue on what is the possible reason?

You are writing the string name of the array which is [B@fe6526 or similar.

I think you wanted this one:

byte[] testing = values.getValue(Bytes.toBytes("data"), Bytes.toBytes("lastLine"));
context.write(new ImmutableBytesWritable(testing), new IntWritable(1));

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