写入HBase的数据不对
如
读入的数据是
Hello Hadoop
Hadoop is easy
存入数据库就成了
Hellop
Hadoop
isllop
easy
public class WordCountReducerHbase extends TableReducer<Text,IntWritable,
ImmutableBytesWritable>{
private IntWritable result = new IntWritable();
public void reduce(Text key,Iterable<IntWritable> values, Context context)
throws IOException,InterruptedException{
int sum = 0;
for(IntWritable val :values){
sum += val.get();
}
result.set(sum);
Put put = new Put(key.toString().getBytes()); //put实例化,每一个词存一行
//列族为content,列修饰符为count,列值为数目
System.out.println("key="+key.toString());
put.add(Bytes.toBytes("content"), Bytes.toBytes("count"),
Bytes.toBytes(String.valueOf(sum)));
System.out.println("put="+put.getRow().toString());
context.write(new ImmutableBytesWritable(key.toString().getBytes()), put);
}
}
key 是从map获取的值
put的时候改成如上红色部分,先转换成String,再转换成Byte[]存储