【发布时间】:2021-03-19 06:26:09
【问题描述】:
我正在使用 dynamoDB 和 java。我有一个用例,我必须使用过滤器表达式进行扫描。我有名为 Order 的表和许多字段。对于我的扫描表达式,我需要三个名为 "field1","field2","field3"。
基本上我的查询看起来像
select * from Order where (field1 is null OR field2 is null) AND (field3 != "Test")
我只能使用 OR 来形成扫描表达式,但我被困在如何在这里添加 AND 上。看起来我们只能使用一个运算符。我们还有其他方法可以实现这一目标吗?
以下是仅使用 OR 条件的代码 sn-p。我想在下面的 sn-p 中添加 AND 条件。
final HashMap<String, Condition> scanFilter = new HashMap<>();
scanFilter.put("field1", new Condition().withComparisonOperator(ComparisonOperator.NULL));
scanFilter.put("field2", new Condition().withComparisonOperator(ComparisonOperator.NULL));
final DynamoDBScanExpression expression = new DynamoDBScanExpression()
.withConsistentRead(false)
.withConditionalOperator(ConditionalOperator.OR)
.withScanFilter(scanFilter);
final ScanResultPage<SnapshotByGrantee> scanResult = scanPage(Order.class, expression, exclusiveStartKey, limit);
【问题讨论】:
-
您是否使用 awscli 或其他方法验证了您提议的过滤器表达式确实有效?然后研究如何使用 Java SDK 来表达它。
标签: amazon-web-services amazon-dynamodb dynamodb-queries