HBase表A有一个列族"info",2个列为"info:name"、"info:age", table = conn.getTable(tableName); Scan scan = new Scan(); 补全上述代码,实现查询name为"XiaoMing"的数据
时间: 2024-01-10 11:03:13 浏览: 29
以下是补全的代码:
```
table = conn.getTable(tableName);
Scan scan = new Scan();
Filter filter = new SingleColumnValueFilter(Bytes.toBytes("info"), Bytes.toBytes("name"), CompareOperator.EQUAL, Bytes.toBytes("XiaoMing"));
scan.setFilter(filter);
ResultScanner scanner = table.getScanner(scan);
for (Result result : scanner) {
String name = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("name")));
String age = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("age")));
System.out.println("Name: " + name + ", Age: " + age);
}
scanner.close();
```
以上代码使用了单列值过滤器(SingleColumnValueFilter),过滤条件为列族为"info",列名为"name",值为"XiaoMing"。查询结果会打印出符合条件的行的"name"和"age"列的值。