Search in sources :

Example 1 with ByteIterator

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

the class ElasticsearchClient method scan.

/**
   * Perform a range scan for a set of records in the database. Each field/value
   * pair from the result will be stored in a HashMap.
   *
   * @param table
   *          The name of the table
   * @param startkey
   *          The record key of the first record to read.
   * @param recordcount
   *          The number of records to read
   * @param fields
   *          The list of fields to read, or null for all of them
   * @param result
   *          A Vector of HashMaps, where each HashMap is a set field/value
   *          pairs for one record
   * @return Zero on success, a non-zero error code on error. See this class's
   *         description for a discussion of error codes.
   */
@Override
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
    try {
        final RangeQueryBuilder rangeQuery = rangeQuery("_id").gte(startkey);
        final SearchResponse response = client.prepareSearch(indexKey).setTypes(table).setQuery(rangeQuery).setSize(recordcount).execute().actionGet();
        HashMap<String, ByteIterator> entry;
        for (SearchHit hit : response.getHits()) {
            entry = new HashMap<>(fields.size());
            for (String field : fields) {
                entry.put(field, new StringByteIterator((String) hit.getSource().get(field)));
            }
            result.add(entry);
        }
        return Status.OK;
    } catch (Exception e) {
        e.printStackTrace();
        return Status.ERROR;
    }
}
Also used : StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) SearchHit(org.elasticsearch.search.SearchHit) StringByteIterator(com.yahoo.ycsb.StringByteIterator) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) DBException(com.yahoo.ycsb.DBException) UnknownHostException(java.net.UnknownHostException) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 2 with ByteIterator

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

the class AerospikeClient method write.

private Status write(String table, String key, WritePolicy writePolicy, HashMap<String, ByteIterator> values) {
    Bin[] bins = new Bin[values.size()];
    int index = 0;
    for (Map.Entry<String, ByteIterator> entry : values.entrySet()) {
        bins[index] = new Bin(entry.getKey(), entry.getValue().toArray());
        ++index;
    }
    Key keyObj = new Key(namespace, table, key);
    try {
        client.put(writePolicy, keyObj, bins);
        return Status.OK;
    } catch (AerospikeException e) {
        System.err.println("Error while writing key " + key + ": " + e);
        return Status.ERROR;
    }
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) Bin(com.aerospike.client.Bin) HashMap(java.util.HashMap) Map(java.util.Map) Key(com.aerospike.client.Key)

Example 3 with ByteIterator

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

the class ArangoDBClient method insert.

/**
   * Insert a record in the database. Any field/value pairs in the specified
   * values HashMap will be written into the record with the specified record
   * key.
   * 
   * @param table
   *      The name of the table
   * @param key
   *      The record key of the record to insert.
   * @param values
   *      A HashMap of field/value pairs to insert in the record
   * @return Zero on success, a non-zero error code on error. See the
   *     {@link DB} class's description for a discussion of error codes.
   */
