繁体   English   中英

如何从HBase结果中读取字符串?

[英]How to read a string from HBase result?

我正在使用HBase MapReduce( docs )从HBase表读取字符串。 这是代码的一部分:

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);
        }

    }
}

有一个reducer可以将字符串输出到另一个HBase表,当我尝试使用来自mapper的一些硬代码字符串对其进行测试时,该适配器工作正常。 我已经从HBase Shell中检查了要读取的字符串是否设置正确。

但是,当我尝试将其作为行ID输入到HBase的另一个表中时,它变为未知字符串,如下所示:

[B @ fe2851
列=结果:计数,时间戳= 1415868730030,值= \\ x00 \\ x00 \\ x00 \\ x01
[B @ fe331c
列=结果:计数,时间戳= 1415868730030,值= \\ x00 \\ x00 \\ x00 \\ x01
[B @ fe6526
列=结果:计数,时间戳= 1415868730030,值= \\ x00 \\ x00 \\ x00 \\ x01
[B @ fe7a98
列=结果:计数,时间戳= 1415868730030,值= \\ x00 \\ x00 \\ x00 \\ x01

以下是预期结果:

苹果
列=结果:计数,时间戳= 1415868730030,值= \\ x00 \\ x00 \\ x00 \\ x01
橙子
列=结果:计数,时间戳= 1415868730030,值= \\ x00 \\ x00 \\ x00 \\ x01
香蕉
列=结果:计数,时间戳= 1415868730030,值= \\ x00 \\ x00 \\ x00 \\ x01
菠萝
列=结果:计数,时间戳= 1415868730030,值= \\ x00 \\ x00 \\ x00 \\ x01

关于可能原因的任何线索?

您正在写的数组的字符串名称是[B@fe6526或类似名称。

我想您想要这个:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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