Search in sources :

Example 6 with IndexProtocol

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

the class CompiledComparison method getIndexInfo.

// Asif: If the size of aray is two this implies that it is
// a relation ship index & so the key field will be null in both the indexes
// as key is not a meaningful entity. The 0th element will refer to LHS
// operand
// and 1th element will refer to RHS operannd
public IndexInfo[] getIndexInfo(ExecutionContext context) throws TypeMismatchException, AmbiguousNameException, NameResolutionException {
    IndexInfo[] indexInfo = privGetIndexInfo(context);
    if (indexInfo != null) {
        if (indexInfo == NO_INDEXES_IDENTIFIER) {
            return null;
        } else {
            return indexInfo;
        }
    }
    if (!IndexUtils.indexesEnabled)
        return null;
    // get the path and index key to try
    PathAndKey pAndK = getPathAndKey(context);
    IndexInfo[] newIndexInfo = null;
    if (pAndK == null) {
        IndexData[] indexData = // findOnlyFunctionalIndex.
        QueryUtils.getRelationshipIndexIfAny(_left, _right, context, this._operator);
        if (indexData != null) {
            newIndexInfo = new IndexInfo[2];
            for (int i = 0; i < 2; ++i) {
                newIndexInfo[i] = new IndexInfo(null, i == 0 ? _left : _right, indexData[i].getIndex(), indexData[i].getMatchLevel(), indexData[i].getMapping(), i == 0 ? this._operator : reflectOperator(this._operator));
            }
        }
    } else {
        CompiledValue path = pAndK._path;
        CompiledValue indexKey = pAndK._key;
        IndexData indexData = null;
        // CompiledLike should not use HashIndex and PrimarKey Index.
        if (this instanceof CompiledLike) {
            indexData = QueryUtils.getAvailableIndexIfAny(path, context, OQLLexerTokenTypes.LITERAL_like);
        } else {
            indexData = QueryUtils.getAvailableIndexIfAny(path, context, this._operator);
        }
        IndexProtocol index = null;
        if (indexData != null) {
            index = indexData.getIndex();
        }
        if (index != null && index.isValid()) {
            newIndexInfo = new IndexInfo[1];
            newIndexInfo[0] = new IndexInfo(indexKey, path, index, indexData.getMatchLevel(), indexData.getMapping(), reflectOnOperator(indexKey));
        }
    }
    if (newIndexInfo != null) {
        privSetIndexInfo(newIndexInfo, context);
    } else {
        privSetIndexInfo(NO_INDEXES_IDENTIFIER, context);
    }
    return newIndexInfo;
}
Also used : IndexProtocol(org.apache.geode.cache.query.internal.index.IndexProtocol) IndexData(org.apache.geode.cache.query.internal.index.IndexData)

Example 7 with IndexProtocol

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

the class CompiledIn method getIndexInfo.

/**
   * If the size of aray is two this implies that it is a relation ship index & so the key field
   * will be null in both the indexes as key is not a meaningful entity. The 0th element will refer
   * to LHS operand and 1th element will refer to RHS operannd
   */
public IndexInfo[] getIndexInfo(ExecutionContext context) throws TypeMismatchException, AmbiguousNameException, NameResolutionException {
    IndexInfo[] indexInfo = privGetIndexInfo(context);
    if (indexInfo != null) {
        // TODO: == check is identity only
        if (indexInfo == NO_INDEXES_IDENTIFIER) {
            return null;
        } else {
            return indexInfo;
        }
    }
    if (!IndexUtils.indexesEnabled)
        return null;
    // get the path and index key to try
    PathAndKey pAndK = getPathAndKey(context);
    IndexInfo[] newIndexInfo = null;
    if (pAndK != null) {
        CompiledValue path = pAndK._path;
        CompiledValue indexKey = pAndK._key;
        IndexData indexData = QueryUtils.getAvailableIndexIfAny(path, context, TOK_EQ);
        IndexProtocol index = null;
        if (indexData != null) {
            index = indexData.getIndex();
        }
        if (index != null && index.isValid()) {
            newIndexInfo = new IndexInfo[1];
            newIndexInfo[0] = new IndexInfo(indexKey, path, index, indexData.getMatchLevel(), indexData.getMapping(), TOK_EQ);
        }
    }
    if (newIndexInfo != null) {
        privSetIndexInfo(newIndexInfo, context);
    } else {
        privSetIndexInfo(NO_INDEXES_IDENTIFIER, context);
    }
    return newIndexInfo;
}
Also used : IndexProtocol(org.apache.geode.cache.query.internal.index.IndexProtocol) IndexData(org.apache.geode.cache.query.internal.index.IndexData)

Example 8 with IndexProtocol

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

the class IndexCreationJUnitTest method testIndexCreationWithImport.

