Search in sources :

Example 46 with ByteIterator

use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class HBaseClient2Test method testRead.

@Test
public void testRead() throws Exception {
    setUp();
    final String rowKey = "row1";
    final Put p = new Put(Bytes.toBytes(rowKey));
    p.addColumn(Bytes.toBytes(COLUMN_FAMILY), Bytes.toBytes("column1"), Bytes.toBytes("value1"));
    p.addColumn(Bytes.toBytes(COLUMN_FAMILY), Bytes.toBytes("column2"), Bytes.toBytes("value2"));
    table.put(p);
    final HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
    final Status status = client.read(tableName, rowKey, null, result);
    assertEquals(Status.OK, status);
    assertEquals(2, result.size());
    assertEquals("value1", result.get("column1").toString());
    assertEquals("value2", result.get("column2").toString());
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 47 with ByteIterator

use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class AbstractDBTestCases method testInsertReadDelete.

/**
 * Test method for {@link DB#insert}, {@link DB#read}, and {@link DB#delete} .
 */
@Test
public void testInsertReadDelete() {
    final DB client = getDB();
    final String table = getClass().getSimpleName();
    final String id = "delete";
    HashMap<String, ByteIterator> inserted = new HashMap<String, ByteIterator>();
    inserted.put("a", new ByteArrayByteIterator(new byte[] { 1, 2, 3, 4 }));
    Status result = client.insert(table, id, inserted);
    assertThat("Insert did not return success (0).", result, is(Status.OK));
    HashMap<String, ByteIterator> read = new HashMap<String, ByteIterator>();
    Set<String> keys = Collections.singleton("a");
    result = client.read(table, id, keys, read);
    assertThat("Read did not return success (0).", result, is(Status.OK));
    for (String key : keys) {
        ByteIterator iter = read.get(key);
        assertThat("Did not read the inserted field: " + key, iter, notNullValue());
        assertTrue(iter.hasNext());
        assertThat(iter.nextByte(), is(Byte.valueOf((byte) 1)));
        assertTrue(iter.hasNext());
        assertThat(iter.nextByte(), is(Byte.valueOf((byte) 2)));
        assertTrue(iter.hasNext());
        assertThat(iter.nextByte(), is(Byte.valueOf((byte) 3)));
        assertTrue(iter.hasNext());
        assertThat(iter.nextByte(), is(Byte.valueOf((byte) 4)));
        assertFalse(iter.hasNext());
    }
    result = client.delete(table, id);
    assertThat("Delete did not return success (0).", result, is(Status.OK));
    read.clear();
    result = client.read(table, id, null, read);
    assertThat("Read, after delete, did not return not found (1).", result, is(Status.NOT_FOUND));
    assertThat("Found the deleted fields.", read.size(), is(0));
    result = client.delete(table, id);
    assertThat("Delete did not return not found (1).", result, is(Status.NOT_FOUND));
}
Also used : Status(site.ycsb.Status) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) ByteIterator(site.ycsb.ByteIterator) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) HashMap(java.util.HashMap) DB(site.ycsb.DB) Test(org.junit.Test)

Example 48 with ByteIterator

use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class JdbcDBClientTest method insertRow.

/*
        Inserts a row of deterministic values for the given insertKey using the jdbcDBClient.
     */
private HashMap<String, ByteIterator> insertRow(String insertKey) {
    HashMap<String, ByteIterator> insertMap = new HashMap<String, ByteIterator>();
    for (int i = 0; i < 3; i++) {
        insertMap.put(FIELD_PREFIX + i, new StringByteIterator(buildDeterministicValue(insertKey, FIELD_PREFIX + i)));
    }
    jdbcDBClient.insert(TABLE_NAME, insertKey, insertMap);
    return insertMap;
}
Also used : StringByteIterator(site.ycsb.StringByteIterator) ByteIterator(site.ycsb.ByteIterator) HashMap(java.util.HashMap) StringByteIterator(site.ycsb.StringByteIterator)

Example 49 with ByteIterator

use of site.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, Map<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 : ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) BaseDocument(com.arangodb.entity.BaseDocument) DocumentCreateOptions(com.arangodb.model.DocumentCreateOptions) HashMap(java.util.HashMap) Map(java.util.Map) ArangoDBException(com.arangodb.ArangoDBException)

Example 50 with ByteIterator

use of site.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) {
    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 : ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) VPackSlice(com.arangodb.velocypack.VPackSlice) MapBuilder(com.arangodb.util.MapBuilder) IOException(java.io.IOException) ArangoDBException(com.arangodb.ArangoDBException) IOException(java.io.IOException) DBException(site.ycsb.DBException)

Aggregations

ByteIterator (site.ycsb.ByteIterator)131 HashMap (java.util.HashMap)98 StringByteIterator (site.ycsb.StringByteIterator)92 Status (site.ycsb.Status)62 Test (org.junit.Test)53 ByteArrayByteIterator (site.ycsb.ByteArrayByteIterator)34 DBException (site.ycsb.DBException)30 Map (java.util.Map)20 IOException (java.io.IOException)10 Put (org.apache.hadoop.hbase.client.Put)8 ArrayList (java.util.ArrayList)7 Vector (java.util.Vector)7 ByteBuffer (java.nio.ByteBuffer)6 HashSet (java.util.HashSet)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 NumericByteIterator (site.ycsb.NumericByteIterator)5 EntityProperty (com.microsoft.azure.storage.table.EntityProperty)4 Properties (java.util.Properties)4 Assume.assumeNoException (org.junit.Assume.assumeNoException)4 DB (site.ycsb.DB)4