use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class ScyllaCQLClientTest method testReadSingleColumn.
@Test
public void testReadSingleColumn() {
insertRow();
final HashMap<String, ByteIterator> result = new HashMap<>();
final Set<String> fields = Sets.newHashSet("field1");
final Status status = client.read(TABLE, DEFAULT_ROW_KEY, fields, result);
assertThat(status, is(Status.OK));
assertThat(result.entrySet(), hasSize(1));
final Map<String, String> strResult = StringByteIterator.getStringMap(result);
assertThat(strResult, hasEntry("field1", "value2"));
}
use of site.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;
}
}
use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class CloudSpannerClient method scanUsingQuery.
private Status scanUsingQuery(String table, String startKey, int recordCount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
Iterable<String> columns = fields == null ? STANDARD_FIELDS : fields;
Statement query;
if (fields == null || fields.size() == fieldCount) {
query = Statement.newBuilder(standardScan).bind("startKey").to(startKey).bind("count").to(recordCount).build();
} else {
Joiner joiner = Joiner.on(',');
query = Statement.newBuilder("SELECT ").append(joiner.join(fields)).append(" FROM ").append(table).append(" WHERE id>=@startKey LIMIT @count").bind("startKey").to(startKey).bind("count").to(recordCount).build();
}
try (ResultSet resultSet = dbClient.singleUse(timestampBound).executeQuery(query)) {
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, "scanUsingQuery()", e);
return Status.ERROR;
}
}
use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class AzureCosmosClient 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
*/
@Override
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
try {
CosmosQueryRequestOptions queryOptions = new CosmosQueryRequestOptions();
queryOptions.setMaxDegreeOfParallelism(AzureCosmosClient.maxDegreeOfParallelism);
queryOptions.setMaxBufferedItemCount(AzureCosmosClient.maxBufferedItemCount);
CosmosContainer container = AzureCosmosClient.containerCache.get(table);
if (container == null) {
container = AzureCosmosClient.database.getContainer(table);
AzureCosmosClient.containerCache.put(table, container);
}
List<SqlParameter> paramList = new ArrayList<>();
paramList.add(new SqlParameter("@startkey", startkey));
SqlQuerySpec querySpec = new SqlQuerySpec(this.createSelectTop(fields, recordcount) + " FROM root r WHERE r.id >= @startkey", paramList);
CosmosPagedIterable<ObjectNode> pagedIterable = container.queryItems(querySpec, queryOptions, ObjectNode.class);
Iterator<FeedResponse<ObjectNode>> pageIterator = pagedIterable.iterableByPage(AzureCosmosClient.preferredPageSize).iterator();
while (pageIterator.hasNext()) {
List<ObjectNode> pageDocs = pageIterator.next().getResults();
for (ObjectNode doc : pageDocs) {
Map<String, String> stringResults = new HashMap<>(doc.size());
Iterator<Map.Entry<String, JsonNode>> nodeIterator = doc.fields();
while (nodeIterator.hasNext()) {
Entry<String, JsonNode> pair = nodeIterator.next();
stringResults.put(pair.getKey().toString(), pair.getValue().toString());
}
HashMap<String, ByteIterator> byteResults = new HashMap<>(doc.size());
StringByteIterator.putAllAsByteIterators(byteResults, stringResults);
result.add(byteResults);
}
}
return Status.OK;
} catch (CosmosException e) {
if (!AzureCosmosClient.includeExceptionStackInLog) {
e = null;
}
LOGGER.error("Failed to query key {} from collection {} in database {}", startkey, table, AzureCosmosClient.databaseName, e);
}
return Status.ERROR;
}
use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.
the class AzureClient method readSubset.
/*
* Read subset of properties instead of full fields with projection.
*/
public Status readSubset(String key, Set<String> fields, Map<String, ByteIterator> result) {
String whereStr = String.format("RowKey eq '%s'", key);
TableQuery<TableServiceEntity> projectionQuery = TableQuery.from(TableServiceEntity.class).where(whereStr).select(fields.toArray(new String[0]));
EntityResolver<HashMap<String, ByteIterator>> resolver = new EntityResolver<HashMap<String, ByteIterator>>() {
public HashMap<String, ByteIterator> resolve(String partitionkey, String rowKey, Date timeStamp, HashMap<String, EntityProperty> properties, String etag) {
HashMap<String, ByteIterator> tmp = new HashMap<String, ByteIterator>();
for (Entry<String, EntityProperty> entry : properties.entrySet()) {
String key = entry.getKey();
ByteIterator val = new ByteArrayByteIterator(entry.getValue().getValueAsByteArray());
tmp.put(key, val);
}
return tmp;
}
};
try {
for (HashMap<String, ByteIterator> tmp : cloudTable.execute(projectionQuery, resolver)) {
for (Entry<String, ByteIterator> entry : tmp.entrySet()) {
String fieldName = entry.getKey();
ByteIterator fieldVal = entry.getValue();
result.put(fieldName, fieldVal);
}
}
return Status.OK;
} catch (Exception e) {
return Status.ERROR;
}
}
Aggregations