@Override
public Status insert(String table, String key, HashMap<String, ByteIterator> values) {
    try {
        BaseDocument toInsert = new BaseDocument(key);
        for (Map.Entry<String, ByteIterator> entry : values.entrySet()) {
            toInsert.addAttribute(entry.getKey(), byteIteratorToString(entry.getValue()));
        }
        arangoDriver.createDocument(table, toInsert, true, /*create collection if not exist*/
        waitForSync);
        return Status.OK;
    } catch (ArangoException e) {
        if (e.getErrorNumber() != ErrorNums.ERROR_ARANGO_UNIQUE_CONSTRAINT_VIOLATED) {
            logger.error("Fail to insert: {} {} with ex {}", table, key, e.toString());
        } else {
            logger.debug("Trying to create document with duplicate key: {} {}", table, key);
            return Status.BAD_REQUEST;
        }
    } catch (RuntimeException e) {
        logger.error("Exception while trying insert {} {} with ex {}", table, key, e.toString());
    }
    return Status.ERROR;
}
Also used : StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) BaseDocument(com.arangodb.entity.BaseDocument) ArangoException(com.arangodb.ArangoException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with ByteIterator

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

the class ArangoDBClient method scan.

/**
   * Perform a range scan for a set of records in the database. Each
   * field/value pair from the result will be stored in a HashMap.
   * 
   * @param table
   *      The name of the table
   * @param startkey
   *      The record key of the first record to read.
   * @param recordcount
   *      The number of records to read
   * @param fields
   *      The list of fields to read, or null for all of them
   * @param result
   *      A Vector of HashMaps, where each HashMap is a set field/value
   *      pairs for one record
   * @return Zero on success, a non-zero error code on error. See the
   *     {@link DB} class's description for a discussion of error codes.
   */
@Override
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
    DocumentCursor<BaseDocument> cursor = null;
    try {
        String aqlQuery = String.format("FOR target IN %s FILTER target._key >= @key SORT target._key ASC LIMIT %d RETURN %s ", table, recordcount, constructReturnForAQL(fields, "target"));
        Map<String, Object> bindVars = new MapBuilder().put("key", startkey).get();
        cursor = arangoDriver.executeDocumentQuery(aqlQuery, bindVars, null, BaseDocument.class);
        Iterator<BaseDocument> iterator = cursor.entityIterator();
        while (iterator.hasNext()) {
            BaseDocument aDocument = iterator.next();
            HashMap<String, ByteIterator> aMap = new HashMap<String, ByteIterator>(aDocument.getProperties().size());
            if (!this.fillMap(aMap, aDocument.getProperties())) {
                return Status.ERROR;
            }
            result.add(aMap);
        }
        return Status.OK;
    } catch (Exception e) {
        logger.error("Exception while trying scan {} {} {} with ex {}", table, startkey, recordcount, e.toString());
    } finally {
        if (cursor != null) {
            try {
                cursor.close();
            } catch (ArangoException e) {
                logger.error("Fail to close cursor", e);
            }
        }
    }
    return Status.ERROR;
}
Also used : StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) BaseDocument(com.arangodb.entity.BaseDocument) HashMap(java.util.HashMap) MapBuilder(com.arangodb.util.MapBuilder) ArangoException(com.arangodb.ArangoException) DBException(com.yahoo.ycsb.DBException) ArangoException(com.arangodb.ArangoException)

Example 5 with ByteIterator

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

the class ArangoDB3Client method mapToJson.

private String mapToJson(HashMap<String, ByteIterator> values) {
    VPackBuilder builder = new VPackBuilder().add(ValueType.OBJECT);
    for (Map.Entry<String, ByteIterator> entry : values.entrySet()) {
        builder.add(entry.getKey(), byteIteratorToString(entry.getValue()));
    }
    builder.close();
    return arangoDB.util().deserialize(builder.slice(), String.class);
}
Also used : StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) VPackBuilder(com.arangodb.velocypack.VPackBuilder) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ByteIterator (com.yahoo.ycsb.ByteIterator)87 HashMap (java.util.HashMap)70 StringByteIterator (com.yahoo.ycsb.StringByteIterator)52 Status (com.yahoo.ycsb.Status)33 ByteArrayByteIterator (com.yahoo.ycsb.ByteArrayByteIterator)30 Test (org.junit.Test)30 DBException (com.yahoo.ycsb.DBException)20 Map (java.util.Map)14 IOException (java.io.IOException)8 EntityProperty (com.microsoft.azure.storage.table.EntityProperty)5 Vector (java.util.Vector)5 BaseDocument (com.arangodb.entity.BaseDocument)4 DynamicTableEntity (com.microsoft.azure.storage.table.DynamicTableEntity)4 DB (com.yahoo.ycsb.DB)4 ByteBuffer (java.nio.ByteBuffer)4 ArrayList (java.util.ArrayList)4 Put (org.apache.hadoop.hbase.client.Put)4 MongoCollection (com.allanbank.mongodb.MongoCollection)3 DocumentBuilder (com.allanbank.mongodb.bson.builder.DocumentBuilder)3 ArangoDBException (com.arangodb.ArangoDBException)3