Search in sources :

Example 56 with QueryObserverAdapter

use of org.apache.geode.cache.query.internal.QueryObserverAdapter in project geode by apache.

the class CustomerOptimizationsJUnitTest method testLiteralBheaviour_2.

@Test
public void testLiteralBheaviour_2() throws Exception {
    QueryService qs = CacheUtils.getQueryService();
    Region rgn = CacheUtils.getRegion("/pos");
    for (int i = 100; i < 1000; ++i) {
        Portfolio pf = new Portfolio(i);
        pf.setCreateTime(10l);
        rgn.put("" + i, pf);
    }
    String[] queries = new String[] { "select  distinct p.status  from /pos p  where  p.createTime = 10l AND  p.status IN SET( 'active') AND  true" };
    SelectResults[][] sr = new SelectResults[queries.length][2];
    for (int i = 0; i < queries.length; ++i) {
        Query q = qs.newQuery(queries[i]);
        sr[i][0] = (SelectResults) q.execute();
    }
    final List indexUsed = new ArrayList();
    qs.createIndex("PortFolioID", IndexType.FUNCTIONAL, "ID", "/pos");
    qs.createIndex("CreateTime", IndexType.FUNCTIONAL, "createTime", "/pos");
    qs.createIndex("Status", IndexType.FUNCTIONAL, "status", "/pos");
    qs.createIndex("Type", IndexType.FUNCTIONAL, "\"type\"", "/pos");
    final boolean[] expectedIndexUsed = new boolean[] { true };
    final boolean[] actualIndexUsed = new boolean[] { false };
    final boolean[] expectedProjectionCallabck = new boolean[] { false };
    final boolean[] actualProjectionCallback = new boolean[] { false };
    final boolean[] expectedUnionCallback = { false };
    final boolean[] actualUnionCallback = new boolean[queries.length];
    final boolean[] expectedIntersectionCallback = { false };
    final boolean[] actualIntersectionCallback = new boolean[queries.length];
    ObjectType[] expectedTypes = new ObjectType[] { new ObjectTypeImpl(String.class) };
    QueryObserverHolder.setInstance(new QueryObserverAdapter() {

        private int i = 0;

        public void invokedQueryUtilsUnion(SelectResults r1, SelectResults r2) {
            actualUnionCallback[i] = true;
        }

        public void invokedQueryUtilsIntersection(SelectResults r1, SelectResults r2) {
            actualIntersectionCallback[i] = true;
        }

        public void beforeIndexLookup(Index index, int oper, Object key) {
            actualIndexUsed[i] = true;
            indexUsed.add(index);
        }

        public void beforeApplyingProjectionOnFilterEvaluatedResults(Object preProjectionApplied) {
            actualProjectionCallback[i] = true;
        }

        public void afterQueryEvaluation(Object result) {
            ++i;
        }
    });
    for (int i = 0; i < queries.length; ++i) {
        Query q = qs.newQuery(queries[i]);
        sr[i][1] = (SelectResults) q.execute();
        assertEquals(expectedUnionCallback[i], actualUnionCallback[i]);
        assertEquals(expectedTypes[i], sr[i][1].getCollectionType().getElementType());
        assertEquals(expectedIndexUsed[i], actualIndexUsed[i]);
        assertEquals(expectedIntersectionCallback[i], actualIntersectionCallback[i]);
        assertEquals(expectedProjectionCallabck[i], actualProjectionCallback[i]);
    }
    assertEquals(indexUsed.size(), 1);
    assertEquals(((Index) indexUsed.iterator().next()).getName(), "Status");
    CacheUtils.compareResultsOfWithAndWithoutIndex(sr, this);
}
Also used : Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) ArrayList(java.util.ArrayList) ObjectTypeImpl(org.apache.geode.cache.query.internal.types.ObjectTypeImpl) Index(org.apache.geode.cache.query.Index) ObjectType(org.apache.geode.cache.query.types.ObjectType) SelectResults(org.apache.geode.cache.query.SelectResults) QueryService(org.apache.geode.cache.query.QueryService) QueryObserverAdapter(org.apache.geode.cache.query.internal.QueryObserverAdapter) Region(org.apache.geode.cache.Region) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 57 with QueryObserverAdapter

use of org.apache.geode.cache.query.internal.QueryObserverAdapter in project geode by apache.

