需求来自于,模糊查找当天的所有记录,并查找对应列的记录数

public static void main(String[] args) throws Exception{
//创建HBase连接 Configuration conf
= HBaseConfiguration.create();
//设定需要查询的表 HTable table
= new HTable(conf,"EVENT_LOG_LBS_HIS"); Scan scan = new Scan();
//设定模糊时间戳 String startStr
= "-20160530";
//使用Hbase内置过滤器 scan.setFilter(findCount(startStr)); ResultScanner rowscan
= table.getScanner(scan); int i = 1;
//遍历结果
for(Result rs : rowscan){ System.out.println("第" + i + "条: rowkey= " + Bytes.toString(rs.getRow())); i++;
//根据结果行中某一列的值,进行条件筛选 String aaa
= Bytes.toString(rs.getValue("f1".getBytes(),"LS_channel_type".getBytes())); if(aaa.equals("2"){ System.out.println(Bytes.toString(rs.getRow())); } } public static FilterList findCount(String startstr){ Filter filter = new RowFilter(CompareFilter.CompareOp.GREATER_OR_EQUAL,new RegexStringComparator(startstr)); return filter; }

 其实可以都写成内置过滤器,不过HBase还没有深入学习,暂时先这样写啦~

相关文章:

  • 2021-12-27
  • 2021-11-09
  • 2022-12-23
  • 2021-05-31
  • 1970-01-01
  • 2021-12-05
  • 2021-07-07
  • 2021-05-16
猜你喜欢
  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
  • 2022-01-21
  • 2021-06-06
  • 2021-12-27
相关资源
相似解决方案