# common-hbase **Repository Path**: cnsugar/common-hbase ## Basic Information - **Project Name**: common-hbase - **Description**: hbase操作工具类库 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 9 - **Forks**: 0 - **Created**: 2019-01-08 - **Last Updated**: 2026-01-24 ## Categories & Tags **Categories**: database-dev **Tags**: None ## README # common-hbase #### 介绍 hbase操作工具类库 #### 测试示例 ```java @TestAlgorithm public void testCreateTable() { HBaseUtils.createTable("SUGAR_TEST"); } @TestAlgorithm public 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); } @TestAlgorithm public void testPutMap() { Map 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"); } @TestAlgorithm public void testGet() { TestEntity entity = HBaseUtils.get("0266e33d15264525258890", TestEntity.class); System.out.println(entity); } @TestAlgorithm public void testGetMap() { Map 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); } @TestAlgorithm public void testScan() { List list = HBaseUtils.scan(new Scan(), TestEntity.class); System.out.println(list); } @TestAlgorithm public void testScanMap() { List> 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); }` ```