Search in sources :

Example 51 with ObjectType

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

the class QCompiler method iteratorDef.

public void iteratorDef() {
    // find type id and colln on the stack
    // can be null
    ObjectType type = assembleType();
    // can be null
    CompiledID id = (CompiledID) TypeUtils.checkCast(pop(), CompiledID.class);
    CompiledValue colln = (CompiledValue) TypeUtils.checkCast(pop(), CompiledValue.class);
    if (type == null) {
        type = TypeUtils.OBJECT_TYPE;
    }
    push(new CompiledIteratorDef(id == null ? null : id.getId(), type, colln));
}
Also used : ObjectType(org.apache.geode.cache.query.types.ObjectType)

Example 52 with ObjectType

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

the class QCompiler method typecast.

public void typecast() {
    // pop expr and type, apply type, then push result
    AbstractCompiledValue cmpVal = (AbstractCompiledValue) TypeUtils.checkCast(pop(), AbstractCompiledValue.class);
    ObjectType objType = assembleType();
    cmpVal.setTypecast(objType);
    push(cmpVal);
}
Also used : ObjectType(org.apache.geode.cache.query.types.ObjectType)

Example 53 with ObjectType

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

the class IndexWithSngleFrmAndMultCondQryJUnitTest method executeQuery_2.

private void executeQuery_2(Region region, boolean checkReferentialIntegrity) throws Exception {
    // Region region = CacheUtils.createRegion("pos", Portfolio.class);
    QueryService qs;
    qs = CacheUtils.getQueryService();
    String[] queries = { "SELECT DISTINCT * FROM /pos pf where pf.description = 'XXXX'  and pf.status='active' and pf.createTime = 5 " };
    SelectResults[][] sr = new SelectResults[queries.length][2];
    ObjectType resType1 = null, resType2 = null;
    for (int i = 0; i < queries.length; i++) {
        Query q = null;
        try {
            q = CacheUtils.getQueryService().newQuery(queries[i]);
            QueryObserverImpl observer = new QueryObserverImpl();
            QueryObserverHolder.setInstance(observer);
            sr[i][0] = (SelectResults) q.execute();
            if (!observer.isIndexesUsed) {
                CacheUtils.log("NO INDEX USED");
            } else {
                fail("How did Index get created!!1?");
            }
            // CacheUtils.log(Utils.printResult(r));
            resType1 = ((SelectResults) sr[i][0]).getCollectionType().getElementType();
            resSize1 = (((SelectResults) sr[i][0]).size());
            CacheUtils.log(resType1);
            assertEquals(1, resSize1);
            set1 = (((SelectResults) sr[i][0]).asSet());
            Iterator iter = set1.iterator();
            while (iter.hasNext()) {
                valPf1 = iter.next();
                isActive1 = ((Portfolio) valPf1).isActive();
                assertTrue(isActive1);
                assertEquals("XXXX", ((Portfolio) valPf1).description);
                assertEquals(5, ((Portfolio) valPf1).getCreateTime());
            }
        } catch (Exception e) {
            e.printStackTrace();
            fail(q.getQueryString());
        }
    }
    // Create an Index on status and execute the same query again.
    qs = CacheUtils.getQueryService();
    Index index1 = qs.createIndex("statusIndex", IndexType.FUNCTIONAL, "pf.status", "/pos pf");
    for (int i = 0; i < queries.length; i++) {
        Query q = null;
        try {
            q = CacheUtils.getQueryService().newQuery(queries[i]);
            QueryObserverImpl observer2 = new QueryObserverImpl();
            QueryObserverHolder.setInstance(observer2);
            sr[i][1] = (SelectResults) q.execute();
            if (observer2.isIndexesUsed) {
                assertEquals(1, observer2.indexesUsed.size());
            } else {
                fail("FAILED: Index NOT Used");
            }
            resType2 = ((SelectResults) sr[i][1]).getCollectionType().getElementType();
            resSize2 = (((SelectResults) sr[i][1]).size());
            CacheUtils.log(resType2);
            // strg2=resType2.getFieldNames();
            set2 = (((SelectResults) sr[i][1]).asSet());
            Iterator iter = set2.iterator();
            while (iter.hasNext()) {
                valPf2 = iter.next();
                // valPf2=stc2.get(strg2[0]);
                // valPos2=stc2.get(strg2[1]);
                isActive2 = ((Portfolio) valPf2).isActive();
                assertTrue(isActive2);
                assertEquals("XXXX", ((Portfolio) valPf2).description);
                assertEquals(5, ((Portfolio) valPf2).getCreateTime());
            }
        } catch (Exception e) {
            e.printStackTrace();
            fail(q.getQueryString());
        }
    }
    if ((resType1).equals(resType2)) {
        CacheUtils.log("Both Search Results are of the same Type i.e.--> " + resType1);
    } else {
        fail("FAILED:Search result Type is different in both the cases");
    }
    if (resSize1 == resSize2 || resSize1 != 0) {
        CacheUtils.log("Search Results size is Non Zero and equal in both cases i.e.  Size= " + resSize1);
    } else {
        fail("FAILED:Search result size is different in both the cases");
    }
    itert2 = set2.iterator();
    itert1 = set1.iterator();
    while (itert1.hasNext()) {
        Object pos2 = itert2.next();
        Object pos1 = itert1.next();
        Object posFromRegion = region.get(((Portfolio) pos1).getPk());
        if (!pos1.equals(pos2))
            fail("FAILED: In both the Cases the first member of StructSet i.e. Portfolio are different. ");
        if (checkReferentialIntegrity) {
            assertTrue(pos2 == pos1);
            assertTrue(pos2 == posFromRegion);
        }
        if (((Portfolio) pos2).isActive() != ((Portfolio) pos1).isActive())
            fail("FAILED: Status of the Portfolios found are different");
        if (((Portfolio) pos2).getID() != ((Portfolio) pos1).getID())
            fail("FAILED: IDs of the Portfolios found are different");
    }
    CacheUtils.compareResultsOfWithAndWithoutIndex(sr, this);
}
Also used : Query(org.apache.geode.cache.query.Query) 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) Iterator(java.util.Iterator)

