Search in sources :

Example 1 with ByteIterator

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

the class GoraClientTest method testRead.

/**
 * Test read performs a read record test from the database.
 */
@Test
public void testRead() {
    insertData();
    HashMap<String, ByteIterator> results = new HashMap<>();
    // this could be null as well
    Set<String> fields = new HashSet<>();
    Status result = benchmarkClient.read(Constants.TEST_TABLE, Constants.TEST_KEY_1, fields, results);
    assertEquals(Status.OK, result);
    assertEquals(DATA_TO_INSERT.size(), results.size());
    assertEquals(DATA_TO_INSERT.get(Constants.TEST_FIELD_0).toString(), results.get(Constants.TEST_FIELD_0).toString());
    assertEquals(Constants.TEST_VALUE_0, results.get(Constants.TEST_FIELD_0).toString());
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) Test(org.junit.Test)

Example 2 with ByteIterator

use of site.ycsb.ByteIterator 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 3 with ByteIterator

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

the class ElasticsearchClient 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 this 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) {
    try {
        final RangeQueryBuilder rangeQuery = rangeQuery("_id").gte(startkey);
        final SearchResponse response = client.prepareSearch(indexKey).setTypes(table).setQuery(rangeQuery).setSize(recordcount).execute().actionGet();
        HashMap<String, ByteIterator> entry;
        for (SearchHit hit : response.getHits()) {
            entry = new HashMap<>(fields.size());
            for (String field : fields) {
                entry.put(field, new StringByteIterator((String) hit.getSource().get(field)));
            }
            result.add(entry);
        }
        return Status.OK;
    } catch (Exception e) {
        e.printStackTrace();
        return Status.ERROR;
    }
}
Also used : ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) SearchHit(org.elasticsearch.search.SearchHit) StringByteIterator(site.ycsb.StringByteIterator) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) UnknownHostException(java.net.UnknownHostException) DBException(site.ycsb.DBException) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 4 with ByteIterator

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

the class ElasticsearchClientTest method testRead.

/**
 * Test of read method, of class ElasticsearchClient.
 */
@Test
public void testRead() {
    Set<String> fields = MOCK_DATA.keySet();
    HashMap<String, ByteIterator> resultParam = new HashMap<>(10);
    Status result = instance.read(MOCK_TABLE, MOCK_KEY1, fields, resultParam);
    assertEquals(Status.OK, result);
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 5 with ByteIterator

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

the class ElasticsearchClient method scan.

@Override
public Status scan(final String table, final String startkey, final int recordcount, final Set<String> fields, final Vector<HashMap<String, ByteIterator>> result) {
    try {
        refreshIfNeeded();
        final RangeQueryBuilder query = new RangeQueryBuilder(KEY).gte(startkey);
        final SearchResponse response = client.prepareSearch(indexKey).setQuery(query).setSize(recordcount).get();
        for (final SearchHit hit : response.getHits()) {
            final HashMap<String, ByteIterator> entry;
            if (fields != null) {
                entry = new HashMap<>(fields.size());
                for (final String field : fields) {
                    entry.put(field, new StringByteIterator((String) hit.getSource().get(field)));
                }
            } else {
                entry = new HashMap<>(hit.getSource().size());
                for (final Map.Entry<String, Object> field : hit.getSource().entrySet()) {
                    if (KEY.equals(field.getKey())) {
                        continue;
                    }
                    entry.put(field.getKey(), new StringByteIterator((String) field.getValue()));
                }
            }
            result.add(entry);
        }
        return Status.OK;
    } catch (final Exception e) {
        e.printStackTrace();
        return Status.ERROR;
    }
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) StringByteIterator(site.ycsb.StringByteIterator) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) HashMap(java.util.HashMap) Map(java.util.Map) UnknownHostException(java.net.UnknownHostException) DBException(site.ycsb.DBException) SearchResponse(org.elasticsearch.action.search.SearchResponse)

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