
- DynamoDB Tutorial
- DynamoDB - Home
- DynamoDB - Overview
- DynamoDB - Basic Concepts
- DynamoDB - Environment
- DynamoDB - Operations Tools
- DynamoDB - Data Types
- DynamoDB - Create Table
- DynamoDB - Load Table
- DynamoDB - Query Table
- DynamoDB - Delete Table
- DynamoDB - API Interface
- DynamoDB - Creating Items
- DynamoDB - Getting Items
- DynamoDB - Update Items
- DynamoDB - Delete Items
- DynamoDB - Batch Writing
- DynamoDB - Batch Retrieve
- DynamoDB - Querying
- DynamoDB - Scan
- DynamoDB - Indexes
- Global Secondary Indexes
- Local Secondary Indexes
- DynamoDB - Aggregation
- DynamoDB - Access Control
- DynamoDB - Permissions API
- DynamoDB - Conditions
- Web Identity Federation
- DynamoDB - Data Pipeline
- DynamoDB - Data Backup
- DynamoDB - Monitoring
- DynamoDB - CloudTrail
- DynamoDB - MapReduce
- DynamoDB - Table Activity
- DynamoDB - Error Handling
- DynamoDB - Best Practices
- DynamoDB Useful Resources
- DynamoDB - Quick Guide
- DynamoDB - Useful Resources
- DynamoDB - Discussion
DynamoDB - Aggregation
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.
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
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
Use DescribeTable to get a count of the table items, however, note that it provides stale data. Also, utilize the Java getScannedCount method.
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());
Calculating Average and Sum
Utilize indices and a query/scan to retrieve and filter values before processing. Then simply operate on those values through an object.