Example 54 with ObjectType

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

the class IndexWithSngleFrmAndMultCondQryJUnitTest method executeQuery.

private void executeQuery(Region region, boolean checkReferentialIntegrity) throws Exception {
    QueryService qs;
    qs = CacheUtils.getQueryService();
    String[] queries = { "SELECT DISTINCT pf FROM /pos pf,  positions.values pos where pf.description = 'XXXX'  and pos.secId= 'IBM' " };
    SelectResults[][] sr = new SelectResults[queries.length][2];
    ObjectType resType1 = null, resType2 = null;
    for (int i = 0; i < queries.length; i++) {
        Query q = null;
        try {
            q = CacheUtils.getQueryService().newQuery(queries[i]);
            QueryObserverImpl observer = new QueryObserverImpl();
            QueryObserverHolder.setInstance(observer);
            sr[i][0] = (SelectResults) q.execute();
            if (!observer.isIndexesUsed) {
                CacheUtils.log("NO INDEX USED");
            } else {
                fail("How did Index get created?");
            }
            // CacheUtils.log(Utils.printResult(r));
            resType1 = ((SelectResults) sr[i][0]).getCollectionType().getElementType();
            resSize1 = (((SelectResults) sr[i][0]).size());
            CacheUtils.log(resType1);
            set1 = (((SelectResults) sr[i][0]).asSet());
            Iterator iter = set1.iterator();
            while (iter.hasNext()) {
                valPf1 = iter.next();
                isActive1 = ((Portfolio) valPf1).isActive();
            }
        } catch (Exception e) {
            e.printStackTrace();
            fail(q.getQueryString());
        }
    }
    // Create an Index on status and execute the same query again.
    qs = CacheUtils.getQueryService();
    Index index1 = qs.createIndex("statusIndex", IndexType.FUNCTIONAL, "pf.status", "/pos pf");
    Index index2 = (Index) qs.createIndex("secIdIndex", IndexType.FUNCTIONAL, "pos.secId", "/pos pf, pf.positions.values pos");
    Index index3 = qs.createIndex("descriptionIndex", IndexType.FUNCTIONAL, "pf.description", "/pos pf");
    for (int i = 0; i < queries.length; i++) {
        Query q = null;
        try {
            q = CacheUtils.getQueryService().newQuery(queries[i]);
            QueryObserverImpl observer2 = new QueryObserverImpl();
            QueryObserverHolder.setInstance(observer2);
            sr[i][1] = (SelectResults) q.execute();
            if (observer2.isIndexesUsed) {
                assertEquals(1, observer2.indexesUsed.size());
            } else {
                fail("FAILED: Index NOT Used");
            }
            resType2 = ((SelectResults) sr[i][1]).getCollectionType().getElementType();
            resSize2 = (((SelectResults) sr[i][1]).size());
            CacheUtils.log(resType2);
            // strg2=resType2.getFieldNames();
            set2 = (((SelectResults) sr[i][1]).asSet());
            Iterator iter = set2.iterator();
            while (iter.hasNext()) {
                valPf2 = iter.next();
                // valPf2=stc2.get(strg2[0]);
                // valPos2=stc2.get(strg2[1]);
                isActive2 = ((Portfolio) valPf2).isActive();
            }
        } catch (Exception e) {
            e.printStackTrace();
            fail(q.getQueryString());
        }
    }
    if ((resType1).equals(resType2)) {
        CacheUtils.log("Both Search Results are of the same Type i.e.--> " + resType1);
    } else {
        fail("FAILED:Search result Type is different in both the cases");
    }
    if (resSize1 == resSize2 || resSize1 != 0) {
        CacheUtils.log("Search Results size is Non Zero and equal in both cases i.e.  Size= " + resSize1);
    } else {
        fail("FAILED:Search result size is different in both the cases");
    }
    itert2 = set2.iterator();
    itert1 = set1.iterator();
    while (itert1.hasNext()) {
        Object pos2 = itert2.next();
        Object pos1 = itert1.next();
        Object posFromRegion = region.get(((Portfolio) pos1).getPk());
        if (!pos1.equals(pos2))
            fail("FAILED: In both the Cases the first member of StructSet i.e. Portfolio are different. ");
        if (checkReferentialIntegrity) {
            assertTrue(pos2 == pos1);
            assertTrue(pos2 == posFromRegion);
        }
        if (((Portfolio) pos2).isActive() != ((Portfolio) pos1).isActive())
            fail("FAILED: Status of the Portfolios found are different");
        if (((Portfolio) pos2).getID() != ((Portfolio) pos1).getID())
            fail("FAILED: IDs of the Portfolios found are different");
    }
    CacheUtils.compareResultsOfWithAndWithoutIndex(sr, this);
}
Also used : Query(org.apache.geode.cache.query.Query) 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) Iterator(java.util.Iterator)

