【发布时间】:2016-07-22 11:44:23
【问题描述】:
QueryRequest 和 QuerySpec 有什么区别?
QuerySpec spec = new QuerySpec()
.withKeyConditionExpression("#n_channel = :v_channel")
.withFilterExpression("#n_type = :v_type")
.withNameMap( new NameMap()
.with( "#n_type", DATABASE_CONTENT_TYPE_NAME )
.with( "#n_channel", PRIMARY_KEY_NAME ))
.withValueMap(new ValueMap()
.withString(":v_type", type)
.withString(":v_channel",channelId))
.withConsistentRead(true);
使用 QuerySpec - 有效
keyConditions.put( PRIMARY_KEY_NAME, new Condition().withComparisonOperator( ComparisonOperator.EQ ).withAttributeValueList( new AttributeValue().withS( channelId ) ) );
keyConditions.put( RANGE_KEY_NAME, new Condition().withComparisonOperator( ComparisonOperator.NOT_NULL ) );//default value
typeFilterExpression = "#n_type = :v_type";
nameMap.with( "#n_type", DATABASE_CONTENT_TYPE_NAME );
values.put( ":v_type", new AttributeValue().withS( type ) );
//
QueryRequest request = new QueryRequest().withTableName( tableName )
.withKeyConditions( keyConditions ).withLimit( QUERY_LIMIT )
.withReturnConsumedCapacity( ReturnConsumedCapacity.TOTAL ).withConsistentRead( false );
if( StringUtils.isNotBlank( typeFilterExpression ) ) {
request.withFilterExpression( typeFilterExpression );
}
if( !MapUtils.isEmpty( nameMap ) ) {
request.withExpressionAttributeNames( nameMap );
}
if( !MapUtils.isEmpty( values ) ) {
request.withExpressionAttributeValues( values );
}
使用相同的 QueryRequest - 不起作用。
com.amazonaws.AmazonServiceException: Attempted conditional constraint is not an indexable operation
亚马逊版: 编译'com.amazonaws:aws-java-sdk:1.10.65'
谢谢!
【问题讨论】:
-
请分享QueryRequest的变量数据,其中一个是错误的。
-
我已经为请求添加了变量。
标签: amazon-web-services amazon amazon-dynamodb