简体   繁体   中英

Does DynamoDB have a default/no-op FilterExpression?

I want to scan a small DynamoDB table using Boto3, and optionally allow the caller of this code to indicate when optional conditions should apply to this scan.

It would be convenient in code to do this:

scan_kwargs = {'Select': 'ALL_ATTRIBUTES'}
filter_exp = ''  # WHAT DO HERE?
if condition1:
    filter_exp &= Attr('attribute').is_in(['blah', 'bloop'])
if condition2:
    filter_exp &= Attr('deleted').is_eq(True)
scan_kwargs.update({'FilterExpression': filter_exp})
response = table.scan(**scan_kwargs)

I'm trying to figure out if there is something I can set FilterExpression to be by default (indicated above in comment), for the scan to work when there are no filters to be applied.

As far as I can tell, this is impossible.

Bit scrappy, but I figured I could do...

filter_exp = Attr('pKey').exists()

... where pKey is the primary key or another mandatory field in the table.

It's definitely not the "correct" solution, but might be the most reliable no-op filter that I can build upon conditionally.

If I am right in interpreting the documentation , a scan operation consumes the same amount of read capacity regardless of any filter expressions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM