[英]How to get all results in a query to a aws dynamodb table?
the first example given in http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryingJavaDocumentAPI.html which returns a ItemCollection http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryingJavaDocumentAPI.html中给出的第一个示例,它返回一个 ItemCollection
According to http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html#Pagination we need to get the lastevaluatedkey and perform the query again but there isn't any getlastevaluatedkey for a ItemCollection that is returned from dynamoDb.getTable("tableName").query(keyattribute)根据http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html#Pagination我们需要获取 lastevaluatedkey 并再次执行查询,但没有任何 getlastevaluatedkey 从返回的 ItemCollection dynamoDb.getTable("tableName").query(keyattribute)
Also ItemCollection documentation states that n/w calls would be made if iterated across page boundary so do we have to make calls till again as given in http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html#Pagination or not ItemCollection 文档还指出,如果跨页面边界迭代,将进行 n/w 调用,所以我们是否必须再次调用,如http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html 中给出的#分页与否
getLastEvaluatedKey is a method of QueryResult (or ScanResult). getLastEvaluatedKey 是QueryResult (或 ScanResult)的一种方法。
In the example you refer to, a collection of QueryOutcome is used, bypassing the QueryResult.在您引用的示例中,使用了 QueryOutcome 的集合,绕过了 QueryResult。 To get the last evaluated key, you could try doing this
要获得最后评估的密钥,您可以尝试这样做
QueryRequest request = new QueryRequest();
request.setTableName(tablename);
QueryResult result = dynamoDB.query(request);
ItemCollection<QueryOutcome> items = result.getItems();
Map<String,AttributeValue> lastKey = result.getLastEvaluatedKey();
I hope this helps.我希望这有帮助。
Once you have the Map - you can further process the returned data.拥有地图后 - 您可以进一步处理返回的数据。 For example, in this example, the key name and data are pushed into two ArrayList objects:
例如,在本例中,键名和数据被推送到两个ArrayList对象中:
ArrayList<String> keys = new ArrayList<String>();
ArrayList<String> keyVals = new ArrayList<String>();
for (Map<String, AttributeValue> item : result.getItems()) {
Set<String> key = item.keySet();
Collection<AttributeValue> values = item.values();
for (Iterator<String> it = key.iterator(); it.hasNext(); ) {
String f = it.next();
System.out.println(f);
keys.add(f);
}
for (Iterator<AttributeValue> it2 = values.iterator(); it2.hasNext(); ) {
AttributeValue v1 = it2.next();
String yy= v1.getS();
keyVals.add(yy);
}
}
Then you can do what you need to do with the returned data然后你可以对返回的数据做你需要做的事情
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.