@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; }
/** * 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); } }
ExecutionContext context = new QueryExecutionContext(this.parameters, pr.getCache()); int limit = this.query.getLimit(parameters); Collection mergedResults = coalesceOrderedResults(resultCollector, context, cs, limit);
@Test public void testDefaultReturnedFromCacheGetWhenNoValueWasPut() { Object key = new Object(); Object value = new Object(); QueryExecutionContext context = new QueryExecutionContext(null, null); assertEquals(value, context.cacheGet(key, value)); }
new QueryExecutionContext(null, (InternalCache) this.cqService.getCache()));
@Test public void testNullReturnedFromCacheGetWhenNoValueWasPut() { Object key = new Object(); QueryExecutionContext context = new QueryExecutionContext(null, null); assertNull(context.cacheGet(key)); }
private void executeSequentially(Collection<Collection> resultCollector, List buckets) throws QueryException, InterruptedException, ForceReattemptException { ExecutionContext context = new QueryExecutionContext(this.parameters, this.pr.getCache(), this.query); CompiledSelect cs = this.query.getSimpleSelect(); int limit = this.query.getLimit(parameters); if (cs != null && cs.isOrderBy()) { for (Integer bucketID : this._bucketsToQuery) { List<Integer> singleBucket = Collections.singletonList(bucketID); context.setBucketList(singleBucket); executeQueryOnBuckets(resultCollector, context); } Collection mergedResults = coalesceOrderedResults(resultCollector, context, cs, limit); resultCollector.clear(); resultCollector.add(mergedResults); } else { context.setBucketList(buckets); executeQueryOnBuckets(resultCollector, context); } }
@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)); }
public SelectResults getEmptyResultSet(Object[] parameters, InternalCache cache, Query query) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException { ExecutionContext context = new QueryExecutionContext(parameters, cache, query); computeDependencies(context); context.newScope((Integer) context.cacheGet(scopeID)); context.pushExecCache((Integer) context.cacheGet(scopeID)); SelectResults results = null; try { Iterator iter = iterators.iterator(); while (iter.hasNext()) { CompiledIteratorDef iterDef = (CompiledIteratorDef) iter.next(); RuntimeIterator rIter = iterDef.getRuntimeIterator(context); context.bindIterator(rIter); } results = prepareEmptyResultSet(context, false); } finally { context.popScope(); context.popExecCache(); } return results; }
/** * Should be constructed from DefaultQueryService * * @see QueryService#newQuery */ public DefaultQuery(String queryString, InternalCache cache, boolean isForRemote) { this.queryString = queryString; QCompiler compiler = new QCompiler(); this.compiledQuery = compiler.compileQuery(queryString); CompiledSelect cs = getSimpleSelect(); if (cs != null && !isForRemote && (cs.isGroupBy() || cs.isOrderBy())) { QueryExecutionContext ctx = new QueryExecutionContext(null, cache); try { cs.computeDependencies(ctx); } catch (QueryException qe) { throw new QueryInvalidException("", qe); } } this.traceOn = compiler.isTraceRequested() || QUERY_VERBOSE; this.cache = cache; this.stats = new DefaultQueryStatistics(); this.cancelationTask = Optional.empty(); }
@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)); }
ExecutionContext context = new QueryExecutionContext(parameters, this.cache, this); context.setBucketRegion(pr, bukRgn); context.setCqQueryContext(this.isCqQuery);
@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); }
@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); }
@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); }
ExecutionContext context = new QueryExecutionContext(params, this.cache, this); indexObserver = this.startTrace(); if (qe != null) {