java hbase 条件查询_用java查询HBase中某表的一批数据

本文演示了如何使用Java编程语言查询HBase数据库中特定表的数据。通过配置HBase连接参数,设置PrefixFilter过滤器,针对表`car_table`查询以特定前缀开头的行,并获取`lte`家族下的多个列值,包括`cid`、`time`、`pci`等信息。
摘要由CSDN通过智能技术生成

packagedb.query;importjava.io.IOException;importorg.apache.hadoop.conf.Configuration;importorg.apache.hadoop.hbase.HBaseConfiguration;importorg.apache.hadoop.hbase.client.HTable;importorg.apache.hadoop.hbase.client.Result;importorg.apache.hadoop.hbase.client.ResultScanner;importorg.apache.hadoop.hbase.client.Scan;importorg.apache.hadoop.hbase.filter.Filter;importorg.apache.hadoop.hbase.filter.PrefixFilter;importorg.apache.hadoop.hbase.util.Bytes;public classHBaseQuery {public static voidmain(String[] args) {

Configuration conf=HBaseConfiguration.create();

conf=HBaseConfiguration.create();

conf.set("hbase.zookeeper.quorum", "192.168.1.154");

conf.set("hbase.zookeeper.property.clientPort", "2181");

conf.set("hbase.master", "192.168.1.154:6000");

String tableName= "car_table";

HTable table;try{

table= newHTable(conf, tableName);//设置查询条件//使用前缀过滤器

Filter filter = new PrefixFilter(Bytes.toBytes("144860945858310137-"));

Scan scan= newScan();

scan.setFilter(filter);//scan.setStartRow(Bytes.toBytes("144860945858310137-0000000000000"));//scan.setStopRow(Bytes.toBytes("144860945858310137-9999999999999"));

scan.addFamily(Bytes.toBytes("lte"));

scan.addColumn(Bytes.toBytes("lte"), Bytes.toBytes("cid"));

scan.addColumn(Bytes.toBytes("lte"), Bytes.toBytes("time"));

scan.addColumn(Bytes.toBytes("lte"), Bytes.toBytes("pci"));

scan.addColumn(Bytes.toBytes("lte"), Bytes.toBytes("st"));

scan.addColumn(Bytes.toBytes("lte"), Bytes.toBytes("ed"));

scan.addColumn(Bytes.toBytes("lte"), Bytes.toBytes("ta"));

scan.addColumn(Bytes.toBytes("lte"), Bytes.toBytes("lat"));

scan.addColumn(Bytes.toBytes("lte"), Bytes.toBytes("lng"));

ResultScanner results=table.getScanner(scan);for(Result result: results){

String rowkey=Bytes.toString(result.getRow());

String cid= Bytes.toString(result.getValue(Bytes.toBytes("lte"), Bytes.toBytes("cid")));

String time= Bytes.toString(result.getValue(Bytes.toBytes("lte"), Bytes.toBytes("time")));

String pci= Bytes.toString(result.getValue(Bytes.toBytes("lte"), Bytes.toBytes("pci")));

String st= Bytes.toString(result.getValue(Bytes.toBytes("lte"), Bytes.toBytes("st")));

String ed= Bytes.toString(result.getValue(Bytes.toBytes("lte"), Bytes.toBytes("ed")));

String ta= Bytes.toString(result.getValue(Bytes.toBytes("lte"), Bytes.toBytes("ta")));

String lat= Bytes.toString(result.getValue(Bytes.toBytes("lte"), Bytes.toBytes("lat")));

String lng= Bytes.toString(result.getValue(Bytes.toBytes("lte"), Bytes.toBytes("lng")));

System.out.println("rowkey : "+rowkey+" cid : "+cid+", time: "+time+", pci: "+pci+", st: "+st+", ed: "+ed+", ta: "+ta+", lat: "+lat+", lon: "+lng);

}

}catch(IOException e) {//TODO Auto-generated catch block

e.printStackTrace();

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值