hbase时间段查询、模糊匹配

比较运算符 CompareFilter.CompareOp
EQUAL                                  相等
GREATER                              大于
GREATER_OR_EQUAL           大于等于
LESS                                      小于
LESS_OR_EQUAL                  小于等于
NOT_EQUAL                        不等于

SingleColumnValueFilter列值过滤器(时间段查询)

FilterList filterList=new FilterList();
String stime = "2016-07-27 00:00:00";
String etime = "2016-07-30 12:04:42";
Filter stimeFilter = new SingleColumnValueFilter(Bytes.toBytes("base_info"),Bytes.toBytes("dateTime"), CompareOp.GREATER_OR_EQUAL, Bytes.toBytes(stime));
filterList.addFilter(stimeFilter);
Filter etimeFilter = new SingleColumnValueFilter(Bytes.toBytes("base_info"),Bytes.toBytes("dateTime"), CompareOp.LESS_OR_EQUAL,Bytes.toBytes(etime));
filterList.addFilter(etimeFilter);
scan.setFilter(filterList);
模糊匹配

FilterList filterList=new FilterList();
SubstringComparator comp = new SubstringComparator("123456789");
Filter likeFilter = new SingleColumnValueFilter(Bytes.toBytes("base_info"),
Bytes.toBytes("userId"), CompareOp.EQUAL, comp);
filterList.addFilter(likeFilter);
scan.setFilter(filterList);
完全匹配

Filter equalFilter = new SingleColumnValueFilter(Bytes.toBytes("base_info"),
Bytes.toBytes("userId"), CompareOp.EQUAL, "123456789");
PageFilter指定页面行数,返回对应行数的结果集。最多返回100条数据

FilterList filterList=new FilterList();
Filter pageFilter = new PageFilter(100);
filterList.addFilter(pageFilter);
多条件联合查询

FilterList filterList=new FilterList();
//如果先设置最大返回条数,会先查询出100条数据,在这100条数据中  再过滤userId为123456789的数据。filter顺序要特别注意,会造成查询不准确。
Filter pageFilter = new PageFilter(100);
filterList.addFilter(pageFilter);
SubstringComparator comp = new SubstringComparator("123456789");
Filter likeFilter = new SingleColumnValueFilter(Bytes.toBytes("base_info"),
Bytes.toBytes("userId"), CompareOp.EQUAL, comp);
filterList.addFilter(likeFilter);
scan.setFilter(filterList);






你可能感兴趣的:(Hbase)