Search in sources :

Example 6 with StringByteIterator

use of com.yahoo.ycsb.StringByteIterator in project YCSB by brianfrankcooper.

the class GoogleDatastoreClient method read.

@Override
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
    LookupRequest.Builder lookupRequest = LookupRequest.newBuilder();
    lookupRequest.addKeys(buildPrimaryKey(table, key));
    lookupRequest.getReadOptionsBuilder().setReadConsistency(this.readConsistency);
    // Note above, datastore lookupRequest always reads the entire entity, it
    // does not support reading a subset of "fields" (properties) of an entity.
    logger.debug("Built lookup request as: " + lookupRequest.toString());
    LookupResponse response = null;
    try {
        response = datastore.lookup(lookupRequest.build());
    } catch (DatastoreException exception) {
        logger.error(String.format("Datastore Exception when reading (%s): %s %s", exception.getMessage(), exception.getMethodName(), exception.getCode()));
        // will bubble up to the user as part of the YCSB Status "name".
        return new Status("ERROR-" + exception.getCode(), exception.getMessage());
    }
    if (response.getFoundCount() == 0) {
        return new Status("ERROR-404", "Not Found, key is: " + key);
    } else if (response.getFoundCount() > 1) {
        // entity back. Unexpected State.
        return Status.UNEXPECTED_STATE;
    }
    Entity entity = response.getFound(0).getEntity();
    logger.debug("Read entity: " + entity.toString());
    Map<String, Value> properties = entity.getProperties();
    Set<String> propertiesToReturn = (fields == null ? properties.keySet() : fields);
    for (String name : propertiesToReturn) {
        if (properties.containsKey(name)) {
            result.put(name, new StringByteIterator(properties.get(name).getStringValue()));
        }
    }
    return Status.OK;
}
Also used : Status(com.yahoo.ycsb.Status) StringByteIterator(com.yahoo.ycsb.StringByteIterator) DatastoreException(com.google.datastore.v1.client.DatastoreException)

Example 7 with StringByteIterator

use of com.yahoo.ycsb.StringByteIterator in project YCSB by brianfrankcooper.

the class RedisClient method read.

// XXX jedis.select(int index) to switch to `table`
@Override
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
    if (fields == null) {
        StringByteIterator.putAllAsByteIterators(result, jedis.hgetAll(key));
    } else {
        String[] fieldArray = (String[]) fields.toArray(new String[fields.size()]);
        List<String> values = jedis.hmget(key, fieldArray);
        Iterator<String> fieldIterator = fields.iterator();
        Iterator<String> valueIterator = values.iterator();
        while (fieldIterator.hasNext() && valueIterator.hasNext()) {
            result.put(fieldIterator.next(), new StringByteIterator(valueIterator.next()));
        }
        assert !fieldIterator.hasNext() && !valueIterator.hasNext();
    }
    return result.isEmpty() ? Status.ERROR : Status.OK;
}
Also used : StringByteIterator(com.yahoo.ycsb.StringByteIterator)

Example 8 with StringByteIterator

use of com.yahoo.ycsb.StringByteIterator in project YCSB by brianfrankcooper.

the class JdbcDBClient method read.

@Override
public Status read(String tableName, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
    try {
        StatementType type = new StatementType(StatementType.Type.READ, tableName, 1, "", getShardIndexByKey(key));
        PreparedStatement readStatement = cachedStatements.get(type);
        if (readStatement == null) {
            readStatement = createAndCacheReadStatement(type, key);
        }
        readStatement.setString(1, key);
        ResultSet resultSet = readStatement.executeQuery();
        if (!resultSet.next()) {
            resultSet.close();
            return Status.NOT_FOUND;
        }
        if (result != null && fields != null) {
            for (String field : fields) {
                String value = resultSet.getString(field);
                result.put(field, new StringByteIterator(value));
            }
        }
        resultSet.close();
        return Status.OK;
    } catch (SQLException e) {
        System.err.println("Error in processing read of table " + tableName + ": " + e);
        return Status.ERROR;
    }
}
Also used : StringByteIterator(com.yahoo.ycsb.StringByteIterator)

Example 9 with StringByteIterator

use of com.yahoo.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);
        }
        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;
    }
}
Also used : StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StringByteIterator(com.yahoo.ycsb.StringByteIterator)

Example 10 with StringByteIterator

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

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