@Test
public void testIndexCreationWithImport() throws Exception {
    // Task ID: ICM16
    QueryService qs;
    qs = CacheUtils.getQueryService();
    Index i3 = qs.createIndex("typeIndex", IndexType.FUNCTIONAL, "\"type\"", "/portfolios type Portfolio, positions b", "IMPORT org.apache.geode.cache.\"query\".data.Portfolio");
    // TASK ICM3 Region 'IMPORT' not found:....[BUG : Verified Fixed ]
    // Index i4=(Index)qs.createIndex("boolFunctionIndex",
    // IndexType.FUNCTIONAL,"boolFunction(pf.status)","/portfolios pf,
    // pf.positions.values b");
    // TASK ICM5 org.apache.geode.cache.query.IndexInvalidException
    // remove any commented Index from Array
    Object[] indices = { i3 };
    for (int j = 0; j < indices.length; j++) {
        CacheUtils.log(((IndexProtocol) indices[j]).isValid());
        boolean r = ((IndexProtocol) indices[j]).isValid();
        if (r == true) {
            CacheUtils.log(((IndexProtocol) indices[j]).getName());
            CacheUtils.log("Test: testIndexCreation PASS");
        } else {
            fail("Test: testIndexCreation FAILED");
        }
    }
}
Also used : IndexProtocol(org.apache.geode.cache.query.internal.index.IndexProtocol) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) 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)

Example 9 with IndexProtocol

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

the class QueryJUnitTest method creatingACompiledJunctionWithACompiledInClauseDoesNotThrowException.

@Test
public void creatingACompiledJunctionWithACompiledInClauseDoesNotThrowException() throws Exception {
    Cache cache = CacheUtils.getCache();
    RegionFactory<Integer, Portfolio> rf = cache.createRegionFactory(RegionShortcut.REPLICATE);
    Region regionA = rf.create("regionA");
    Region regionB = rf.create("regionB");
    for (int i = 1; i <= 100; i++) {
        regionA.put(Integer.toString(i), new TestUserObject("" + i, "" + i, "" + i, "" + i));
        regionB.put(Integer.toString(i), new TestUserObject("" + i, "" + i, "" + i, "" + i));
    }
    QueryService qs = CacheUtils.getQueryService();
    Index regionAUserCodeIndex = (IndexProtocol) qs.createIndex("regionAUserCodeIndex", IndexType.FUNCTIONAL, "userId", "/regionA ");
    Index regionBUserCodeIndex = (IndexProtocol) qs.createIndex("regionAUserCodeIndex", IndexType.FUNCTIONAL, "userId", "/regionB ");
    Index regionAUserNameIndex = (IndexProtocol) qs.createIndex("regionAUserNameIndex", IndexType.FUNCTIONAL, "userName", "/regionA ");
    Index regionBUserNameIndex = (IndexProtocol) qs.createIndex("regionBUserNameIndex", IndexType.FUNCTIONAL, "userName", "/regionB ");
    Query query = qs.newQuery("select regionB.userId,regionA.professionCode,regionB.postCode,regionB.userName from /regionA regionA,/regionB regionB where regionA.userId = regionB.userId and regionA.professionCode in Set('1','2','3') and regionB.postCode = '1' and regionB.userId='1'");
    SelectResults results = (SelectResults) query.execute();
    assertTrue(results.size() > 0);
}
Also used : IndexProtocol(org.apache.geode.cache.query.internal.index.IndexProtocol) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Portfolio(org.apache.geode.cache.query.data.Portfolio) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 10 with IndexProtocol

use of org.apache.geode.cache.query.internal.index.IndexProtocol 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

IndexProtocol (org.apache.geode.cache.query.internal.index.IndexProtocol)11 Index (org.apache.geode.cache.query.Index)4 IndexData (org.apache.geode.cache.query.internal.index.IndexData)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 Test (org.junit.Test)4 QueryService (org.apache.geode.cache.query.QueryService)3 DefaultQueryService (org.apache.geode.cache.query.internal.DefaultQueryService)3 CompactMapRangeIndex (org.apache.geode.cache.query.internal.index.CompactMapRangeIndex)3 CompactRangeIndex (org.apache.geode.cache.query.internal.index.CompactRangeIndex)3 RangeIndex (org.apache.geode.cache.query.internal.index.RangeIndex)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Portfolio (org.apache.geode.cache.query.data.Portfolio)2 AbstractIndex (org.apache.geode.cache.query.internal.index.AbstractIndex)2 StructTypeImpl (org.apache.geode.cache.query.internal.types.StructTypeImpl)2 ObjectType (org.apache.geode.cache.query.types.ObjectType)2 StructType (org.apache.geode.cache.query.types.StructType)2 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 ListIterator (java.util.ListIterator)1