从ID的字符串数组中获取所有对象,从DynamoDB SDK Java获取

发布于 2025-02-04 03:17:06 字数 681 浏览 3 评论 0原文

我要实现的是从ID的字符串数组中,从DynamoDB中获取所有这些ID的项目。 实际上,我以一种非常懒惰的方式完成了这项工作:

public Note findNote(final String noteID) {
        DynamoDbTable<Note> noteTable = getTable();
        Key key = Key.builder().partitionValue(noteID).build();

        Note result = noteTable.getItem(key);
        return result;
    }

public ArrayList<Note> findNotes(String[] notes){
        ArrayList<Note> notess= new ArrayList<Note>();
        for (int i = 0; i < notes.length; i++) {
           notess.add(findNote(notes[i]));
        }
        return notess;
    }

但是它效率很低,可以做到这一点,但是对于大阵列,我会做一些与数组长度一样多的查询。

有什么方法可以更有效或使用单个查询?

谢谢!

What I want to achieve is from an String array of ids, get all items with those ids from the DynamoDB.
I actually accomplished that in a very lazy way:

public Note findNote(final String noteID) {
        DynamoDbTable<Note> noteTable = getTable();
        Key key = Key.builder().partitionValue(noteID).build();

        Note result = noteTable.getItem(key);
        return result;
    }

public ArrayList<Note> findNotes(String[] notes){
        ArrayList<Note> notess= new ArrayList<Note>();
        for (int i = 0; i < notes.length; i++) {
           notess.add(findNote(notes[i]));
        }
        return notess;
    }

But its pretty inefficient, does the work, but for big arrays I will have do as many queries as the array length.

Any way to do this more efficient or with a single query?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∞觅青森が 2025-02-11 03:17:06

您需要batchgetItem()您可以在一个呼叫中最多检索100个。 RCU成本是相同的,但由于网络流量较小,延迟将有所改善。您可以在非常有用的AWS样品repo中找到一个示例:

https://github.com/aws-samples/aws-dynamodb-examples/blob/blob/master/master/master/dynamodb-sdk-sdk-examples/java/workingwithitems/workingwithitems/batchgetitem.java>

You want batchGetItem() where you can retrieve up to 100 in one call. The RCU cost is the same but the latency will improved due to less network traffic. You can find an example in the very useful AWS Samples repo:

https://github.com/aws-samples/aws-dynamodb-examples/blob/master/DynamoDB-SDK-Examples/java/WorkingWithItems/BatchGetItem.java

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文