Dynamodb 简明教程
DynamoDB - Aggregation
DynamoDB 不提供聚合函数。你必须创新地使用查询、扫描、索引和各种工具来执行这些任务。在所有这一切中,这些操作中查询/扫描的吞吐量开销可能会很大。
DynamoDB does not provide aggregation functions. You must make creative use of queries, scans, indices, and assorted tools to perform these tasks. In all this, the throughput expense of queries/scans in these operations can be heavy.
你还可以选择使用适合偏好 DynamoDB 编码语言的库和其它工具。在使用之前确保其与 DynamoDB 的兼容性。
You also have the option to use libraries and other tools for your preferred DynamoDB coding language. Ensure their compatibility with DynamoDB prior to using it.
Calculate Maximum or Minimum
使用结果的升序/降序存储顺序、Limit 参数以及任何设置顺序的参数来查找最高和最低的值。
Utilize the ascending/descending storage order of results, the Limit parameter, and any parameters which set order to find the highest and lowest values.
例如 -
For example −
Map<String, AttributeValue> eaval = new HashMap<>();
eaval.put(":v1", new AttributeValue().withS("hashval"));
queryExpression = new DynamoDBQueryExpression<Table>()
.withIndexName("yourindexname")
.withKeyConditionExpression("HK = :v1")
.withExpressionAttributeValues(values)
.withScanIndexForward(false); //descending order
queryExpression.setLimit(1);
QueryResultPage<Lookup> res =
dynamoDBMapper.queryPage(Table.class, queryExpression);
Calculate Count
使用 DescribeTable 获取表项计数,但请注意它提供的是旧数据。此外,利用 Java getScannedCount method 。
Use DescribeTable to get a count of the table items, however, note that it provides stale data. Also, utilize the Java getScannedCount method.
使用 LastEvaluatedKey 确保它提供所有结果。
Utilize LastEvaluatedKey to ensure it delivers all results.
例如 -
For example −
ScanRequest scanRequest = new ScanRequest().withTableName(yourtblName);
ScanResult yourresult = client.scan(scanRequest);
System.out.println("#items:" + yourresult.getScannedCount());