Search in sources :

Example 6 with RuntimeIterator

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

the class CompactRangeIndex method verifyInnerAndOuterEntryValues.

/**
   * This evaluates the left and right side of a EQUI-JOIN where condition for which this Index was
   * used. Like, if condition is "p.ID = e.ID", {@link IndexInfo} will contain Left as p.ID, Right
   * as e.ID and operator as TOK_EQ. This method will evaluate p.ID OR e.ID based on if it is inner
   * or outer RegionEntry, and verify the p.ID = e.ID.
   * 
   * This method is called only for Memory indexstore
   * 
   * @return true if entry value and index value are consistent.
   */
protected boolean verifyInnerAndOuterEntryValues(IndexStoreEntry entry, ExecutionContext context, IndexInfo indexInfo, Object keyVal) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
    // Verify index key in value only for memory index store
    CompactRangeIndex index = (CompactRangeIndex) indexInfo._getIndex();
    RuntimeIterator runtimeItr = index.getRuntimeIteratorForThisIndex(context, indexInfo);
    if (runtimeItr != null) {
        runtimeItr.setCurrent(((MemoryIndexStoreEntry) entry).getDeserializedValue());
    }
    return evaluateEntry(indexInfo, context, keyVal);
}
Also used : RuntimeIterator(org.apache.geode.cache.query.internal.RuntimeIterator)

Example 7 with RuntimeIterator

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

the class AbstractIndex method getAllDependentRuntimeIterators.

/**
   * Take all independent iterators from context and remove the one which matches for this Index's
   * independent iterator. Then get all Dependent iterators from given context for this Index's
   * independent iterator.
   *
   * @param context from executing query.
   * @return List of all iterators pertaining to this Index.
   */
private List getAllDependentRuntimeIterators(ExecutionContext context) {
    List<RuntimeIterator> indItrs = context.getCurrScopeDpndntItrsBasedOnSingleIndpndntItr(getRuntimeIteratorForThisIndex(context));
    List<String> definitions = Arrays.asList(this.getCanonicalizedIteratorDefinitions());
    // These are the common iterators between query from clause and index from clause.
    List itrs = new ArrayList();
    for (RuntimeIterator itr : indItrs) {
        if (definitions.contains(itr.getDefinition())) {
            itrs.add(itr);
        }
    }
    return itrs;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) PdxString(org.apache.geode.pdx.internal.PdxString) RuntimeIterator(org.apache.geode.cache.query.internal.RuntimeIterator)

Example 8 with RuntimeIterator

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

the class AbstractIndex method getRuntimeIteratorForThisIndex.

/**
   * Similar to {@link #getRuntimeIteratorForThisIndex(ExecutionContext)} except that this one also
   * matches the iterator name if present with alias used in the {@link IndexInfo}
   * 
   * @return {@link RuntimeIterator}
   */
RuntimeIterator getRuntimeIteratorForThisIndex(ExecutionContext context, IndexInfo info) {
    List<RuntimeIterator> indItrs = context.getCurrentIterators();
    Region rgn = this.getRegion();
    if (rgn instanceof BucketRegion) {
        rgn = ((Bucket) rgn).getPartitionedRegion();
    }
    String regionPath = rgn.getFullPath();
    String definition = this.getCanonicalizedIteratorDefinitions()[0];
    for (RuntimeIterator itr : indItrs) {
        if (itr.getDefinition().equals(regionPath) || itr.getDefinition().equals(definition)) {
            // if iterator has name alias must be used in the query
            if (itr.getName() != null) {
                CompiledValue path = info._path();
                // match the iterator name with alias
                String pathName = getReceiverNameFromPath(path);
                if (path.getType() == OQLLexerTokenTypes.Identifier || itr.getName().equals(pathName)) {
                    return itr;
                }
            } else {
                return itr;
            }
        }
    }
    return null;
}
Also used : BucketRegion(org.apache.geode.internal.cache.BucketRegion) CompiledValue(org.apache.geode.cache.query.internal.CompiledValue) LocalRegion(org.apache.geode.internal.cache.LocalRegion) QRegion(org.apache.geode.cache.query.internal.QRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) PdxString(org.apache.geode.pdx.internal.PdxString) RuntimeIterator(org.apache.geode.cache.query.internal.RuntimeIterator)

Example 9 with RuntimeIterator

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

the class AbstractIndex method evaluateLastColl.

