Search in sources :

Example 41 with StringByteIterator

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

the class VoltDBClientTest method updateTest.

@Test
public void updateTest() {
    Assume.assumeTrue(haveDb);
    try {
        // Create some test data
        final String insertKey = UPDATE_TEST_KEY;
        // Insert row
        // Insert row
        HashMap<String, ByteIterator> insertThenUpdateMap = new HashMap<String, ByteIterator>();
        for (int i = 0; i < NUM_FIELDS; i++) {
            insertThenUpdateMap.put(FIELD_PREFIX + i, new StringByteIterator(buildDeterministicValue(insertKey, FIELD_PREFIX + i)));
        }
        voltClient.insert(TABLE_NAME, insertKey, insertThenUpdateMap);
        // Change the data we inserted...
        for (int i = 0; i < NUM_FIELDS; i++) {
            insertThenUpdateMap.put(FIELD_PREFIX + i, new StringByteIterator(FIELD_PREFIX + i + " has changed"));
        }
        // now do an update
        voltClient.update(TABLE_NAME, insertKey, insertThenUpdateMap);
        // Create a object to put retrieved row in...
        final Set<String> columns = getColumnNameMap();
        Map<String, ByteIterator> testResult = new HashMap<String, ByteIterator>();
        // Read row...
        Status s = voltClient.read(TABLE_NAME, insertKey, columns, testResult);
        if (!s.equals(Status.OK)) {
            fail("Didn't get OK on read.");
        }
        if (!compareContents(insertThenUpdateMap, testResult)) {
            fail("Returned data not the same as inserted data");
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Failed updateTest");
    }
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) StringByteIterator(site.ycsb.StringByteIterator) Assume.assumeNoException(org.junit.Assume.assumeNoException) DBException(site.ycsb.DBException)

Example 42 with StringByteIterator

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

the class RocksDBClientTest method insertUpdateAndRead.

@Test
public void insertUpdateAndRead() throws Exception {
    final Map<String, ByteIterator> newValues = new HashMap<>(NUM_RECORDS);
    final Status insertResult = instance.insert(MOCK_TABLE, MOCK_KEY2, MOCK_DATA);
    assertEquals(Status.OK, insertResult);
    for (int i = 0; i < NUM_RECORDS; i++) {
        newValues.put(FIELD_PREFIX + i, new StringByteIterator("newvalue" + i));
    }
    final Status result = instance.update(MOCK_TABLE, MOCK_KEY2, newValues);
    assertEquals(Status.OK, result);
    // validate that the values changed
    final Map<String, ByteIterator> resultParam = new HashMap<>(NUM_RECORDS);
    instance.read(MOCK_TABLE, MOCK_KEY2, MOCK_DATA.keySet(), resultParam);
    for (int i = 0; i < NUM_RECORDS; i++) {
        assertEquals("newvalue" + i, resultParam.get(FIELD_PREFIX + i).toString());
    }
}
Also used : Status(site.ycsb.Status) StringByteIterator(site.ycsb.StringByteIterator) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator)

Example 43 with StringByteIterator

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

the class KuduYCSBClient method addAllRowsToResult.

private void addAllRowsToResult(RowResultIterator it, int recordcount, List<String> querySchema, Vector<HashMap<String, ByteIterator>> result) throws Exception {
    RowResult row;
    HashMap<String, ByteIterator> rowResult = new HashMap<>(querySchema.size());
    if (it == null) {
        return;
    }
    while (it.hasNext()) {
        if (result.size() == recordcount) {
            return;
        }
        row = it.next();
        int colIdx = 0;
        for (String col : querySchema) {
            rowResult.put(col, new StringByteIterator(row.getString(colIdx)));
            colIdx++;
        }
        result.add(rowResult);
    }
}
Also used : ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) StringByteIterator(site.ycsb.StringByteIterator)

Example 44 with StringByteIterator

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

the class OrientDBClientTest method insertRow.

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

Example 45 with StringByteIterator

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

the class JdbcDBClient method scan.

@Override
public Status scan(String tableName, String startKey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
    try {
        StatementType type = new StatementType(StatementType.Type.SCAN, tableName, 1, "", getShardIndexByKey(startKey));
        PreparedStatement scanStatement = cachedStatements.get(type);
        if (scanStatement == null) {
            scanStatement = createAndCacheScanStatement(type, startKey);
        }
        // SQL Server TOP syntax is at first
        if (sqlserverScans) {
            scanStatement.setInt(1, recordcount);
            scanStatement.setString(2, startKey);
        // FETCH FIRST and LIMIT are at the end
        } else {
            scanStatement.setString(1, startKey);
            scanStatement.setInt(2, recordcount);
        }
        ResultSet resultSet = scanStatement.executeQuery();
        for (int i = 0; i < recordcount && resultSet.next(); i++) {
            if (result != null && fields != null) {
                HashMap<String, ByteIterator> values = new HashMap<String, ByteIterator>();
                for (String field : fields) {
                    String value = resultSet.getString(field);
                    values.put(field, new StringByteIterator(value));
                }
                result.add(values);
            }
        }
        resultSet.close();
        return Status.OK;
    } catch (SQLException e) {
        System.err.println("Error in processing scan of table: " + tableName + e);
        return Status.ERROR;
    }
}
Also used : StringByteIterator(site.ycsb.StringByteIterator) ByteIterator(site.ycsb.ByteIterator) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StringByteIterator(site.ycsb.StringByteIterator)

Aggregations

StringByteIterator (site.ycsb.StringByteIterator)49 ByteIterator (site.ycsb.ByteIterator)32 HashMap (java.util.HashMap)31 Status (site.ycsb.Status)19 DBException (site.ycsb.DBException)15 Test (org.junit.Test)12 Map (java.util.Map)8 IOException (java.io.IOException)5 Assume.assumeNoException (org.junit.Assume.assumeNoException)4 UnknownHostException (java.net.UnknownHostException)3 SearchResponse (org.elasticsearch.action.search.SearchResponse)3 SearchHit (org.elasticsearch.search.SearchHit)3 JsonObject (com.couchbase.client.java.document.json.JsonObject)2 Collections.emptyMap (java.util.Collections.emptyMap)2 User (org.apache.gora.benchmark.generated.User)2 GoraException (org.apache.gora.util.GoraException)2 SolrQuery (org.apache.solr.client.solrj.SolrQuery)2 SolrServerException (org.apache.solr.client.solrj.SolrServerException)2 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)2 SolrDocumentList (org.apache.solr.common.SolrDocumentList)2