@Test
  public void iteratingNestedQueriesShouldWork() throws Exception {
    String[] queries = new String[] {
        "SELECT DISTINCT * FROM " + SEPARATOR + "pos where NOT(SELECT DISTINCT * FROM " + SEPARATOR
            + "pos p where p.ID = 0).isEmpty",
        "-- AMBIGUOUS\n" + "import org.apache.geode.cache.\"query\".data.Portfolio; "
            + "SELECT DISTINCT * FROM " + SEPARATOR
            + "pos TYPE Portfolio where status = ELEMENT(SELECT DISTINCT * FROM " + SEPARATOR
            + "pos p TYPE Portfolio where ID = 0).status",
        "SELECT DISTINCT * FROM " + SEPARATOR + "pos where status = ELEMENT(SELECT DISTINCT * FROM "
            + SEPARATOR + "pos p where p.ID = 0).status",
        "SELECT DISTINCT * FROM " + SEPARATOR
            + "pos x where status = ELEMENT(SELECT DISTINCT * FROM " + SEPARATOR
            + "pos p where p.ID = x.ID).status",
        "SELECT DISTINCT * FROM " + SEPARATOR
            + "pos x where status = ELEMENT(SELECT DISTINCT * FROM " + SEPARATOR
            + "pos p where p.ID = 0).status",};

    for (int i = 0; i < queries.length; i++) {
      Object r = null;
      String queryStr = queries[i];
      Query q = qs.newQuery(queryStr);
      CacheUtils.getLogger().fine("Executing:" + queryStr);
      try {
        r = q.execute();
        if (i == 1) {
          fail("should have thrown an AmbiguousNameException");
        }
      } catch (AmbiguousNameException e) {
        if (i != 1) {
          throw e; // if it's 1 then pass
        }
      }
      if (r != null) {
        CacheUtils.getLogger().fine(Utils.printResult(r));
      }
    }
  }
TRAC #32429: An issue with nested queries :Iterator for the region in inner query is not
getting resolved.
geode-core/src/integrationTest/java/org/apache/geode/cache/query/QueryServiceRegressionTest.java