从 DynamoDB 中获取价值 [英] Getting values out of DynamoDB

查看:20
本文介绍了从 DynamoDB 中获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始研究 Amazon 的 DynamoDB.显然,可伸缩性很有吸引力,但我正试图让我的头脑脱离 SQL 模式并进入 no-sql 模式.这可以做到吗(具有 dynamodb 的所有可扩展性优势):

I've just started looking into Amazon's DynamoDB. Obviously the scalability appeals, but I'm trying to get my head out of SQL mode and into no-sql mode. Can this be done (with all the scalability advantages of dynamodb):

有大量条目(例如 5 到 1000 万)按某个数字进行索引.每个条目中的一个字段将是创建日期.dynamo db 是否有一种有效的方法可以为我的网络应用程序提供两个日期之间创建的所有条目?

Have a load of entries (say 5 - 10 million) indexed by some number. One of the fields in each entry will be a creation date. Is there an effective way for dynamo db to give my web app all the entries created between two dates?

一个更简单的问题 - dynamo db 可以给我所有字段匹配某个数字的条目.也就是说,会有另一个字段是一个数字,为​​了论证的缘故,让我们说 0 到 10 之间.我可以要求 dynamodb 给我所有有价值的条目,例如6?

A more simple question - can dynamo db give me all entries in which a field matches a certain number. That is, there'll be another field that is a number, for argument's sake lets say between 0 and 10. Can I ask dynamodb to give me all the entries which have value e.g. 6?

这两个查询是否都需要扫描整个数据集(考虑到数据集的大小,我认为这是一个问题?)

Do both of these queries need a scan of the entire dataset (which I assume is a problem given the dataset size?)

非常感谢

推荐答案

dynamo db 有没有一种有效的方法来为我的网络应用程序提供所有在两个日期之间创建的条目?

Is there an effective way for dynamo db to give my web app all the entries created between two dates?

是的,请查看 主键 Amazon DynamoDB 数据模型 中的概念,特别是哈希和范围类型主键:

Yup, please have a look at the of the Primary Key concept within Amazon DynamoDB Data Model, specifically the Hash and Range Type Primary Key:

在这种情况下,主键由两个属性组成.首先attributes 是哈希属性,第二个是范围属性.Amazon DynamoDB 在散列上构建无序散列索引主键属性和范围主上的排序范围索引关键属性.[...]

In this case, the primary key is made of two attributes. The first attributes is the hash attribute and the second one is the range attribute. Amazon DynamoDB builds an unordered hash index on the hash primary key attribute and a sorted range index on the range primary key attribute. [...]

列出的示例完全符合您的用例,即 Reply ( Id, ReplyDateTime, ... ) 表使用 Hash and Range 类型的主键散列属性 Id 和范围属性 ReplyDateTime.

The listed samples feature your use case exactly, namely the Reply ( Id, ReplyDateTime, ... ) table facilitates a primary key of type Hash and Range with a hash attribute Id and a range attribute ReplyDateTime.

您将通过 Query API 使用它,请参阅 RangeKeyCondition 了解详情和查询 Amazon DynamoDB 中的表分别举例.

You'll use this via the Query API, see RangeKeyCondition for details and Querying Tables in Amazon DynamoDB for respective examples.

dynamo db 可以给我所有与某个字段匹配的条目数字.[...] 我可以请 dynamodb 给我所有有价值的条目,例如6?

can dynamo db give me all entries in which a field matches a certain number. [...] Can I ask dynamodb to give me all the entries which have value e.g. 6?

这也是可能的,尽管通过 Scan仅 API(即确实需要读取表中的每个项目),请参阅 ScanFilter 了解详细信息和 扫描 Amazon DynamoDB 中的表 以获取相应示例.

This is possible as well, albeit by means of the Scan API only (i.e. requires to read every item in the table indeed), see ScanFilter for details and Scanning Tables in Amazon DynamoDB for respective examples.

这两个查询是否都需要扫描整个数据集(我假设给定数据集大小是一个问题?)

Do both of these queries need a scan of the entire dataset (which I assume is a problem given the dataset size?)

如前所述,第一种方法适用于 Query,而第二种方法需要 Scan,并且通常,查询操作比扫描操作更有效 - 这是一个很好的入门建议,虽然细节更复杂并且取决于您的用例,请参阅 在 Amazon DynamoDB 中查询和扫描 概览:

As mentioned the first approach works with a Query while the second requires a Scan, and Generally, a query operation is more efficient than a scan operation - this is a good advise to get started, though the details are more complex and depend on your use case, see section Scan and Query Performance within the Query and Scan in Amazon DynamoDB overview:

为了更快的响应时间,请以可以使用的方式设计您的表格Query、Get 或 BatchGetItem API.或者,设计您的应用程序以最小化影响的方式使用扫描操作在您的表的请求率上.有关更多信息,请参阅Amazon DynamoDB 中的预置吞吐量指南.

For quicker response times, design your tables in a way that can use the Query, Get, or BatchGetItem APIs, instead. Or, design your application to use scan operations in a way that minimizes the impact on your table's request rate. For more information, see Provisioned Throughput Guidelines in Amazon DynamoDB.

因此,像往常一样,在应用 NoSQL 解决方案时,您可能需要调整架构以适应这些限制.

So, as usual when applying NoSQL solutions, you might need to adjust your architecture to accommodate these constraints.

这篇关于从 DynamoDB 中获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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