2

I have a table named products. It’s schema is

  1. CustomerNumber (HASH Key of type String)
  2. ProductID (Range Key of type String)

I want to query similar to

SELECT * FROM products WHERE CustomerNumber IN ("cust123","cust234"). 

How to achieve it?

Few observations -

  1. DynamoDBQueryExpression would query only on index/hashKey not not on list of hashKeys like in example above.

  2. Also DynamoDBQueryExpression doesnt support IN , OR operator.

  3. Also BatchLoad uses only Primary Key (in my case customerNumber and productID)record to return batch of records.

  4. Also ,I dont want to scan the table and apply filter on it.

  5. Also creating GSI on customerNumber and then querying it didn't work

1 Answer 1

6

Instead of select * where partitionkey IN ... you would do a separate query equivalent to select * where partitionkey= ... for each value of your IN condition. It costs you a few extra round trips on the network, but that’s all; if you’re concerned about speed you can execute the individual queries in parallel.

Sign up to request clarification or add additional context in comments.

2 Comments

Yep , thanks that answers the question . However how do you suggest to run queries in parallel , right now I am using parallelstreams in java.
Parallel streams is one way to do it. It’s hard to recommend a best way because there are so many factors involved (eg. memory, cpu cores, other loads on the system). You should finish building your application, and then do some performance testing/experimentation to see what the best option is for you. Oh, and remember, don’t optimize until after you have ensured correctness.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.