应用程序引擎数据存储中的可用日期范围查询? [英] Availability date range queries in app engine datastore?

查看:128
本文介绍了应用程序引擎数据存储中的可用日期范围查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

b
$ b

在数据存储中,我有一组可在特定时间段内预订的实体,因此它们具有附加的可用性范围。一个AvailabilityRange实体有一个开始和结束日期,我想找到完全包含所需日期范围的所有AvailabilityRanges。在SQL中,where子句看起来像这样:

  WHERE AvailRange.startDate< :desiredStartDate AND AvailRange.endDate> :desiredEndDate 

对于数据存储区,这是不可能的,因为您不能在多个属性上使用不等式过滤器。另外,我还看到了一些关于将开始日期和结束日期存储在单个多值列表属性中的旧评论(因此您可以在单个属性中使用不等式过滤器),但这在app引擎中无效 - 请参阅第3节博文: http://aleatory.clientsideweb.net / 2009/11/28 / google-app-engine-datastore-gotchas / 我还看到了一些建议,例如,存储列表属性中的所有可用日期,以便您可以对该列表属性执行直接平等过滤器,但是如果您需要在范围内实现最新的粒度,那么该解决方案并不会真正起作用。



因此,现在看来这对数据存储来说是不可能的。我现在的解决方案是使用App Engine搜索服务来存储可用范围文档(因为搜索服务DOES允许多个不相等过滤器),然后将这些文档映射回数据存储中的实体。



任何人都有更好的建议?

),您可以运行两个仅用于查询键的查询 - 一个用于开始日期和一个用于结束日期,然后查找结果的交集。只有键的查询几乎免费且速度非常快。



如果您的数据存在一些其他限制,则可以使用它们来优化此过程。例如,如果可用性范围具有持续时间限制,则可以遍历开始日期查询,直到达到实体不再可用的日期为止,因为开始日期与期望的结束日期相距太远。然后对结束日期查询执行相同操作。


I've looked through a bunch of other threads on this topic, and so far I haven't found any satisfactory answers, so I wanted to double check if it's really just not feasible with the datastore.

In the datastore I have a set of entities that can be booked for particular time periods, and thus they have availability ranges attached to them. An AvailabilityRange entity has a start and end date, and I want to find all the AvailabilityRanges that completely encompass a desired date range. In SQL the where clause would look something like:

WHERE AvailRange.startDate < :desiredStartDate AND AvailRange.endDate > :desiredEndDate

With the datastore this isn't possible because you can't have inequality filters on multiple properties. Also, I saw some old comments about storing the start and end date in a single multivalued list property (so then you'd have inequality filters on a single property), but this doesn't work in app engine - see #3 on this blog post: http://aleatory.clientsideweb.net/2009/11/28/google-app-engine-datastore-gotchas/ .

I've also seen advice that recommends, for example, storing all of the available days in a list property so you can then do straight equality filters on that list property, but that solution doesn't really work if you need down-to-the-minute granularity on your ranges.

Thus, right now it seems like this just isn't possible with the datastore. My workaround plan for now is to use the App Engine Search service to store availability range documents (because the search service DOES allow multiple inequality filters), and then map those back to entities in the datastore.

Anyone have any better advice?

解决方案

If you have a relatively small number of entities (not in millions), you can run two keys-only queries - one for start date and one for end date, and then find the intersection of results. Keys-only queries are almost free and very fast.

If there are some other limitations on your data, you can use them to optimize this process. For example, if the availability range has a duration limit, you can loop through the start-date query until you reach a date at which an entity can no longer be available, because the start date is too far away from the desired end date. Then do the same with the end date query.

这篇关于应用程序引擎数据存储中的可用日期范围查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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