Search in sources :

Example 11 with StringByteIterator

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()));
        }
    }
}
Also used : StringByteIterator(com.yahoo.ycsb.StringByteIterator) JsonNode(org.codehaus.jackson.JsonNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with StringByteIterator

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;
    }
}
Also used : StringByteIterator(com.yahoo.ycsb.StringByteIterator) HashMap(java.util.HashMap) AtomicMap(org.infinispan.atomic.AtomicMap) Map(java.util.Map) DBException(com.yahoo.ycsb.DBException) IOException(java.io.IOException)

Example 13 with StringByteIterator

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;
}
Also used : QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) StringByteIterator(com.yahoo.ycsb.StringByteIterator) SolrDocumentList(org.apache.solr.common.SolrDocumentList) IOException(java.io.IOException) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 14 with StringByteIterator

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());
    }
}
Also used : Status(com.yahoo.ycsb.Status) StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) HashMap(java.util.HashMap) StringByteIterator(com.yahoo.ycsb.StringByteIterator)

Example 15 with StringByteIterator

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);
}
Also used : Status(com.yahoo.ycsb.Status) StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) HashMap(java.util.HashMap) StringByteIterator(com.yahoo.ycsb.StringByteIterator) Test(org.junit.Test)

Aggregations

StringByteIterator (com.yahoo.ycsb.StringByteIterator)33 ByteIterator (com.yahoo.ycsb.ByteIterator)21 HashMap (java.util.HashMap)17 Status (com.yahoo.ycsb.Status)13 Test (org.junit.Test)9 DBException (com.yahoo.ycsb.DBException)5 IOException (java.io.IOException)5 SolrQuery (org.apache.solr.client.solrj.SolrQuery)4 SolrServerException (org.apache.solr.client.solrj.SolrServerException)4 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)4 SolrDocumentList (org.apache.solr.common.SolrDocumentList)4 Map (java.util.Map)3 JsonObject (com.couchbase.client.java.document.json.JsonObject)2 SolrDocument (org.apache.solr.common.SolrDocument)2 ReadOp (com.ceph.rados.ReadOp)1 ReadResult (com.ceph.rados.ReadOp.ReadResult)1 RadosException (com.ceph.rados.exceptions.RadosException)1 RadosObjectInfo (com.ceph.rados.jna.RadosObjectInfo)1 JsonNode (com.couchbase.client.deps.com.fasterxml.jackson.databind.JsonNode)1 TemporaryFailureException (com.couchbase.client.java.error.TemporaryFailureException)1