Is there a way to query multiple hash keys using a single query in Amazon's AWS SDK for Java?
Here's my issue; I have a DB table for project statuses. The Hash Key is the status of a project (ie: new, assigned, processing, or complete). The range key is a set of project IDs. Currently, I've got a query setup to simply find all the projects listed as a status(hash) of "assigned" and another query set to look for a status of "processing". Is there a way to do this using a single query rather than sending multiple queries for each status I need to find? Code below:
DynamoDBMapper mapper = new DynamoDBMapper(new AmazonDynamoDBClient(credentials));
PStatus assignedStatus = new PStatus();
assignedStatus.setStatus("assigned");
PStatus processStatus = new PStatus();
processStatus.setStatus("processing");
DynamoDBQueryExpression<PStatus> queryAssigned = new DynamoDBQueryExpression<PStatus>().withHashKeyValues(assignedStatus);
DynamoDBQueryExpression<PStatus> queryProcessing = new DynamoDBQueryExpression<PStatus>().withHashKeyValues(processStatus);
List<PStatus> assigned = mapper.query(PStatus.class, queryAssigned);
List<PStatus> process = mapper.query(PStatus.class, queryProcessing);
So basically, I'd like to know if it's possible to eliminate the queryAssigned
and assigned
variables and handle both assignedStatus
and processStatus
via the same query, process
, to find projects that are not new or complete.
DynamoDB supports two types of primary keys: Partition key: A simple primary key, composed of one attribute known as the partition key. Attributes in DynamoDB are similar in many ways to fields or columns in other database systems.
A Query operation can retrieve a maximum of 1 MB of data. This limit applies before the filter expression is evaluated.
For faster response times, design your tables and indexes so that your applications can use Query instead of Scan . (For tables, you can also consider using the GetItem and BatchGetItem APIs.)
DynamoDB supports two types of read operations: Query and Scan. To find information, a query operation uses either the primary key or the index key. Scan, as the name implies, is a read call that scans the entire table for a specified result. DynamoDB is designed to be query-optimized.
No, as of today there is no way to send multiple queries in the same request. If you're concerned about latency, you could make multiple requests simultaneously in different threads. This would require the same amount of network bandwidth as a "dual query" would if Dynamo offered it (assuming you're making 2, not hundreds).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With