in azurecosmos/src/main/java/site/ycsb/db/AzureCosmosClient.java [427:484]
public Status scan(String table, String startkey, int recordcount, Set<String> fields,
Vector<HashMap<String, ByteIterator>> result) {
try {
long st = System.nanoTime();
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()) {
FeedResponse<ObjectNode> feedResponse = pageIterator.next();
List<ObjectNode> pageDocs = feedResponse.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);
}
}
if (scanSuccessLatencyTimer != null) {
long en = System.nanoTime();
long latency = (en - st) / 1000;
scanSuccessLatencyTimer.record(latency, TimeUnit.MICROSECONDS);
scanSuccessCounter.increment();
}
return Status.OK;
} catch (CosmosException e) {
int statusCode = e.getStatusCode();
if (!AzureCosmosClient.includeExceptionStackInLog) {
e = null;
}
LOGGER.error(QUERY_EXCEPTION, "Failed to query key {} from collection {} in database {} statusCode {}",
startkey, table, AzureCosmosClient.databaseName, statusCode, e);
}
if (scanFailureCounter != null) {
scanFailureCounter.increment();
}
return Status.ERROR;
}