What Jason said. In onRegion functions RegionFunctionContext should be used, as 
shown in the following example from the user’s guide (see 
http://geode-docs.cfapps.io/docs/developing/query_additional/query_on_a_single_node.html
 for the complete example):

Query query = queryService.newQuery(qstr);

//If function is executed on region, context is RegionFunctionContext
RegionFunctionContext rContext = (RegionFunctionContext)context;

SelectResults results = (SelectResults) query.execute(rContext)
Using the region function context ensures that no data is queried twice, which 
is not guaranteed if local data set is used instead. RegionFunctionContext has 
the full picture of what subsets of region data (buckets) to target on what 
nodes to avoid duplication due to redundancy.

Edin

> On Jan 13, 2016, at 11:14 AM, Jason Huynh <[email protected]> wrote:
> 
> The Region.query() method converts the provided predicate into a select query 
> string and uses the local query service to execute the query.  As Mark has 
> mentioned, if you pass the RegionFunctionContext (directly cast the 
> FunctionContext to a RegionFunctionContext), that should provide similar 
> behavior.
> 
> On Wed, Jan 13, 2016 at 10:45 AM, Lyndon Adams <[email protected] 
> <mailto:[email protected]>> wrote:
> I always use the region query method if the query is simple.
> 
> Sent from my iPhone
> 
> On 13 Jan 2016, at 18:30, Real Wes Williams <[email protected] 
> <mailto:[email protected]>> wrote:
> 
>> 
>> When I’m in a function that was executed onRegion, is it safe to execute the 
>> query on the local region? Or use QueryService?
>> 
>> The doc on Region.query omits mention when it says:
>> 
>>    * When executed from a client, this method always runs on the server.
>>    * However application should use QueryService to execute queries.
>>    * ...
>>    */
>>   public <E> SelectResults<E> query(String queryPredicate)
>>   throws FunctionDomainException, TypeMismatchException, 
>> NameResolutionException,
>>          QueryInvocationTargetException;
>> 
>> But the Spring GemFireTemplate has:
>> 
>>      @Override
>>      public <E> SelectResults<E> query(final String query) {
>>              try {
>>                      return this.getRegion().query(query);
>> 
>> 
>> Thanks,
>> Wes
>> 
> 

Reply via email to