Using HINT and TRACE with GemfireTemplate.query method

129 views Asked by At

I am trying to add a Trace to an OQL Query as mentioned in the docs, using GemfireTemplate query method. But the OQL validation fails with QueryInvalidException "unexpected tokern: <". Any ideas?

1

There are 1 answers

0
John Blum On BEST ANSWER

This is not a bug with SDG's GemfireTemplate, nor a problem with SDG in general.

There are 2 ways to query in GemFire/Geode.

  1. First, is to use the QueryService, which can be obtained from the cache. Alternatively, you can obtai the QueryService from the ClientCache or even from the Pool attached to the Region on which you are running the OQL query. This is all handled for you automatically when using SDG's Repository abstraction extension.

  2. The second way to query a Region is to pass a query "PREDICATE" to the Region.query(:String) method.

Which GemFire/Geode API do you think the GemfireTemplate.query(:String) method is using?

GemfireTemplate.query(:String) uses the Region.query(:String) API.

The GemfireTemplate.find(:String) method uses the QueryService.

Only the QueryService can accept fully valid OQL queries, e.g. <TRACE> SELECT * FROM /SomeRegion WHERE id = 1, where as the Region.query(:String) method ONLY accepts the OQL Query PREDICATE, i.e. id = 1.

Any other OQL Query reserved words or query syntax in general, passed to the GemfireTemplate.query(:String) method (and by extension Region.query(:String) API) results in a invalid OQL Query.

If you want to pass <HINT 'IDIndex', ...> <TRACE> SELECT * FROM /SomeRegion WHERE id = 1 AND ..., then you should call GemfireTemplate.find(:String), which uses the GemFire/Geode QueryService that accepts the complete OQL Query syntax.

Alternatively, you can use the Spring Data for Apache Geode (or VMware Tanzu GemFire) Repository extension.

It is even still possible to add HINTS, TRACES, LIMITS or other query facilities to derived Repository query methods as well as query methods annotated with @Query. See the documentation for more details.