Inequality operators on two properties at once

140 views
Skip to first unread message

Mohsin Hijazee

unread,
Apr 23, 2013, 12:31:08 PM4/23/13
to google-a...@googlegroups.com
I have a very simple problem to which I cannot find an appropriate solution. I have a simple model that records multiple timespans for an equipment which indicates what time ranges are in which that equipment can be used. 

For instance:

  • Monday 12:00 AM to 3:00 AM
  • Monday 7:00 AM to 11:00 AM
  • Tuesday 4:30 PM to 5:00 PM
Now for a single equipment, I would want to retain this information. My use case is that I would be selecting a day and a start and end range (say 4:00 PM to 9:00 PM) to check what equipment is available. But unfortunately, inequality operators on two different properties within single property aren't allowed so that's not possible:

SELECT * FROM Equipment WHERE from_time >= 1600 AND to_time <= 2100

How you would suggest to model such a thing on Google App Engine? 




Moises Belchin

unread,
Apr 23, 2013, 12:39:33 PM4/23/13
to Google App Engine
You can create an index for your query or use TextSearch.

Hope that helps.

Regards.



Saludos.
Moisés Belchín.


2013/4/23 Mohsin Hijazee <mohsin...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Message has been deleted

Google Tasks Backup Moderator

unread,
Apr 24, 2013, 11:45:58 PM4/24/13
to google-a...@googlegroups.com
If TextSearch doesn't help, and since Datastore doesn't allow more than one property per query to have inequality filters, then I can see only two possibilities, depending on the amount of data that you expect to have.

If the amount of data is small, you could filter on one property using GQL (e.g. "SELECT * FROM Equipment WHERE from_time >= 1600") and then filter the rest in code.

If you have a large dataset, where performing the single inequality filter would return too many results, then the only other option that I can see is to use Cloud SQL.

Regards,

Julie


On 24 April 2013 19:19, Mohsin Hijazee <mohsin...@gmail.com> wrote:
So simply put, we cannot have a condition such as from_field > 5 and to_field < 10? How we would go about that then?

Vinny P

unread,
Apr 26, 2013, 2:42:49 PM4/26/13
to google-a...@googlegroups.com

There are a couple of suggestions that I can see:

1. The datastore is not intended to be the be-all, end-all data storage solution. As you can see, it has its' strengths and weaknesses. In your case, I recommend using Cloud SQL.

2. Consider other solutions. Google Apps Script's ScriptDB ( https://developers.google.com/apps-script/scriptdb ) can do inequalities, and so can Google Spreadsheets API ( https://developers.google.com/google-apps/spreadsheets/#sending_a_structured_query_for_rows ).

2. If you absolutely insist on using the datastore, let me ask a question: are the time ranges that you're using highly standardized? For instance instead of expressing times can you express availability as morning/middle-of-day/afternoon/evening? So instead of doing queries that are number based you can do boolean equality searches (example: search all equipment entities that have the property tuesday_morning_available and wednesday_afternoon_available set to true).

3. Use TextSearch as Julie and Moises have already suggested.

4. As Julie suggested, query using one inequality, then filter on the remaining equality within your code.

5. If you have a small dataset, you can implement a small DB engine entirely in memory within a backend. It's not as reliable as using the datastore, but it can be faster if you implement it correctly.

-----------------
-Vinny P
Technology & Media Advisor
Chicago, IL

My Go side project: http://invalidmail.com/
Reply all
Reply to author
Forward
0 new messages