我可以仅使用分区键查询 DynamoDBMapper 吗? [英] Can I query DynamoDBMapper with partition key only?

查看:23
本文介绍了我可以仅使用分区键查询 DynamoDBMapper 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过这个关于如何仅使用分区键进行查询的页面.但是,我的情况是使用 DynamoDBMapper 类 来制作查询,似乎在那里工作的内容不适用.

I've seen this page about how to query with partition keys only. However, my case is using DynamoDBMapper class to make the query, what seemed to work there does not apply.

这是我的代码的一部分:

Here's a part of my code:

private final DynamoDBMapper mapper; 
List<QueryResult> queryResult = mapper.query(QueryResult.class, queryExpression);

我查询的表有一个主分区键id和主排序键timestamp.

The table I query has a primary partition key id and primary sort key timestamp.

我想查询指定id的所有行,eav看起来像:

I wanted to query all the rows with designatedid, eav looks like:

{:id={S: 0123456,}}

但是如果 id 有重复(这是有道理的,因为它是分区键),它总是给我

but if the id has duplicates (which makes sense cause it's partition key), it always gives me

"The provided key element does not match the schema"

不知道如何解决这个问题.由于与其他表共享代码,DynamoDBMapper 类是必须的.

Not sure how to resolve this. Due to sharing code with other tables, DynamoDBMapper class is a must.

任何帮助表示赞赏!谢谢.

Any help appreciated! Thanks.

推荐答案

这是一个工作示例:

final MyItem hashKeyValues = MyItem.builder()
                             .hashKeyField("abc")
                             .build();

final DynamoDBQueryExpression<MyItem> queryExpression = new DynamoDBQueryExpression<>();
queryExpression.withHashKeyValues(hashKeyValues);
queryExpression.setConsistentRead(false); //or true

final PaginatedQueryList<MyItem> response = dynamoDBMapper.query(MyItem.class, queryExpression);

这篇关于我可以仅使用分区键查询 DynamoDBMapper 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