DynamoDB使用List中的属性进行扫描

时间:2018-06-11 15:59:55

标签: java list spring-boot amazon-dynamodb dynamodb-queries

我正在尝试使用DynamoDb和带弹簧启动的java进行扫描。

 public Integer method(Long initialDate, Long endDate, Integer input,
        Integer input1, Integer input2, List<Integer> inputList) {

        DynamoDBMapper mapper = new DynamoDBMapper( client );

        Map<String, AttributeValue> attributes = new HashMap<>();

        List<String> inputListString = new ArrayList<>();
        for (Integer i : inputList) {
            inputListString.add( i.toString() );
        }

        attributes.put( ":initialDate", new AttributeValue().withN( initialDate.toString() ) );
        attributes.put( ":endDate", new AttributeValue().withN( endDate.toString() ) );
        attributes.put( ":input", new AttributeValue().withN( input.toString() ) );
        attributes.put( ":input1", new AttributeValue().withN( input1.toString() ) );
        attributes.put( ":input2", new AttributeValue().withN( input2.toString() ) );
        attributes.put( ":inputList", new AttributeValue().withSS( inputList ) );

        DynamoDBScanExpression scanExpression = new DynamoDBScanExpression().withFilterExpression(
            "attribute1 <> (:inputList) AND attribute = :input AND attribute1 = :input1 AND attribute2 = :input2 AND creationDate BETWEEN :initialDate AND :endDate" )
            .withExpressionAttributeValues( attributes );

        return mapper.count( DynamoEventEntity.class, scanExpression );
    }

我的问题是我必须根据inputList扫描并查找具有attribute1 =这样的输入的寄存器(整数转换为字符串)。 例如:

Registers:
1:
  attribute1 : 2
2:
  attribute1 : 0
3:
  attribute1 : 1
4:
  attribute1 : 0
5:
  attribute1 : 2

如果我在inputList = [0,2]中引入它必须返回registers1,2,4和5(count = 4),但它不起作用。 其余的输入过滤器工作正常。

我也尝试过:

DynamoDBScanExpression scanExpression = new DynamoDBScanExpression().withFilterExpression(
            "contains(attribute1,:inputList) AND attribute2 = :input AND attribute2 = :input1 AND attribute3 = :input2 AND creationDate BETWEEN :initialDate AND :endDate" )
            .withExpressionAttributeValues( attributes );

DynamoDBScanExpression scanExpression = new DynamoDBScanExpression().withFilterExpression(
            "attribute1 in (:inputList) AND attribute2 = :input AND attribute2 = :input1 AND attribute3 = :input2 AND creationDate BETWEEN :initialDate AND :endDate" )
            .withExpressionAttributeValues( attributes );

但它不起作用

提前谢谢。

0 个答案:

没有答案