use of com.ibm.watson.discovery.v2.model.QueryResult in project aws-sdk-android by aws-amplify.
the class DynamoDBMapper method query.
/**
* Queries an Amazon DynamoDB table and returns the matching results as an
* unmodifiable list of instantiated objects. The table to query is
* determined by looking at the annotations on the specified class, which
* declares where to store the object data in Amazon DynamoDB, and the query
* expression parameter allows the caller to filter results and control how
* the query is executed.
* <p>
* When the query is on any local/global secondary index, callers should be
* aware that the returned object(s) will only contain item attributes that
* are projected into the index. All the other unprojected attributes will
* be saved as type default values.
* <p>
* Callers should also be aware that the returned list is unmodifiable, and
* any attempts to modify the list will result in an
* UnsupportedOperationException.
* <p>
* You can specify the pagination loading strategy for this query operation.
* By default, the list returned is lazily loaded when possible.
*
* @param <T> The type of the objects being returned.
* @param clazz The class annotated with DynamoDB annotations describing how
* to store the object data in Amazon DynamoDB.
* @param queryExpression Details on how to run the query, including any
* conditions on the key values
* @param config The configuration to use for this query, which overrides
* the default provided at object construction.
* @return An unmodifiable list of the objects constructed from the results
* of the query operation.
* @see PaginatedQueryList
* @see PaginationLoadingStrategy
*/
public <T> PaginatedQueryList<T> query(Class<T> clazz, DynamoDBQueryExpression<T> queryExpression, DynamoDBMapperConfig config) {
config = mergeConfig(config);
final QueryRequest queryRequest = createQueryRequestFromExpression(clazz, queryExpression, config);
final QueryResult queryResult = db.query(applyUserAgent(queryRequest));
return new PaginatedQueryList<T>(this, clazz, db, queryRequest, queryResult, config.getPaginationLoadingStrategy(), config);
}
use of com.ibm.watson.discovery.v2.model.QueryResult in project aws-athena-query-federation by awslabs.
the class DynamoDBRecordHandler method getIterator.
/*
Creates an iterator that can iterate through a Query or Scan, sending paginated requests as necessary
*/
private Iterator<Map<String, AttributeValue>> getIterator(Split split, String tableName, Schema schema) {
AmazonWebServiceRequest request = buildReadRequest(split, tableName, schema);
return new Iterator<Map<String, AttributeValue>>() {
AtomicReference<Map<String, AttributeValue>> lastKeyEvaluated = new AtomicReference<>();
AtomicReference<Iterator<Map<String, AttributeValue>>> currentPageIterator = new AtomicReference<>();
@Override
public boolean hasNext() {
return currentPageIterator.get() == null || currentPageIterator.get().hasNext() || lastKeyEvaluated.get() != null;
}
@Override
public Map<String, AttributeValue> next() {
if (currentPageIterator.get() != null && currentPageIterator.get().hasNext()) {
return currentPageIterator.get().next();
}
Iterator<Map<String, AttributeValue>> iterator;
try {
if (request instanceof QueryRequest) {
QueryRequest paginatedRequest = ((QueryRequest) request).withExclusiveStartKey(lastKeyEvaluated.get());
logger.info("Invoking DDB with Query request: {}", request);
QueryResult queryResult = invokerCache.get(tableName).invoke(() -> ddbClient.query(paginatedRequest));
lastKeyEvaluated.set(queryResult.getLastEvaluatedKey());
iterator = queryResult.getItems().iterator();
} else {
ScanRequest paginatedRequest = ((ScanRequest) request).withExclusiveStartKey(lastKeyEvaluated.get());
logger.info("Invoking DDB with Scan request: {}", request);
ScanResult scanResult = invokerCache.get(tableName).invoke(() -> ddbClient.scan(paginatedRequest));
lastKeyEvaluated.set(scanResult.getLastEvaluatedKey());
iterator = scanResult.getItems().iterator();
}
} catch (TimeoutException | ExecutionException e) {
throw new RuntimeException(e);
}
currentPageIterator.set(iterator);
if (iterator.hasNext()) {
return iterator.next();
} else {
return null;
}
}
};
}
Aggregations