CacheSerializableRunnable getCacheSerializableRunnableForPRQueryAndCompareResults(
      final String regionName, final String localRegion,
      final boolean fullQueryOnPortfolioPositions) {

    SerializableRunnable PrRegion = new CacheSerializableRunnable("PRQuery") {
      @Override
      public void run2() throws CacheException {

        Cache cache = getCache();
        // Querying the localRegion and the PR region

        String[] queries;

        if (fullQueryOnPortfolioPositions) {
          queries = new String[] {"import org.apache.geode.cache.\"query\".data.Position;"
              + "select distinct r.ID, status, mktValue "
              + "from $1 r, r.positions.values pVal TYPE Position "
              + "where r.status = 'active' AND pVal.mktValue >= 25.00",

              "import org.apache.geode.cache.\"query\".data.Position;" + "select distinct * "
                  + "from $1 r, r.positions.values pVal TYPE Position "
                  + "where r.status = 'active' AND pVal.mktValue >= 25.00",

              "import org.apache.geode.cache.\"query\".data.Position;" + "select distinct ID "
                  + "from $1 r, r.positions.values pVal TYPE Position "
                  + "where r.status = 'active' AND pVal.mktValue >= 25.00",

              "select distinct * " + "from $1 " + "where status = 'active'",

              "import org.apache.geode.cache.\"query\".data.Position;"
                  + "select distinct r from $1 r, "
                  + "r.positions.values pVal TYPE Position where pVal.mktValue < $2",

              "select p.positions.get('acc') from $1 p",

          };
        } else {
          queries = new String[] {"ID = 0 OR ID = 1", "ID > 4 AND ID < 9", "ID = 5", "ID < 5 ",
              "ID <= 5"};
        }

        Object[][] r = new Object[queries.length][2];
        Region local = cache.getRegion(localRegion);
        Region region = cache.getRegion(regionName);
        assertNotNull(region);

        final String[] expectedExceptions =
            new String[] {RegionDestroyedException.class.getName(), ReplyException.class.getName(),
                CacheClosedException.class.getName(), ForceReattemptException.class.getName(),
                QueryInvocationTargetException.class.getName()};

        for (final String exception : expectedExceptions) {
          getCache().getLogger().info(
              "<ExpectedException action=add>" + exception + "</ExpectedException>");
        }

        QueryService qs = getCache().getQueryService();
        try {
          for (int j = 0; j < queries.length; j++) {
            synchronized (region) {
              Object[] params;
              if (fullQueryOnPortfolioPositions) {
                params = new Object[] {local, (j % 25) * 1.0 + 1};
                r[j][0] = qs.newQuery(queries[j]).execute(params);
              } else {
                r[j][0] = local.query(queries[j]);
              }
              if (fullQueryOnPortfolioPositions) {
                params = new Object[] {region, (j % 25) * 1.0 + 1};
                r[j][1] = qs.newQuery(queries[j]).execute(params);
              } else {
                r[j][1] = region.query(queries[j]);
              }
            }
          }
          compareTwoQueryResults(r, queries.length);
        } catch (QueryInvocationTargetException e) {
          // If cause is RegionDestroyedException then its ok
          Throwable cause = e.getCause();
          if (!(cause instanceof RegionDestroyedException)) {
            // throw an unchecked exception so the controller can examine the cause and see whether
            // or not it's okay
            throw new TestException(
                "PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught unexpected query exception",
                e);
          }
        }

        catch (QueryException e) {
          LogWriterUtils.getLogWriter().error(
              "PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught QueryException while querying"
                  + e,
              e);
          throw new TestException(
              "PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught unexpected query exception",
              e);
        }

        catch (RegionDestroyedException rde) {
          LogWriterUtils.getLogWriter().info(
              "PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught a RegionDestroyedException while querying as expected ",
              rde);

        } catch (CancelException cce) {
          LogWriterUtils.getLogWriter().info(
              "PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught a CancelException while querying as expected ",
              cce);

        } finally {
          for (final String expectedException : expectedExceptions) {
            getCache().getLogger().info(
                "<ExpectedException action=remove>" + expectedException + "</ExpectedException>");
          }
        }

      }

    };
    return (CacheSerializableRunnable) PrRegion;
  }
This function <br>
1. Creates & executes a query with Logical Operators on the given PR Region 2. Executes the
same query on the local region <br>
3. Compares the appropriate resultSet <br>
geode-core/src/distributedTest/java/org/apache/geode/cache/query/partitioned/PRQueryDUnitHelper.java