use of org.hypertable.thriftgen.ScanSpec in project YCSB by brianfrankcooper.
the class HypertableClient method scan.
/**
* Perform a range scan for a set of records in the database. Each field/value
* pair from the result will be stored in a HashMap.
*
* @param table
* The name of the table
* @param startkey
* The record key of the first record to read.
* @param recordcount
* The number of records to read
* @param fields
* The list of fields to read, or null for all of them
* @param result
* A Vector of HashMaps, where each HashMap is a set field/value
* pairs for one record
* @return Zero on success, a non-zero error code on error
*/
@Override
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
// SELECT _columnFamily:fields FROM table WHERE (ROW >= startkey)
// LIMIT recordcount MAX_VERSIONS 1;
ScanSpec spec = new ScanSpec();
RowInterval elem = new RowInterval();
elem.setStart_inclusive(true);
elem.setStart_row(startkey);
spec.addToRow_intervals(elem);
if (null != fields) {
for (String field : fields) {
spec.addToColumns(columnFamily + ":" + field);
}
}
spec.setVersions(1);
spec.setRow_limit(recordcount);
SerializedCellsReader reader = new SerializedCellsReader(null);
try {
long sc = connection.scanner_open(ns, table, spec);
String lastRow = null;
boolean eos = false;
while (!eos) {
reader.reset(connection.scanner_get_cells_serialized(sc));
while (reader.next()) {
String currentRow = new String(reader.get_row());
if (!currentRow.equals(lastRow)) {
result.add(new HashMap<String, ByteIterator>());
lastRow = currentRow;
}
result.lastElement().put(new String(reader.get_column_qualifier()), new ByteArrayByteIterator(reader.get_value()));
}
eos = reader.eos();
if (debug) {
System.out.println("Number of rows retrieved so far: " + result.size());
}
}
connection.scanner_close(sc);
} catch (ClientException e) {
if (debug) {
System.err.println("Error doing scan: " + e.message);
}
return Status.ERROR;
} catch (TException e) {
if (debug) {
System.err.println("Error doing scan");
}
return Status.ERROR;
}
return Status.OK;
}
Aggregations