use of org.apache.geode.cache.query.internal.QueryExecutionContext in project geode by apache.
the class IndexHintJUnitTest method testTwoIndexHint.
// Tests the grammar for a hint with two index names
@Test
public void testTwoIndexHint() throws Exception {
createRegion();
QueryService qs = CacheUtils.getQueryService();
DefaultQuery query = (DefaultQuery) qs.newQuery("<hint 'FirstIndex', 'SecondIndex'> select * from /Portfolios p where p.ID > 10");
QueryExecutionContext qec = new QueryExecutionContext(new Object[1], CacheUtils.getCache(), query);
query.executeUsingContext(qec);
assertTrue(qec.isHinted("FirstIndex"));
assertTrue(qec.isHinted("SecondIndex"));
}
use of org.apache.geode.cache.query.internal.QueryExecutionContext in project geode by apache.
the class IndexHintJUnitTest method testIndexHintOrdering.
// Tests that index hints are ordered correctly
@Test
public void testIndexHintOrdering() throws Exception {
createRegion();
QueryService qs = CacheUtils.getQueryService();
DefaultQuery query = (DefaultQuery) qs.newQuery("<hint 'FirstIndex','SecondIndex','ThirdIndex','FourthIndex'>select * from /Portfolios p where p.ID > 10");
QueryExecutionContext qec = new QueryExecutionContext(new Object[1], CacheUtils.getCache(), query);
query.executeUsingContext(qec);
assertTrue(qec.isHinted("FirstIndex"));
assertTrue(qec.isHinted("SecondIndex"));
assertTrue(qec.isHinted("ThirdIndex"));
assertTrue(qec.isHinted("FourthIndex"));
assertEquals(-4, qec.getHintSize("FirstIndex"));
assertEquals(-3, qec.getHintSize("SecondIndex"));
assertEquals(-2, qec.getHintSize("ThirdIndex"));
assertEquals(-1, qec.getHintSize("FourthIndex"));
}
use of org.apache.geode.cache.query.internal.QueryExecutionContext in project geode by apache.
the class IndexHintJUnitTest method testSingleIndexHint.
// tests the grammar for a hint with a single index name
@Test
public void testSingleIndexHint() throws Exception {
createRegion();
QueryService qs = CacheUtils.getQueryService();
DefaultQuery query = (DefaultQuery) qs.newQuery("<hint 'FirstIndex'> select * from /Portfolios p where p.ID > 10");
QueryExecutionContext qec = new QueryExecutionContext(new Object[1], CacheUtils.getCache(), query);
query.executeUsingContext(qec);
assertTrue(qec.isHinted("FirstIndex"));
assertEquals(-1, qec.getHintSize("FirstIndex"));
}
use of org.apache.geode.cache.query.internal.QueryExecutionContext in project geode by apache.
the class PRQueryProcessor method executeWithThreadPool.
private void executeWithThreadPool(Collection<Collection> resultCollector) throws QueryException, InterruptedException, ForceReattemptException {
if (Thread.interrupted())
throw new InterruptedException();
java.util.List callableTasks = buildCallableTaskList(resultCollector);
ExecutorService execService = PRQueryExecutor.getExecutorService();
boolean reattemptNeeded = false;
ForceReattemptException fre = null;
if (callableTasks != null && !callableTasks.isEmpty()) {
List futures = null;
try {
futures = execService.invokeAll(callableTasks, 300, TimeUnit.SECONDS);
} catch (RejectedExecutionException rejectedExecutionEx) {
throw rejectedExecutionEx;
}
if (futures != null) {
Iterator itr = futures.iterator();
while (itr.hasNext() && !execService.isShutdown() && !execService.isTerminated()) {
// this._prds.partitionedRegion.checkReadiness();
Future fut = (Future) itr.next();
QueryTask.BucketQueryResult bqr = null;
try {
bqr = (QueryTask.BucketQueryResult) fut.get(BUCKET_QUERY_TIMEOUT, TimeUnit.SECONDS);
// if (retry.booleanValue()) {
// reattemptNeeded = true;
// fre = (ForceReattemptException)bqr.getException();
// } else {
// handles an exception if there was one,
bqr.handleAndThrowException();
// }
if (bqr.retry) {
reattemptNeeded = true;
}
} catch (TimeoutException e) {
throw new InternalGemFireException(LocalizedStrings.PRQueryProcessor_TIMED_OUT_WHILE_EXECUTING_QUERY_TIME_EXCEEDED_0.toLocalizedString(BUCKET_QUERY_TIMEOUT), e);
} catch (ExecutionException ee) {
Throwable cause = ee.getCause();
if (cause instanceof QueryException) {
throw (QueryException) cause;
} else {
throw new InternalGemFireException(LocalizedStrings.PRQueryProcessor_GOT_UNEXPECTED_EXCEPTION_WHILE_EXECUTING_QUERY_ON_PARTITIONED_REGION_BUCKET.toLocalizedString(), cause);
}
}
}
CompiledSelect cs = this.query.getSimpleSelect();
if (cs != null && (cs.isOrderBy() || cs.isGroupBy())) {
ExecutionContext context = new QueryExecutionContext(this.parameters, pr.getCache());
int limit = this.query.getLimit(parameters);
Collection mergedResults = coalesceOrderedResults(resultCollector, context, cs, limit);
resultCollector.clear();
resultCollector.add(mergedResults);
}
}
}
if (execService == null || execService.isShutdown() || execService.isTerminated()) {
this._prds.partitionedRegion.checkReadiness();
}
if (reattemptNeeded) {
throw fre;
}
}
use of org.apache.geode.cache.query.internal.QueryExecutionContext in project geode by apache.
the class RangeIndexAPIJUnitTest method testQueryMethod_4.
/**
* Tests the query method of RangeIndex which just contains not equal keys. That is if the where
* clause looks like a != 7 and a != 8 & a!=9
*/
@Test
public void testQueryMethod_4() throws Exception {
QueryService qs;
qs = CacheUtils.getQueryService();
AbstractIndex i1 = (AbstractIndex) qs.createIndex("idIndex", IndexType.FUNCTIONAL, "ID", "/portfolios");
AbstractIndex i2 = (AbstractIndex) qs.createIndex("statusIndex", IndexType.FUNCTIONAL, "status", "/portfolios");
AbstractIndex i3 = (AbstractIndex) qs.createIndex("status.toString()", IndexType.FUNCTIONAL, "status.toString", "/portfolios");
Set results = new HashSet();
DefaultQuery q = new DefaultQuery("select * from /portfolios", CacheUtils.getCache(), false);
q.setRemoteQuery(false);
ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache(), q);
bindIterators(context, "/portfolios");
Set keysToRemove = new HashSet();
keysToRemove.add(new Integer(5));
i1.query(results, keysToRemove, context);
assertEquals(11, results.size());
for (int i = 0; i < 12; ) {
if (i != 5) {
assertTrue(results.contains(region.get(new Integer(i))));
}
++i;
}
results.clear();
keysToRemove.clear();
keysToRemove.add(new Integer(5));
keysToRemove.add(new Integer(8));
i1.query(results, keysToRemove, context);
assertEquals(10, results.size());
for (int i = 0; i < 12; ) {
if (i != 5 && i != 8) {
assertTrue(results.contains(region.get(new Integer(i))));
}
++i;
}
results.clear();
keysToRemove.clear();
keysToRemove.add("active");
keysToRemove.add("inactive");
i2.query(results, keysToRemove, context);
assertEquals(2, results.size());
for (int i = 10; i < 12; ) {
assertTrue(results.contains(region.get(new Integer(i))));
++i;
}
}
Aggregations