Search in sources :

Example 26 with ByteArrayByteIterator

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

the class AbstractDBTestCases method testInsertReadUpdate.

/**
 * Test method for {@link DB#insert}, {@link DB#read}, and {@link DB#update} .
 */
@Test
public void testInsertReadUpdate() {
    DB client = getDB();
    final String table = getClass().getSimpleName();
    final String id = "update";
    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());
    }
    HashMap<String, ByteIterator> updated = new HashMap<String, ByteIterator>();
    updated.put("a", new ByteArrayByteIterator(new byte[] { 5, 6, 7, 8 }));
    result = client.update(table, id, updated);
    assertThat("Update did not return success (0).", result, is(Status.OK));
    read.clear();
    result = client.read(table, id, null, read);
    assertThat("Read, after update, 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) 5)));
        assertTrue(iter.hasNext());
        assertThat(iter.nextByte(), is(Byte.valueOf((byte) 6)));
        assertTrue(iter.hasNext());
        assertThat(iter.nextByte(), is(Byte.valueOf((byte) 7)));
        assertTrue(iter.hasNext());
        assertThat(iter.nextByte(), is(Byte.valueOf((byte) 8)));
        assertFalse(iter.hasNext());
    }
}
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 27 with ByteArrayByteIterator

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

the class AbstractDBTestCases method testInsertReadUpdateWithUpsert.

/**
 * Test method for {@link DB#insert}, {@link DB#read}, and {@link DB#update} .
 */
@Test
public void testInsertReadUpdateWithUpsert() {
    Properties props = new Properties();
    props.setProperty("mongodb.upsert", "true");
    DB client = getDB(props);
    final String table = getClass().getSimpleName();
    final String id = "updateWithUpsert";
    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());
    }
    HashMap<String, ByteIterator> updated = new HashMap<String, ByteIterator>();
    updated.put("a", new ByteArrayByteIterator(new byte[] { 5, 6, 7, 8 }));
    result = client.update(table, id, updated);
    assertThat("Update did not return success (0).", result, is(Status.OK));
    read.clear();
    result = client.read(table, id, null, read);
    assertThat("Read, after update, 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) 5)));
        assertTrue(iter.hasNext());
        assertThat(iter.nextByte(), is(Byte.valueOf((byte) 6)));
        assertTrue(iter.hasNext());
        assertThat(iter.nextByte(), is(Byte.valueOf((byte) 7)));
        assertTrue(iter.hasNext());
        assertThat(iter.nextByte(), is(Byte.valueOf((byte) 8)));
        assertFalse(iter.hasNext());
    }
}
Also used : Status(site.ycsb.Status) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) ByteIterator(site.ycsb.ByteIterator) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) HashMap(java.util.HashMap) Properties(java.util.Properties) DB(site.ycsb.DB) Test(org.junit.Test)

Example 28 with ByteArrayByteIterator

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

the class NoSqlDbClient method read.

@Override
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
    Key kvKey = createKey(table, key);
    SortedMap<Key, ValueVersion> kvResult;
    try {
        kvResult = store.multiGet(kvKey, null, null);
    } catch (FaultException e) {
        System.err.println(e);
        return Status.ERROR;
    }
    for (Map.Entry<Key, ValueVersion> entry : kvResult.entrySet()) {
        /* If fields is null, read all fields */
        String field = getFieldFromKey(entry.getKey());
        if (fields != null && !fields.contains(field)) {
            continue;
        }
        result.put(field, new ByteArrayByteIterator(entry.getValue().getValue().getValue()));
    }
    return Status.OK;
}
Also used : FaultException(oracle.kv.FaultException) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) ValueVersion(oracle.kv.ValueVersion) HashMap(java.util.HashMap) Map(java.util.Map) SortedMap(java.util.SortedMap) Key(oracle.kv.Key)

Example 29 with ByteArrayByteIterator

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

the class AccumuloClient method scan.

@Override
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
    // Just make the end 'infinity' and only read as much as we need.
    Scanner scanner = null;
    try {
        scanner = connector.createScanner(table, Authorizations.EMPTY);
        scanner.setRange(new Range(new Text(startkey), null));
        // Have Accumulo send us complete rows, serialized in a single Key-Value pair
        IteratorSetting cfg = new IteratorSetting(100, WholeRowIterator.class);
        scanner.addScanIterator(cfg);
        // If no fields are provided, we assume one column/row.
        if (fields != null) {
            // And add each of them as fields we want.
            for (String field : fields) {
                scanner.fetchColumn(colFam, new Text(field));
            }
        }
        int count = 0;
        for (Entry<Key, Value> entry : scanner) {
            // Deserialize the row
            SortedMap<Key, Value> row = WholeRowIterator.decodeRow(entry.getKey(), entry.getValue());
            HashMap<String, ByteIterator> rowData;
            if (null != fields) {
                rowData = new HashMap<>(fields.size());
            } else {
                rowData = new HashMap<>();
            }
            result.add(rowData);
            // Parse the data in the row, avoid unnecessary Text object creation
            final Text cq = new Text();
            for (Entry<Key, Value> rowEntry : row.entrySet()) {
                rowEntry.getKey().getColumnQualifier(cq);
                rowData.put(cq.toString(), new ByteArrayByteIterator(rowEntry.getValue().get()));
            }
            if (count++ == recordcount) {
                // Done reading the last row.
                break;
            }
        }
    } catch (TableNotFoundException e) {
        System.err.println("Error trying to connect to Accumulo table.");
        e.printStackTrace();
        return Status.ERROR;
    } catch (IOException e) {
        System.err.println("Error deserializing data from Accumulo.");
        e.printStackTrace();
        return Status.ERROR;
    } finally {
        if (null != scanner) {
            scanner.close();
        }
    }
    return Status.OK;
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) Range(org.apache.accumulo.core.data.Range) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) ByteIterator(site.ycsb.ByteIterator) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key)

Aggregations

ByteArrayByteIterator (site.ycsb.ByteArrayByteIterator)29 ByteIterator (site.ycsb.ByteIterator)14 DBException (site.ycsb.DBException)12 HashMap (java.util.HashMap)11 IOException (java.io.IOException)8 Status (site.ycsb.Status)5 ByteBuffer (java.nio.ByteBuffer)4 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 DB (site.ycsb.DB)4 EntityProperty (com.microsoft.azure.storage.table.EntityProperty)3 Cell (org.apache.hadoop.hbase.Cell)3 Result (org.apache.hadoop.hbase.client.Result)3 ColumnDefinitions (com.datastax.driver.core.ColumnDefinitions)2 PreparedStatement (com.datastax.driver.core.PreparedStatement)2 ResultSet (com.datastax.driver.core.ResultSet)2 Row (com.datastax.driver.core.Row)2 Select (com.datastax.driver.core.querybuilder.Select)2 Column (com.google.bigtable.v2.Column)2 Family (com.google.bigtable.v2.Family)2