private List evaluateLastColl(Object value, ExecutionContext context, List itrs, int level) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
    // A tuple is a value generated from RegionEntry value which could be a StructType (Multiple
    // Dependent Iterators) or ObjectType (Single Iterator) value.
    List tuples = new ArrayList(1);
    RuntimeIterator currItrator = (RuntimeIterator) itrs.get(level);
    currItrator.setCurrent(value);
    // If its last iterator then just evaluate final struct.
    if (itrs.size() - 1 == level) {
        if (itrs.size() > 1) {
            Object[] tuple = new Object[itrs.size()];
            for (int i = 0; i < itrs.size(); i++) {
                RuntimeIterator iter = (RuntimeIterator) itrs.get(i);
                tuple[i] = iter.evaluate(context);
            }
            // Its ok to pass type as null as we are only interested in values.
            tuples.add(new StructImpl(new StructTypeImpl(), tuple));
        } else {
            tuples.add(currItrator.evaluate(context));
        }
    } else {
        // Not the last iterator.
        RuntimeIterator nextItr = (RuntimeIterator) itrs.get(level + 1);
        Collection nextLevelValues = nextItr.evaluateCollection(context);
        // If value is null or INVALID then the evaluated collection would be Null.
        if (nextLevelValues != null) {
            for (Object nextLevelValue : nextLevelValues) {
                tuples.addAll(evaluateLastColl(nextLevelValue, context, itrs, level + 1));
            }
        }
    }
    return tuples;
}
Also used : StructImpl(org.apache.geode.cache.query.internal.StructImpl) ArrayList(java.util.ArrayList) StructTypeImpl(org.apache.geode.cache.query.internal.types.StructTypeImpl) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList) RuntimeIterator(org.apache.geode.cache.query.internal.RuntimeIterator)

Example 10 with RuntimeIterator

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

the class AbstractIndex method getRuntimeIteratorForThisIndex.

/**
   * Matches the Collection reference in given context for this index's from-clause in all current
   * independent collection references associated to the context. For example, if a join Query has
   * "/region1 p, region2 e" from clause context contains two region references for p and e and
   * Index could be used for any of those of both of those regions.
   *
   * Note: This Index contains its own from clause definition which corresponds to a region
   * collection reference in given context and must be contained at 0th index in
   * {@link AbstractIndex#canonicalizedDefinitions}.
   * 
   * @return {@link RuntimeIterator} this should not be null ever.
   */
RuntimeIterator getRuntimeIteratorForThisIndex(ExecutionContext context) {
    List<RuntimeIterator> indItrs = context.getCurrentIterators();
    Region rgn = this.getRegion();
    if (rgn instanceof BucketRegion) {
        rgn = ((Bucket) rgn).getPartitionedRegion();
    }
    String regionPath = rgn.getFullPath();
    String definition = this.getCanonicalizedIteratorDefinitions()[0];
    for (RuntimeIterator itr : indItrs) {
        if (itr.getDefinition().equals(regionPath) || itr.getDefinition().equals(definition)) {
            return itr;
        }
    }
    return null;
}
Also used : BucketRegion(org.apache.geode.internal.cache.BucketRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) QRegion(org.apache.geode.cache.query.internal.QRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) PdxString(org.apache.geode.pdx.internal.PdxString) RuntimeIterator(org.apache.geode.cache.query.internal.RuntimeIterator)

Aggregations

RuntimeIterator (org.apache.geode.cache.query.internal.RuntimeIterator)13 List (java.util.List)7 ArrayList (java.util.ArrayList)5 CompiledIteratorDef (org.apache.geode.cache.query.internal.CompiledIteratorDef)4 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)4 PdxString (org.apache.geode.pdx.internal.PdxString)4 Iterator (java.util.Iterator)3 CompiledValue (org.apache.geode.cache.query.internal.CompiledValue)3 QueryObserver (org.apache.geode.cache.query.internal.QueryObserver)3 Collection (java.util.Collection)2 Map (java.util.Map)2 Set (java.util.Set)2 Region (org.apache.geode.cache.Region)2 IndexInvalidException (org.apache.geode.cache.query.IndexInvalidException)2 CompiledID (org.apache.geode.cache.query.internal.CompiledID)2 CompiledIndexOperation (org.apache.geode.cache.query.internal.CompiledIndexOperation)2 CompiledOperation (org.apache.geode.cache.query.internal.CompiledOperation)2 CompiledPath (org.apache.geode.cache.query.internal.CompiledPath)2 QRegion (org.apache.geode.cache.query.internal.QRegion)2 BucketRegion (org.apache.geode.internal.cache.BucketRegion)2