Currently ODATA defines query protocol that uses query path and options to specify desired data using a filter based approach:
The following is the example to fetch all movie names in a movie catalog that match the genre 'Adventure'
GET /v2/Catalog/Genres('Adventure')/Name HTTP/1.1
The current approach seems to have several limitations:
- It cannot do boolean operations to for example match genres of 'Humor' AND 'Adventure'
- It creates a strong linkage between a logical schema and a physical schema and exposes this to the query client
- It requires too much knowledge on part of the query client and seems complex to use
An alternative may be to use the Contextual Query Language or CQL [SearchRetrievePt5]. CQL has been around for many years and is in use in diverse communities to provide interoperable access to various data stores.
CQL provides much simpler more intuitive syntax that does not have the restrictions noted above. Here is a simple example of a complex query for a fictitious MovieCatalog context:
movie.genre = "history" AND movie.year > 1980 AND movie.year < 1982 AND movie.actor = "Quinn"
It seems easily possible to define a CQL profile for ODATA that would specify how CQL queries are invoked as part of an ODATA RESTFul query.
The following is a possible way to express this CQL query in a RESTFUL GET:
GET /v2/Catalog/search?query=movie.genre = "history" AND movie.year > 1980 AND movie.year < 1982 AND movie.actor = "Quinn" HTTP/1.1
Note above query is shown without the required url encoding for convenience.
The result would be:
- a more functional query protocol
- based on existing OASIS specification with established use in several communities
- easier syntax for query client
- Easier to map to existing data stores with less hardwiring between logical and physical schema
Some additional points are:
- Get by ID does not get impacted
- Will need to define a odata context for CQL
- ODATA context will define ODATA specific indexes, relations, relation modifiers (options/parameters) etc. to support odata specific features such as functions, operators, granularity of data returned etc.
[SearchRetrievePt5]
searchRetrieve: Part 5. CQL: The Contextual Query Language Version 1.0. 13 April 2012. OASIS Committee Specification 01. http://docs.oasis-open.org/search-ws/searchRetrieve/v1.0/cs01/part5-cql/searchRetrieve-v1.0-cs01-part5-cql.html.