使用批处理方法在DynamoDB中分页

发布于 2025-01-30 18:34:47 字数 299 浏览 2 评论 0原文

我在DynamoDB中有2张桌子,即产品和卖家。

Seller: sellerId (partitionKey) (No sort key available)
Products: productId (partitionKey) and sellerId (sortKey)

我想在Spring Boot中开发一个API,我将其作为输入传递,并期望出售相应产品的卖家列表。 我将不得不首先使用Productid获取产品列表,然后在其中使用SellerId来获取卖方数据。我目前正在考虑使用映射。 我该如何分页我的结果?

I have 2 tables in DynamoDB, namely products and sellers.

Seller: sellerId (partitionKey) (No sort key available)
Products: productId (partitionKey) and sellerId (sortKey)

I want to develop an API in spring boot where I pass in productId as the input and expect a paginated list of sellers who sell the corresponding products.
I will have to first fetch a list of products using the productId and then use the sellerId in them to fetch seller data. I am currently thinking of using mapper.query for the first call and mapper.batchLoad for the second call.
How can I paginate my results?

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

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

发布评论

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

评论(1

萌无敌 2025-02-06 18:34:48

您可以使用DynamoDB使用单桌设计,而不是维护2个表。

以下是您可以在DynamoDB中对表进行建模的方式。

方式1

方法2(推荐)

您也可以使用字符串集来存储卖家。 字符串集确保列表中的独特字符串。这将为您节省创建额外的行以存储产品&卖方映射。

以这种方式,您可以获取卖方-ID和产品查询,然后您可以提出批次阅读的请求以获取卖家的详细信息。

对于分页

  • ,要么可以使用do/while循环,然后继续查询直到lastEvaledkeykey变为null。
  • 或返回lastEvalecekekey返回客户端以获取下一组数据。

Instead of maintaining 2 tables, you can use single-table design with DynamoDB.

Below is how you can model your table in DynamoDB.

Way 1

enter image description here

Way 2 (Recommended)

You can also use string set to store sellers. String Set ensures unique strings in the list. This will save you to create extra rows to store product & seller mapping.

enter image description here

With this way, you can get seller-ids along with product query, and then you can make a batch-read request to get details of sellers.

For Pagination

  • Either you can use do/while loop, and continue query until LastEvaluatedKey becomes null.
  • Or return LastEvaluatedKey to client to get next set of data.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文