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());
}
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;
}
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;
}
}
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);
}
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;
}
}
Aggregations