读MOB数据
功能简介
HBase MOB数据读出与普通HBase数据的读出没有什么区别,对客户来说是透明的。为了使用HBase MOB功能需要在“hbase-site.xml”中添加HBase MOB相关的配置项,具体请参阅HBase MOB配置章节,除此之外还需要在指定column family上开启MOB功能。
代码样例
public void testMOBDataRead() {
LOG.info("Entering testMOBDataRead.");
ResultScanner scanner = null;
Table table = null;
Admin admin = null;
try {
// get table object representing table tableName
table = conn.getTable(tableName);
admin = conn.getAdmin();
admin.flush(table.getName());
Scan scan = new Scan();
// get table scanner
scanner = table.getScanner(scan);
for (Result result : scanner) {
byte[] value = result.getValue(Bytes.toBytes("mobcf"),
Bytes.toBytes("cf1"));
String string = Bytes.toString(value);
LOG.info("value:" + string);
}
LOG.info("MOB data read successfully.");
} catch (Exception e) {
LOG.error("MOB data read failed " ,e);
} finally {
if(scanner != null){
scanner.close();
}
if (table != null) {
try {
// Close table object
table.close();
} catch (IOException e) {
LOG.error("Close table failed " ,e);
}
}
if (admin != null) {
try {
// Close the Admin object.
admin.close();
} catch (IOException e) {
LOG.error("Close admin failed " ,e);
}
}
}
LOG.info("Exiting testMOBDataRead.");
}