大家好,小弟最近研究hadoop研究,
小弟希望在hbase中利用filterlist篩選出很多筆資料,
但是篩選的條件的個數可以是變數,小弟想到的方法是利用array但是顯然filter並沒有array。
請問各位先進有什麼方法可以解決類似的問題呢?
附上小弟的程式碼
代碼:
Configuration conf = HBaseConfiguration.create();
HTable table = new HTable(conf, TABLENAME);
Scan scan = new Scan();
scan.addColumn(Bytes.toBytes(TABLENAME), Bytes.toBytes("COLUMN"));//family name & column name
List<Filter> filters = new ArrayList<Filter>();
for(channelnum=0;channelnum<args.length-2;channelnum++){
Filter filter[channelnum] = new ValueFilter(CompareFilter.CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes(args[channelnum+2])));
filters.add(filter[channelnum]);
}
FilterList filterlist = new FilterList(FilterList.Operator.MUST_PASS_ONE, filters);
scan.setFilter(filterlist);
ResultScanner scanner = table.getScanner(scan);
for(Result res : scanner){
for (KeyValue kv : res.raw()) {
System.out.println(String.format("row:%s, family:%s, qualifier:%s, qualifiervalue:%s, timestamp:%s.",
Bytes.toString(kv.getRow()),
Bytes.toString(kv.getFamily()),
Bytes.toString(kv.getQualifier()),
Bytes.toString(kv.getValue()),
kv.getTimestamp()));
}
}
scanner.close();