While App Engine's datastore does limit which queries you're able to
execute, there are various workarounds, which, while not ideal from a
development point of view, do ensure that query execution time is minimized
so your app can achieve the best possible scalability. One common pattern is
determining whether an entity meets the conditions of a certain query at
write time, then setting a boolean flag on that entity. When you need to run
the query, instead of managing multiple sub-queries and merging, you only
need to filter on this boolean field. When new queries are added, you can
run a task to re-process all existing entities and set their flags
accordingly. This is quite different from executing your query on runtime,
but should be much more efficient.

- Jason



On Mon, Oct 26, 2009 at 10:22 AM, king <kingalpha...@gmail.com> wrote:

>
> Hi there, can anyone from Google shines some light on the issue I
> posted last week?  I just need to find out if it is a major limitation
> on google's part with no workaround so that I can move forward
> accordingly. Thanks a lot.
>
> On Oct 23, 11:01 am, king <kingalpha...@gmail.com> wrote:
> > Thanks so much for the feedback.  I actually tried to extend the Key
> > CONTAINS concept to other fields but ran into a big wall right away.
> > It would be great to get your 2 cents.  Here is the root of my
> > problem:
> >
> > I have a student object, it has a number of qualifying attributes, for
> > example:
> > int gpa: 1 = 0 to 2.0, 2 = 2.0 to 3.0, 3 = 3.0 to 4.0
> > int ageGroup: 1 = 0 to 17, 2 = 18 to 30, 3 = 30 to 65, 4 = 65+
> > ArrayList schoolPreference: [0] = 'MIT', [1] = 'Stanford', [2] =
> > 'Harvard', [3] = 'Yale'
> >
> > Now, I need to create a query to find out all the students where (gpa
> > = 2 or gpa = 3) AND (age group = 3 or age group = 4) AND
> > (schoolPreference contains MIT or Yale, or both)
> >
> > As far as I know, GAE doesn't support OR operator in a query, so the
> > only way I can get the query above to work is to have multiple sub-
> > queries and do a manual join on all the datastore resultsets to
> > artificially create a union. If so, big problem arises:
> >
> > Since I have so many OR sub-conditions, if every OR translates into a
> > separate sub-query, literally speaking, I need to do a full
> > permutation of all the conditions (full product of all the OR and AND
> > conditions)  in all my sub-queries to achieve my goal, which doesn't
> > make any sense if I keep adding more value types (such as more schools
> > being selected in the student preference criteria) into my attributes,
> > not to mention adding more attributes to my student object.  Is there
> > any way to accomplish this query in GAE?  Your help is greatly
> > appreciated because this can be the deal breaker of whether my whole
> > project can migrate to GAE or not.  Thanks a lot in advance.
> >
> > On Oct 23, 1:51 am, Yasuo Higa <higaya...@gmail.com> wrote:
> >
> >
> >
> > > Hi Andy,
> >
> > > >> query.setFilter("key == :keyList");
> > > >> List<Master> list = (List<Master>) query.execute(keyList);
> >
> > > > I'd like to know if that works with GAE/J, because it is illegal
> JDOQL
> > > > syntax and would be a bug. JDOQL is supposed to follow Java syntax,
> > > > and you simply cannot do
> > > > Key == List<Key>
> > > > and get success in Java.
> >
> > > You are right, but unfortunately the above query works on GAE/J.
> >
> > > I should have recommended the following query:
> >
> > > List<Key> keys = ...;
> > > List<Object> ids = new ArrayList<Object>();
> > > for (Key key : keys) {
> > >     ids.add(pm.newObjectIdInstance(Master.class, key));}
> >
> > > List<Master> list = (List<Master>) pm.getObjectsById(ids);
> >
> > > Thanks,
> >
> > > Yasuo Higa
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to