use of org.apache.geode.cache.query.internal.index.IndexData in project geode by apache.
the class CompiledUndefined method getIndexInfo.
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;
// TODO:Asif : Check if the condition is such that Primary Key Index is used
// & its key is DEFINED
// , then are we returning all the values of the region ?
// & that if the key is UNDEFINED are we returning an empty set.?
IndexData indexData = QueryUtils.getAvailableIndexIfAny(this._value, context, _is_defined ? TOK_NE : TOK_EQ);
IndexProtocol index = null;
IndexInfo[] newIndexInfo = null;
if (indexData != null) {
index = indexData.getIndex();
}
if (index != null && index.isValid()) {
newIndexInfo = new IndexInfo[1];
/*
* Pass the Key as null as the key is not of type CompiledValue( but of type
* QueryService.UNDEFINED)
*/
newIndexInfo[0] = new IndexInfo(null, this._value, index, indexData.getMatchLevel(), indexData.getMapping(), _is_defined ? TOK_NE : TOK_EQ);
}
if (newIndexInfo != null) {
privSetIndexInfo(newIndexInfo, context);
} else {
privSetIndexInfo(NO_INDEXES_IDENTIFIER, context);
}
return newIndexInfo;
}
use of org.apache.geode.cache.query.internal.index.IndexData in project geode by apache.
the class QueryUtils method getRelationshipIndexIfAny.
/**
* Returns the pair of RangeIndexes available for a composite condition ( equi join across the
* region). It will either return two indexes or will return null. *
*
* @param lhs One of the operands of the equi-join condition
* @param rhs The other operand of the equi-join condition
* @param context ExecutionContext object
* @param operator The operator which necesarily has to be an equality ( ' = ' )
* @return An array of IndexData object with 0th IndexData for the lhs operand & 1th object for
* rhs operad
*/
static IndexData[] getRelationshipIndexIfAny(CompiledValue lhs, CompiledValue rhs, ExecutionContext context, int operator) throws AmbiguousNameException, TypeMismatchException, NameResolutionException {
if (operator != OQLLexerTokenTypes.TOK_EQ) {
// Operator must be '='
return null;
}
// Do not use PrimaryKey Index
IndexData lhsIndxData = QueryUtils.getAvailableIndexIfAny(lhs, context, false);
if (lhsIndxData == null) {
return null;
}
// Do not use PrimaryKey Index
IndexData rhsIndxData = QueryUtils.getAvailableIndexIfAny(rhs, context, false);
if (rhsIndxData == null) {
// release the lock held on lhsIndex as it will not be used
Index index = lhsIndxData.getIndex();
Index prIndex = ((AbstractIndex) index).getPRIndex();
if (prIndex != null) {
((PartitionedIndex) prIndex).releaseIndexReadLockForRemove();
} else {
((AbstractIndex) index).releaseIndexReadLockForRemove();
}
return null;
}
IndexProtocol lhsIndx = lhsIndxData.getIndex();
IndexProtocol rhsIndx = rhsIndxData.getIndex();
if (lhsIndx.isValid() && rhsIndx.isValid()) {
return new IndexData[] { lhsIndxData, rhsIndxData };
}
return null;
}
use of org.apache.geode.cache.query.internal.index.IndexData in project geode by apache.
the class IndexManagerJUnitTest method testBestIndexPick.
@Test
public void testBestIndexPick() throws Exception {
QueryService qs;
qs = CacheUtils.getQueryService();
qs.createIndex("statusIndex", IndexType.FUNCTIONAL, "status", "/portfolios, positions");
QCompiler compiler = new QCompiler();
List list = compiler.compileFromClause("/portfolios pf");
ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache());
context.newScope(context.associateScopeID());
Iterator iter = list.iterator();
while (iter.hasNext()) {
CompiledIteratorDef iterDef = (CompiledIteratorDef) iter.next();
context.addDependencies(new CompiledID("dummy"), iterDef.computeDependencies(context));
RuntimeIterator rIter = iterDef.getRuntimeIterator(context);
context.bindIterator(rIter);
context.addToIndependentRuntimeItrMap(iterDef);
}
CompiledPath cp = new CompiledPath(new CompiledID("pf"), "status");
// TASK ICM1
String[] defintions = { "/portfolios", "index_iter1.positions" };
IndexData id = IndexUtils.findIndex("/portfolios", defintions, cp, "*", CacheUtils.getCache(), true, context);
Assert.assertEquals(id.getMatchLevel(), 0);
Assert.assertEquals(id.getMapping()[0], 1);
Assert.assertEquals(id.getMapping()[1], 2);
String[] defintions1 = { "/portfolios" };
IndexData id1 = IndexUtils.findIndex("/portfolios", defintions1, cp, "*", CacheUtils.getCache(), true, context);
Assert.assertEquals(id1.getMatchLevel(), -1);
Assert.assertEquals(id1.getMapping()[0], 1);
String[] defintions2 = { "/portfolios", "index_iter1.positions", "index_iter1.coll1" };
IndexData id2 = IndexUtils.findIndex("/portfolios", defintions2, cp, "*", CacheUtils.getCache(), true, context);
Assert.assertEquals(id2.getMatchLevel(), 1);
Assert.assertEquals(id2.getMapping()[0], 1);
Assert.assertEquals(id2.getMapping()[1], 2);
Assert.assertEquals(id2.getMapping()[2], 0);
}
use of org.apache.geode.cache.query.internal.index.IndexData 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;
}
use of org.apache.geode.cache.query.internal.index.IndexData 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;
}
Aggregations