20,811
社区成员
发帖
与我相关
我的任务
分享
public class HbaseQuery
{
public static String deviceSet = SystemUtils.getCfg().getProperty("hbase.zookeeper.quorum");
public String getOneRecordByRowkey(String tablename, String rowKey)
throws IOException
{
String record = "";
try {
HTable table = (HTable)XmfSvc.hTablePool.getTable(tablename);
Get get = new Get(rowKey.getBytes());
Result rs = table.get(get);
for (KeyValue kv : rs.raw()) {
record = new String(kv.getValue(), "UTF-8");
}
return record;
} catch (IOException e) {
e.printStackTrace();
}return null;
}
public List<String> scaneByPrefixFilter(String tablename, String rowPrefix)
{
List value = new LinkedList();
try {
HTable table = (HTable)XmfSvc.hTablePool.getTable(tablename);
Scan s = new Scan();
s.setFilter(new PrefixFilter(rowPrefix.getBytes()));
ResultScanner rs = table.getScanner(s);
for (Result r : rs) {
KeyValue[] kv = r.raw();
for (int i = 0; i < kv.length; i++) {
value.add(new String(kv[i].getRow(), "UTF-8") + ":---:" + new String(kv[i].getFamily()) + ":" + new String(kv[i].getQualifier()) + ":---:" + new String(kv[i].getValue()));
}
}
rs.close();
return value;
} catch (IOException e) {
e.printStackTrace();
}return null;
}