使用查询(Python boto3)从Dynamo DB表中获取所有记录

发布于 2025-02-01 14:07:02 字数 473 浏览 4 评论 0原文

我在Dynamo DB中有一张桌子,有200万张记录。该表有日期(yyyy-mm-dd)作为分区键,并且我将作为排序键。当前,我们正在使用boto3.client.dynamodb.query基于keyconditionexpression获取数据,其中x是日期。我想根据一年来查询记录吗? KeyConditionExpression表达式属性值是什么?

dynamo db中的示例行:

{"date": {"s" : "2022-04-29"},"account_id": {"s" :"6208378688923445"}}

date是分区键,account_id是零为键。我想通过2022年查询所有记录。

I have a table in Dynamo Db with 2 million records. The table has date (yyyy-mm-dd) as partition key and account I'd as sort key. Currently, we are using boto3.client.dynamodb.query to fetch the data based on KeyConditionExpression where X is date. I want to query the records based on just year? What should KeyConditionExpression and Expression Attribute Values be?

Sample row in Dynamo Db :

{"date": {"s" : "2022-04-29"},"account_id": {"s" :"6208378688923445"}}

Here date is partition key and account_id is sort key. I want to query all the records with year 2022.

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

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

发布评论

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

评论(1

爱,才寂寞 2025-02-08 14:07:02

查询只能在单个分区密钥上操作。如果要运行此查询,则需要将GSI与本年度作为分区密钥添加。这具有额外的写入和存储成本。如果您不需要经常运行此查询,则仅扫描表并在应用程序层中过滤可能会便宜。如果您有200万个记录,并且每个记录为500个字节,则扫描成本小于$ 0.02

A query can only operate on a single partition key. If you want to run this query, you need to add a GSI with the year as the partition key. This has additional write and storage costs. If you don’t need to run this query very often, it may be cheaper to just scan the table and filter in the application layer. If you have 2 million records and each record is 500 bytes, the cost of a scan is less than $0.02

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