use of com.yahoo.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class MemcachedClient method fromJson.
protected static void fromJson(String value, Set<String> fields, Map<String, ByteIterator> result) throws IOException {
JsonNode json = MAPPER.readTree(value);
boolean checkFields = fields != null && !fields.isEmpty();
for (Iterator<Map.Entry<String, JsonNode>> jsonFields = json.getFields(); jsonFields.hasNext(); ) /* increment in loop body */
{
Map.Entry<String, JsonNode> jsonField = jsonFields.next();
String name = jsonField.getKey();
if (checkFields && fields.contains(name)) {
continue;
}
JsonNode jsonValue = jsonField.getValue();
if (jsonValue != null && !jsonValue.isNull()) {
result.put(name, new StringByteIterator(jsonValue.asText()));
}
}
}
use of com.yahoo.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class InfinispanClient method read.
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
try {
Map<String, String> row;
if (clustered) {
row = AtomicMapLookup.getAtomicMap(infinispanManager.getCache(table), key, false);
} else {
Cache<String, Map<String, String>> cache = infinispanManager.getCache(table);
row = cache.get(key);
}
if (row != null) {
result.clear();
if (fields == null || fields.isEmpty()) {
StringByteIterator.putAllAsByteIterators(result, row);
} else {
for (String field : fields) {
result.put(field, new StringByteIterator(row.get(field)));
}
}
}
return Status.OK;
} catch (Exception e) {
LOGGER.error(e);
return Status.ERROR;
}
}
use of com.yahoo.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class SolrClient method read.
/**
* Read a record from the database. Each field/value pair from the result will be stored in a
* HashMap.
*
* @param table
* The name of the table
* @param key
* The record key of the record to read.
* @param fields
* The list of fields to read, or null for all of them
* @param result
* A HashMap of field/value pairs for the result
* @return Zero on success, a non-zero error code on error or "not found".
*/
@Override
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
try {
Boolean returnFields = false;
String[] fieldList = null;
if (fields != null) {
returnFields = true;
fieldList = fields.toArray(new String[fields.size()]);
}
SolrQuery query = new SolrQuery();
query.setQuery("id:" + key);
if (returnFields) {
query.setFields(fieldList);
}
final QueryResponse response = client.query(table, query);
SolrDocumentList results = response.getResults();
if ((results != null) && (results.getNumFound() > 0)) {
for (String field : results.get(0).getFieldNames()) {
result.put(field, new StringByteIterator(String.valueOf(results.get(0).getFirstValue(field))));
}
}
return checkStatus(response.getStatus());
} catch (IOException | SolrServerException e) {
e.printStackTrace();
}
return Status.ERROR;
}
use of com.yahoo.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class SolrClientBaseTest method testUpdate.
@Test
public void testUpdate() throws Exception {
HashMap<String, ByteIterator> newValues = new HashMap<>(NUM_RECORDS);
for (int i = 0; i < NUM_RECORDS; i++) {
newValues.put("field" + i, new StringByteIterator("newvalue" + i));
}
Status result = instance.update(MOCK_TABLE, MOCK_KEY1, newValues);
assertEquals(Status.OK, result);
//validate that the values changed
HashMap<String, ByteIterator> resultParam = new HashMap<>(NUM_RECORDS);
instance.read(MOCK_TABLE, MOCK_KEY1, MOCK_DATA.keySet(), resultParam);
for (int i = 0; i < NUM_RECORDS; i++) {
assertEquals("newvalue" + i, resultParam.get("field" + i).toString());
}
}
use of com.yahoo.ycsb.StringByteIterator in project YCSB by brianfrankcooper.
the class RestClientTest method insert_404.
@Test
public void insert_404() {
HashMap<String, ByteIterator> data = new HashMap<String, ByteIterator>();
data.put(DATA_TAG, new StringByteIterator(INPUT_DATA));
Status status = rc.insert(null, ABSENT_RESOURCE, data);
assertEquals(Status.NOT_FOUND, status);
}
Aggregations