use of com.yahoo.ycsb.ByteArrayByteIterator in project YCSB by brianfrankcooper.
the class AccumuloClient method scan.
@Override
public Status scan(String t, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
try {
checkTable(t);
} catch (TableNotFoundException e) {
System.err.println("Error trying to connect to Accumulo table." + e);
return Status.ERROR;
}
// There doesn't appear to be a way to create a range for a given
// LENGTH. Just start and end keys. So we'll do this the hard way for
// now:
// Just make the end 'infinity' and only read as much as we need.
scanScanner.clearColumns();
scanScanner.setRange(new Range(new Text(startkey), null));
// If no fields are provided, we assume one column/row.
if (fields != null) {
// And add each of them as fields we want.
for (String field : fields) {
scanScanner.fetchColumn(colFam, new Text(field));
}
}
String rowKey = "";
HashMap<String, ByteIterator> currentHM = null;
int count = 0;
// Begin the iteration.
for (Entry<Key, Value> entry : scanScanner) {
// Check for a new row.
if (!rowKey.equals(entry.getKey().getRow().toString())) {
if (count++ == recordcount) {
// Done reading the last row.
break;
}
rowKey = entry.getKey().getRow().toString();
if (fields != null) {
// Initial Capacity for all keys.
currentHM = new HashMap<String, ByteIterator>(fields.size());
} else {
// An empty result map.
currentHM = new HashMap<String, ByteIterator>();
}
result.add(currentHM);
}
// Now add the key to the hashmap.
Value v = entry.getValue();
byte[] buf = v.get();
currentHM.put(entry.getKey().getColumnQualifier().toString(), new ByteArrayByteIterator(buf));
}
return Status.OK;
}
use of com.yahoo.ycsb.ByteArrayByteIterator in project YCSB by brianfrankcooper.
the class AccumuloClient method read.
@Override
public Status read(String t, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
try {
checkTable(t);
} catch (TableNotFoundException e) {
System.err.println("Error trying to connect to Accumulo table." + e);
return Status.ERROR;
}
try {
// Pick out the results we care about.
for (Entry<Key, Value> entry : getRow(new Text(key), null)) {
Value v = entry.getValue();
byte[] buf = v.get();
result.put(entry.getKey().getColumnQualifier().toString(), new ByteArrayByteIterator(buf));
}
} catch (Exception e) {
System.err.println("Error trying to reading Accumulo table" + key + e);
return Status.ERROR;
}
return Status.OK;
}
use of com.yahoo.ycsb.ByteArrayByteIterator in project YCSB by brianfrankcooper.
the class AsyncHBaseClient method scan.
@Override
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
setTable(table);
final Scanner scanner = client.newScanner(lastTableBytes);
scanner.setFamily(columnFamilyBytes);
scanner.setStartKey(startkey.getBytes(UTF8_CHARSET));
// No end key... *sniff*
if (fields != null) {
scanner.setQualifiers(getQualifierList(fields));
}
// no filters? *sniff*
ArrayList<ArrayList<KeyValue>> rows = null;
try {
int numResults = 0;
while ((rows = scanner.nextRows().join(joinTimeout)) != null) {
for (final ArrayList<KeyValue> row : rows) {
final HashMap<String, ByteIterator> rowResult = new HashMap<String, ByteIterator>(row.size());
for (final KeyValue column : row) {
rowResult.put(new String(column.qualifier()), // be GC'd.
new ByteArrayByteIterator(column.value()));
if (debug) {
System.out.println("Got scan result for key: " + Bytes.pretty(column.key()));
}
}
result.add(rowResult);
numResults++;
if (numResults >= recordcount) {
// if hit recordcount, bail out
break;
}
}
}
scanner.close().join(joinTimeout);
return Status.OK;
} catch (InterruptedException e) {
System.err.println("Thread interrupted");
Thread.currentThread().interrupt();
} catch (Exception e) {
System.err.println("Failure reading from row with key " + startkey + ": " + e.getMessage());
return Status.ERROR;
}
return Status.ERROR;
}
use of com.yahoo.ycsb.ByteArrayByteIterator in project YCSB by brianfrankcooper.
the class RiakUtils method deserializeTable.
/**
* Deserializes an input byte array, transforming it into a list of (String, ByteIterator) pairs (i.e. a Map).
*
* @param aValue A byte array containing the table to deserialize.
* @param theResult A Map containing the deserialized table.
*/
private static void deserializeTable(final byte[] aValue, final Map<String, ByteIterator> theResult) {
final ByteArrayInputStream anInputStream = new ByteArrayInputStream(aValue);
byte[] aSizeBuffer = new byte[4];
try {
while (anInputStream.available() > 0) {
anInputStream.read(aSizeBuffer);
final int aColumnNameLength = fromBytes(aSizeBuffer);
final byte[] aColumnNameBuffer = new byte[aColumnNameLength];
anInputStream.read(aColumnNameBuffer);
anInputStream.read(aSizeBuffer);
final int aColumnValueLength = fromBytes(aSizeBuffer);
final byte[] aColumnValue = new byte[aColumnValueLength];
anInputStream.read(aColumnValue);
theResult.put(new String(aColumnNameBuffer), new ByteArrayByteIterator(aColumnValue));
}
} catch (Exception e) {
throw new IllegalStateException(e);
} finally {
close(anInputStream);
}
}
use of com.yahoo.ycsb.ByteArrayByteIterator 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