I want to query the dynamodb table with boolean or condition like SQL
e.g. Get me all the items where attribute1 = "no" or attribute2="no"
I tried with scanRequest.withScanFilter
but all the conditions are performed by doing boolean ANDing. How do I do boolean ORing.?
Yes, like all the other database management systems, DynamoDB also supports all the conditional operators, User can specify a condition that is satisfied for a put, update, or delete operation to work on an item.
Querying is a very powerful operation in DynamoDB. It allows you to select multiple Items that have the same partition ("HASH") key but different sort ("RANGE") keys.
High-performance reads and writes are easy to manage with DynamoDB, and you can expect performance that is effectively constant across widely varying loads.
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.
You can set ConditionalOperator of your ScanRequest to "OR". The default value is "AND"
http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Scan.html
ScanRequest scanRequest = new ScanRequest("tableName");
scanRequest.setConditionalOperator(ConditionalOperator.OR);
Map<String, Condition> scanFilter = new HashMap<String, Condition>();
scanFilter.put("attribute1", new Condition().withAttributeValueList(new AttributeValue("no")).withComparisonOperator(ComparisonOperator.EQ));
scanFilter.put("attribute2", new Condition().withAttributeValueList(new AttributeValue("no")).withComparisonOperator(ComparisonOperator.EQ));
scanRequest.setScanFilter(scanFilter);
ScanResult scanResult = dynamo.scan(scanRequest);
for(Map<String, AttributeValue> item : scanResult.getItems()) {
System.out.println(item);
}
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