Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. private MapDriver<ImmutableBytesWritable, Result, Text, Text> mapDriver;
  2. private HopperHbaseMapper hopperHbaseMapper;
  3.  
  4. @Before
  5. public void setUp() {
  6. hopperHbaseMapper = new HopperHbaseMapper();
  7. mapDriver = MapDriver.newMapDriver(hopperHbaseMapper);
  8. }
  9.  
  10. @Test
  11. public void testMapHbase() throws Exception {
  12. String testKey = "123";
  13. ImmutableBytesWritable key = new ImmutableBytesWritable(testKey.getBytes());
  14. List<KeyValue> keyValues = new ArrayList<KeyValue>();
  15. KeyValue keyValue1 = new KeyValue(testKey.getBytes(), "0".getBytes(), "first_name".getBytes(), "Joe".getBytes());
  16. KeyValue keyValue2 = new KeyValue(testKey.getBytes(), "0".getBytes(), "last_name".getBytes(), "Blow".getBytes());
  17. keyValues.add(keyValue1);
  18. keyValues.add(keyValue2);
  19. Result result = new Result(keyValues);
  20. mapDriver.withInput(key, result);
  21. mapDriver.withOutput(new Text(testKey), new Text(testKey + "tJoetBlow"));
  22. mapDriver.runTest();
  23. }
  24.  
  25. TreeSet<KeyValue> set = new TreeSet<KeyValue>(KeyValue.COMPARATOR);
  26.  
  27. byte[] row = Bytes.toBytes("row01");
  28. byte[] cf = Bytes.toBytes("cf");
  29. set.add(new KeyValue(row, cf, "cone".getBytes(), Bytes.toBytes("row01_cone_one")));
  30. set.add(new KeyValue(row, cf, "ctwo".getBytes(), Bytes.toBytes("row01_ctwo_two")));
  31. set.add(new KeyValue(row, cf, "cthree".getBytes(), Bytes.toBytes("row01_cthree_three")));
  32. set.add(new KeyValue(row, cf, "cfour".getBytes(), Bytes.toBytes("row01_cfour_four")));
  33. set.add(new KeyValue(row, cf, "cfive".getBytes(), Bytes.toBytes("row01_cfive_five")));
  34. set.add(new KeyValue(row, cf, "csix".getBytes(), Bytes.toBytes("row01_csix_six")));
  35.  
  36. KeyValue[] kvs = new KeyValue[set.size()];
  37. set.toArray(kvs);
  38.  
  39. Result result = new Result(kvs);
  40. mapDriver.withInput(key, result);
  41.  
  42. import org.apache.hadoop.hbase.{CellUtil, KeyValue}
  43. import scala.collection.immutable.TreeSet
  44.  
  45.  
  46. implicit val ordering = KeyValue.COMPARATOR
  47.  
  48. val cells = TreeSet(
  49. CellUtil.createCell(toBytes("myRowKey"), toBytes("myColumnFamily"),toBytes("myQualifier1"), 1000L, KeyValue.Type.Minimum.getCode, toBytes("myValue1")),
  50. CellUtil.createCell(toBytes("myRowKey"), toBytes("myColumnFamily"),toBytes("myQualifier2"), 1000L, KeyValue.Type.Minimum.getCode, toBytes("myValue2")),
  51. CellUtil.createCell(toBytes("myRowKey"), toBytes("myColumnFamily"),toBytes("myQualifier3"), 1000L, KeyValue.Type.Minimum.getCode, toBytes("myValue3")),
  52. CellUtil.createCell(toBytes("myRowKey"), toBytes("myColumnFamily"),toBytes("myQualifier4"), 1000L, KeyValue.Type.Minimum.getCode, toBytes("myValue4")),
  53. CellUtil.createCell(toBytes("myRowKey"), toBytes("myColumnFamily"),toBytes("myQualifier5"), 1000L, KeyValue.Type.Minimum.getCode, toBytes("myValue5"))
  54. )
  55.  
  56. val result = Result.create(cells.toArray)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement