DynamoDB Query Operation - Number of Items Read

How Many Items are Read by DynamoDB Query Operation?

Question

A CustomerOrders DynamoDB table has following items. CustomerName (PK) Order Item Cost Albert Einstein Candle 15 Albert Einstein Spaceship Toy 50 Albert Einstein Hair Comb 5 Isaac Newton Bag of Apples 25 Following operation is executed: aws dynamodb query \ --table-name CustomerOrders \ --key-condition-expression " CustomerName = :name " \ --filter-expression "Cost > :amount" \ --expression-attribute-values '{ ":name": { "S": "Albert Einstein" }, ":amount": { "N": "20" } }' How many items are read by the DynamoDB query operation?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Answer: C.

The query operation is used to search items based on primary key values.The name of the partition key attribute and a single value for that attribute must be provided with the query.

The query returns all items with that partition key value.

A filter expression parameter can be used to narrow down the results based on some required criteria.

A filter expression is applied AFTER a query operation competes, but BEFORE the results are returned to the client.

Therefore, a query operation consumes the same amount of read capacity, regardless of whether a filter expression is present.This means that all items with the primary key of “Albert Einstein” are returned for the query operation in this scenario.Thus, the correct answer is 3.

Reference:

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html

The DynamoDB query operation is querying the CustomerOrders table with a Key Condition Expression and a Filter Expression. The Key Condition Expression specifies that the partition key (PK) is equal to "Albert Einstein", which means that the query will only retrieve items that have "Albert Einstein" as their partition key. The Filter Expression specifies that the "Cost" attribute must be greater than 20.

To evaluate the query operation, DynamoDB will scan the CustomerOrders table and retrieve all items that have "Albert Einstein" as their partition key. It will then apply the filter expression to the retrieved items and return only the items that satisfy the filter condition.

Let's evaluate each item in the table:

  1. CustomerName: "Albert Einstein", Order Item: "Candle", Cost: 15. This item has "Albert Einstein" as its partition key, but its cost is less than 20, so it does not satisfy the filter condition.

  2. CustomerName: "Albert Einstein", Order Item: "Spaceship Toy", Cost: 50. This item has "Albert Einstein" as its partition key, and its cost is greater than 20, so it satisfies the filter condition.

  3. CustomerName: "Albert Einstein", Order Item: "Hair Comb", Cost: 5. This item has "Albert Einstein" as its partition key, but its cost is less than 20, so it does not satisfy the filter condition.

  4. CustomerName: "Isaac Newton", Order Item: "Bag of Apples", Cost: 25. This item has "Isaac Newton" as its partition key, so it is not retrieved by the query operation.

Therefore, only 1 item with "Albert Einstein" as its partition key and a cost greater than 20 is retrieved by the query operation. Therefore, the answer is A. 1.