Skip to content

What's the behavior of DynamoDB's FilterExpression in Scan(), when attribute name or type is mismatched (AWS SDK Java v2)

0

Summary:

  • Using AWS SDK Java v2, will the DynamoDbClient.Scan(ScanRequest) raise exceptions if ScanRequest's FilterExpression has some attribute names not exist in the scanned table / there's a mismatch in the type of an attribute's value that we provided v.s. the attribute type in the table?

In detail:

  • Suppose we have a Ddb table StudentTable and we do a Scan() with some FilterExpression on the table. Say the filter is: "StudentID (Number) < 500000 AND isGraduated (Boolean) is False".
  • If in the table, we actually have StudentID as String, and we don't have any attribute named isGraduated, will the Scan raise exception or simply return empty result (which I assume is the case)?

What I've tried:

  • I've read through the AWS doc and AWS SDK doc on DynamoDB's Scan(), ConditionalExpression, and FilterExpression, but didn't find these scenarios explicitly mentioned.
  • I'm also working on a personal test on these behaviors but am having some setup issue (that's why I post the question here now, also for double check). I will update this post if I managed to do the test.

asked a year ago145 views

1 Answer
0

When using DynamoDB's FilterExpression in a Scan operation with the AWS SDK for Java v2, the behavior for attribute name or type mismatches is as follows:

For attribute names that don't exist in the table items:

  • The Scan operation will not raise an exception
  • Items that don't have the specified attribute will be filtered out
  • If no items match the criteria due to missing attributes, you'll get an empty result set with Count=0

For type mismatches between the FilterExpression and the actual attribute types in the table:

  • The Scan operation will not raise an exception for type mismatches
  • Items with mismatched types will be filtered out from the results
  • The operation will complete successfully, but may return fewer or no items

In your specific example with "StudentID (Number) < 500000 AND isGraduated (Boolean) is False":

  • If StudentID is actually a String in the table, those items won't match the numeric comparison
  • If isGraduated doesn't exist in any items, those items won't match that condition
  • Due to the AND operator, no items would match both conditions, resulting in an empty result set

The Scan operation will still return metadata like ScannedCount (showing how many items were examined) even if Count=0 (showing how many items passed the filter). This is normal behavior as FilterExpressions are applied after items are read but before they're returned to you.
Sources
DynamoDbClient (AWS SDK for Java - 2.21.29)
Scan - Amazon DynamoDB
ScanFilter (legacy) - Amazon DynamoDB
DynamoDbAsyncClient (AWS SDK for Java - 2.21.29)

answered a year ago

AWS
EXPERT

reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.