大数据全系列 教程
1869个小节阅读:465.1k
目录
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
xxxxxxxxxx
/**查找某用户(rowkey以15893647910为前缀),并且type = 0所有通话记录
* 列族:basic
* 列:dnum,type,date,length
*/
public void findByFilter(String prefix,int type) throws IOException {
Scan scan = new Scan();
//指定查询的列族 select basic:* from itbaizhan:phone_log
scan.addFamily(Bytes.toBytes("basic"));
//指定查询的列
// select basic:dnum,basic:type,basic:date,basic:length
// from itbaizhan:phone_log
scan.addColumn(Bytes.toBytes("basic"),Bytes.toBytes("dnum"));
scan.addColumn(Bytes.toBytes("basic"),Bytes.toBytes("type"));
scan.addColumn(Bytes.toBytes("basic"),Bytes.toBytes("date"));
scan.addColumn(Bytes.toBytes("basic"),Bytes.toBytes("length"));
//两个查询条件之间的关系 and,必须同时满足才能查询出来
FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);
//rowkey前缀过滤器
PrefixFilter prefixFilter = new PrefixFilter(Bytes.toBytes(prefix));
filterList.addFilter(prefixFilter);
//列值过滤器
SingleColumnValueFilter valueFilter =
new SingleColumnValueFilter(
Bytes.toBytes("basic"),Bytes.toBytes("type"),
CompareOperator.EQUAL,Bytes.toBytes(0)
);
filterList.addFilter(valueFilter);
//为scan设置filterList
scan.setFilter(filterList);
//执行查询,并返回结果集
ResultScanner resultScanner = table.getScanner(scan);
//解析resultScanner
for(Result result:resultScanner){
printMsg(result);
}
}
private void printMsg(Result result) {
//1.解析result
Cell[] cells = result.rawCells();
String rowInfo = "rowkey:"+Bytes.toString(CellUtil.cloneRow(cells[0]));
rowInfo +=","+Bytes.toString(CellUtil.cloneQualifier(cells[0]))
+":"+Bytes.toString(CellUtil.cloneValue(cells[0]));
rowInfo +=","+Bytes.toString(CellUtil.cloneQualifier(cells[1]))
+":"+Bytes.toString(CellUtil.cloneValue(cells[1]));
rowInfo +=","+Bytes.toString(CellUtil.cloneQualifier(cells[2]))
+":"+Bytes.toInt(CellUtil.cloneValue(cells[2]));
rowInfo +=","+Bytes.toString(CellUtil.cloneQualifier(cells[3]))
+":"+Bytes.toInt(CellUtil.cloneValue(cells[3]));
//2输出
System.out.println(rowInfo);
}
public static void main(String[] args) throws IOException {
CallLogDemo callLogDemo = new CallLogDemo();
callLogDemo.before();
callLogDemo.findByFilter("15893647910",0);
callLogDemo.after();
}