使用MapReduce程序将值发送到HBase表时出错

时间:2016-12-23 06:27:20

标签: java mapreduce hbase

我编写了一个mapreduce程序,我需要从特定的列族中读取HBase表中的数据。

例如,HBase表中的数据如下所示:

Row    Column+Cell

1        column=Name:FName, timestamp=...,value=ABC

1        column=Name:LName, timestamp=...,value=XYZ

现在我需要将FName和LName作为FullName附加到同一列族下的另一列中。在地图中,我提取数据并附加数据并发送到reducer。

在Reducer中,我只是获取键值对,并尝试将FullName添加到表中。

我的reducer实现如下:

public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
  Put put = new Put(Bytes.toBytes(key.toString()));
  put.add(Bytes.toBytes("Name"), Bytes.toBytes("FullName"), Bytes.toBytes(values.toString()));
  context.write(null, put);
}

当我检查hbase表中的Fullname时,值不是&#34; ABCXYZ&#34;相反,我得到的值为org.apache.hadoop.mapreduce.task.ReduceContextImpl$ValueIterable

请告诉我如何解决此问题。

1 个答案:

答案 0 :(得分:0)

reduce函数中的

values参数是Iterable,而不是单个值。这是因为通常使用reduce来减少具有相同键的多个值。但是在你的程序中,每个键只有一个值。您可以使用values.next()从此可迭代中获取第一个值。在不调用next()的情况下,您只需在Iterable对象本身上调用toString()方法,该方法将打印其类名。

顺便说一句,因为您不需要减少多个值,您可以将hadoop配置为完全运行而不使用reducer - 仅使用映射器。