private ResultScanner scanner;
private Result cached;
public ScannerResultGenerator(final String tableName, final RowSpec rowspec,
final Filter filter) throws IllegalArgumentException, IOException {
HTablePool pool = RESTServlet.getInstance().getTablePool();
HTable table = pool.getTable(tableName);
try {
Scan scan;
if (rowspec.hasEndRow()) {
scan = new Scan(rowspec.getStartRow(), rowspec.getEndRow());
} else {
scan = new Scan(rowspec.getStartRow());
}
if (rowspec.hasColumns()) {
byte[][] columns = rowspec.getColumns();
for (byte[] column: columns) {
byte[][] split = KeyValue.parseColumn(column);
if (split.length > 1 && (split[1] != null && split[1].length != 0)) {
scan.addColumn(split[0], split[1]);
} else {
scan.addFamily(split[0]);
}
}
} else {
for (HColumnDescriptor family:
table.getTableDescriptor().getFamilies()) {
scan.addFamily(family.getName());
}
}
scan.setTimeRange(rowspec.getStartTime(), rowspec.getEndTime());
scan.setMaxVersions(rowspec.getMaxVersions());
if (filter != null) {
scan.setFilter(filter);
}
// always disable block caching on the cluster when scanning
scan.setCacheBlocks(false);
scanner = table.getScanner(scan);
cached = null;
id = Long.toString(System.currentTimeMillis()) +
Integer.toHexString(scanner.hashCode());
} finally {
pool.putTable(table);
}
}