Amazon AWS DynamoDB question.
Are there any examples of using RangeKeyCondition and ComparisonOperators such as CONTAINS, IN, BETWEEN. I am trying to retrieve data based on a composite RangeKey (concatenated and delimited). For example date +author+keywords for books table. Assume the HashValue is "book" in this case (it can be book,dvd,video,link etc). I would like to select all books that contain a the keyword "magic" or all books by author "John Doe". A sample record/item would look like this:
Hash------Range----------------------------------------------------------------- attribute1 ... attributex
book------2012-1-20~john doe~adventure~magic~travel----------------description ... some stuff
In trying to use the conditional operator IN or CONTAINS , I get the following error: object(CFSimpleXML)20 public '__type' => string 'com.amazon.coral.validate#ValidationException' (length=45) public 'message' => string 'Attempted conditional constraint is not an indexable operation'
Couldn't find any examples using these ComparisonOperators. Any help would be greatly appreciated.
Thanks.
It is important to realize the difference between the two search APIs Query and Scan in Amazon DynamoDB:
Query
A query operation searches only primary key attribute values and supports a subset of comparison operators on key attribute values to refine the search process. A query returns all of the item data for the matching primary keys (all of each item's attributes) up to 1MB of data per query operation. [...]
[..] For information about each comparison operator available for query operations, see the API entry for Query.
[emphasis mine]
Scan
A scan operation scans the entire table. You can specify filters to apply to the results to refine the values returned to you, after the complete scan. Amazon DynamoDB puts a 1MB limit on the scan (the limit applies before the results are filtered). [...]
[...] For information about each comparison operator available for scan operations, see the API entry for Scan.
Now, the supported subset for the RangeKeyCondition:ComparisonOperator of the Query API excludes CONTAINS
and IN
, which are both available within the Scan API though; only the comparison operator BETWEEN
is available within both APIs.
This limitation most likely stems from performance considerations, i.e. supporting CONTAINS
would probably defeat the DynamoDB goal of predictable performance/throughput.
As usual with NoSQL solutions, you will need to account for these limitations by tailoring your application design accordingly, i.e. addressing both your use case and the specific NoSQL architecture you are targeting at.
Good luck!
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