the class CustomerOptimizationsJUnitTest method testLiteralBehaviour_1.

@Test
public void testLiteralBehaviour_1() throws Exception {
    QueryService qs = CacheUtils.getQueryService();
    Region rgn = CacheUtils.getRegion("/pos");
    for (int i = 100; i < 200; ++i) {
        Portfolio pf = new Portfolio(i);
        pf.setCreateTime(10l);
        rgn.put("" + i, pf);
    }
    String[] queries = new String[] { "select  distinct p.status  from /pos p  where  true" };
    SelectResults[][] sr = new SelectResults[queries.length][2];
    for (int i = 0; i < queries.length; ++i) {
        Query q = qs.newQuery(queries[i]);
        sr[i][0] = (SelectResults) q.execute();
    }
    final List indexUsed = new ArrayList();
    qs.createIndex("PortFolioID", IndexType.FUNCTIONAL, "ID", "/pos");
    qs.createIndex("CreateTime", IndexType.FUNCTIONAL, "createTime", "/pos");
    qs.createIndex("Status", IndexType.FUNCTIONAL, "status", "/pos");
    qs.createIndex("Type", IndexType.FUNCTIONAL, "\"type\"", "/pos");
    final boolean[] expectedIndexUsed = new boolean[] { false };
    final boolean[] actualIndexUsed = new boolean[] { false };
    final boolean[] expectedProjectionCallabck = new boolean[] { false };
    final boolean[] actualProjectionCallback = new boolean[] { false };
    final boolean[] expectedUnionCallback = { false };
    final boolean[] actualUnionCallback = new boolean[queries.length];
    final boolean[] expectedIntersectionCallback = { false };
    final boolean[] actualIntersectionCallback = new boolean[queries.length];
    ObjectType[] expectedTypes = new ObjectType[] { new ObjectTypeImpl(String.class) };
    QueryObserverHolder.setInstance(new QueryObserverAdapter() {

        private int i = 0;

        public void invokedQueryUtilsUnion(SelectResults r1, SelectResults r2) {
            actualUnionCallback[i] = true;
        }

        public void invokedQueryUtilsIntersection(SelectResults r1, SelectResults r2) {
            actualIntersectionCallback[i] = true;
        }

        public void beforeIndexLookup(Index index, int oper, Object key) {
            actualIndexUsed[i] = true;
            indexUsed.add(index);
        }

        public void beforeApplyingProjectionOnFilterEvaluatedResults(Object preProjectionApplied) {
            actualProjectionCallback[i] = true;
        }

        public void afterQueryEvaluation(Object result) {
            ++i;
        }
    });
    for (int i = 0; i < queries.length; ++i) {
        Query q = qs.newQuery(queries[i]);
        sr[i][1] = (SelectResults) q.execute();
        assertEquals(expectedUnionCallback[i], actualUnionCallback[i]);
        assertEquals(expectedTypes[i], sr[i][1].getCollectionType().getElementType());
        assertEquals(expectedIndexUsed[i], actualIndexUsed[i]);
        assertEquals(expectedIntersectionCallback[i], actualIntersectionCallback[i]);
        assertEquals(expectedProjectionCallabck[i], actualProjectionCallback[i]);
    }
    assertEquals(indexUsed.size(), 0);
    CacheUtils.compareResultsOfWithAndWithoutIndex(sr, this);
}
Also used : Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) ArrayList(java.util.ArrayList) ObjectTypeImpl(org.apache.geode.cache.query.internal.types.ObjectTypeImpl) Index(org.apache.geode.cache.query.Index) ObjectType(org.apache.geode.cache.query.types.ObjectType) SelectResults(org.apache.geode.cache.query.SelectResults) QueryService(org.apache.geode.cache.query.QueryService) QueryObserverAdapter(org.apache.geode.cache.query.internal.QueryObserverAdapter) Region(org.apache.geode.cache.Region) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 58 with QueryObserverAdapter

use of org.apache.geode.cache.query.internal.QueryObserverAdapter in project geode by apache.

the class CustomerOptimizationsJUnitTest method testProjectionEvaluationDuringIndexResultsWithComplexWhereClause_UNIMPLEMENTED_2.

@Ignore
@Test
public void testProjectionEvaluationDuringIndexResultsWithComplexWhereClause_UNIMPLEMENTED_2() throws QueryException {
    QueryService qs = CacheUtils.getQueryService();
    Region rgn = CacheUtils.getRegion("/pos");
    for (int i = 100; i < 200; ++i) {
        Portfolio pf = new Portfolio(i);
        pf.setCreateTime(10l);
        rgn.put("" + i, pf);
    }
    String[] queries = new String[] { "select  p.status as sts, p as pos from /pos p  where   (p.ID IN  SET( 0,1,2,3,4,5,101,102,103,104,105) AND p.createTime > 9l) OR (p.ID IN  SET( 20,30,110,120) AND p.createTime > 7l)" };
    SelectResults[][] sr = new SelectResults[queries.length][2];
    for (int i = 0; i < queries.length; ++i) {
        Query q = qs.newQuery(queries[i]);
        sr[i][0] = (SelectResults) q.execute();
    }
    qs.createIndex("PortFolioID", IndexType.FUNCTIONAL, "ID", "/pos");
    qs.createIndex("CreateTime", IndexType.FUNCTIONAL, "createTime", "/pos");
    final boolean[] expectedIndexUsed = new boolean[] { true };
    final boolean[] actualIndexUsed = new boolean[] { false };
    final boolean[] expectedProjectionCallabck = new boolean[] { false };
    final boolean[] actualProjectionCallback = new boolean[] { false };
    final boolean[] expectedUnionCallback = { true };
    final boolean[] actualUnionCallback = new boolean[queries.length];
    final boolean[] expectedIntersectionCallback = { false };
    final boolean[] actualIntersectionCallback = new boolean[queries.length];
    ObjectType[] expectedTypes = new ObjectType[] { new StructTypeImpl(new String[] { "sts", "pos" }, new ObjectType[] { new ObjectTypeImpl(String.class), new ObjectTypeImpl(Portfolio.class) }) };
    QueryObserverHolder.setInstance(new QueryObserverAdapter() {

        private int i = 0;

        public void invokedQueryUtilsUnion(SelectResults r1, SelectResults r2) {
            actualUnionCallback[i] = true;
        }

        public void invokedQueryUtilsIntersection(SelectResults r1, SelectResults r2) {
            actualIntersectionCallback[i] = true;
        }

        public void beforeIndexLookup(Index index, int oper, Object key) {
            actualIndexUsed[i] = true;
        }

        public void beforeApplyingProjectionOnFilterEvaluatedResults(Object preProjectionApplied) {
            actualProjectionCallback[i] = true;
        }

        public void afterQueryEvaluation(Object result) {
            ++i;
        }
    });
    for (int i = 0; i < queries.length; ++i) {
        Query q = qs.newQuery(queries[i]);
        sr[i][1] = (SelectResults) q.execute();
        assertEquals(expectedUnionCallback[i], actualUnionCallback[i]);
        assertEquals(expectedTypes[i], sr[i][1].getCollectionType().getElementType());
        assertEquals(expectedIndexUsed[i], actualIndexUsed[i]);
        assertEquals(expectedIntersectionCallback[i], actualIntersectionCallback[i]);
        assertEquals(expectedProjectionCallabck[i], actualProjectionCallback[i]);
    }
    CacheUtils.compareResultsOfWithAndWithoutIndex(sr, this);
}
Also used : Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) ObjectTypeImpl(org.apache.geode.cache.query.internal.types.ObjectTypeImpl) Index(org.apache.geode.cache.query.Index) ObjectType(org.apache.geode.cache.query.types.ObjectType) SelectResults(org.apache.geode.cache.query.SelectResults) QueryService(org.apache.geode.cache.query.QueryService) QueryObserverAdapter(org.apache.geode.cache.query.internal.QueryObserverAdapter) StructTypeImpl(org.apache.geode.cache.query.internal.types.StructTypeImpl) Region(org.apache.geode.cache.Region) Ignore(org.junit.Ignore) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 59 with QueryObserverAdapter

use of org.apache.geode.cache.query.internal.QueryObserverAdapter in project geode by apache.

the class CustomerOptimizationsJUnitTest method testBug39851.

@Test
public void testBug39851() throws QueryException {
    QueryService qs = CacheUtils.getQueryService();
    Region rgn = CacheUtils.getRegion("/pos");
    for (int i = 100; i < 200; ++i) {
        Portfolio pf = new Portfolio(i);
        pf.setCreateTime(10l);
        rgn.put("" + i, pf);
    }
    String[] queries = new String[] { "select  p.status as sts, p as pos from /pos p  where  p.ID IN  ( Select x.ID from /pos x where x.ID > 10) " };
    SelectResults[][] sr = new SelectResults[queries.length][2];
    for (int i = 0; i < queries.length; ++i) {
        Query q = qs.newQuery(queries[i]);
        sr[i][0] = (SelectResults) q.execute();
    }
    qs.createIndex("PortFolioID", IndexType.FUNCTIONAL, "ID", "/pos");
    final boolean[] expectedIndexUsed = new boolean[] { true, true };
    final boolean[] actualIndexUsed = new boolean[] { false, false };
    final boolean[] expectedProjectionCallabck = new boolean[] { false, false };
    final boolean[] actualProjectionCallback = new boolean[] { false, false };
    final boolean[] expectedUnionCallback = { false };
    final boolean[] actualUnionCallback = new boolean[queries.length];
    final boolean[] expectedIntersectionCallback = { false };
    final boolean[] actualIntersectionCallback = new boolean[queries.length];
    ObjectType[] expectedTypes = new ObjectType[] { new StructTypeImpl(new String[] { "sts", "pos" }, new ObjectType[] { new ObjectTypeImpl(String.class), new ObjectTypeImpl(Portfolio.class) }) };
    QueryObserverHolder.setInstance(new QueryObserverAdapter() {

        private int i = 0;

        public void invokedQueryUtilsUnion(SelectResults r1, SelectResults r2) {
            actualUnionCallback[i] = true;
        }

        public void invokedQueryUtilsIntersection(SelectResults r1, SelectResults r2) {
            actualIntersectionCallback[i] = true;
        }

        public void beforeIndexLookup(Index index, int oper, Object key) {
            actualIndexUsed[i] = true;
        }

        public void beforeApplyingProjectionOnFilterEvaluatedResults(Object preProjectionApplied) {
            actualProjectionCallback[i] = true;
        }

        public void afterQueryEvaluation(Object result) {
            ++i;
        }
    });
    for (int i = 0; i < queries.length; ++i) {
        Query q = qs.newQuery(queries[i]);
        sr[i][1] = (SelectResults) q.execute();
        assertEquals(expectedUnionCallback[i], actualUnionCallback[i]);
        assertEquals(expectedTypes[i], sr[i][1].getCollectionType().getElementType());
        assertEquals(expectedIndexUsed[i], actualIndexUsed[i]);
        assertEquals(expectedProjectionCallabck[i], actualProjectionCallback[i]);
        assertEquals(expectedIntersectionCallback[i], actualIntersectionCallback[i]);
    }
    CacheUtils.compareResultsOfWithAndWithoutIndex(sr, this);
}
Also used : Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) ObjectTypeImpl(org.apache.geode.cache.query.internal.types.ObjectTypeImpl) Index(org.apache.geode.cache.query.Index) ObjectType(org.apache.geode.cache.query.types.ObjectType) SelectResults(org.apache.geode.cache.query.SelectResults) QueryService(org.apache.geode.cache.query.QueryService) QueryObserverAdapter(org.apache.geode.cache.query.internal.QueryObserverAdapter) StructTypeImpl(org.apache.geode.cache.query.internal.types.StructTypeImpl) Region(org.apache.geode.cache.Region) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 60 with QueryObserverAdapter

use of org.apache.geode.cache.query.internal.QueryObserverAdapter in project geode by apache.

the class CustomerOptimizationsJUnitTest method testInAndRangeCombination.

@Test
public void testInAndRangeCombination() throws Exception {
    QueryService qs = CacheUtils.getQueryService();
    Region rgn = CacheUtils.getRegion("/pos");
    for (int i = 100; i < 200; ++i) {
        Portfolio pf = new Portfolio(i);
        pf.setCreateTime(10l);
        rgn.put("" + i, pf);
    }
    String[] queries = new String[] { "select  distinct p.status  from /pos p  where  p.ID > 11 AND  p.ID < 19 and  p.createTime IN  SET( 10L) " };
    SelectResults[][] sr = new SelectResults[queries.length][2];
    for (int i = 0; i < queries.length; ++i) {
        Query q = qs.newQuery(queries[i]);
        sr[i][0] = (SelectResults) q.execute();
    }
    qs.createIndex("PortFolioID", IndexType.FUNCTIONAL, "ID", "/pos");
    qs.createIndex("CreateTime", IndexType.FUNCTIONAL, "createTime", "/pos");
    qs.createIndex("Status", IndexType.FUNCTIONAL, "status", "/pos");
    qs.createIndex("Type", IndexType.FUNCTIONAL, "\"type\"", "/pos");
    final boolean[] expectedIndexUsed = new boolean[] { true };
    final boolean[] actualIndexUsed = new boolean[] { false };
    final boolean[] expectedProjectionCallabck = new boolean[] { false };
    final boolean[] actualProjectionCallback = new boolean[] { false };
    final boolean[] expectedUnionCallback = { false };
    final boolean[] actualUnionCallback = new boolean[queries.length];
    final List indexesUsed = new ArrayList();
    final boolean[] expectedIntersectionCallback = { false };
    final boolean[] actualIntersectionCallback = new boolean[queries.length];
    ObjectType[] expectedTypes = new ObjectType[] { new ObjectTypeImpl(String.class) };
    QueryObserverHolder.setInstance(new QueryObserverAdapter() {

        private int i = 0;

        public void invokedQueryUtilsUnion(SelectResults r1, SelectResults r2) {
            actualUnionCallback[i] = true;
        }

        public void invokedQueryUtilsIntersection(SelectResults r1, SelectResults r2) {
            actualIntersectionCallback[i] = true;
        }

        public void beforeIndexLookup(Index index, int oper, Object key) {
            actualIndexUsed[i] = true;
            indexesUsed.add(index);
        }

        public void beforeApplyingProjectionOnFilterEvaluatedResults(Object preProjectionApplied) {
            actualProjectionCallback[i] = true;
        }

        public void afterQueryEvaluation(Object result) {
            ++i;
        }
    });
    for (int i = 0; i < queries.length; ++i) {
        Query q = qs.newQuery(queries[i]);
        sr[i][1] = (SelectResults) q.execute();
        assertEquals(expectedUnionCallback[i], actualUnionCallback[i]);
        assertEquals(expectedTypes[i], sr[i][1].getCollectionType().getElementType());
        assertEquals(expectedIndexUsed[i], actualIndexUsed[i]);
        assertEquals(expectedIntersectionCallback[i], actualIntersectionCallback[i]);
        assertEquals(expectedProjectionCallabck[i], actualProjectionCallback[i]);
    }
    assertEquals(indexesUsed.size(), 1);
    assertEquals(((Index) indexesUsed.iterator().next()).getName(), "CreateTime");
    CacheUtils.compareResultsOfWithAndWithoutIndex(sr, this);
}
Also used : Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) ArrayList(java.util.ArrayList) ObjectTypeImpl(org.apache.geode.cache.query.internal.types.ObjectTypeImpl) Index(org.apache.geode.cache.query.Index) ObjectType(org.apache.geode.cache.query.types.ObjectType) SelectResults(org.apache.geode.cache.query.SelectResults) QueryService(org.apache.geode.cache.query.QueryService) QueryObserverAdapter(org.apache.geode.cache.query.internal.QueryObserverAdapter) Region(org.apache.geode.cache.Region) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

QueryObserverAdapter (org.apache.geode.cache.query.internal.QueryObserverAdapter)63 SelectResults (org.apache.geode.cache.query.SelectResults)59 Test (org.junit.Test)55 Query (org.apache.geode.cache.query.Query)54 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)51 Portfolio (org.apache.geode.cache.query.data.Portfolio)49 Region (org.apache.geode.cache.Region)48 QueryObserver (org.apache.geode.cache.query.internal.QueryObserver)38 Index (org.apache.geode.cache.query.Index)36 QueryService (org.apache.geode.cache.query.QueryService)35 ObjectTypeImpl (org.apache.geode.cache.query.internal.types.ObjectTypeImpl)23 Collection (java.util.Collection)18 ObjectType (org.apache.geode.cache.query.types.ObjectType)18 LocalRegion (org.apache.geode.internal.cache.LocalRegion)14 AttributesFactory (org.apache.geode.cache.AttributesFactory)12 Cache (org.apache.geode.cache.Cache)11 List (java.util.List)10 ArrayList (java.util.ArrayList)9 RegionAttributes (org.apache.geode.cache.RegionAttributes)9 StructTypeImpl (org.apache.geode.cache.query.internal.types.StructTypeImpl)7