Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private MapDriver<ImmutableBytesWritable, Result, Text, Text> mapDriver;
- private HopperHbaseMapper hopperHbaseMapper;
- @Before
- public void setUp() {
- hopperHbaseMapper = new HopperHbaseMapper();
- mapDriver = MapDriver.newMapDriver(hopperHbaseMapper);
- }
- @Test
- public void testMapHbase() throws Exception {
- String testKey = "123";
- ImmutableBytesWritable key = new ImmutableBytesWritable(testKey.getBytes());
- List<KeyValue> keyValues = new ArrayList<KeyValue>();
- KeyValue keyValue1 = new KeyValue(testKey.getBytes(), "0".getBytes(), "first_name".getBytes(), "Joe".getBytes());
- KeyValue keyValue2 = new KeyValue(testKey.getBytes(), "0".getBytes(), "last_name".getBytes(), "Blow".getBytes());
- keyValues.add(keyValue1);
- keyValues.add(keyValue2);
- Result result = new Result(keyValues);
- mapDriver.withInput(key, result);
- mapDriver.withOutput(new Text(testKey), new Text(testKey + "tJoetBlow"));
- mapDriver.runTest();
- }
- 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);
- import org.apache.hadoop.hbase.{CellUtil, KeyValue}
- import scala.collection.immutable.TreeSet
- implicit val ordering = KeyValue.COMPARATOR
- val cells = TreeSet(
- CellUtil.createCell(toBytes("myRowKey"), toBytes("myColumnFamily"),toBytes("myQualifier1"), 1000L, KeyValue.Type.Minimum.getCode, toBytes("myValue1")),
- CellUtil.createCell(toBytes("myRowKey"), toBytes("myColumnFamily"),toBytes("myQualifier2"), 1000L, KeyValue.Type.Minimum.getCode, toBytes("myValue2")),
- CellUtil.createCell(toBytes("myRowKey"), toBytes("myColumnFamily"),toBytes("myQualifier3"), 1000L, KeyValue.Type.Minimum.getCode, toBytes("myValue3")),
- CellUtil.createCell(toBytes("myRowKey"), toBytes("myColumnFamily"),toBytes("myQualifier4"), 1000L, KeyValue.Type.Minimum.getCode, toBytes("myValue4")),
- CellUtil.createCell(toBytes("myRowKey"), toBytes("myColumnFamily"),toBytes("myQualifier5"), 1000L, KeyValue.Type.Minimum.getCode, toBytes("myValue5"))
- )
- val result = Result.create(cells.toArray)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement