首先来can下表:
hbase(main):004:0> scan 'scores'
ROW COLUMN+CELL
zkb column=course:, timestamp=1356625587787, value=90
zkb column=course:art, timestamp=1356625587791, value=87
zkb column=course:math, timestamp=1356625587789, value=97
zkb column=grade:, timestamp=1356625587776, value=5
1 row(s) in 0.2280 seconds
然后是写的一个scan filter 函数:
public static void scanValueByFilter(String tableName,String row) throws IOException{
HTable table = new HTable(conf, tableName);
Scan scan = new Scan();
scan.setFilter(new PrefixFilter(row.getBytes()));
ResultScanner resultScanner = table.getScanner(scan);
for(Result rs:resultScanner){
for(KeyValue kv:rs.raw()){
StringBuilder sb = new StringBuilder();
System.out.println(sb.append("Row/Family:qual: ").append(new String(kv.getRow())).append("/").append(new String(kv.getFamily())).append(":").append(new String(kv.getQualifier())));
System.out.println("kv.getFamily(): "+new String(kv.getFamily()));
System.out.println("kv.getRow(): "+new String(kv.getRow()));
System.out.println("kv.getQualifier(): "+new String(kv.getQualifier()));
System.out.println("kv.getTimestamp(): "+new String(String.valueOf(kv.getTimestamp())));
System.out.println(new String(kv.getValue()));
System.out.println("---------------------------------");
}
}
}
直接调用: HBaseClient.scanValueByFilter(tablename,"zkb");
结果:
Row/Family:qual: zkb/course:
kv.getFamily(): course
kv.getRow(): zkb
kv.getQualifier():
kv.getTimestamp(): 1356626264657
90
---------------------------------
Row/Family:qual: zkb/course:art
kv.getFamily(): course
kv.getRow(): zkb
kv.getQualifier(): art
kv.getTimestamp(): 1356626264680
87
---------------------------------
Row/Family:qual: zkb/course:math
kv.getFamily(): course
kv.getRow(): zkb
kv.getQualifier(): math
kv.getTimestamp(): 1356626264674
97 www.zzzyk.com
---------------------------------
Row/Family:qual: zkb/grade:
kv.getFamily(): grade
kv.getRow(): zkb
kv.getQualifier():
kv.getTimestamp(): 1356626264637
5