Search in sources :

Example 16 with ByteIterator

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

the class CloudSpannerClient method scan.

@Override
public Status scan(String table, String startKey, int recordCount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
    if (queriesForReads) {
        return scanUsingQuery(table, startKey, recordCount, fields, result);
    }
    Iterable<String> columns = fields == null ? STANDARD_FIELDS : fields;
    KeySet keySet = KeySet.newBuilder().addRange(KeyRange.closedClosed(Key.of(startKey), Key.of())).build();
    try (ResultSet resultSet = dbClient.singleUse(timestampBound).read(table, keySet, columns, Options.limit(recordCount))) {
        while (resultSet.next()) {
            HashMap<String, ByteIterator> row = new HashMap<>();
            decodeStruct(columns, resultSet, row);
            result.add(row);
        }
        return Status.OK;
    } catch (Exception e) {
        LOGGER.log(Level.INFO, "scan()", e);
        return Status.ERROR;
    }
}
Also used : KeySet(com.google.cloud.spanner.KeySet) StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) HashMap(java.util.HashMap) ResultSet(com.google.cloud.spanner.ResultSet) DBException(com.yahoo.ycsb.DBException)

Example 17 with ByteIterator

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

the class AsyncHBaseClient method update.

@Override
public Status update(String table, String key, HashMap<String, ByteIterator> values) {
    setTable(table);
    if (debug) {
        System.out.println("Setting up put for key: " + key);
    }
    final byte[][] qualifiers = new byte[values.size()][];
    final byte[][] byteValues = new byte[values.size()][];
    int idx = 0;
    for (final Entry<String, ByteIterator> entry : values.entrySet()) {
        qualifiers[idx] = entry.getKey().getBytes();
        byteValues[idx++] = entry.getValue().toArray();
        if (debug) {
            System.out.println("Adding field/value " + entry.getKey() + "/" + Bytes.pretty(entry.getValue().toArray()) + " to put request");
        }
    }
    final PutRequest put = new PutRequest(lastTableBytes, key.getBytes(), columnFamilyBytes, qualifiers, byteValues);
    if (!durability) {
        put.setDurable(false);
    }
    if (!clientSideBuffering) {
        put.setBufferable(false);
        try {
            client.put(put).join(joinTimeout);
        } catch (InterruptedException e) {
            System.err.println("Thread interrupted");
            Thread.currentThread().interrupt();
        } catch (Exception e) {
            System.err.println("Failure reading from row with key " + key + ": " + e.getMessage());
            return Status.ERROR;
        }
    } else {
        // hooray! Asynchronous write. But without a callback and an async
        // YCSB call we don't know whether it succeeded or not
        client.put(put);
    }
    return Status.OK;
}
Also used : ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) PutRequest(org.hbase.async.PutRequest) DBException(com.yahoo.ycsb.DBException) IOException(java.io.IOException)

Example 18 with ByteIterator

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

the class AsyncHBaseTest method testScan.

@Test
public void testScan() throws Exception {
    // Fill with data
    final String colStr = "row_number";
    final byte[] col = Bytes.toBytes(colStr);
    final int n = 10;
    final List<Put> puts = new ArrayList<Put>(n);
    for (int i = 0; i < n; i++) {
        final byte[] key = Bytes.toBytes(String.format("%05d", i));
        final byte[] value = java.nio.ByteBuffer.allocate(4).putInt(i).array();
        final Put p = new Put(key);
        p.addColumn(Bytes.toBytes(COLUMN_FAMILY), col, value);
        puts.add(p);
    }
    table.put(puts);
    // Test
    final Vector<HashMap<String, ByteIterator>> result = new Vector<HashMap<String, ByteIterator>>();
    // Scan 5 records, skipping the first
    client.scan(tableName, "00001", 5, null, result);
    assertEquals(5, result.size());
    for (int i = 0; i < 5; i++) {
        final HashMap<String, ByteIterator> row = result.get(i);
        assertEquals(1, row.size());
        assertTrue(row.containsKey(colStr));
        final byte[] bytes = row.get(colStr).toArray();
        final ByteBuffer buf = ByteBuffer.wrap(bytes);
        final int rowNum = buf.getInt();
        assertEquals(i + 1, rowNum);
    }
}
Also used : StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Vector(java.util.Vector) ByteBuffer(java.nio.ByteBuffer) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 19 with ByteIterator

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

the class AsyncHBaseTest method testRead.

@Test
public void testRead() throws Exception {
    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(com.yahoo.ycsb.Status) StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) HashMap(java.util.HashMap) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 20 with ByteIterator

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

the class AzureClient method insertOrUpdate.

private Status insertOrUpdate(String key, HashMap<String, ByteIterator> values) {
    HashMap<String, EntityProperty> properties = new HashMap<String, EntityProperty>();
    for (Entry<String, ByteIterator> entry : values.entrySet()) {
        String fieldName = entry.getKey();
        byte[] fieldVal = entry.getValue().toArray();
        properties.put(fieldName, new EntityProperty(fieldVal));
    }
    DynamicTableEntity entity = new DynamicTableEntity(partitionKey, key, properties);
    TableOperation insertOrReplace = TableOperation.insertOrReplace(entity);
    try {
        cloudTable.execute(insertOrReplace);
        return Status.OK;
    } catch (Exception e) {
        return Status.ERROR;
    }
}
Also used : EntityProperty(com.microsoft.azure.storage.table.EntityProperty) DynamicTableEntity(com.microsoft.azure.storage.table.DynamicTableEntity) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) HashMap(java.util.HashMap) TableOperation(com.microsoft.azure.storage.table.TableOperation) DBException(com.yahoo.ycsb.DBException)

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