我在hbase中开发了一组查询,我需要读取多个列族。但是,当我添加多个列族时,我的程序无法检索任何结果。
添加我要检索的列族的代码是:
Scan scan = new Scan(generateKey(start_key),generateKey(end_key));
for (int i = 0; i <= families.length - 1; i++) {
try {
if(table.getTableDescriptor().hasFamily(Bytes.toBytes(families[i]))){
scan.addFamily(Bytes.toBytes(families[i]));
}
} catch (IOException e) {
e.printStackTrace();
}
}
获取结果并在迭代循环中运行的代码:
while (res!=null && !res.isEmpty()){
byte [] column1_bytes = res.getValue(Bytes.toBytes(families[i]),Bytes.toBytes("COLUMN1"));
byte [] column2_bytes = res.getValue(Bytes.toBytes(families[i]),Bytes.toBytes("COLUMN2"));
String column1 = Bytes.toString(column1_bytes).toString();
String column2 = Bytes.toString(column2_bytes).toString();
intervalTopTopic.put(column1, (long) Integer.parseInt(column2));
res = rs.next();
}