yazabara February 2016

DynamoDB. How to scan list with contains

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 );

How to get items list?

I need get not deleted items with prefix.

I have an error:

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

I've tried write the simmilar scan-request:

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

But it doesn't work.

Answers


yazabara February 2016

 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 );

Post Status

Asked in February 2016
Viewed 2,105 times
Voted 11
Answered 1 times

Search




Leave an answer