use of site.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class VoltDBClientTest method updateTest.
@Test
public void updateTest() {
Assume.assumeTrue(haveDb);
try {
// Create some test data
final String insertKey = UPDATE_TEST_KEY;
// Insert row
// Insert row
HashMap<String, ByteIterator> insertThenUpdateMap = new HashMap<String, ByteIterator>();
for (int i = 0; i < NUM_FIELDS; i++) {
insertThenUpdateMap.put(FIELD_PREFIX + i, new StringByteIterator(buildDeterministicValue(insertKey, FIELD_PREFIX + i)));
}
voltClient.insert(TABLE_NAME, insertKey, insertThenUpdateMap);
// Change the data we inserted...
for (int i = 0; i < NUM_FIELDS; i++) {
insertThenUpdateMap.put(FIELD_PREFIX + i, new StringByteIterator(FIELD_PREFIX + i + " has changed"));
}
// now do an update
voltClient.update(TABLE_NAME, insertKey, insertThenUpdateMap);
// Create a object to put retrieved row in...
final Set<String> columns = getColumnNameMap();
Map<String, ByteIterator> testResult = new HashMap<String, ByteIterator>();
// Read row...
Status s = voltClient.read(TABLE_NAME, insertKey, columns, testResult);
if (!s.equals(Status.OK)) {
fail("Didn't get OK on read.");
}
if (!compareContents(insertThenUpdateMap, testResult)) {
fail("Returned data not the same as inserted data");
}
} catch (Exception e) {
e.printStackTrace();
fail("Failed updateTest");
}
}
use of site.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class RocksDBClientTest method insertUpdateAndRead.
@Test
public void insertUpdateAndRead() throws Exception {
final Map<String, ByteIterator> newValues = new HashMap<>(NUM_RECORDS);
final Status insertResult = instance.insert(MOCK_TABLE, MOCK_KEY2, MOCK_DATA);
assertEquals(Status.OK, insertResult);
for (int i = 0; i < NUM_RECORDS; i++) {
newValues.put(FIELD_PREFIX + i, new StringByteIterator("newvalue" + i));
}
final Status result = instance.update(MOCK_TABLE, MOCK_KEY2, newValues);
assertEquals(Status.OK, result);
// validate that the values changed
final Map<String, ByteIterator> resultParam = new HashMap<>(NUM_RECORDS);
instance.read(MOCK_TABLE, MOCK_KEY2, MOCK_DATA.keySet(), resultParam);
for (int i = 0; i < NUM_RECORDS; i++) {
assertEquals("newvalue" + i, resultParam.get(FIELD_PREFIX + i).toString());
}
}
use of site.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class KuduYCSBClient method addAllRowsToResult.
private void addAllRowsToResult(RowResultIterator it, int recordcount, List<String> querySchema, Vector<HashMap<String, ByteIterator>> result) throws Exception {
RowResult row;
HashMap<String, ByteIterator> rowResult = new HashMap<>(querySchema.size());
if (it == null) {
return;
}
while (it.hasNext()) {
if (result.size() == recordcount) {
return;
}
row = it.next();
int colIdx = 0;
for (String col : querySchema) {
rowResult.put(col, new StringByteIterator(row.getString(colIdx)));
colIdx++;
}
result.add(rowResult);
}
}
use of site.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class OrientDBClientTest method insertRow.
/*
Inserts a row of deterministic values for the given insertKey using the orientDBClient.
*/
private Map<String, ByteIterator> insertRow(String insertKey) {
HashMap<String, ByteIterator> insertMap = new HashMap<>();
for (int i = 0; i < 3; i++) {
insertMap.put(FIELD_PREFIX + i, new StringByteIterator(buildDeterministicValue(insertKey, FIELD_PREFIX + i)));
}
orientDBClient.insert(CLASS, insertKey, insertMap);
return insertMap;
}
use of site.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class JdbcDBClient method scan.
@Override
public Status scan(String tableName, String startKey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
try {
StatementType type = new StatementType(StatementType.Type.SCAN, tableName, 1, "", getShardIndexByKey(startKey));
PreparedStatement scanStatement = cachedStatements.get(type);
if (scanStatement == null) {
scanStatement = createAndCacheScanStatement(type, startKey);
}
// SQL Server TOP syntax is at first
if (sqlserverScans) {
scanStatement.setInt(1, recordcount);
scanStatement.setString(2, startKey);
// FETCH FIRST and LIMIT are at the end
} else {
scanStatement.setString(1, startKey);
scanStatement.setInt(2, recordcount);
}
ResultSet resultSet = scanStatement.executeQuery();
for (int i = 0; i < recordcount && resultSet.next(); i++) {
if (result != null && fields != null) {
HashMap<String, ByteIterator> values = new HashMap<String, ByteIterator>();
for (String field : fields) {
String value = resultSet.getString(field);
values.put(field, new StringByteIterator(value));
}
result.add(values);
}
}
resultSet.close();
return Status.OK;
} catch (SQLException e) {
System.err.println("Error in processing scan of table: " + tableName + e);
return Status.ERROR;
}
}
Aggregations