zoukankan      html  css  js  c++  java
  • Hbase 过滤器的使用

    
    
              Filter filter=  new RowFilter(CompareFilter.CompareOp.EQUAL,new RegexStringComparator("."+day));//任意以day结尾的row
               Filter filter=   new RowFilter(CompareFilter.CompareOp.EQUAL, new SubstringComparator(day)); //包含给定字符串的row


    根据前缀进行那一天的查询
    */ public Map<String,Long> prefixQuery(String tableName,String day){ Map<String,Long> map=new HashMap<>(); HTable table= getTable(tableName); Scan scan=new Scan(); // Filter filter=new PrefixFilter(Bytes.toBytes(day)); Filter filter= new RowFilter(CompareFilter.CompareOp.EQUAL,new RegexStringComparator("."+day));//任意以day结尾的row // Filter filter= new RowFilter(CompareFilter.CompareOp.EQUAL, new SubstringComparator(day)); //包含给定字符串的row scan.setFilter(filter); try { ResultScanner rs= table.getScanner(scan); for (Result result:rs){ String row=Bytes.toString(result.getRow()); /* 读取的同时会映射为对象,对象其中的一个成员为: @HBaseColumn(qualifier = "logCount", isKpi = true, defaultFuncName = MeasureAggregator.FUNC_SUM) public Long logCount; //广告展示次数 然而,scan数据为: 总结,就是希望读取的内容格式是Long,而实际上存储的形式确是String。所以会出现读取异常的错误。 */ long value= Long.parseLong(Bytes.toString(result.getValue(Bytes.toBytes("info"),Bytes.toBytes("accountNum")))); map.put(row,value); } } catch (IOException e) { e.printStackTrace(); } return map; }
  • 相关阅读:
    2.6
    zuoye
    练习1
    练习
    练习
    4
    3
    2
    1
    1.3
  • 原文地址:https://www.cnblogs.com/hejunhong/p/10283938.html
Copyright © 2011-2022 走看看