private ObjectType createIndexResultSetType() { List currentIterators = this.initContext.getCurrentIterators(); int len = currentIterators.size(); ObjectType type = null; ObjectType fieldTypes[] = new ObjectType[len]; int start = this.isFirstItrOnEntry ? 0 : 1; for (; start < len; start++) { RuntimeIterator iter = (RuntimeIterator) currentIterators.get(start); fieldTypes[start] = iter.getElementType(); } if (!this.isFirstItrOnEntry) { fieldTypes[0] = addnlProjType; } type = (len == 1) ? fieldTypes[0] : new StructTypeImpl(this.canonicalIterNames, fieldTypes); return type; }
/** * The struct type calculation is modified if the 0th iterator is modified to make it dependent * on Entry */ private ObjectType createIndexResultSetType() { List currentIterators = this.initContext.getCurrentIterators(); int len = currentIterators.size(); ObjectType[] fieldTypes = new ObjectType[len]; int start = this.isFirstItrOnEntry ? 0 : 1; for (; start < len; start++) { RuntimeIterator iter = (RuntimeIterator) currentIterators.get(start); fieldTypes[start] = iter.getElementType(); } if (!this.isFirstItrOnEntry) { fieldTypes[0] = this.addnlProjType; } return len == 1 ? fieldTypes[0] : new StructTypeImpl(this.canonicalIterNames, fieldTypes); }
private ObjectType createIndexResultSetType() { List currentIterators = this.initContext.getCurrentIterators(); int len = currentIterators.size(); ObjectType type = null; // String fieldNames[] = new String[len]; ObjectType fieldTypes[] = new ObjectType[len]; int start = this.isFirstItrOnEntry ? 0 : 1; for (; start < len; start++) { RuntimeIterator iter = (RuntimeIterator) currentIterators.get(start); // fieldNames[start] = iter.getInternalId(); fieldTypes[start] = iter.getElementType(); } if (!this.isFirstItrOnEntry) { // fieldNames[0] = "iter1"; fieldTypes[0] = addnlProjType; } type = (len == 1) ? fieldTypes[0] : new StructTypeImpl(this.canonicalIterNames, fieldTypes); return type; }
public Object evaluateKey(Object object) { Object value = object; ExecutionContext newContext = null; Object key = null; try { if (object instanceof RegionEntry) { RegionEntry regionEntry = (RegionEntry) object; newContext = createExecutionContext(regionEntry); value = getTargetObjectForUpdate(regionEntry); } // context we use is the update context, from IMQEvaluator List iterators = newContext.getCurrentIterators(); RuntimeIterator itr = (RuntimeIterator) iterators.get(0); itr.setCurrent(value); key = this.indexedExpr.evaluate(newContext); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Could not reevaluate key for hash index"); } throw new Error("Could not reevaluate key for hash index", e); } if (key == null) { key = IndexManager.NULL; } return key; }
private void doNestedExpansion(int level, ExecutionContext expansionContext, List expandedResults, Object lowerBoundKey, Object upperBoundKey, int lowerBoundOperator, int upperBoundOperator, Object value) throws TypeMismatchException, AmbiguousNameException, FunctionDomainException, NameResolutionException, QueryInvocationTargetException, IMQException { List iterList = expansionContext.getCurrentIterators(); int iteratorSize = iterList.size(); if (level == iteratorSize) { expand(expansionContext, expandedResults, lowerBoundKey, upperBoundKey, lowerBoundOperator, upperBoundOperator, value); } else { RuntimeIterator rIter = (RuntimeIterator) iterList.get(level); Collection c = rIter.evaluateCollection(expansionContext); if (c == null) return; Iterator cIter = c.iterator(); while (cIter.hasNext()) { rIter.setCurrent(cIter.next()); doNestedExpansion(level + 1, expansionContext, expandedResults, lowerBoundKey, upperBoundKey, lowerBoundOperator, upperBoundOperator, value); } } }
/** * @param add true if adding to index, false if removing */ private void doNestedIterations(int level, boolean add, ExecutionContext context) throws TypeMismatchException, AmbiguousNameException, FunctionDomainException, NameResolutionException, QueryInvocationTargetException, IMQException { List iterList = context.getCurrentIterators(); if (level == this.iteratorSize) { applyProjection(add, context); } else { RuntimeIterator rIter = (RuntimeIterator) iterList.get(level); // System.out.println("Level = "+level+" Iter = "+rIter.getDef()); Collection c = rIter.evaluateCollection(context); if (c == null) return; Iterator cIter = c.iterator(); while (cIter.hasNext()) { rIter.setCurrent(cIter.next()); doNestedIterations(level + 1, add, context); } } }
/** * @param add true if adding to index, false if removing */ private void doNestedIterations(int level, boolean add, ExecutionContext context) throws TypeMismatchException, AmbiguousNameException, FunctionDomainException, NameResolutionException, QueryInvocationTargetException, IMQException { List iterList = context.getCurrentIterators(); if (level == this.iteratorSize) { applyProjection(add, context); } else { RuntimeIterator rIter = (RuntimeIterator) iterList.get(level); // System.out.println("Level = "+level+" Iter = "+rIter.getDef()); Collection c = rIter.evaluateCollection(context); if (c == null) return; Iterator cIter = c.iterator(); while (cIter.hasNext()) { rIter.setCurrent(cIter.next()); doNestedIterations(level + 1, add, context); } } }
@Override public void expansion(List expandedResults, Object lowerBoundKey, Object upperBoundKey, int lowerBoundOperator, int upperBoundOperator, Object value) throws IMQException { try { ExecutionContext expansionContext = createExecutionContext(value); List iterators = expansionContext.getCurrentIterators(); RuntimeIterator iter = (RuntimeIterator) iterators.get(0); iter.setCurrent(value); // first iter level is region entries, we can ignore as we already broke it down in the // index doNestedExpansion(1, expansionContext, expandedResults, lowerBoundKey, upperBoundKey, lowerBoundOperator, upperBoundOperator, value); } catch (Exception e) { throw new IMQException(e); } }
private void doNestedIterations(int level, ExecutionContext context) throws TypeMismatchException, AmbiguousNameException, FunctionDomainException, NameResolutionException, QueryInvocationTargetException, IMQException { List iterList = context.getCurrentIterators(); if (level == this.iteratorSize) { applyProjection(context); } else { RuntimeIterator rIter = (RuntimeIterator) iterList.get(level); Collection collection = rIter.evaluateCollection(context); if (collection == null) { return; } for (Object aCollection : collection) { rIter.setCurrent(aCollection); doNestedIterations(level + 1, context); } } }
List finalList = context.getCurrentIterators(); RuntimeIterator[][] itrsForResultFields = new RuntimeIterator[1][]; CompiledValue gj = null;
SelectResults sr = null; List currentIterators = context.getCurrentIterators(); if (projAttrs == null) { if (currentIterators.size() == 1) {
private SelectResults doIterationEvaluate(ExecutionContext context, boolean evaluateWhereClause) throws TypeMismatchException, FunctionDomainException, NameResolutionException, QueryInvocationTargetException { SelectResults results = prepareEmptyResultSet(context, false); // TODO: SELF : Work on limit implementation on bulk get // check for bulk get optimization if (evaluateWhereClause) { List tmpResults = optimizeBulkGet(context); if (tmpResults != null) { // (has only one iterator) RuntimeIterator rIter = (RuntimeIterator) context.getCurrentIterators().get(0); for (Iterator itr = tmpResults.iterator(); itr.hasNext();) { Object currObj = itr.next(); rIter.setCurrent(currObj); QueryObserver observer = QueryObserverHolder.getInstance(); observer.beforeIterationEvaluation(rIter, currObj); applyProjectionAndAddToResultSet(context, results, this.orderByAttrs == null); } return results; } } int numElementsInResult = 0; try { doNestedIterations(0, results, context, evaluateWhereClause, numElementsInResult); } catch (CompiledSelect.NullIteratorException ignore) { return null; } return results; }
/** * 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; }
List iterList = context.getCurrentIterators();
List<RuntimeIterator> indItrs = context.getCurrentIterators(); Region rgn = this.getRegion(); if (rgn instanceof BucketRegion) {
private SelectResults applyProjectionOnCollection(SelectResults resultSet, ExecutionContext context, boolean ignoreOrderBy) throws TypeMismatchException, FunctionDomainException, NameResolutionException, QueryInvocationTargetException { List iterators = context.getCurrentIterators(); if (projAttrs == null && (this.orderByAttrs == null || ignoreOrderBy)) {
private void applyProjection(ExecutionContext context) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException, IMQException { List currrentRuntimeIters = context.getCurrentIterators(); Object indexKey = this.indexedExpr.evaluate(context); // based on the first key convert the rest to PdxString or String if (!AbstractIndex.this.isIndexedPdxKeysFlagSet) { setPdxStringFlag(indexKey); } indexKey = getPdxStringForIndexedPdxKeys(indexKey); Object indxResultSet; if (this.iteratorSize == 1) { RuntimeIterator iter = (RuntimeIterator) currrentRuntimeIters.get(0); indxResultSet = iter.evaluate(context); } else { Object tuple[] = new Object[this.iteratorSize]; for (int i = 0; i < this.iteratorSize; i++) { RuntimeIterator iter = (RuntimeIterator) currrentRuntimeIters.get(i); tuple[i] = iter.evaluate(context); } Support.Assert(this.indexResultSetType instanceof StructTypeImpl, "The Index ResultType should have been an instance of StructTypeImpl rather than ObjectTypeImpl. The indxeResultType is " + this.indexResultSetType); indxResultSet = new StructImpl((StructTypeImpl) this.indexResultSetType, tuple); } // Keep Entry value in fly until all keys are evaluated RegionEntry entry = ((DummyQRegion) context.getBindArgument(1)).getEntry(); saveMapping(indexKey, indxResultSet, entry); }
doNestedIterationsForIndexInit(0, this.initContext.getCurrentIterators());
doNestedIterationsForIndexInit(0, this.initContext.getCurrentIterators());
doNestedIterationsForIndexInit(0, this.initContext.getCurrentIterators());