Search in sources :

Example 16 with ObjectTypeImpl

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

the class ResultsCollectionWrapperLimitJUnitTest method testEmpty.

@Test
public void testEmpty() {
    List ordered = new ArrayList();
    for (int i = 1; i < 11; ++i) {
        ordered.add(new Integer(i));
    }
    ResultsCollectionWrapper wrapper = new ResultsCollectionWrapper(new ObjectTypeImpl(Object.class), ordered, 0);
    assertEquals(0, wrapper.size());
}
Also used : ArrayList(java.util.ArrayList) ObjectTypeImpl(org.apache.geode.cache.query.internal.types.ObjectTypeImpl) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 17 with ObjectTypeImpl

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

the class ResultsCollectionWrapperLimitJUnitTest method testConstructorBehaviour.

@Test
public void testConstructorBehaviour() {
    // Create a Collection of unordered data elements
    HashSet unordered = new HashSet();
    for (int i = 1; i < 11; ++i) {
        unordered.add(new Integer(i));
    }
    ResultsCollectionWrapper wrapper = new ResultsCollectionWrapper(new ObjectTypeImpl(Object.class), unordered, 15);
    assertEquals(10, wrapper.size());
    assertFalse(wrapper.iterator() instanceof ResultsCollectionWrapper.LimitIterator);
    try {
        wrapper.add(new Integer(7));
    } catch (UnsupportedOperationException uoe) {
    // Ok
    }
    wrapper = new ResultsCollectionWrapper(new ObjectTypeImpl(Object.class), unordered, 5);
    assertEquals(5, wrapper.size());
    assertFalse(wrapper.iterator() instanceof ResultsCollectionWrapper.LimitIterator);
    try {
        wrapper.add(new Integer(7));
    } catch (UnsupportedOperationException uoe) {
    // Ok
    }
    List ordered = new ArrayList();
    for (int i = 1; i < 11; ++i) {
        ordered.add(new Integer(i));
    }
    wrapper = new ResultsCollectionWrapper(new ObjectTypeImpl(Object.class), ordered, 20);
    assertEquals(10, wrapper.size());
    assertFalse(wrapper.iterator() instanceof ResultsCollectionWrapper.LimitIterator);
    try {
        wrapper.add(new Integer(7));
    } catch (UnsupportedOperationException uoe) {
    // Ok
    }
    wrapper = new ResultsCollectionWrapper(new ObjectTypeImpl(Object.class), ordered, 5);
    assertEquals(5, wrapper.size());
    assertTrue(wrapper.iterator() instanceof ResultsCollectionWrapper.LimitIterator);
    try {
        wrapper.add(new Integer(7));
    } catch (UnsupportedOperationException uoe) {
    // Ok
    }
}
Also used : ObjectTypeImpl(org.apache.geode.cache.query.internal.types.ObjectTypeImpl) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 18 with ObjectTypeImpl

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

the class ResultsCollectionWrapperLimitJUnitTest method testToArrayParameterized.

@Test
public void testToArrayParameterized() {
    List ordered = new ArrayList();
    for (int i = 1; i < 11; ++i) {
        ordered.add(new Integer(i));
    }
    ResultsCollectionWrapper wrapper = new ResultsCollectionWrapper(new ObjectTypeImpl(Object.class), ordered, 5);
    Object[] toArray = new Object[5];
    wrapper.toArray(toArray);
    assertEquals(wrapper.size(), toArray.length);
    Iterator itr = wrapper.iterator();
    for (int i = 1; i < 6; ++i) {
        assertEquals(toArray[i - 1], itr.next());
    }
    assertFalse(itr.hasNext());
}
Also used : ArrayList(java.util.ArrayList) ObjectTypeImpl(org.apache.geode.cache.query.internal.types.ObjectTypeImpl) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 19 with ObjectTypeImpl

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

the class CustomerOptimizationsJUnitTest method testUnionDuringIndexEvaluationWithMultipleFilters.

@Test
public void testUnionDuringIndexEvaluationWithMultipleFilters() 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" };
    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 = { 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 20 with ObjectTypeImpl

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

the class CustomerOptimizationsJUnitTest method testNestedJunction.

@Test
public void testNestedJunction() throws Exception {
    QueryService qs = CacheUtils.getQueryService();
    Region rgn = CacheUtils.getRegion("/pos");
    for (int i = 100; i < 10000; ++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 IN SET( 10l ) OR  p.status IN SET( 'active') )AND  p.ID >  0 " };
    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[] { true };
    final boolean[] actualProjectionCallback = new boolean[] { false };
    final boolean[] expectedUnionCallback = { false };
    final boolean[] actualUnionCallback = new boolean[queries.length];
    final boolean[] expectedIntersectionCallback = { true };
    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(), 3);
    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

ObjectTypeImpl (org.apache.geode.cache.query.internal.types.ObjectTypeImpl)53 Test (org.junit.Test)37 SelectResults (org.apache.geode.cache.query.SelectResults)31 ArrayList (java.util.ArrayList)27 Portfolio (org.apache.geode.cache.query.data.Portfolio)27 QueryService (org.apache.geode.cache.query.QueryService)25 ObjectType (org.apache.geode.cache.query.types.ObjectType)25 List (java.util.List)24 Query (org.apache.geode.cache.query.Query)24 Region (org.apache.geode.cache.Region)23 QueryObserverAdapter (org.apache.geode.cache.query.internal.QueryObserverAdapter)23 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)20 UnitTest (org.apache.geode.test.junit.categories.UnitTest)17 Index (org.apache.geode.cache.query.Index)16 StructTypeImpl (org.apache.geode.cache.query.internal.types.StructTypeImpl)14 Collection (java.util.Collection)11 Iterator (java.util.Iterator)10 ResultsBag (org.apache.geode.cache.query.internal.ResultsBag)8 ResultsCollectionWrapper (org.apache.geode.cache.query.internal.ResultsCollectionWrapper)8 AttributesFactory (org.apache.geode.cache.AttributesFactory)7