Example 55 with ObjectType

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

the class QueryObjectSerializationJUnitTest method testSerializationOfQueryResults.

/**
   * Tests the serialization of many, but not all of the possible ResultSets
   */
@Test
public void testSerializationOfQueryResults() throws IOException, ClassNotFoundException {
    Collection data = new java.util.ArrayList();
    data.add(null);
    data.add(null);
    data.add("some string");
    data.add(Long.MAX_VALUE);
    data.add(45);
    data.add(QueryService.UNDEFINED);
    ObjectType elementType = new SimpleObjectType();
    // Undefined
    checkRoundTrip(QueryService.UNDEFINED);
    // ResultsBag
    ResultsBag rbWithoutData = new ResultsBag();
    // avoid NPE in equals
    rbWithoutData.setElementType(elementType);
    checkRoundTrip(rbWithoutData);
    ResultsBag rbWithData = new ResultsBag(data, (CachePerfStats) null);
    // avoid NPE in equals
    rbWithData.setElementType(elementType);
    checkRoundTrip(rbWithData);
    /*
     * Set rbWithoutDataAsSet = new ResultsBag().asSet(); ResultsCollectionWrapper rcw = new
     * ResultsCollectionWrapper(elementType, rbWithoutDataAsSet, -1); checkRoundTrip(rcw); Set
     * rbWithDataAsSet = new ResultsBag(data, (CachePerfStats)null).asSet();
     * ResultsCollectionWrapper rcwWithData = new ResultsCollectionWrapper(elementType,
     * rbWithDataAsSet, -1); checkRoundTrip(rcwWithData);
     */
    // SortedResultSet
    SortedResultSet srsWithoutData = new SortedResultSet();
    // avoid NPE in equals
    srsWithoutData.setElementType(elementType);
    checkRoundTrip(srsWithoutData);
    SortedResultSet srsWithData = new SortedResultSet();
    // avoid NPE in equals
    srsWithData.setElementType(elementType);
    checkRoundTrip(srsWithData);
// SortedStructSet
// SortedStructSet sssWithoutData = new SortedStructSet();
// checkRoundTrip(sssWithoutData);
}
Also used : ObjectType(org.apache.geode.cache.query.types.ObjectType) Collection(java.util.Collection) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Aggregations

ObjectType (org.apache.geode.cache.query.types.ObjectType)95 SelectResults (org.apache.geode.cache.query.SelectResults)66 QueryService (org.apache.geode.cache.query.QueryService)46 Test (org.junit.Test)46 Query (org.apache.geode.cache.query.Query)45 Iterator (java.util.Iterator)44 Region (org.apache.geode.cache.Region)40 StructType (org.apache.geode.cache.query.types.StructType)38 Portfolio (org.apache.geode.cache.query.data.Portfolio)32 Struct (org.apache.geode.cache.query.Struct)30 StructTypeImpl (org.apache.geode.cache.query.internal.types.StructTypeImpl)29 ObjectTypeImpl (org.apache.geode.cache.query.internal.types.ObjectTypeImpl)25 CompiledSelect (org.apache.geode.cache.query.internal.CompiledSelect)24 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)23 ArrayList (java.util.ArrayList)21 List (java.util.List)20 Index (org.apache.geode.cache.query.Index)20 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)20 QueryObserverAdapter (org.apache.geode.cache.query.internal.QueryObserverAdapter)18 HashSet (java.util.HashSet)14