简体   繁体   English

在DynamoDB中将时间戳记用作属性

[英]Using timestamp as an Attribute in DynamoDB

I'm quite new to DynamoDB, but have some experience in Cassandra. 我对DynamoDB还是很陌生,但是对Cassandra有一些经验。 I'm trying to adapt a pattern I followed in Cassandra, where each column represented a timestamped event, and wondering if it will carry over gracefully into DynamoDB or if I need to change my approach. 我正在尝试适应在Cassandra中遵循的模式,其中每列代表一个带有时间戳的事件,并想知道它是否会优雅地延续到DynamoDB中,或者是否需要更改我的方法。

My goal is to query a set of documents within a date range by using the milliseconds-since-epoch timestamp as an Attribute name. 我的目标是通过使用毫秒-自纪元时间戳作为属性名称来查询日期范围内的一组文档。 I'm successfully storing the following as each report is generated with each new report being added under its own column: 我成功存储了以下内容,因为生成了每个报告,并将每个新报告添加到其自己的列下:

{ PartitionKey:customerId,
  SortKey:reportName_yyyymm,
  '#millis_1#':{'report':doc_1},
  '#millis_2#':{'report':doc_2},
  . . .
  '#millis_n#':{'report':doc_n}
}

My question is, given a millisecond-based date range, and the accompanying Partition and Sort keys, is it possible to query the set of Attributes that fall within that range or must I retrieve all columns for the matching keys and filter them at the client? 我的问题是,给定基于毫秒的日期范围以及随附的分区和排序键,是否有可能查询该范围内的属性集,或者我必须检索所有匹配键的列并在客户端进行过滤?

Welcome to the most powerful NoSQL database ;) 欢迎使用功能最强大的NoSQL数据库;)

To kick off with the positive news, there is no way to query out specific attributes. 要从正面新闻开始,就没有办法查询特定的属性。 You can project certain attributes in a query. 您可以在查询中投影某些属性。 But you would have to write your own logic to determine which attributes or columns should be included in the projected query. 但是,您必须编写自己的逻辑来确定应将哪些属性或列包含在投影查询中。 To get close to your solution you could use a map attribute inside an item with the milliseconds as a key. 为了接近您的解决方案,您可以在项目内部使用map属性,以毫秒为键。 But there is another thing you have to be aware of when starting on this path. 但是,从这条路径开始时,您还需要注意另一件事。

There is a maximum total item size of 400KB for each item in DynamoDB, including key and attribute names.( Limits in DynamoDB Items ) This means you can only store so many attributes in an item. DynamoDB中每个项目的最大项目总大小为400KB,包括键名和属性名。( DynamoDB项目中的限制 )这意味着您只能在一个项目中存储这么多属性。 This is especially true if you intend to put the actual report inside of the attribute. 如果您打算将实际报告放入属性中,则尤其如此。 Which I would advise against, also because you will be burning up read capacity units every time you get one attribute out of the whole item. 我建议您这样做,也是因为每次您从整个项目中获得一个属性时,您就会消耗读取容量单位。 You would be better of putting this data in a separate table with the keys in the map. 您最好将此数据与地图中的键放在单独的表中。 But truthfully in DynamoDB I would split this whole thing up, just add the milliseconds to the sort key and make every document its own item. 但实际上,在DynamoDB中,我将把整个事情分解开,只将毫秒添加到sort键中,并使每个文档成为自己的项目。 That way you can directly query to these items and you can use the "between" where clause to select specific date-time ranges. 这样,您可以直接查询这些项目,并且可以使用“ between” where子句来选择特定的日期时间范围。 Please let me you meant something else. 请让我你有其他意思。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM