Search in sources :

Example 31 with StructSetOrResultsSet

use of org.apache.geode.cache.query.functional.StructSetOrResultsSet in project geode by apache.

the class IndexUseJUnitTest method testCompactMapIndexUsageWithIndexOnSingleKey.

@Test
public void testCompactMapIndexUsageWithIndexOnSingleKey() throws Exception {
    String[] queries = { "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.maap['key2'] >= 3" };
    String[] queriesIndexNotUsed = { "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.maap.get('key2') >= 3" };
    LocalRegion testRgn = (LocalRegion) CacheUtils.createRegion("testRgn", null);
    int ID = 1;
    // and so on
    for (; ID <= 30; ++ID) {
        MapKeyIndexData mkid = new MapKeyIndexData(ID);
        for (int j = 1; j <= ID; ++j) {
            mkid.addKeyValue("key1", j * 1);
            mkid.addKeyValue("key2", j * 2);
            mkid.addKeyValue("key3", j * 3);
        }
        testRgn.put(ID, mkid);
    }
    evaluateMapTypeIndexUsage("objs.maap['key2']", "/testRgn objs", queries, queriesIndexNotUsed, CompactRangeIndex.class);
    String query = "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.liist[0] >= 2";
    SelectResults withoutIndex, withIndex;
    Query q = CacheUtils.getQueryService().newQuery(query);
    CacheUtils.getLogger().info("Executing query: " + query);
    withoutIndex = (SelectResults) q.execute();
    CacheUtils.log("Executed query: " + query);
    Index i2 = qs.createIndex("Index2", IndexType.FUNCTIONAL, "objs.liist[0]", "/testRgn objs");
    assertTrue(i2 instanceof CompactRangeIndex);
    CacheUtils.getLogger().info("Executing query: " + query);
    QueryObserverImpl observer = new QueryObserverImpl();
    QueryObserverHolder.setInstance(observer);
    withIndex = (SelectResults) q.execute();
    CacheUtils.log("Executing query: " + query + " with index created");
    if (!observer.isIndexesUsed) {
        fail("Index is NOT uesd");
    }
    Iterator itr = observer.indexesUsed.iterator();
    assertTrue(itr.hasNext());
    String temp = itr.next().toString();
    assertEquals(temp, "Index2");
    StructSetOrResultsSet ssOrrs = new StructSetOrResultsSet();
    ssOrrs.CompareQueryResultsWithoutAndWithIndexes(new Object[][] { { withoutIndex, withIndex } }, 1, queries);
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) Query(org.apache.geode.cache.query.Query) StructSetOrResultsSet(org.apache.geode.cache.query.functional.StructSetOrResultsSet) Iterator(java.util.Iterator) Index(org.apache.geode.cache.query.Index) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 32 with StructSetOrResultsSet

use of org.apache.geode.cache.query.functional.StructSetOrResultsSet in project geode by apache.

the class IndexUseJUnitTest method testCompactMapIndexUsageManyGetKeysWithVariousValueTypes.

@Test
public void testCompactMapIndexUsageManyGetKeysWithVariousValueTypes() throws Exception {
    QueryService qs;
    qs = CacheUtils.getQueryService();
    LocalRegion testRgn = (LocalRegion) CacheUtils.createRegion("testRgn", null);
    int ID = 1;
    for (; ID <= 30; ++ID) {
        TestObject object = new TestObject(ID);
        testRgn.put(ID, object);
    }
    String[] queries = { "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.testFields.get('string') = '1'", "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.testFields.get('double') > 1D", "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.testFields.get('integer') > 1", "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.testFields.get('long') > 1L" };
    String[] queriesIndexNotUsed = { "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.testFields['string'] = '1'", "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.testFields['double'] > 1D", "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.testFields['integer'] > 1", "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.testFields['long'] > 1L" };
    Object[][] r = new Object[queries.length][2];
    qs = CacheUtils.getQueryService();
    // Execute Queries without Indexes
    for (int i = 0; i < queries.length; i++) {
        Query q = null;
        try {
            q = CacheUtils.getQueryService().newQuery(queries[i]);
            CacheUtils.getLogger().info("Executing query: " + queries[i]);
            r[i][0] = q.execute();
            CacheUtils.log("Executed query: " + queries[i]);
        } catch (Exception e) {
            e.printStackTrace();
            fail(q.getQueryString());
        }
    }
    Index i1 = qs.createIndex("Index1", IndexType.FUNCTIONAL, "itr1.testFields.get('string')", "/testRgn itr1");
    Index i2 = qs.createIndex("Index2", IndexType.FUNCTIONAL, "itr1.testFields.get('double')", "/testRgn itr1");
    Index i3 = qs.createIndex("Index3", IndexType.FUNCTIONAL, "itr1.testFields.get('integer')", "/testRgn itr1");
    Index i4 = qs.createIndex("Index4", IndexType.FUNCTIONAL, "itr1.testFields.get('long')", "/testRgn itr1");
    Index i5 = qs.createIndex("Index5", IndexType.FUNCTIONAL, "itr1.testFields.get('complex')", "/testRgn itr1");
    assertTrue(i1 instanceof CompactRangeIndex);
    // Execute Queries with Indexes
    for (int i = 0; i < queries.length; i++) {
        Query q = null;
        try {
            q = CacheUtils.getQueryService().newQuery(queries[i]);
            CacheUtils.getLogger().info("Executing query: " + queries[i]);
            QueryObserverImpl observer = new QueryObserverImpl();
            QueryObserverHolder.setInstance(observer);
            r[i][1] = q.execute();
            CacheUtils.log("Executing query: " + queries[i] + " with index created");
            if (!observer.isIndexesUsed) {
                fail("Index is NOT uesd");
            }
            Iterator itr = observer.indexesUsed.iterator();
            assertTrue(itr.hasNext());
            String temp = itr.next().toString();
            assertEquals(temp, "Index" + (i + 1));
        } catch (Exception e) {
            e.printStackTrace();
            fail(q.getQueryString());
        }
    }
    StructSetOrResultsSet ssOrrs = new StructSetOrResultsSet();
    ssOrrs.CompareQueryResultsWithoutAndWithIndexes(r, queries.length, queries);
    // Test queries index not used
    for (int i = 0; i < queriesIndexNotUsed.length; i++) {
        Query q = null;
        try {
            q = CacheUtils.getQueryService().newQuery(queriesIndexNotUsed[i]);
            CacheUtils.getLogger().info("Executing query: " + queriesIndexNotUsed[i]);
            QueryObserverImpl observer = new QueryObserverImpl();
            QueryObserverHolder.setInstance(observer);
            CacheUtils.log("Executing query: " + queriesIndexNotUsed[i] + " with index created");
            q.execute();
            assertFalse(observer.isIndexesUsed);
            Iterator itr = observer.indexesUsed.iterator();
            assertFalse(itr.hasNext());
        } catch (Exception e) {
            e.printStackTrace();
            fail(q.getQueryString());
        }
    }
}
Also used : Query(org.apache.geode.cache.query.Query) StructSetOrResultsSet(org.apache.geode.cache.query.functional.StructSetOrResultsSet) Index(org.apache.geode.cache.query.Index) LocalRegion(org.apache.geode.internal.cache.LocalRegion) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) QueryService(org.apache.geode.cache.query.QueryService) Iterator(java.util.Iterator) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 33 with StructSetOrResultsSet

use of org.apache.geode.cache.query.functional.StructSetOrResultsSet in project geode by apache.

the class IndexUseJUnitTest method evaluateMapTypeIndexUsageAllKeys.

private void evaluateMapTypeIndexUsageAllKeys() throws Exception {
    QueryService qs;
    qs = CacheUtils.getQueryService();
    LocalRegion testRgn = (LocalRegion) CacheUtils.createRegion("testRgn", null);
    int ID = 1;
    // and so on
    for (; ID <= 30; ++ID) {
        MapKeyIndexData mkid = new MapKeyIndexData(ID);
        for (int j = 1; j <= ID; ++j) {
            mkid.maap.put("key1", j * 1);
            mkid.maap.put("key2", j * 2);
            mkid.maap.put("key3", j * 3);
        }
        testRgn.put(ID, mkid);
    }
    String[] queries = { "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.maap['key2'] >= 16" };
    String[] queriesIndexNotUsed = { "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.maap.get('key2') >= 16" };
    Object[][] r = new Object[queries.length][2];
    qs = CacheUtils.getQueryService();
    // Execute Queries without Indexes
    for (int i = 0; i < queries.length; i++) {
        Query q = null;
        try {
            q = CacheUtils.getQueryService().newQuery(queries[i]);
            CacheUtils.getLogger().info("Executing query: " + queries[i]);
            r[i][0] = q.execute();
            CacheUtils.log("Executed query: " + queries[i]);
        } catch (Exception e) {
            e.printStackTrace();
            fail(q.getQueryString());
        }
    }
    Index i1 = qs.createIndex("Index1", IndexType.FUNCTIONAL, "objs.maap[*]", "/testRgn objs");
    // Execute Queries with Indexes
    for (int i = 0; i < queries.length; i++) {
        Query q = null;
        try {
            q = CacheUtils.getQueryService().newQuery(queries[i]);
            CacheUtils.getLogger().info("Executing query: " + queries[i]);
            QueryObserverImpl observer = new QueryObserverImpl();
            QueryObserverHolder.setInstance(observer);
            r[i][1] = q.execute();
            CacheUtils.log("Executing query: " + queries[i] + " with index created");
            if (!observer.isIndexesUsed) {
                fail("Index is NOT used");
            }
            Iterator itr = observer.indexesUsed.iterator();
            assertTrue(itr.hasNext());
            String temp = itr.next().toString();
            assertEquals(temp, "Index1");
        } catch (Exception e) {
            e.printStackTrace();
            fail(q.getQueryString());
        }
    }
    StructSetOrResultsSet ssOrrs = new StructSetOrResultsSet();
    ssOrrs.CompareQueryResultsWithoutAndWithIndexes(r, queries.length, queries);
    // Test queries index not used
    for (int i = 0; i < queriesIndexNotUsed.length; i++) {
        Query q = null;
        try {
            q = CacheUtils.getQueryService().newQuery(queriesIndexNotUsed[i]);
            CacheUtils.getLogger().info("Executing query: " + queriesIndexNotUsed[i]);
            QueryObserverImpl observer = new QueryObserverImpl();
            QueryObserverHolder.setInstance(observer);
            CacheUtils.log("Executing query: " + queriesIndexNotUsed[i] + " with index created");
            q.execute();
            assertFalse(observer.isIndexesUsed);
            Iterator itr = observer.indexesUsed.iterator();
            assertFalse(itr.hasNext());
        } catch (Exception e) {
            e.printStackTrace();
            fail(q.getQueryString());
        }
    }
}
Also used : Query(org.apache.geode.cache.query.Query) StructSetOrResultsSet(org.apache.geode.cache.query.functional.StructSetOrResultsSet) Index(org.apache.geode.cache.query.Index) LocalRegion(org.apache.geode.internal.cache.LocalRegion) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) QueryService(org.apache.geode.cache.query.QueryService) Iterator(java.util.Iterator)

Example 34 with StructSetOrResultsSet

use of org.apache.geode.cache.query.functional.StructSetOrResultsSet in project geode by apache.

the class IndexUseJUnitTest method testCompactMapIndexUsageManyKeysWithVariousValueTypes.

@Test
public void testCompactMapIndexUsageManyKeysWithVariousValueTypes() throws Exception {
    QueryService qs;
    qs = CacheUtils.getQueryService();
    LocalRegion testRgn = (LocalRegion) CacheUtils.createRegion("testRgn", null);
    int ID = 1;
    for (; ID <= 30; ++ID) {
        TestObject object = new TestObject(ID);
        testRgn.put(ID, object);
    }
    String[] queries = { "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.testFields['string'] = '1'", "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.testFields['double'] > 1D", "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.testFields['integer'] > 1", "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.testFields['long'] > 1L" };
    String[] queriesIndexNotUsed = { "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.testFields.get('string') = '1'", "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.testFields.get('double') > 1D", "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.testFields.get('integer') > 1", "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.testFields.get('long') > 1L" };
    Object[][] r = new Object[queries.length][2];
    qs = CacheUtils.getQueryService();
    // Execute Queries without Indexes
    for (int i = 0; i < queries.length; i++) {
        Query q = null;
        try {
            q = CacheUtils.getQueryService().newQuery(queries[i]);
            CacheUtils.getLogger().info("Executing query: " + queries[i]);
            r[i][0] = q.execute();
            CacheUtils.log("Executed query: " + queries[i]);
        } catch (Exception e) {
            e.printStackTrace();
            fail(q.getQueryString());
        }
    }
    Index i1 = qs.createIndex("Index1", IndexType.FUNCTIONAL, "itr1.testFields['string']", "/testRgn itr1");
    Index i2 = qs.createIndex("Index2", IndexType.FUNCTIONAL, "itr1.testFields['double']", "/testRgn itr1");
    Index i3 = qs.createIndex("Index3", IndexType.FUNCTIONAL, "itr1.testFields['integer']", "/testRgn itr1");
    Index i4 = qs.createIndex("Index4", IndexType.FUNCTIONAL, "itr1.testFields['long']", "/testRgn itr1");
    Index i5 = qs.createIndex("Index5", IndexType.FUNCTIONAL, "itr1.testFields['complex']", "/testRgn itr1");
    assertTrue(i1 instanceof CompactRangeIndex);
    // Execute Queries with Indexes
    for (int i = 0; i < queries.length; i++) {
        Query q = null;
        try {
            q = CacheUtils.getQueryService().newQuery(queries[i]);
            CacheUtils.getLogger().info("Executing query: " + queries[i]);
            QueryObserverImpl observer = new QueryObserverImpl();
            QueryObserverHolder.setInstance(observer);
            r[i][1] = q.execute();
            CacheUtils.log("Executing query: " + queries[i] + " with index created");
            if (!observer.isIndexesUsed) {
                fail("Index is NOT uesd");
            }
            Iterator itr = observer.indexesUsed.iterator();
            assertTrue(itr.hasNext());
            String temp = itr.next().toString();
            assertEquals(temp, "Index" + (i + 1));
        } catch (Exception e) {
            e.printStackTrace();
            fail(q.getQueryString());
        }
    }
    StructSetOrResultsSet ssOrrs = new StructSetOrResultsSet();
    ssOrrs.CompareQueryResultsWithoutAndWithIndexes(r, queries.length, queries);
    // Test queries index not used
    for (int i = 0; i < queriesIndexNotUsed.length; i++) {
        Query q = null;
        try {
            q = CacheUtils.getQueryService().newQuery(queriesIndexNotUsed[i]);
            CacheUtils.getLogger().info("Executing query: " + queriesIndexNotUsed[i]);
            QueryObserverImpl observer = new QueryObserverImpl();
            QueryObserverHolder.setInstance(observer);
            CacheUtils.log("Executing query: " + queriesIndexNotUsed[i] + " with index created");
            q.execute();
            assertFalse(observer.isIndexesUsed);
            Iterator itr = observer.indexesUsed.iterator();
            assertFalse(itr.hasNext());
        } catch (Exception e) {
            e.printStackTrace();
            fail(q.getQueryString());
        }
    }
}
Also used : Query(org.apache.geode.cache.query.Query) StructSetOrResultsSet(org.apache.geode.cache.query.functional.StructSetOrResultsSet) Index(org.apache.geode.cache.query.Index) LocalRegion(org.apache.geode.internal.cache.LocalRegion) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) QueryService(org.apache.geode.cache.query.QueryService) Iterator(java.util.Iterator) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 35 with StructSetOrResultsSet

use of org.apache.geode.cache.query.functional.StructSetOrResultsSet in project geode by apache.

the class IndexedMergeEquiJoinScenariosJUnitTest method testNonNestedQueries.

@Test
public void testNonNestedQueries() throws Exception {
    CacheUtils.getQueryService();
    IndexManager.TEST_RANGEINDEX_ONLY = true;
    try {
        String[] queries = { /*
           * 1*
           * "select distinct * from /Portfolios1 pf1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 "
           * + "where pf1.status = pf2.status and c1.name = c2.name", /*2
           */
        "select distinct * from /Portfolios1 pf1, pf1.positions.values pos1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status and c1.name = c2.name or pos1.secId = 'IBM'", /* 3 */
        "select distinct * from /Portfolios1 pf1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or c1.name = c2.name", /* 4 */
        "Select distinct * " + "from /Portfolios1 pfos, pfos.positions.values Pos1, /Countries1 c1, /Countries2 c2, /Countries3 c3, /Portfolios3 pfo3 " + "where Pos1.secId = 'YHOO' and c1.name = c2.name or c3.name = 'INDIA' and pfo3.status != 'inactive' or pfo3.\"type\" = 'type1' and pfo3.status = pfos.status ", /* 5 */
        "Select distinct * " + "from /Portfolios1 pfos, pfos.positions.values Pos1, /Countries1 c1, /Countries2 c2, /Countries3 c3, /Portfolios3 pfo3 " + "where Pos1.secId = 'YHOO' or c1.name = c2.name or c3.name = 'INDIA' and pfo3.status != 'inactive' or pfo3.\"type\" = 'type1' and pfo3.status = pfos.status ", /* 6 */
        "Select distinct * " + "from /Portfolios1 pfos, " + "pfos.positions.values Pos1, " + "/Countries1 c1, " + "/Countries2 c2, " + "/Countries3 c3, " + "/Portfolios3 pfo3 " + "where Pos1.secId = 'YHOO' or " + "c1.name = c2.name or " + "pfo3.status != 'inactive' or " + "pfo3.status = pfos.status ", /* 7 */
        "Select distinct * " + "from /Countries1 c1, c1.states sts1, sts1.districts dists, dists.cities ct1, dists.villages villgs1, " + "/Countries2 c2, " + "/Countries3 c3, " + "/Portfolios3 pfo3 " + "where " + "c1.name = c2.name or " + "ct1.name != 'PUNE' or " + "villgs1.name = 'MAHARASHTRA_VILLAGE1'", /* 8 */
        "Select distinct * " + "from /Countries1 c1, c1.states sts1, sts1.districts dists, dists.cities ct1, dists.villages villgs1, " + "/Countries2 c2, " + "/Countries3 c3 " + "where " + "c1.name = c2.name and " + "ct1.name != 'PUNE' and " + "villgs1.name = 'MAHARASHTRA_VILLAGE1'", /* 9 */
        "Select distinct * " + "from /Countries1 c1, c1.states sts1, sts1.districts dists1, dists1.cities ct1, dists1.villages villgs1, " + "/Countries2 c2, c2.states s2, " + "/Countries3 c3, c3.states sts3, sts3.districts dists3, dists3.cities ct3, dists3.villages villgs3 " + "where " + "c1.name = c2.name and " + "ct1.name != 'PUNE' and " + "villgs1.name = 'MAHARASHTRA_VILLAGE1' or " + "villgs1.name = villgs3.name or " + "s2.name = 'PUNJAB' or " + "ct1.name = ct3.name and " + "dists3.name = 'MUMBAIDIST'", /* 10 */
        "Select distinct * " + "from /Countries1 c1, c1.states sts1, sts1.districts dists1, dists1.cities ct1, dists1.villages villgs1, " + "/Countries2 c2, c2.states s2, " + "/Countries3 c3, c3.states sts3, sts3.districts dists3, dists3.cities ct3, dists3.villages villgs3 " + "where " + "c1.name = c2.name or " + "ct1.name != 'PUNE' and " + "villgs1.name = 'MAHARASHTRA_VILLAGE1' or " + "villgs1.name = villgs3.name or " + "s2.name = 'PUNJAB' or " + "ct1.name = ct3.name and " + "dists3.name = 'MUMBAIDIST'", /* 11 */
        "Select distinct * " + "from /Countries1 c1, c1.states sts1, sts1.districts dists1, dists1.cities ct1, dists1.villages villgs1, " + "/Countries2 c2, c2.states s2, " + "/Countries3 c3, c3.states sts3, sts3.districts dists3, dists3.cities ct3, dists3.villages villgs3 " + "where " + "c1.name = c2.name and " + "ct1.name != 'PUNE' or " + "villgs1.name = 'MAHARASHTRA_VILLAGE1' or " + "villgs1.name = villgs3.name or " + "s2.name = 'PUNJAB' or " + "ct1.name = ct3.name and " + "dists3.name = 'MUMBAIDIST'", /* 12 */
        "Select distinct * " + "from /Countries1 c1, c1.states sts1, sts1.districts dists1, dists1.cities ct1, dists1.villages villgs1, " + "/Countries2 c2, c2.states s2, " + "/Countries3 c3, c3.states sts3, sts3.districts dists3, dists3.cities ct3, dists3.villages villgs3 " + "where " + "c1.name = c2.name and " + "ct1.name != 'PUNE' or " + "villgs1.name = 'MAHARASHTRA_VILLAGE1' and " + "villgs1.name = villgs3.name or " + "s2.name = 'PUNJAB' or " + "ct1.name = ct3.name or " + "dists3.name = 'MUMBAIDIST'", /* 13 */
        "Select distinct * " + "from /Countries1 c1, c1.states sts1, sts1.districts dists1, dists1.cities ct1, dists1.villages villgs1, " + "/Countries2 c2, c2.states s2, " + "/Countries3 c3, c3.states sts3, sts3.districts dists3, dists3.cities ct3, dists3.villages villgs3 " + "where " + "c1.name = c2.name and " + "ct1.name != 'PUNE' and " + "villgs1.name = 'MAHARASHTRA_VILLAGE1' and " + "villgs1.name = villgs3.name or " + "s2.name = 'PUNJAB' and " + "ct1.name = ct3.name and " + "dists3.name = 'MUMBAIDIST'", /* 14 */
        "Select distinct * " + "from /Countries1 c1, c1.states sts1, sts1.districts dists1, dists1.cities ct1, dists1.villages villgs1, " + "/Countries2 c2, c2.states s2, " + "/Countries3 c3, c3.states sts3, sts3.districts dists3, dists3.cities ct3, dists3.villages villgs3 " + "where " + "c1.name = c2.name or " + "ct1.name != 'PUNE' or " + "villgs1.name = 'MAHARASHTRA_VILLAGE1' or " + "villgs1.name = villgs3.name or " + "s2.name = 'PUNJAB' or " + "ct1.name = ct3.name or " + "dists3.name = 'MUMBAIDIST'", /* 15 */
        "Select distinct * " + "from /Countries1 c1, c1.states sts1, sts1.districts dists1, dists1.cities ct1, dists1.villages villgs1, " + "/Countries2 c2, c2.states s2, " + "/Countries3 c3, c3.states sts3, sts3.districts dists3, dists3.cities ct3, dists3.villages villgs3 " + "where " + "c1.name = c2.name and " + "ct1.name != 'PUNE' and " + "villgs1.name = 'MAHARASHTRA_VILLAGE1' and " + "villgs1.name = villgs3.name and " + "s2.name = 'PUNJAB' and " + "ct1.name = ct3.name and " + "dists3.name = 'MUMBAIDIST'", /* 16 */
        "Select distinct * " + "from /Countries1 c1, c1.states sts1, sts1.districts dists1, dists1.cities ct1, dists1.villages villgs1, " + "/Countries2 c2, c2.states s2, " + "/Countries3 c3, c3.states sts3, sts3.districts dists3, dists3.cities ct3, dists3.villages villgs3 " + "where " + "c1.name = c2.name and " + "sts1.name != 'PUNJAB' and " + "ct1.name != 'PUNE' and " + "villgs1.name = 'MAHARASHTRA_VILLAGE1' and " + "villgs1.name = villgs3.name and " + "sts3.name != sts1.name and " + "s2.name = 'PUNJAB' and " + "ct1.name = ct3.name and " + "dists3.name = 'MUMBAIDIST' and dists3.name != s2.name", /* 17 */
        "Select distinct * " + "from /Portfolios1 pfos, " + "pfos.positions.values Pos1, " + "/Countries1 c1, " + "/Countries2 c2, " + "/Countries3 c3, " + "/Portfolios3 pfo3 " + "where Pos1.secId = 'YHOO' and " + "c1.name = c2.name or " + "pfo3.status != 'inactive' and " + "pfo3.status = pfos.status ", /* 18 */
        "Select distinct * " + "from /Portfolios1 pfos, " + "pfos.positions.values Pos1, " + "/Countries1 c1, " + "/Countries2 c2, " + "/Countries3 c3, " + "/Portfolios3 pfo3 " + "where Pos1.secId = 'YHOO' and " + "c1.name = c2.name or " + "pfo3.status != 'inactive' and " + "pfo3.status = pfos.status ", /* 19 */
        "Select distinct * " + "from /Portfolios1 pfos, " + "pfos.positions.values Pos1, " + "/Countries1 c1, c1.states sts1, sts1.districts dists1, dists1.cities ct1, dists1.villages villgs1, " + "/Countries2 c2, " + "/Countries3 c3, " + "/Portfolios3 pfo3 " + "where Pos1.secId = 'YHOO' and " + "c1.name = c2.name or " + "pfo3.status != 'inactive' and " + "pfo3.status = pfos.status and villgs1.name = 'MAHARASHTRA_VILLAGE1' ", /* 20 */
        "Select distinct * " + "from /Portfolios1 pfos, " + "pfos.positions.values Pos1, " + "/Countries1 c1, c1.states sts1, sts1.districts dists1, dists1.cities ct1, dists1.villages villgs1, " + "/Countries2 c2, " + "/Countries3 c3, " + "/Portfolios3 pfo3 " + "where Pos1.secId = 'YHOO' and " + "c1.name = c2.name or " + "pfo3.status != 'inactive' and " + "pfo3.status = pfos.status and villgs1.name = 'MAHARASHTRA_VILLAGE1' or pfos.ID != 0", /* 21 */
        "Select distinct * " + "from /Portfolios1 pfos, " + "pfos.positions.values Pos1, " + "/Countries1 c1, c1.states sts1, sts1.districts dists1, dists1.cities ct1, dists1.villages villgs1, " + "/Countries2 c2, " + "/Countries3 c3, " + "/Portfolios3 pfo3 " + "where Pos1.secId = 'YHOO' and " + "c1.name = c2.name or " + "pfo3.status != 'inactive' and " + "pfo3.status = pfos.status and villgs1.name = 'MAHARASHTRA_VILLAGE1' or pfos.ID != 0", /* 22 */
        "Select distinct * " + "from /Portfolios1 pfos, " + "pfos.positions.values Pos1, " + "/Countries1 c1, c1.states sts1, sts1.districts dists1, dists1.cities ct1, dists1.villages villgs1, " + "/Countries2 c2, " + "/Countries3 c3, " + "/Portfolios3 pfo3 " + "where Pos1.secId = 'YHOO' and " + "c1.name = c2.name or " + "pfo3.status != 'inactive' and " + "pfo3.status = pfos.status and villgs1.name = 'MAHARASHTRA_VILLAGE1' or pfos.ID != 0", /* 23 */
        "Select distinct * " + "from /Portfolios1 pfos, " + "pfos.positions.values Pos1, " + "/Countries1 c1, " + "/Countries2 c2, " + "/Countries3 c3, " + "/Portfolios3 pfo3 " + "where Pos1.secId = 'YHOO' and " + "(c1.name = c2.name or " + "pfo3.status != 'inactive') and " + "pfo3.status = pfos.status ", /* 24 */
        "Select distinct * " + "from /Portfolios1 pfos, " + "pfos.positions.values Pos1, " + "/Countries1 c1, c1.states s1, " + "/Countries2 c2, c2.states s2, " + "/Countries3 c3, " + "/Portfolios3 pfo3 " + "where Pos1.secId = 'YHOO' and " + "((c1.name = c2.name or " + "pfo3.status != 'inactive') and " + "pfo3.status = pfos.status) or s1.name = 'MAHARASHTRA' and s2.name != 'MAHARASHTRA'", /* 25 */
        "Select distinct * " + "from /Portfolios1 pfos, " + "pfos.positions.values Pos1, " + "/Countries1 c1, c1.states sts1, sts1.districts dists1, dists1.cities ct1, dists1.villages villgs1, " + "/Countries2 c2, " + "/Countries3 c3, " + "/Portfolios3 pfo3 " + "where (Pos1.secId = 'YHOO' and " + "c1.name = c2.name or " + "pfo3.status != 'inactive') and " + "pfo3.status = pfos.status and villgs1.name = 'MAHARASHTRA_VILLAGE1' ", /* 26 */
        "Select distinct * " + "from /Portfolios1 pfos, " + "pfos.positions.values Pos1, " + "/Countries1 c1, c1.states sts1, sts1.districts dists1, dists1.cities ct1, dists1.villages villgs1, " + "/Countries2 c2, " + "/Countries3 c3, " + "/Portfolios3 pfo3 " + "where Pos1.secId = 'YHOO' and " + "c1.name = c2.name or " + "pfo3.status != 'inactive' and " + "pfo3.status = pfos.status and (villgs1.name = 'MAHARASHTRA_VILLAGE1' or pfos.ID != 0)", /* 27 */
        "Select distinct * " + "from /Portfolios1 pfos, " + "pfos.positions.values Pos1, " + "/Countries1 c1, c1.states sts1, sts1.districts dists1, dists1.cities ct1, dists1.villages villgs1, " + "/Countries2 c2, " + "/Countries3 c3, " + "/Portfolios3 pfo3 " + "where Pos1.secId = 'YHOO' and " + "(c1.name = c2.name or " + "pfo3.status != 'inactive') and " + "pfo3.status = pfos.status and (villgs1.name = 'MAHARASHTRA_VILLAGE1' or pfos.ID != 0)", /* 28 */
        "Select distinct * " + "from /Portfolios1 pfos, " + "pfos.positions.values Pos1, " + "/Countries1 c1, c1.states sts1, sts1.districts dists1, dists1.cities ct1, dists1.villages villgs1, " + "/Countries2 c2, " + "/Countries3 c3, " + "/Portfolios3 pfo3 " + "where Pos1.secId = 'YHOO' and " + "(c1.name = c2.name or " + "pfo3.status != 'inactive' and " + "pfo3.status = pfos.status and (villgs1.name = 'MAHARASHTRA_VILLAGE1' or pfos.ID != 0))", /* 29 */
        "select distinct * from /Portfolios1 pf1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or false or c1.name = c2.name", /* 30 */
        "select distinct * from /Portfolios1 pf1, pf1.positions.values pos1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or c1.name = c2.name and pos1.secId = 'IBM' and true", /* 31 */
        "select distinct * from /Portfolios1 pf1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or c1.name = c2.name and true", /* 32 */
        "select distinct * from /Portfolios1 pf1, pf1.positions.values pos1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status and c1.name = c2.name or pos1.secId = 'IBM'", /* 33 */
        "select distinct * from /Portfolios1 pf1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or c1.name = c2.name and false", /* 34 */
        "select distinct * from /Portfolios1 pf1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or false or c1.name = c2.name or pf2.ID = 1 or c1.name = 'INDIA'", /* 35 */
        "select distinct * from /Portfolios1 pf1, pf1.positions.values pos1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or c1.name = c2.name and pos1.secId = 'IBM' and true or pf1.ID != 3", /* 36 */
        "select distinct * from /Portfolios1 pf1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or c1.name = c2.name and true or pf1.ID = pf2.ID", /* 37 */
        "select distinct * from /Portfolios1 pf1, pf1.positions.values pos1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status and c1.name = c2.name or pos1.secId = 'IBM' or false and pf1.ID = pf2.ID", /* 38 */
        "select distinct * from /Portfolios1 pf1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or c1.name = c2.name and false and pf1.ID = pf2.ID", /* 39 */
        "select distinct * from /Portfolios1 pf1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or false or c1.name = c2.name or c1.name = 'INDIA' or pf1.ID = 2", /* 40 */
        "select distinct * from /Portfolios1 pf1, pf1.positions.values pos1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or c1.name = c2.name and pos1.secId = 'IBM' and true", /* 41 */
        "select distinct * from /Portfolios1 pf1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or c1.name = c2.name and true or c1.name = 'INDIA' or pf1.ID = 2", /* 42 */
        "select distinct * from /Portfolios1 pf1, pf1.positions.values pos1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status and c1.name = c2.name or pos1.secId = 'IBM' or c1.name = 'INDIA' or pf2.ID = 2", /* 43 */
        "select distinct * from /Portfolios1 pf1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or c1.name = c2.name and false or c1.name = 'INDIA' or pf2.ID = 2", // FAILING /*44*/
        "select distinct * from /Portfolios1 pf1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or false or c1.name = c2.name or pf2.ID = 1 or c1.name = 'INDIA' or c1.name = 'INDIA' or pf1.ID = 2", /* 45 */
        "select distinct * from /Portfolios1 pf1, pf1.positions.values pos1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or c1.name = c2.name and pos1.secId = 'IBM' and true or pf1.ID != 3 or c1.name = 'INDIA' or pf1.ID = 2", /* 46 */
        "select distinct * from /Portfolios1 pf1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or c1.name = c2.name and true or pf1.ID = pf2.ID or c1.name = 'INDIA' or pf2.ID = 2", /* 47 */
        "select distinct * from /Portfolios1 pf1, pf1.positions.values pos1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status and c1.name = c2.name or pos1.secId = 'IBM' or false and pf1.ID = pf2.ID or c1.name = 'INDIA' or pf1.ID = 2", /* 48 */
        "select distinct * from /Portfolios1 pf1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or c1.name = c2.name and false and pf1.ID = pf2.ID or c1.name = 'INDIA' or pf2.ID = 2", /* 49 */
        "select distinct * from /Portfolios1 pf1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or false or c1.name = c2.name and c1.name = 'INDIA' and pf1.ID = 2", /* 50 */
        "select distinct * from /Portfolios1 pf1, pf1.positions.values pos1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or c1.name = c2.name and pos1.secId = 'IBM' and true and c1.name = 'INDIA' and pf2.ID = 2", /* 51 */
        "select distinct * from /Portfolios1 pf1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or c1.name = c2.name and true and c1.name = 'INDIA' and pf2.ID = 2", /* 52 */
        "select distinct * from /Portfolios1 pf1, pf1.positions.values pos1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status and c1.name = c2.name or pos1.secId = 'IBM' and c1.name = 'INDIA' and pf2.ID = 2", /* 53 */
        "select distinct * from /Portfolios1 pf1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or c1.name = c2.name and false and c1.name = 'INDIA' and pf2.ID = 2", /* 54 */
        "select distinct * from /Portfolios1 pf1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or false or c1.name = c2.name or pf2.ID = 1 or c1.name = 'INDIA' and c1.name = 'INDIA' and pf2.ID = 2", /* 55 */
        "select distinct * from /Portfolios1 pf1, pf1.positions.values pos1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or c1.name = c2.name and pos1.secId = 'IBM' and true or pf1.ID != 3 and c1.name = 'INDIA' and pf2.ID = 2", /* 56 */
        "select distinct * from /Portfolios1 pf1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or c1.name = c2.name and true or pf1.ID = pf2.ID and c1.name = 'INDIA' and pf2.ID = 2", /* 57 */
        "select distinct * from /Portfolios1 pf1, pf1.positions.values pos1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status and c1.name = c2.name or pos1.secId = 'IBM' or false and pf1.ID = pf2.ID and c1.name = 'INDIA' and pf2.ID = 2", /* 58 */
        "select distinct * from /Portfolios1 pf1, /Portfolios2 pf2, /Countries1 c1, /Countries2 c2 " + "where pf1.status = pf2.status or c1.name = c2.name and false and pf1.ID = pf2.ID and c1.name = 'INDIA' and pf2.ID = 2" };
        SelectResults[][] rs = new SelectResults[queries.length][2];
        for (int i = 0; i < queries.length; i++) {
            CacheUtils.log("Running query number :" + (i + 1) + " without Index");
            Query q = null;
            q = CacheUtils.getQueryService().newQuery(queries[i]);
            rs[i][0] = (SelectResults) q.execute();
        }
        CacheUtils.log("Now creating Indexes");
        createIndex();
        CacheUtils.log("All indexes created ");
        for (int j = 0; j < queries.length; j++) {
            CacheUtils.log("Running query number :" + (j + 1) + " with Index");
            if (j == 4) {
                System.out.print("Hi");
            }
            Query q2 = null;
            q2 = CacheUtils.getQueryService().newQuery(queries[j]);
            QueryObserverImpl observer = new QueryObserverImpl();
            QueryObserverHolder.setInstance(observer);
            try {
                rs[j][1] = (SelectResults) q2.execute();
                if (!observer.isIndexesUsed) {
                    fail("------------ INDEX IS NOT USED FOR THE QUERY:: " + q2.getQueryString());
                }
            } catch (Exception e) {
                System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!CAUGHT EXCPETION AT QUERY NO: " + (j + 1));
                e.printStackTrace();
                fail();
            }
        }
        StructSetOrResultsSet ssORrs = new StructSetOrResultsSet();
        ssORrs.CompareQueryResultsWithoutAndWithIndexes(rs, queries.length, queries);
    } finally {
        IndexManager.TEST_RANGEINDEX_ONLY = false;
    }
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) Query(org.apache.geode.cache.query.Query) StructSetOrResultsSet(org.apache.geode.cache.query.functional.StructSetOrResultsSet) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

StructSetOrResultsSet (org.apache.geode.cache.query.functional.StructSetOrResultsSet)35 QueryService (org.apache.geode.cache.query.QueryService)23 Test (org.junit.Test)23 SelectResults (org.apache.geode.cache.query.SelectResults)19 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)17 Query (org.apache.geode.cache.query.Query)16 LocalRegion (org.apache.geode.internal.cache.LocalRegion)16 Region (org.apache.geode.cache.Region)15 Index (org.apache.geode.cache.query.Index)13 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)13 Cache (org.apache.geode.cache.Cache)12 QueryException (org.apache.geode.cache.query.QueryException)12 Iterator (java.util.Iterator)9 CancelException (org.apache.geode.CancelException)8 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)8 QueryInvalidException (org.apache.geode.cache.query.QueryInvalidException)8 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)8 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)8 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)8 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)8