在 java 中使用具有 OR 和 AND 条件的 Amazon/AWS DynamodB scanfilter

Using Amazon/AWS DynamodB scanfilter with both OR and AND conditions in java

我正在使用 dynamoDB 并使用 java。我有一个用例,我必须使用过滤器 expression.I 进行扫描,并具有 table 命名的 Order 和许多字段。对于我的扫描表达式,我需要三个字段命名 “字段 1”,“字段 2”,“字段 3”。

基本上我的查询看起来像

select * from Order where (field1 is  null OR field2 is null) AND (field3 != "Test")

我只能用 OR 形成扫描表达式,但我对如何在此处添加 AND 感到困惑。看起来我们只能使用一个操作员。我们还有其他方法可以实现吗?

以下是仅使用 OR 条件的代码片段。我想在以下代码段中添加 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);
       

这就是我最终完成的工作!!

        Map<String, AttributeValue> expressionAttributeValues = new HashMap<>();
        expressionAttributeValues.put("col1", new AttributeValue().withS("value1"));
        expressionAttributeValues.put(":col3", new AttributeValue().withS("value2"));
        expressionAttributeValues.put(":col3", new AttributeValue().withS("value3"));
        Map<String, String> expressionAttributeNames= new HashMap<>();
        expressionAttributeNames.put("#col4", "col4");
        final DynamoDBScanExpression expression = new DynamoDBScanExpression()
                .withConsistentRead(false)
                .withFilterExpression("(attribute_not_exists("+something1+")  or  attribute_not_exists("+something2+") ) AND (not  (#col4 in (:test1, :test2, :test3 ))) ")
                .withExpressionAttributeNames(expressionAttributeNames)
                .withExpressionAttributeValues(expressionAttributeValues);