Search in sources :

Example 36 with StructTypeImpl

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

the class CustomerOptimizationsJUnitTest method testProjectionEvaluationDuringIndexResults_UNIMPLEMENTED.

@Ignore
@Test
public void testProjectionEvaluationDuringIndexResults_UNIMPLEMENTED() throws QueryException {
    QueryService qs = CacheUtils.getQueryService();
    String[] queries = new String[] { "select  p.status from /pos p, p.positions pos where p.ID > 0 ", "select  p.status as sts, p as pos from /pos p  where ( p.ID IN  SET( 0,1,2,3) and p.createTime > 0L) OR (p.ID IN  SET( 2,3) and p.createTime > 5L)", "select  p.status as sts, p as pos from /pos p  where  p.ID IN  SET( 0,1,2,3) and p.createTime > 0L" };
    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");
    ObjectType[] expectedTypes = new ObjectType[] { new ObjectTypeImpl(String.class), new StructTypeImpl(new String[] { "sts", "pos" }, new ObjectType[] { new ObjectTypeImpl(String.class), new ObjectTypeImpl(Portfolio.class) }), new StructTypeImpl(new String[] { "sts", "pos" }, new ObjectType[] { new ObjectTypeImpl(String.class), new ObjectTypeImpl(Portfolio.class) }) };
    final boolean[] expectedCallback = { false, false, false };
    final boolean[] actualCallback = new boolean[queries.length];
    QueryObserverHolder.setInstance(new QueryObserverAdapter() {

        private int i = 0;

        public void beforeApplyingProjectionOnFilterEvaluatedResults(Object preProjectionApplied) {
            actualCallback[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(expectedCallback[i], actualCallback[i]);
        assertEquals(expectedTypes[i], sr[i][1].getCollectionType().getElementType());
    }
    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) 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) Ignore(org.junit.Ignore) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 37 with StructTypeImpl

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

the class StructBagLimitBehaviourJUnitTest method getBagObject.

public ResultsBag getBagObject(Class clazz) {
    ObjectType[] types = new ObjectType[] { new ObjectTypeImpl(clazz), new ObjectTypeImpl(clazz) };
    StructType type = new StructTypeImpl(new String[] { "field1", "field2" }, types);
    return new StructBag(type, null);
}
Also used : ObjectType(org.apache.geode.cache.query.types.ObjectType) StructType(org.apache.geode.cache.query.types.StructType) ObjectTypeImpl(org.apache.geode.cache.query.internal.types.ObjectTypeImpl) StructTypeImpl(org.apache.geode.cache.query.internal.types.StructTypeImpl)

Example 38 with StructTypeImpl

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

the class IndexCreationJUnitTest method testIndexObjectTypeWithRegionConstraint.

@Test
public void testIndexObjectTypeWithRegionConstraint() throws Exception {
    QueryService qs;
    qs = CacheUtils.getQueryService();
    Index i1 = qs.createIndex("Index1", IndexType.FUNCTIONAL, "b.secId", "/portfolios pf, pf.positions.values b");
    ObjectType type = ((IndexProtocol) i1).getResultSetType();
    String[] fieldNames = { "index_iter1", "index_iter2" };
    ObjectType[] fieldTypes = { new ObjectTypeImpl(Portfolio.class), new ObjectTypeImpl(Object.class) };
    // ObjectType expectedType = new StructTypeImpl( fieldNames,fieldTypes);
    ObjectType expectedType = new StructTypeImpl(fieldNames, fieldTypes);
    if (!(type instanceof StructType && type.equals(expectedType))) {
        fail("The ObjectType obtained from index is not of the expected type. Type obtained from index=" + type);
    }
    Index i2 = qs.createIndex("Index2", IndexType.FUNCTIONAL, "pf.ID", "/portfolios.values pf");
    type = ((IndexProtocol) i2).getResultSetType();
    expectedType = new ObjectTypeImpl(Portfolio.class);
    if (!type.equals(expectedType)) {
        fail("The ObjectType obtained from index is not of the expected type. Type obtained from index=" + type);
    }
    Index i3 = qs.createIndex("Index3", IndexType.FUNCTIONAL, "pos.secId", "/portfolios['0'].positions.values pos");
    type = ((IndexProtocol) i3).getResultSetType();
    expectedType = new ObjectTypeImpl(Object.class);
    if (!type.equals(expectedType)) {
        fail("The ObjectType obtained from index is not of the expected type. Type obtained from index=" + type);
    }
    Index i4 = qs.createIndex("Index4", IndexType.PRIMARY_KEY, "ID", "/portfolios");
    type = ((IndexProtocol) i4).getResultSetType();
    expectedType = new ObjectTypeImpl(Portfolio.class);
    if (!type.equals(expectedType)) {
        fail("The ObjectType obtained from index is not of the expected type. Type obtained from index=" + type);
    }
}
Also used : IndexProtocol(org.apache.geode.cache.query.internal.index.IndexProtocol) ObjectType(org.apache.geode.cache.query.types.ObjectType) StructType(org.apache.geode.cache.query.types.StructType) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) Portfolio(org.apache.geode.cache.query.data.Portfolio) ObjectTypeImpl(org.apache.geode.cache.query.internal.types.ObjectTypeImpl) StructTypeImpl(org.apache.geode.cache.query.internal.types.StructTypeImpl) RangeIndex(org.apache.geode.cache.query.internal.index.RangeIndex) CompactMapRangeIndex(org.apache.geode.cache.query.internal.index.CompactMapRangeIndex) Index(org.apache.geode.cache.query.Index) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

StructTypeImpl (org.apache.geode.cache.query.internal.types.StructTypeImpl)38 ObjectType (org.apache.geode.cache.query.types.ObjectType)29 SelectResults (org.apache.geode.cache.query.SelectResults)21 ObjectTypeImpl (org.apache.geode.cache.query.internal.types.ObjectTypeImpl)14 StructType (org.apache.geode.cache.query.types.StructType)14 ArrayList (java.util.ArrayList)12 List (java.util.List)12 Test (org.junit.Test)12 Iterator (java.util.Iterator)9 Portfolio (org.apache.geode.cache.query.data.Portfolio)9 QueryService (org.apache.geode.cache.query.QueryService)8 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)8 Query (org.apache.geode.cache.query.Query)7 QueryObserverAdapter (org.apache.geode.cache.query.internal.QueryObserverAdapter)7 Region (org.apache.geode.cache.Region)6 Index (org.apache.geode.cache.query.Index)6 Struct (org.apache.geode.cache.query.Struct)6 ListIterator (java.util.ListIterator)5 UnitTest (org.apache.geode.test.junit.categories.UnitTest)4 Collection (java.util.Collection)3