gpt4 book ai didi

java - 使用和不使用分页的 DynamoDB Table.scan

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:13:53 27 4
gpt4 key购买 nike

我试图理解以下两个代码段之间的区别。一个使用页面来获取扫描结果,而第二个则不使用。我想知道如果数据库中的项目总数非常大,第二种方法是否可行? AWS 文档说扫描结果限制为 1 Mb。这对版本 2 有何影响?它只会获得前 1 MB 的结果,还是会在每页之后调用数据库?

请注意,我使用的是 table.scan API,它不同于 DynamoDBClient.scan API。参见 http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/dynamodbv2/document/Table.html获取 API 详细信息。

版本 1(使用页面):

            ItemCollection<ScanOutcome> items = table.scan(spec);
items.pages().forEach(page -> {
for (Item item : page) {
response.add(item);
}
});

版本 2(遍历没有页面的项目):

            ItemCollection<ScanOutcome> items = table.scan(spec);
for (Item item : items) {
response.add(item);
}

最佳答案

Tofig 是正确的。这两种方法之间没有区别。关于扫描结果限制为 1 MB 的声明仅适用于低级 API,不适用于文档 API。
来自 ItemCollection 的文档

A collection of Item's. An ItemCollection object maintains a cursor pointing to its current pages of data. Initially the cursor is positioned before the first page. The next method moves the cursor to the next row, and because it returns false when there are no more rows in the ItemCollection object, it can be used in a while loop to iterate through the collection. Network calls can be triggered when the collection is iterated across page boundaries.

关于java - 使用和不使用分页的 DynamoDB Table.scan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39473108/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com