程式碼示例:
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("-------------finished----------------");
程式碼示例:
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----------------");