MRUnit在hbase Result对象中传递值 [英] MRUnit passing values in hbase Result object
本文介绍了MRUnit在hbase Result对象中传递值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用MRUnit测试我的映射器。我将键和值列表作为输入从测试类传递给映射器。
问题是:
I am testing my mapper with MRUnit. I am passing key and list of values as input to the mapper from the test class. The problem is :
String key=1234_abc;
ArrayList<KeyValue> list = new ArrayList<KeyValue>();
KeyValue k1 = new KeyValue(Bytes.toBytes(key),"cf".getBytes(), "Val1".getBytes(),Bytes.toBytes("abc.com"));
KeyValue k2 = new KeyValue(Bytes.toBytes(key), "cf".getBytes(), "Val2".getBytes(),Bytes.toBytes("165"));
Result result = new Result(list);
mapDriver.withInput(key, result);
问题是在结果对象中只保留了第一个键值。其他人被存储为空。
The problem is while in the result object only the first keyvalue is retained. The others are getting stored as null.
推荐答案
问题是HBase以字典顺序存储列。它看起来像结果(KeyValue [] kvs)或结果(列表kvs)构造函数期望在同一顺序。
The problem is HBase stores columns in a lexicographic order. It looks like the Result(KeyValue[] kvs) or Result(List kvs) constructor expects in the same order.
这是解决方案!
TreeSet<KeyValue> set = new TreeSet<KeyValue>(KeyValue.COMPARATOR);
byte[] row = Bytes.toBytes("row01");
byte[] cf = Bytes.toBytes("cf");
set.add(new KeyValue(row, cf, "cone".getBytes(), Bytes.toBytes("row01_cone_one")));
set.add(new KeyValue(row, cf, "ctwo".getBytes(), Bytes.toBytes("row01_ctwo_two")));
set.add(new KeyValue(row, cf, "cthree".getBytes(), Bytes.toBytes("row01_cthree_three")));
set.add(new KeyValue(row, cf, "cfour".getBytes(), Bytes.toBytes("row01_cfour_four")));
set.add(new KeyValue(row, cf, "cfive".getBytes(), Bytes.toBytes("row01_cfive_five")));
set.add(new KeyValue(row, cf, "csix".getBytes(), Bytes.toBytes("row01_csix_six")));
KeyValue[] kvs = new KeyValue[set.size()];
set.toArray(kvs);
Result result = new Result(kvs);
mapDriver.withInput(key, result);
希望这会有所帮助!
这篇关于MRUnit在hbase Result对象中传递值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文