DynamoDB。如何使用contains扫描列表

时间:2016-02-08 15:42:34

标签: java amazon amazon-dynamodb

ValueMap attributes = new ValueMap()
.withBoolean( ":p_deleted", true )
.withString( ":p_prefix", prefix );
ScanSpec scanSpec = new ScanSpec()
.withFilterExpression( UAwsBasic.DATABASE_JSON_DEFINITION_NAME + ".deleted = :p_deleted and " + dynamoDbCommon.RANGE_KEY_NAME + " contains :p_prefix" ).withValueMap( attributes );

ItemCollection< ScanOutcome > items1 = dynamoDbCommon.scanList(getTableName(), scanSpec );

如何获取物品清单?

我需要获取带有前缀的已删除项目。

我有一个错误:

Caused by: com.amazonaws.AmazonServiceException: Invalid FilterExpression: Syntax error; token: "contains", near: "path contains :p_prefix"

我已尝试编写simmilar scan-request:

ScanSpec scanSpec = new ScanSpec().withScanFilters( new ScanFilter[] { typeFilter, deletedFilter } ).withConditionalOperator( ConditionalOperator.AND );

但它没有用。

1 个答案:

答案 0 :(得分:0)

 ValueMap values = new ValueMap().withString( ":p_status", "READY" ).withString( ":p_prefix", prefix );

NameMap names = new NameMap().with( "#status_name", "status" ).with( "#path_name", CDynamoDbCommon.RANGE_KEY_NAME );


scanSpec = new ScanSpec()
    .withFilterExpression( UAwsBasic.DATABASE_JSON_DEFINITION_NAME + ".#status_name = :p_status AND contains( #path_name , :p_prefix)" )
    .withNameMap( names ).withValueMap( values )
    .withMaxResultSize( 10 ).withExclusiveStartKey( CDynamoDbCommon.PRIMARY_KEY_NAME, primaryLast, CDynamoDbCommon.RANGE_KEY_NAME, hashLast );