scan的操作:
hbase(main):002:0> scan 'scores'
ROW COLUMN+CELL
zkb column=course:, timestamp=1356629086396, value=90
zkb column=course:art, timestamp=1356629086401, value=87
zkb column=course:math, timestamp=1356629086398, value=97
zkb column=grade:, timestamp=1356629086385, value=5
1 row(s) in 0.2260 seconds
public static void scanBySingleColumnValueFilter(String tableName,
String family, String qual, String value) throws IOException {//这个地方需要注意value的数据类型,否则及其容易出错
HTable table = new HTable(conf, tableName);
byte[] b_family = Bytes.toBytes(family);
byte[] b_qual = Bytes.toBytes(qual);
byte[] b_value = Bytes.toBytes(value);
FilterList filterList = new FilterList();
SingleColumnValueFilter singleColumnValueFilter = new SingleColumnValueFilter(
b_family, b_qual, CompareOp.EQUAL, b_value);
// singleColumnValueFilter.setFilterIfMissing(true);
filterList.addFilter(singleColumnValueFilter);
Scan scan = new Scan();
scan.setFilter(filterList);
scan.addColumn(b_family, b_qual);
ResultScanner rs = table.getScanner(scan);
showResultScanner(rs);
}
show结果
public static void showResultScanner(ResultScanner rs){
for(Result r:rs){
for(KeyValue kv : r.raw()){
System.out.print(new String(kv.getRow()) + " ");
System.out.print(new String(kv.getFamily()) + ":");
System.out.print(new String(kv.getQualifier()) + " ");
System.out.print(kv.getTimestamp() + " ");
System.out.println(new String(kv.getValue()));
}
}
}
在主函数里调用的时候
System.out.println("=========== scanBySingleColumnValueFilter =======");
HBaseClient.scanBySingleColumnValueFilter(tablename, "course", "art", "87");
结果:
=========== scanBySingleColumnValueFilter =======
zkb course:art 1357053302173 87。。。。没什么问题