简体   繁体   English

DynamoDB是否有默认/无操作FilterExpression?

[英]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. 我想使用Boto3扫描一个小的DynamoDB表,并且可选地允许此代码的调用者指示何时可应用于此扫描的可选条件。

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. 我正在试图弄清楚是否有什么我可以将FilterExpression设置为默认值(在注释中上面指出),以便在没有应用过滤器时扫描工作。

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. ...其中pKey是表中的主键或其他必填字段。

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. 如果我正确地解释文档 ,则无论使用何种过滤器表达式,扫描操作都会消耗相同数量的读取容量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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