Chapter 7. Querying, Events, and Searching

Object Query Language

The query language that is built in to GemFire is called Object Query Language (OQL). The OQL language was developed by the Object Data Management Group as a standard for object databases. Before we start on the virtues of OQL, we must talk about why all GemFire applications are not based on OQL.

When we issue an OQL statement, we can’t be 100% certain which hosts contain the data that we are looking for. Therefore, the OQL query is sent to all members within the distributed system and is run on all CPUs; the results from all of the hosts have to be combined and presented in the result set. This might seem like a lot of work; however, OQL can be faster than disk-based architectures because GemFire normally operates out of memory-based storage rather than disk.

So, to get extreme scale we use GemFire for what it does best: key–value storage. Then, when we can’t design our way to using what GemFire does best, we can use OQL and treat it like an object database. So, what does OQL look like? Let’s see:

SELECT person FROM /people person
WHERE person.firstName = 'Charlie'

This query uses the people region, iterates through the values, and finds all of the people whose first name is Charlie. The interesting part comes into play when we begin thinking about the object side of this equation. We can rewrite the query to iterate over the values of the hashmap like this:

SELECT person ...

Get Scaling Data Services with Pivotal GemFire now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.