use of com.yahoo.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class CloudSpannerClient method scan.
@Override
public Status scan(String table, String startKey, int recordCount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
if (queriesForReads) {
return scanUsingQuery(table, startKey, recordCount, fields, result);
}
Iterable<String> columns = fields == null ? STANDARD_FIELDS : fields;
KeySet keySet = KeySet.newBuilder().addRange(KeyRange.closedClosed(Key.of(startKey), Key.of())).build();
try (ResultSet resultSet = dbClient.singleUse(timestampBound).read(table, keySet, columns, Options.limit(recordCount))) {
while (resultSet.next()) {
HashMap<String, ByteIterator> row = new HashMap<>();
decodeStruct(columns, resultSet, row);
result.add(row);
}
return Status.OK;
} catch (Exception e) {
LOGGER.log(Level.INFO, "scan()", e);
return Status.ERROR;
}
}
use of com.yahoo.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class AsyncHBaseClient method update.
@Override
public Status update(String table, String key, HashMap<String, ByteIterator> values) {
setTable(table);
if (debug) {
System.out.println("Setting up put for key: " + key);
}
final byte[][] qualifiers = new byte[values.size()][];
final byte[][] byteValues = new byte[values.size()][];
int idx = 0;
for (final Entry<String, ByteIterator> entry : values.entrySet()) {
qualifiers[idx] = entry.getKey().getBytes();
byteValues[idx++] = entry.getValue().toArray();
if (debug) {
System.out.println("Adding field/value " + entry.getKey() + "/" + Bytes.pretty(entry.getValue().toArray()) + " to put request");
}
}
final PutRequest put = new PutRequest(lastTableBytes, key.getBytes(), columnFamilyBytes, qualifiers, byteValues);
if (!durability) {
put.setDurable(false);
}
if (!clientSideBuffering) {
put.setBufferable(false);
try {
client.put(put).join(joinTimeout);
} catch (InterruptedException e) {
System.err.println("Thread interrupted");
Thread.currentThread().interrupt();
} catch (Exception e) {
System.err.println("Failure reading from row with key " + key + ": " + e.getMessage());
return Status.ERROR;
}
} else {
// hooray! Asynchronous write. But without a callback and an async
// YCSB call we don't know whether it succeeded or not
client.put(put);
}
return Status.OK;
}
use of com.yahoo.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class AsyncHBaseTest method testScan.
@Test
public void testScan() throws Exception {
// Fill with data
final String colStr = "row_number";
final byte[] col = Bytes.toBytes(colStr);
final int n = 10;
final List<Put> puts = new ArrayList<Put>(n);
for (int i = 0; i < n; i++) {
final byte[] key = Bytes.toBytes(String.format("%05d", i));
final byte[] value = java.nio.ByteBuffer.allocate(4).putInt(i).array();
final Put p = new Put(key);
p.addColumn(Bytes.toBytes(COLUMN_FAMILY), col, value);
puts.add(p);
}
table.put(puts);
// Test
final Vector<HashMap<String, ByteIterator>> result = new Vector<HashMap<String, ByteIterator>>();
// Scan 5 records, skipping the first
client.scan(tableName, "00001", 5, null, result);
assertEquals(5, result.size());
for (int i = 0; i < 5; i++) {
final HashMap<String, ByteIterator> row = result.get(i);
assertEquals(1, row.size());
assertTrue(row.containsKey(colStr));
final byte[] bytes = row.get(colStr).toArray();
final ByteBuffer buf = ByteBuffer.wrap(bytes);
final int rowNum = buf.getInt();
assertEquals(i + 1, rowNum);
}
}
use of com.yahoo.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class AsyncHBaseTest method testRead.
@Test
public void testRead() throws Exception {
final String rowKey = "row1";
final Put p = new Put(Bytes.toBytes(rowKey));
p.addColumn(Bytes.toBytes(COLUMN_FAMILY), Bytes.toBytes("column1"), Bytes.toBytes("value1"));
p.addColumn(Bytes.toBytes(COLUMN_FAMILY), Bytes.toBytes("column2"), Bytes.toBytes("value2"));
table.put(p);
final HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
final Status status = client.read(tableName, rowKey, null, result);
assertEquals(Status.OK, status);
assertEquals(2, result.size());
assertEquals("value1", result.get("column1").toString());
assertEquals("value2", result.get("column2").toString());
}
use of com.yahoo.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class AzureClient method insertOrUpdate.
private Status insertOrUpdate(String key, HashMap<String, ByteIterator> values) {
HashMap<String, EntityProperty> properties = new HashMap<String, EntityProperty>();
for (Entry<String, ByteIterator> entry : values.entrySet()) {
String fieldName = entry.getKey();
byte[] fieldVal = entry.getValue().toArray();
properties.put(fieldName, new EntityProperty(fieldVal));
}
DynamicTableEntity entity = new DynamicTableEntity(partitionKey, key, properties);
TableOperation insertOrReplace = TableOperation.insertOrReplace(entity);
try {
cloudTable.execute(insertOrReplace);
return Status.OK;
} catch (Exception e) {
return Status.ERROR;
}
}
Aggregations