Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "hadoop1,hadoop2,hadoop3");
HTable table = new HTable(conf, "DataCollection1");
System.out.println("scan1");
Scan scan1 = new Scan();
new PrefixFilter(Bytes.toBytes("row"));
Filter filter3= new PrefixFilter(Bytes.toBytes("2017-01-01"));
scan1.setFilter(filter3);
scan1.setMaxVersions();
ResultScanner scanner1 = table.getScanner(scan1);
System.out.println("scan2");
int count=0;
JSONArray array = new JSONArray();
for (Result r : scanner1) {
System.out.println("sssss");
JSONObject mapOfColValues = new JSONObject();// 创建json对象就是一个{name:wp}
for (KeyValue kv : r.raw()) {
System.out.println(String.format("row:%s, family:%s, qualifier:%s, qualifiervalue:%s, timestamp:%s.",
Bytes.toString(kv.getRow()),
Bytes.toString(kv.getFamily()),
Bytes.toString(kv.getQualifier()),
Bytes.toString(kv.getValue()),
kv.getTimestamp()));
mapOfColValues.put(Bytes.toString(kv.getQualifier()),Bytes.toString(kv.getValue()));
}
array.add(mapOfColValues);
count++;
System.out.println(count);
}
scanner1.close();
table.close();
//pool.close();
System.out.println(count);
System.out.println("-------------finished----------------");
以上是我主要的代码, DataCollection1表的数据有7000万多条,我查询一天的数据(大概10万条左右), 到了循环scanner1的时候就卡住了,不知道为什么就是很慢。rowkey的设计是“时间|ID”,真的不知道该怎么弄,求教大神解答