refactor(hbase-lesson):调整 HBase 查询示例代码

- 注释掉 scanRowsWithFilter 方法调用
-重新组织 getKeyValue 方法参数
- 调整 scan.setLimit 参数值
- 修改行键前缀过滤器条件
- 优化代码格式和结构
This commit is contained in:
dev_xulongjin 2025-04-26 17:25:08 +08:00
parent 5a6475fb14
commit d62bb73cf3

View File

@ -29,9 +29,8 @@ public class task_DML_select {
// scanRows(table);
// getKeyValue(table,"000000");
// scanRowsWithFilter(table);
getFamily(table);
// 关闭连接
@ -122,7 +121,7 @@ public class task_DML_select {
//scan.withStopRow(Bytes.toBytes(stopMd5),false);
// 设置总共要扫描的行数
scan.setLimit(100000);
scan.setLimit(10000);
ResultScanner scanner = table.getScanner(scan);
// 扫描时的 迭代器
@ -142,13 +141,17 @@ public class task_DML_select {
Scan scan = new Scan();
scan.withStartRow(Bytes.toBytes("000001"), true);
scan.setLimit(10);
scan.setLimit(2);
// 行键前缀过滤器
Filter filter1 = new PrefixFilter(Bytes.toBytes("cd")); // 行键前缀过滤器
Filter filter1 = new PrefixFilter(Bytes.toBytes("00")); // 行键前缀过滤器
// 列值过滤器匹配到条件的行整行数据都将返回
SingleColumnValueFilter filter2 = new SingleColumnValueFilter(Bytes.toBytes("extra_info"), Bytes.toBytes("city"), CompareOperator.EQUAL, Bytes.toBytes("南京"));
SingleColumnValueFilter filter2 =
new SingleColumnValueFilter(Bytes.toBytes("extra_info"),
Bytes.toBytes("city"),
CompareOperator.EQUAL,
Bytes.toBytes("南京"));
ArrayList<Filter> filterList = new ArrayList<Filter>();
filterList.add(filter1);
@ -158,11 +161,9 @@ public class task_DML_select {
FilterList filters = new FilterList(FilterList.Operator.MUST_PASS_ALL, filterList);
//FilterListWithAND filters = new FilterListWithAND(filterList);
// 给scan参数设置过滤器条件
scan.setFilter(filters);
ResultScanner scanner = table.getScanner(scan);
Iterator<Result> iterator = scanner.iterator(); // 拿到行迭代器