dQRegion.setEntry(target); Object params[] = {dQRegion}; ExecutionContext context = new ExecutionContext(params, this.cache); context.newScope(IndexCreationHelper.INDEX_QUERY_SCOPE_ID); context.setDependencyGraph(dependencyGraph); context.addToIndependentRuntimeItrMapForIndexCreation(iterDef); context.bindIterator(rIter); dependencyGraph = context.getDependencyGraph();
private void addResultToResults(ExecutionContext context, Collection results, Object key, Object result) { if (context != null && context.isCqQueryContext()) { results.add(new CqEntry(key, result)); } else { results.add(result); } }
/** * Added to reset the state from the last execution. This is added for CQs only. */ @Override public void reset() { super.reset(); this.execCacheStack.clear(); }
@Override public Set computeDependencies(ExecutionContext context) throws TypeMismatchException, AmbiguousNameException, NameResolutionException { int len = this._args.length; for (int i = 0; i < len; i++) { context.addDependencies(this, this._args[i].computeDependencies(context)); } return context.getDependencySet(this, true); }
@Override public Set computeDependencies(ExecutionContext context) throws TypeMismatchException, AmbiguousNameException, NameResolutionException { CompiledValue v = context.resolve(getId()); return context.addDependencies(this, v.computeDependencies(context)); }
@Override public Set computeDependencies(ExecutionContext context) throws TypeMismatchException, AmbiguousNameException, NameResolutionException { List args = this.args; Iterator i = args.iterator(); while (i.hasNext()) { context.addDependencies(this, ((CompiledValue) i.next()).computeDependencies(context)); } CompiledValue rcvr = getReceiver(context); if (rcvr == null) // implicit iterator operation { // see if it's an implicit operation name RuntimeIterator rcvrItr = context.resolveImplicitOperationName(this.methodName, this.args.size(), true); if (rcvrItr == null) { // no receiver resolved // function call: no functions implemented except keywords in the grammar throw new TypeMismatchException( String.format("Could not resolve method named ' %s '", this.methodName)); } // cache the receiver so we don't have to resolve it again context.cachePut(this, rcvrItr); return context.addDependency(this, rcvrItr); } // receiver is explicit return context.addDependencies(this, rcvr.computeDependencies(context)); }
@Override public SelectResults evaluate(ExecutionContext context) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException { context.newScope((Integer) context.cacheGet(scopeID)); context.pushExecCache((Integer) context.cacheGet(scopeID)); context.setDistinct(this.distinct); if (this.hasUnmappedOrderByCols && context.getBucketList() != null) { throw new QueryInvalidException( "Query contains atleast one order by field which is not present in projected fields."); context.cachePut(QUERY_INDEX_HINTS, hints); if (context.getQuery() != null) { ((DefaultQuery) context.getQuery()).keepResultsSerialized(this, context); CompiledIteratorDef iterDef = (CompiledIteratorDef) iter.next(); RuntimeIterator rIter = iterDef.getRuntimeIterator(context); context.bindIterator(rIter); int numInd = context.getAllIndependentIteratorsOfCurrentScope().size(); StringBuilder preferredIndexCondn = new StringBuilder(); this.evalCanonicalizedExpressionForCSC(csc, context, preferredIndexCondn); context.cachePut(PREF_INDEX_COND, preferredIndexCondn.toString()); Object obj = context.cacheGet(this.whereClause); if (obj != null && (obj instanceof IndexInfo[] || obj.equals(CLAUSE_EVALUATED))) { if (context.cacheGet(this.whereClause) == null) { context.cachePut(this.whereClause, CLAUSE_EVALUATED);
throws TypeMismatchException, NameResolutionException { context.cachePut(scopeID, context.associateScopeID()); context.newScope((Integer) context.cacheGet(scopeID)); context.pushExecCache((Integer) context.cacheGet(scopeID)); try { Iterator iter = this.iterators.iterator(); context.addDependencies(this, iterDef.computeDependencies(context)); RuntimeIterator rIter = iterDef.getRuntimeIterator(context); context.addToIndependentRuntimeItrMap(iterDef); context.bindIterator(rIter); context.addDependencies(this, this.whereClause.computeDependencies(context)); totalDependencySet = context.addDependencies(this, prjExpr.computeDependencies(context)); } else { this.doTreeTransformation(context); return context.getDependencySet(this, true); context.popExecCache(); context.popScope();
@Test public void testSum() throws Exception { CompiledAggregateFunction caf1 = new CompiledAggregateFunction(null, OQLLexerTokenTypes.SUM); ExecutionContext context1 = new ExecutionContext(null, cache); assertThat(caf1.evaluate(context1)).isInstanceOf(Sum.class); CompiledAggregateFunction caf2 = new CompiledAggregateFunction(null, OQLLexerTokenTypes.SUM, true); ExecutionContext context2 = new ExecutionContext(null, cache); assertThat(caf2.evaluate(context2)).isInstanceOf(SumDistinct.class); CompiledAggregateFunction caf3 = new CompiledAggregateFunction(null, OQLLexerTokenTypes.SUM); ExecutionContext context3 = new ExecutionContext(null, cache); context3.setIsPRQueryNode(true); assertThat(caf3.evaluate(context3)).isInstanceOf(Sum.class); CompiledAggregateFunction caf4 = new CompiledAggregateFunction(null, OQLLexerTokenTypes.SUM); QueryExecutionContext context4 = new QueryExecutionContext(null, cache); context4.setBucketList(bucketList); assertThat(caf4.evaluate(context4)).isInstanceOf(Sum.class); CompiledAggregateFunction caf5 = new CompiledAggregateFunction(null, OQLLexerTokenTypes.SUM, true); ExecutionContext context5 = new ExecutionContext(null, cache); context5.setIsPRQueryNode(true); assertThat(caf5.evaluate(context5)).isInstanceOf(SumDistinctPRQueryNode.class); CompiledAggregateFunction caf6 = new CompiledAggregateFunction(null, OQLLexerTokenTypes.SUM, true); QueryExecutionContext context6 = new QueryExecutionContext(null, cache); context6.setBucketList(bucketList); assertThat(caf6.evaluate(context6)).isInstanceOf(DistinctAggregator.class); }
this.initContext.newScope(1); for (int i = 0; i < this.iteratorSize; i++) { CompiledIteratorDef iterDef = (CompiledIteratorDef) this.indexInitIterators.get(i); iterDef.computeDependencies(this.initContext); rIter = iterDef.getRuntimeIterator(this.initContext); this.initContext.addToIndependentRuntimeItrMapForIndexCreation(iterDef); this.initContext.bindIterator(rIter); doNestedIterationsForIndexInit(0, this.initContext.getCurrentIterators()); throw new IMQException(e); } finally { this.initContext.popScope();
/** Creates a new instance of IMQEvaluator */ IMQEvaluator(IndexCreationHelper helper) { this.cache = helper.getCache(); this.fromIterators = helper.getIterators(); this.indexedExpr = helper.getCompiledIndexedExpression(); this.rgn = helper.getRegion(); // The modified iterators for optimizing Index creation this.isFirstItrOnEntry = ((FunctionalIndexCreationHelper) helper).isFirstIteratorRegionEntry; this.isFirstItrOnKey = ((FunctionalIndexCreationHelper) helper).isFirstIteratorRegionKey; this.additionalProj = ((FunctionalIndexCreationHelper) helper).additionalProj; Object[] params1 = {new QRegion(this.rgn, false)}; this.initContext = new ExecutionContext(params1, this.cache); this.canonicalIterNames = ((FunctionalIndexCreationHelper) helper).canonicalizedIteratorNames; if (this.isFirstItrOnEntry) { this.indexInitIterators = this.fromIterators; } else { this.indexInitIterators = ((FunctionalIndexCreationHelper) helper).indexInitIterators; this.modifiedIndexExpr = ((FunctionalIndexCreationHelper) helper).modifiedIndexExpr; this.addnlProjType = ((FunctionalIndexCreationHelper) helper).addnlProjType; } this.iteratorSize = this.indexInitIterators.size(); }
private int applyProjectionAndAddToResultSet(ExecutionContext context, SelectResults resultSet, boolean ignoreOrderBy) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException { List currrentRuntimeIters = context.getCurrentIterators(); if (context.getPartitionedRegion() != null && limitValue < 0) { applyOrderBy = false; if (this.distinct && !((DefaultQuery) context.getQuery()).isRemoteQuery() && !context.getCache().getPdxReadSerialized() && (values[i] instanceof PdxInstance)) { values[i] = ((PdxInstance) values[i]).getObject(); } else { boolean add = true; if (context.isCqQueryContext()) { if (values[0] instanceof Region.Entry) { Region.Entry e = (Region.Entry) values[0]; if (!((DefaultQuery) context.getQuery()).isRemoteQuery()) { if (this.distinct && values[i] instanceof PdxInstance && !context.getCache().getPdxReadSerialized()) { values[i] = ((PdxInstance) values[i]).getObject(); } else if (values[i] instanceof PdxString) {
ExecutionContext externalContext = new ExecutionContext(null, cache); externalContext.setBucketRegion(PartitionedRegion.this, (BucketRegion) bucket); IndexManager indMng = IndexUtils.getIndexManager(cache, bucket, true); try {
if (!createEmptySet) { observer.beforeIndexLookup(indexInfo._index, op, key); context.cachePut(CompiledValue.INDEX_INFO, indexInfo); Boolean orderByClause = (Boolean) context.cacheGet(CompiledValue.CAN_APPLY_ORDER_BY_AT_INDEX); if (orderByClause != null && orderByClause.booleanValue()) { List orderByAttrs = (List) context.cacheGet(CompiledValue.ORDERBY_ATTRIB); useLinkedDataStructure = orderByAttrs.size() == 1; nullValuesAtStart = !((CompiledSortCriterion) orderByAttrs.get(0)).getCriterion(); evaluateProj ? (ObjectType) context.cacheGet(RESULT_TYPE) : null; if (projResultType != null) { resultType = projResultType; projAttrib = (List) context.cacheGet(PROJ_ATTRIB); context.cachePut(RESULT_TYPE, Boolean.TRUE); context.getCache().getLogger() .fine("StructType resultType.class=" + resultType.getClass().getName()); if (useLinkedDataStructure) { set = context.isDistinct() ? new LinkedStructSet((StructTypeImpl) resultType) : new SortedResultsBag<Struct>((StructTypeImpl) resultType, nullValuesAtStart); } else { context.getCache().getLogger() .fine("non-StructType resultType.class=" + resultType.getClass().getName()); if (useLinkedDataStructure) { set = context.isDistinct() ? new LinkedResultSet(resultType) : new SortedResultsBag(resultType, nullValuesAtStart); } else {
@Test public void applyCqOrProjectionWhenContextIsCqShouldAddCqEntryToResults() throws Exception { when(context.isCqQueryContext()).thenReturn(true); when(context.getQuery()).thenReturn(mock(DefaultQuery.class)); List results = new LinkedList(); String value = "value"; index.applyCqOrProjection(null, context, results, value, null, false, "key"); assertTrue(results.get(0) instanceof CqEntry); }
public PrimaryKeyIndexCreationHelper(String fromClause, String indexedExpression, String projectionAttributes, InternalCache cache, ExecutionContext externalContext, IndexManager imgr) throws IndexInvalidException { super(fromClause, projectionAttributes, cache); if (externalContext == null) { context = new ExecutionContext(null, cache); } else { this.context = externalContext; } context.newScope(1); this.region = imgr.region; prepareFromClause(imgr); prepareIndexExpression(indexedExpression); prepareProjectionAttributes(projectionAttributes); }
@Override public Object evaluate(ExecutionContext context) throws RegionNotFoundException { Region rgn; Cache cache = context.getCache(); PartitionedRegion pr = context.getPartitionedRegion(); rgn = context.getBucketRegion(); } else if (pr != null) { BucketRegion br = context.getBucketRegion(); int bucketID = br.getId(); if (context.isCqQueryContext()) { return new QRegion(rgn, true, context); } else {
context.resolveImplicitOperationName(this.methodName, this.args.size(), true); evalRcvr = rcvrItr.evaluate(context); if (context.isCqQueryContext() && evalRcvr instanceof Region.Entry) { Region.Entry re = (Region.Entry) evalRcvr; if (re.isDestroyed()) { PartitionedRegion pr = context.getPartitionedRegion(); if (pr != null && (result instanceof Region)) { if (pr.getFullPath().equals(((Region) result).getFullPath())) { result = context.getBucketRegion();
/** * Applies the query on the event. This method takes care of the performance related changed done * to improve the CQ-query performance. When CQ-query is executed first time, it saves the query * related information in the execution context and uses that info in later executions. */ private boolean evaluateQuery(CqQueryImpl cQuery, Object[] event) throws Exception { ExecutionContext execContext = cQuery.getQueryExecutionContext(); execContext.reset(); execContext.setBindArguments(event); boolean status = false; // Check if the CQ query is executed once. // If not execute the query in normal way. // During this phase the query execution related info are stored in the // ExecutionContext. if (execContext.getScopeNum() <= 0) { SelectResults results = (SelectResults) ((DefaultQuery) cQuery.getQuery()).executeUsingContext(execContext); if (results != null && results.size() > 0) { status = true; } } else { // Execute using the saved query info (in ExecutionContext). // This avoids building resultSet, index look-up, generating build-plans // that are not required for; query execution on single object. CompiledSelect cs = ((DefaultQuery) (cQuery.getQuery())).getSelect(); status = cs.evaluateCq(execContext); } return status; }
Object evalRcvr = rcvr.evaluate(context); if (context.isCqQueryContext() && (evalRcvr instanceof Region.Entry || evalRcvr instanceof CqEntry)) { try { PartitionedRegion pr = context.getPartitionedRegion(); if (pr != null && (obj instanceof Region)) { if (pr.getFullPath().equals(((Region) obj).getFullPath())) { obj = context.getBucketRegion();