@Test public void testExecCachesCanBePushedAndValuesRetrievedAtTheCorrectLevel() { Object key = new Object(); Object value = new Object(); QueryExecutionContext context = new QueryExecutionContext(null, null); context.pushExecCache(1); context.cachePut(key, value); context.pushExecCache(2); assertNull(context.cacheGet(key)); context.popExecCache(); assertEquals(value, context.cacheGet(key)); }
@Override public int getSizeEstimate(ExecutionContext context) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException { IndexInfo[] idxInfo = getIndexInfo(context); assert idxInfo.length == 1; if (context instanceof QueryExecutionContext) { QueryExecutionContext qcontext = (QueryExecutionContext) context; if (qcontext.isHinted(idxInfo[0]._index.getName())) { return qcontext.getHintSize(idxInfo[0]._index.getName()); } } int op = _is_defined ? TOK_NE : TOK_EQ; return idxInfo[0]._index.getSizeEstimate(QueryService.UNDEFINED, op, idxInfo[0]._matchLevel); }
@Override public boolean isBetterFilter(Filter comparedTo, ExecutionContext context, int thisSize) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException { // If the current filter is equality & comparedTo filter is also equality based , then // return the one with lower size estimate is better boolean isThisBetter = true; int thatOperator = comparedTo.getOperator(); // Go with the lowest cost when hint is used. if (context instanceof QueryExecutionContext && ((QueryExecutionContext) context).hasHints()) { return thisSize <= comparedTo.getSizeEstimate(context); } switch (thatOperator) { case TOK_EQ: isThisBetter = false; break; case TOK_NE: case TOK_NE_ALT: // Give preference to Range break; default: throw new IllegalArgumentException("The operator type =" + thatOperator + " is unknown"); } return isThisBetter; }
@Test public void testPutValueReturnedFromCacheGet() { Object key = new Object(); Object value = new Object(); QueryExecutionContext context = new QueryExecutionContext(null, null); context.cachePut(key, value); assertEquals(value, context.cacheGet(key)); }
@Override public Object call() throws Exception { BucketQueryResult bukResult = new BucketQueryResult(this._bucketId); try { List<Integer> bucketList = Collections.singletonList(this._bucketId); ExecutionContext context = new QueryExecutionContext(this.parameters, pr.getCache(), this.query); context.setBucketList(bucketList); executeQueryOnBuckets(this.resultColl, context); } catch (ForceReattemptException | QueryException | CacheRuntimeException fre) { bukResult.setException(fre); } // Exception return bukResult; }
@Test public void testNullReturnedFromCacheGetWhenNoValueWasPut() { Object key = new Object(); QueryExecutionContext context = new QueryExecutionContext(null, null); assertNull(context.cacheGet(key)); }
@Test public void testCount() throws Exception { CompiledAggregateFunction caf1 = new CompiledAggregateFunction(null, OQLLexerTokenTypes.COUNT); ExecutionContext context1 = new ExecutionContext(null, cache); assertThat(caf1.evaluate(context1)).isInstanceOf(Count.class); CompiledAggregateFunction caf2 = new CompiledAggregateFunction(null, OQLLexerTokenTypes.COUNT, true); ExecutionContext context2 = new ExecutionContext(null, cache); assertThat(caf2.evaluate(context2)).isInstanceOf(CountDistinct.class); CompiledAggregateFunction caf3 = new CompiledAggregateFunction(null, OQLLexerTokenTypes.COUNT); ExecutionContext context3 = new ExecutionContext(null, cache); context3.setIsPRQueryNode(true); assertThat(caf3.evaluate(context3)).isInstanceOf(CountPRQueryNode.class); CompiledAggregateFunction caf4 = new CompiledAggregateFunction(null, OQLLexerTokenTypes.COUNT); QueryExecutionContext context4 = new QueryExecutionContext(null, cache); context4.setBucketList(bucketList); assertThat(caf4.evaluate(context4)).isInstanceOf(Count.class); CompiledAggregateFunction caf5 = new CompiledAggregateFunction(null, OQLLexerTokenTypes.COUNT, true); ExecutionContext context5 = new ExecutionContext(null, cache); context5.setIsPRQueryNode(true); assertThat(caf5.evaluate(context5)).isInstanceOf(CountDistinctPRQueryNode.class); CompiledAggregateFunction caf6 = new CompiledAggregateFunction(null, OQLLexerTokenTypes.COUNT, true); QueryExecutionContext context6 = new QueryExecutionContext(null, cache); context6.setBucketList(bucketList); assertThat(caf6.evaluate(context6)).isInstanceOf(DistinctAggregator.class); }
ExecutionContext context = new QueryExecutionContext(params, this.cache, this); indexObserver = this.startTrace(); if (qe != null) { || (((QueryExecutionContext) context).isIndexUsed() && DefaultQueryService.COPY_ON_READ_AT_ENTRY_LEVEL);
@Override public Object cacheGet(Object key) { return cacheGet(key, null); }
boolean foundPreferredCondition = false; if (this.getOperator() == LITERAL_and) { if (context instanceof QueryExecutionContext && ((QueryExecutionContext) context).hasHints() && ((QueryExecutionContext) context).hasMultiHints()) {
|| !((QueryExecutionContext) context).hasMultiHints()) {
resultCollector.add((Collection) results); isIndexUsedForLocalQuery = ((QueryExecutionContext) context).isIndexUsed();
/** * Applies order-by on the results returned from PR nodes and puts the results in the cumulative * result set. The order-by is applied by running a generated query on the each result returned by * the remote nodes. Example generated query: SELECT DISTINCT * FROM $1 p ORDER BY p.ID Where * results are passed as bind parameter. This is added as quick turn-around, this is added based * on most commonly used queries, needs to be investigated further. */ private SelectResults buildSortedResult(CompiledSelect cs, int limit) throws QueryException { try { ExecutionContext localContext = new QueryExecutionContext(this.parameters, this.pr.cache); List<Collection> allResults = new ArrayList<Collection>(); for (Collection<Collection> memberResults : this.resultsPerMember.values()) { for (Collection res : memberResults) { if (res != null) { allResults.add(res); } } } this.cumulativeResults = new NWayMergeResults(allResults, cs.isDistinct(), limit, cs.getOrderByAttrs(), localContext, cs.getElementTypeForOrderByQueries()); return this.cumulativeResults; } catch (Exception ex) { throw new QueryException( "Unable to apply order-by on the partition region cumulative results.", ex); } }
@Test public void testDefaultReturnedFromCacheGetWhenNoValueWasPut() { Object key = new Object(); Object value = new Object(); QueryExecutionContext context = new QueryExecutionContext(null, null); assertEquals(value, context.cacheGet(key, value)); }
@Test public void testAvg() throws Exception { CompiledAggregateFunction caf1 = new CompiledAggregateFunction(null, OQLLexerTokenTypes.AVG); ExecutionContext context1 = new ExecutionContext(null, cache); assertThat(caf1.evaluate(context1)).isInstanceOf(Avg.class); CompiledAggregateFunction caf2 = new CompiledAggregateFunction(null, OQLLexerTokenTypes.AVG, true); ExecutionContext context2 = new ExecutionContext(null, cache); assertThat(caf2.evaluate(context2)).isInstanceOf(AvgDistinct.class); CompiledAggregateFunction caf3 = new CompiledAggregateFunction(null, OQLLexerTokenTypes.AVG); ExecutionContext context3 = new ExecutionContext(null, cache); context3.setIsPRQueryNode(true); assertThat(caf3.evaluate(context3)).isInstanceOf(AvgPRQueryNode.class); CompiledAggregateFunction caf4 = new CompiledAggregateFunction(null, OQLLexerTokenTypes.AVG); QueryExecutionContext context4 = new QueryExecutionContext(null, cache); context4.setBucketList(this.bucketList); assertThat(caf4.evaluate(context4)).isInstanceOf(AvgBucketNode.class); CompiledAggregateFunction caf5 = new CompiledAggregateFunction(null, OQLLexerTokenTypes.AVG, true); ExecutionContext context5 = new ExecutionContext(null, cache); context5.setIsPRQueryNode(true); assertThat(caf5.evaluate(context5)).isInstanceOf(AvgDistinctPRQueryNode.class); CompiledAggregateFunction caf6 = new CompiledAggregateFunction(null, OQLLexerTokenTypes.AVG, true); QueryExecutionContext context6 = new QueryExecutionContext(null, cache); context6.setBucketList(this.bucketList); assertThat(caf6.evaluate(context6)).isInstanceOf(DistinctAggregator.class); }
ExecutionContext context = new QueryExecutionContext(this.parameters, pr.getCache()); int limit = this.query.getLimit(parameters); Collection mergedResults = coalesceOrderedResults(resultCollector, context, cs, limit);
@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); }
@Override public int getSizeEstimate(ExecutionContext context) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException { IndexInfo[] idxInfo = getIndexInfo(context); if (idxInfo == null) { // Asif: This implies it is an independent condition. So evaluate it first // in filter operand return 0; } assert idxInfo.length == 1; Object key = idxInfo[0].evaluateIndexKey(context); if (key != null && key.equals(QueryService.UNDEFINED)) { return 0; } if (context instanceof QueryExecutionContext) { QueryExecutionContext qcontext = (QueryExecutionContext) context; if (qcontext.isHinted(idxInfo[0]._index.getName())) { return qcontext.getHintSize(idxInfo[0]._index.getName()); } } // if the key is the LEFT operand, then reflect the operator // before the index lookup int op = reflectOnOperator(idxInfo[0]._key()); return idxInfo[0]._index.getSizeEstimate(key, op, idxInfo[0]._matchLevel); }
if (context instanceof QueryExecutionContext && ((QueryExecutionContext) context).hasHints()) { return thisSize <= comparedTo.getSizeEstimate(context);
new QueryExecutionContext(null, (InternalCache) this.cqService.getCache()));