【问题标题】:How to read a string from HBase result?如何从 HBase 结果中读取字符串?
【发布时间】:2014-11-13 09:08:37
【问题描述】:

我正在使用 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

有什么可能的原因吗?

【问题讨论】:

    标签: java hadoop hbase


    【解决方案1】:

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

    我想你想要这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-06
      • 2013-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-11
      • 1970-01-01
      相关资源
      最近更新 更多