@Testpublic void testCreateTable() { HBaseUtils.createTable("SUGAR_TEST");}@Testpublic void testPut() { TestEntity entity = new TestEntity(); entity.setServiceId(10002L); entity.setDataType(2); entity.setOnTime(new Date()); entity.setServiceCode("A2000100010001"); entity.setRow("0266e33d15264525258891"); HBaseUtils.put(entity);}@Testpublic void testPutMap() { Map<String, Object> map = new HashMap<>(); map.put("SERVICE_ID", 10003L); map.put("DATA_TYPE", 2); map.put("AT_TIME", null); map.put("SERVICE_CODE", "A3000100010001"); map.put("ROW", "0266e33d15264525258892"); HBaseUtils.putMap(map, "SUGAR_TEST");}@Testpublic void testGet() { TestEntity entity = HBaseUtils.get("0266e33d15264525258890", TestEntity.class); System.out.println(entity);}@Testpublic void testGetMap() { Map<String, Object> map = HBaseUtils.get("SUGAR_TEST", "0266e33d15264525258890", new IValueMapper() { @Override public Object mapValue(String column, byte[] value) { if (value == null || value.length == 0) { return null; } switch (column) { case "AT_TIME": return new Date(Bytes.toLong(value)); case "DEST_PORT": case "DATA_TYPE": return Bytes.toInt(value); case "SERVICE_ID": return Bytes.toLong(value); default: return Bytes.toString(value); } } }); System.out.println(map);}@Testpublic void testScan() { List<TestEntity> list = HBaseUtils.scan(new Scan(), TestEntity.class); System.out.println(list);}@Testpublic void testScanMap() { List<Map<String, Object>> list = HBaseUtils.scan("SUGAR_TEST", new Scan(), new IValueMapper() { @Override public Object mapValue(String column, byte[] value) { if (value == null || value.length == 0) { return null; } switch (column) { case "AT_TIME": return new Date(Bytes.toLong(value)); case "DEST_PORT": case "DATA_TYPE": return Bytes.toInt(value); case "SERVICE_ID": return Bytes.toLong(value); default: return Bytes.toString(value); } } }); System.out.println(list);}`
请发表评论