Search in sources :

Example 26 with StringByteIterator

use of site.ycsb.StringByteIterator in project gora by apache.

the class GoraBenchmarkClient method read.

/**
 * Read a record from the database. Each field/value pair from the result will
 * be stored in a HashMap.
 *
 * @param table The name of the table
 * @param key The record key of the record to read.
 * @param fields The list of fields to read, or null for all of them
 * @param result A HashMap oftestInsert field/value pairs for the result
 * @return The result of the operation.
 */
@Override
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
    try {
        // Check for null is necessary.
        User user = (fields == null || fields.size() == 0) ? dataStore.get(key) : dataStore.get(key, fields.toArray(DUMMY_ARRAY));
        for (int fieldCount = 0; fieldCount < totalFieldCount; fieldCount++) {
            String field = FIELDS[fieldCount + 1];
            int fieldIndex = fieldCount + 1;
            String value = user.get(fieldIndex).toString();
            result.put(field, new StringByteIterator(value));
        }
    } catch (Exception e) {
        LOG.info("There is a problem in reading data from the table \n {}", e.getMessage(), e);
        return Status.ERROR;
    }
    return Status.OK;
}
Also used : User(org.apache.gora.benchmark.generated.User) StringByteIterator(site.ycsb.StringByteIterator) DBException(site.ycsb.DBException) GoraException(org.apache.gora.util.GoraException)

Example 27 with StringByteIterator

use of site.ycsb.StringByteIterator in project gora by apache.

the class GoraBenchmarkClient 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 start key
 * @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 The result of the operation.
 */
@Override
public Status scan(String table, String startKey, int recordCount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
    try {
        Query<String, User> goraQuery = dataStore.newQuery();
        goraQuery.setStartKey(startKey);
        goraQuery.setLimit(recordCount);
        Result<String, User> resultSet = goraQuery.execute();
        while (resultSet.next()) {
            HashMap<String, ByteIterator> resultsMap = new HashMap<>();
            for (int fieldCount = 0; fieldCount < totalFieldCount; fieldCount++) {
                String field = FIELDS[fieldCount + 1];
                int fieldIndex = fieldCount + 1;
                String value = resultSet.get().get(fieldIndex).toString();
                resultsMap.put(field, new StringByteIterator(value));
            }
            result.add(resultsMap);
        }
    } catch (Exception e) {
        LOG.info("There is a problem in scanning data from the table \n {}", e.getMessage(), e);
        return Status.ERROR;
    }
    return Status.OK;
}
Also used : User(org.apache.gora.benchmark.generated.User) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) StringByteIterator(site.ycsb.StringByteIterator) DBException(site.ycsb.DBException) GoraException(org.apache.gora.util.GoraException)

Example 28 with StringByteIterator

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

the class BackoffSelectStrategy method scanSpecificFields.

/**
 * Performs the {@link #scan(String, String, int, Set, Vector)} operation N1Ql only for a subset of the fields.
 *
 * @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 The result of the operation.
 */
private Status scanSpecificFields(final String table, final String startkey, final int recordcount, final Set<String> fields, final Vector<HashMap<String, ByteIterator>> result) {
    String scanSpecQuery = "SELECT " + joinFields(fields) + " FROM `" + bucketName + "` WHERE meta().id >= '$1' LIMIT $2";
    N1qlQueryResult queryResult = bucket.query(N1qlQuery.parameterized(scanSpecQuery, JsonArray.from(formatId(table, startkey), recordcount), N1qlParams.build().adhoc(adhoc).maxParallelism(maxParallelism)));
    if (!queryResult.parseSuccess() || !queryResult.finalSuccess()) {
        throw new RuntimeException("Error while parsing N1QL Result. Query: " + scanSpecQuery + ", Errors: " + queryResult.errors());
    }
    boolean allFields = fields == null || fields.isEmpty();
    result.ensureCapacity(recordcount);
    for (N1qlQueryRow row : queryResult) {
        JsonObject value = row.value();
        if (fields == null) {
            value = value.getObject(bucketName);
        }
        Set<String> f = allFields ? value.getNames() : fields;
        HashMap<String, ByteIterator> tuple = new HashMap<String, ByteIterator>(f.size());
        for (String field : f) {
            tuple.put(field, new StringByteIterator(value.getString(field)));
        }
        result.add(tuple);
    }
    return Status.OK;
}
Also used : ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) StringByteIterator(site.ycsb.StringByteIterator) JsonObject(com.couchbase.client.java.document.json.JsonObject)

Example 29 with StringByteIterator

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

the class GridDBClientTest method testUpdate.

@Test
public void testUpdate() {
    HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
    HashMap<String, ByteIterator> values = new HashMap<String, ByteIterator>();
    insertToDatabase();
    String keyForUpdate = "field2";
    Set<String> fields = Collections.singleton(keyForUpdate);
    String strValueToUpdate = "new_value_2";
    ByteIterator valForUpdate = new StringByteIterator(strValueToUpdate);
    values.put(keyForUpdate, valForUpdate);
    Status updateStatus = myClient.update(TEST_TABLE, DEFAULT_ROW_KEY, values);
    assertEquals(updateStatus, Status.OK);
    // After update, we read the update row for get new value
    myClient.read(TEST_TABLE, DEFAULT_ROW_KEY, fields, result);
    assertNotEquals(result.entrySet(), 0);
    boolean found = false;
    for (int i = 0; i < FIELD_COUNT; i++) {
        ByteIterator iter = result.get("field" + i);
        byte[] byteArray1 = iter.toArray();
        String value = new String(byteArray1);
        // check result has row value is new update value or not
        if (value.equals(strValueToUpdate)) {
            found = true;
        }
    }
    assertEquals(found, true);
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) StringByteIterator(site.ycsb.StringByteIterator) Test(org.junit.Test)

Example 30 with StringByteIterator

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

the class ElasticsearchClientTest method testUpdate.

/**
 * Test of update method, of class ElasticsearchClient.
 */
@Test
public void testUpdate() {
    int i;
    HashMap<String, ByteIterator> newValues = new HashMap<>(10);
    for (i = 1; i <= 10; i++) {
        newValues.put(FIELD_PREFIX + 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<>(10);
    instance.read(MOCK_TABLE, MOCK_KEY1, MOCK_DATA.keySet(), resultParam);
    for (i = 1; i <= 10; i++) {
        assertEquals("newvalue" + i, resultParam.get(FIELD_PREFIX + i).toString());
    }
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) StringByteIterator(site.ycsb.StringByteIterator) Test(org.junit.Test)

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