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

本文是小编为大家收集整理的关于从DynamoDB中获取数值的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我刚刚开始研究亚马逊的 DynamoDB.显然,可扩展性很有吸引力,但我正试图摆脱 SQL 模式并进入 no-sql 模式.可以这样做吗(具有 dynamodb 的所有可扩展性优势):

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

一个更简单的问题 - dynamo db 能否给我一个字段匹配特定数字的所有条目.也就是说,将有另一个字段是数字,为了论证,可以说在 0 到 10 之间.我可以要求 dynamodb 给我所有具有价值的条目,例如6?

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

非常感谢

推荐答案

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

是的,请查看 主键中的一个>概念,特别是哈希和范围类型主键:

<块引用>

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

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

您将通过查询 API 使用它,请参阅RangeKeyCondition 了解详情和在 Amazon DynamoDB 中查询表为各自的例子.

<块引用>

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

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

<块引用>

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

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

<块引用>

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

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

本文地址:https://www.itbaoku.cn/post/597472.html

问题描述

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):

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?

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?)

many thanks

推荐答案

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

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:

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. [...]

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.

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

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?

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?)

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:

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.

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