@Override
    public void execute(FunctionContext context) {
      Cache cache = CacheFactory.getAnyInstance();
      QueryService queryService = cache.getQueryService();
      ArrayList allQueryResults = new ArrayList();
      Object[] args = (Object[]) context.getArguments();
      Set buckets = getBucketsForFilter((Set) args[1]);
      Region localDataSet = new LocalDataSet(
          (PartitionedRegion) CacheFactory.getAnyInstance().getRegion(PartitionedRegionName1),
          buckets);

      try {
        Query query = queryService.newQuery((String) args[0]);
        final ExecutionContext executionContext =
            new QueryExecutionContext(null, (InternalCache) cache, query);
        context.getResultSender()
            .lastResult(((SelectResults) ((LocalDataSet) localDataSet)
                .executeQuery((DefaultQuery) query, executionContext, null, buckets)).asList());
      } catch (Exception e) {
        throw new FunctionException(e);
      }
    }
Test on PR on one server only using filter.
geode-core/src/distributedTest/java/org/apache/geode/cache/query/dunit/QueryUsingFunctionContextDUnitTest.java