use of com.azure.cosmos.models.FeedResponse 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;
}
Aggregations