Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

amazon web services - DynamoDB query with Comparison Operators

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 CONTAINSand IN, which are both available within the Scan API though; only the comparison operator BETWEENis 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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...