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;
}