如何使用AWS DynamoDB QueryRequest类中的addQueryFilterEntry(String,Condition)?

时间:2014-07-09 12:58:39

标签: java amazon-web-services amazon-dynamodb

我一直在查看AWS DynamoDB QueryRequest的文档:http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/dynamodbv2/model/QueryRequest.html#getQueryFilter()

本文档表明addQueryFilterEntryQueryRequest类中的有效函数。但是,我正在使用的Dynamo DB V2罐中似乎缺少符号。有没有人有什么建议可以在返回之前过滤搜索结果?我宁愿不遍历结果并删除应用程序层中的无效结果。

我的代码如下所示:

import com.amazonaws.services.dynamodbv2.model.QueryRequest;

String hashKey = Utilities.normalize(user_id);

Condition hashKeyCondition = new Condition()
    .withComparisonOperator(ComparisonOperator.EQ.toString())
    .withAttributeValueList(new AttributeValue().withS(hashKey));

Map<String, Condition> keyConditions = new HashMap<String, Condition>();
keyConditions.put("UserId", hashKeyCondition);

// Gets count of all matching results.
QueryRequest queryRequest = new QueryRequest().withTableName(storiesTable)
    .withKeyConditions(keyConditions)
    .withSelect(Select.COUNT)
    .withConsistentRead(true);
QueryResult result = dynamoDB.query(queryRequest);
int countResults = result.getCount();

我想补充一下:     queryRequest = queryRequest.addQueryFilterEntry(key,Condition) 这不是编译报告错误找到符号。

2 个答案:

答案 0 :(得分:2)

确保在处理newest AWS Java SDK之前升级到latest documentation site(截至2014年7月10日,它是1.8.3)。

答案 1 :(得分:0)

你需要提供更多细节。

确保您要导入最新的QueryRequest

import com.amazonaws.services.dynamodbv2.model.QueryRequest;