Search in sources :

Example 6 with ByteIterator

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

the class ArangoDB3Client 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) {
    ArangoCursor<VPackSlice> 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 = arangoDB.db(databaseName).query(aqlQuery, bindVars, null, VPackSlice.class);
        while (cursor.hasNext()) {
            VPackSlice aDocument = cursor.next();
            HashMap<String, ByteIterator> aMap = new HashMap<String, ByteIterator>(aDocument.size());
            if (!this.fillMap(aMap, aDocument)) {
                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 (IOException e) {
                logger.error("Fail to close cursor", e);
            }
        }
    }
    return Status.ERROR;
}
Also used : StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) HashMap(java.util.HashMap) VPackSlice(com.arangodb.velocypack.VPackSlice) MapBuilder(com.arangodb.util.MapBuilder) IOException(java.io.IOException) DBException(com.yahoo.ycsb.DBException) ArangoDBException(com.arangodb.ArangoDBException) IOException(java.io.IOException)

Example 7 with ByteIterator

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

the class ArangoDB3Client method update.

/**
   * Update 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, overwriting any existing values with the same field name.
   * 
   * @param table
   *      The name of the table
   * @param key
   *      The record key of the record to write.
   * @param values
   *      A HashMap of field/value pairs to update in the 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 update(String table, String key, HashMap<String, ByteIterator> values) {
    try {
        if (!transactionUpdate) {
            BaseDocument updateDoc = new BaseDocument();
            for (Entry<String, ByteIterator> field : values.entrySet()) {
                updateDoc.addAttribute(field.getKey(), byteIteratorToString(field.getValue()));
            }
            arangoDB.db(databaseName).collection(table).updateDocument(key, updateDoc);
            return Status.OK;
        } else {
            // id for documentHandle
            String transactionAction = "function (id) {" + // use internal database functions
            "var db = require('internal').db;" + // collection.update(document, data, overwrite, keepNull, waitForSync)
            String.format("db._update(id, %s, true, false, %s);}", mapToJson(values), Boolean.toString(waitForSync).toLowerCase());
            TransactionOptions options = new TransactionOptions();
            options.writeCollections(table);
            options.params(createDocumentHandle(table, key));
            arangoDB.db(databaseName).transaction(transactionAction, Void.class, options);
            return Status.OK;
        }
    } catch (ArangoDBException e) {
        logger.error("Exception while trying update {} {} 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) TransactionOptions(com.arangodb.model.TransactionOptions) ArangoDBException(com.arangodb.ArangoDBException)

Example 8 with ByteIterator

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

the class ArangoDB3Client 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()));
        }
        DocumentCreateOptions options = new DocumentCreateOptions().waitForSync(waitForSync);
        arangoDB.db(databaseName).collection(table).insertDocument(toInsert, options);
        return Status.OK;
    } catch (ArangoDBException 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) DocumentCreateOptions(com.arangodb.model.DocumentCreateOptions) HashMap(java.util.HashMap) Map(java.util.Map) ArangoDBException(com.arangodb.ArangoDBException)

Example 9 with ByteIterator

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

the class ElasticsearchClientTest method testRead.

/**
     * Test of read method, of class ElasticsearchClient.
     */
@Test
public void testRead() {
    System.out.println("read");
    Set<String> fields = MOCK_DATA.keySet();
    HashMap<String, ByteIterator> resultParam = new HashMap<String, ByteIterator>(10);
    Status result = instance.read(MOCK_TABLE, MOCK_KEY1, fields, resultParam);
    assertEquals(Status.OK, result);
}
Also used : Status(com.yahoo.ycsb.Status) StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 10 with ByteIterator

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

the class ElasticsearchClientTest method testUpdate.

/**
     * Test of update method, of class ElasticsearchClient.
     */
@Test
public void testUpdate() {
    System.out.println("update");
    int i;
    HashMap<String, ByteIterator> newValues = new HashMap<String, ByteIterator>(10);
    for (i = 1; i <= 10; 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<String, ByteIterator>(10);
    instance.read(MOCK_TABLE, MOCK_KEY1, MOCK_DATA.keySet(), resultParam);
    for (i = 1; i <= 10; 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) Test(org.junit.Test)

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