Set operations in Appengine datastore

二次信任 提交于 2019-12-06 00:21:51

There aren't any built in set operations in the datastore API. I see you having two options:

  1. For smallish sets (hundreds of items) You might get away with doing keys-only queries for both set A and set B, and doing the intersection in your application code. The precise definition of "smallish" will depend on your application.

  2. For largish sets (millions of items) If you know ahead of time which intersections you'll want, you can calculate them each time you insert a new record. For example, assume you have two sets A and B, and you know that you'll eventually want to query on (A intersects B). whenever you insert an A, check to see if it is already in B. If it is, record this fact somewhere (either in a separate entity type, or as a boolean property on A or B itself). Of course, you'll need to do this for your B's also.

With option 1, you can have lots of different sets, but are limited by how big each set is.

With option 2, you can have sets with millions of members, but if you have more than a few sets, trying to define all the possible permutations of sets and operators will get unwieldy.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!