use of org.apache.geode.cache.query.internal.QueryExecutionContext in project geode by apache.
the class PRQueryProcessor method executeSequentially.
private void executeSequentially(Collection<Collection> resultCollector, List buckets) throws QueryException, InterruptedException, ForceReattemptException {
/*
* for (Iterator itr = _bucketsToQuery.iterator(); itr.hasNext(); ) { Integer bId =
* (Integer)itr.next(); doBucketQuery(bId, this._prds, this.query, this.parameters,
* resultCollector); }
*/
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);
}
}
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 RangeIndexAPIJUnitTest method testQueryMethod_3.
/**
* Tests the query method of RangeIndex with takes a bound defined ( lower as well as upper) & may
* contain NotEqaul Keys
*/
@Test
public void testQueryMethod_3() 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();
i1.query(new Integer(5), OQLLexerTokenTypes.TOK_GT, new Integer(10), OQLLexerTokenTypes.TOK_LT, results, null, context);
assertEquals(4, results.size());
for (int i = 6; i < 10; ) {
assertTrue(results.contains(region.get(new Integer(i))));
++i;
}
results.clear();
keysToRemove.clear();
keysToRemove.add(new Integer(10));
keysToRemove.add(new Integer(9));
i1.query(new Integer(5), OQLLexerTokenTypes.TOK_GT, new Integer(10), OQLLexerTokenTypes.TOK_LT, results, keysToRemove, context);
assertEquals(3, results.size());
for (int i = 6; i < 9; ) {
assertTrue(results.contains(region.get(new Integer(i))));
++i;
}
results.clear();
keysToRemove.clear();
keysToRemove.add(new Integer(10));
i1.query(new Integer(5), OQLLexerTokenTypes.TOK_GT, new Integer(10), OQLLexerTokenTypes.TOK_LE, results, keysToRemove, context);
assertEquals(4, results.size());
for (int i = 6; i < 10; ) {
assertTrue(results.contains(region.get(new Integer(i))));
++i;
}
results.clear();
keysToRemove.clear();
i1.query(new Integer(5), OQLLexerTokenTypes.TOK_GT, new Integer(10), OQLLexerTokenTypes.TOK_LE, results, null, context);
assertEquals(5, results.size());
for (int i = 6; i < 11; ) {
assertTrue(results.contains(region.get(new Integer(i))));
++i;
}
results.clear();
keysToRemove.clear();
i1.query(new Integer(5), OQLLexerTokenTypes.TOK_GE, new Integer(10), OQLLexerTokenTypes.TOK_LE, results, null, context);
assertEquals(6, results.size());
for (int i = 5; i < 11; ) {
assertTrue(results.contains(region.get(new Integer(i))));
++i;
}
results.clear();
keysToRemove.clear();
keysToRemove.add(new Integer(5));
i1.query(new Integer(5), OQLLexerTokenTypes.TOK_GE, new Integer(10), OQLLexerTokenTypes.TOK_LE, results, keysToRemove, context);
assertEquals(5, results.size());
for (int i = 6; i < 11; ) {
assertTrue(results.contains(region.get(new Integer(i))));
++i;
}
results.clear();
keysToRemove.clear();
keysToRemove.add(new Integer(5));
keysToRemove.add(new Integer(10));
keysToRemove.add(new Integer(7));
i1.query(new Integer(5), OQLLexerTokenTypes.TOK_GE, new Integer(10), OQLLexerTokenTypes.TOK_LE, results, keysToRemove, context);
assertEquals(3, results.size());
assertTrue(results.contains(region.get(new Integer(6))));
assertTrue(results.contains(region.get(new Integer(8))));
assertTrue(results.contains(region.get(new Integer(9))));
}
use of org.apache.geode.cache.query.internal.QueryExecutionContext in project geode by apache.
the class RangeIndexAPIJUnitTest method testQueryMethod_1.
@Test
public void testQueryMethod_1() 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");
i1.query(new Integer(1), OQLLexerTokenTypes.TOK_EQ, results, context);
assertEquals(1, results.size());
assertTrue(results.iterator().next() == region.get(new Integer(1)));
results.clear();
i1.query(new Integer(1), OQLLexerTokenTypes.TOK_GT, results, context);
assertEquals(10, results.size());
for (int i = 2; i < 12; ++i) {
assertTrue(results.contains(region.get(new Integer(i))));
}
results.clear();
i2.query(new String("active"), OQLLexerTokenTypes.TOK_NE, results, context);
assertEquals(7, results.size());
for (int i = 1; i < 12; ) {
assertTrue(results.contains(region.get(new Integer(i))));
if (i >= 9) {
++i;
} else {
i += 2;
}
}
results.clear();
i3.query(QueryService.UNDEFINED, OQLLexerTokenTypes.TOK_EQ, results, context);
assertEquals(2, results.size());
assertTrue(results.contains(region.get(new Integer(11))));
assertTrue(results.contains(region.get(new Integer(10))));
}
use of org.apache.geode.cache.query.internal.QueryExecutionContext in project geode by apache.
the class RangeIndexAPIJUnitTest method testQueryMethod_2.
/**
* The keysToRemove set will never contain null or UNDEFINED as those conditions never form part
* of RangeJunctionCondnEvaluator. Such null or undefined conditions are treated as separate
* filter operands. This test checks the query method of Index which takes a set of keys which
* need to be removed from the set
*/
@Test
public void testQueryMethod_2() 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();
i1.query(new Integer(1), OQLLexerTokenTypes.TOK_EQ, results, context);
assertEquals(1, results.size());
assertTrue(results.iterator().next() == region.get(new Integer(1)));
results.clear();
keysToRemove.clear();
keysToRemove.add(new Integer(1));
try {
i1.query(new Integer(1), OQLLexerTokenTypes.TOK_EQ, results, keysToRemove, context);
fail("A condition having an equal will be identified at RangeJunction level itself, so this type of condition should throw error in RangeIndex where along with an equal there happens not equal conditions");
} catch (AssertionError error) {
// pass
}
keysToRemove.clear();
results.clear();
keysToRemove.add(new Integer(9));
i1.query(new Integer(1), OQLLexerTokenTypes.TOK_GT, results, keysToRemove, context);
assertEquals(9, results.size());
for (int i = 2; i < 12; ) {
if (i != 9) {
assertTrue(results.contains(region.get(new Integer(i))));
}
++i;
}
keysToRemove.clear();
results.clear();
keysToRemove.add(new Integer(1));
keysToRemove.add(new Integer(10));
i1.query(new Integer(1), OQLLexerTokenTypes.TOK_GE, results, keysToRemove, context);
assertEquals(9, results.size());
for (int i = 2; i < 12; ) {
if (i != 10) {
assertTrue(results.contains(region.get(new Integer(i))));
}
++i;
}
keysToRemove.clear();
results.clear();
keysToRemove.add(new Integer(8));
keysToRemove.add(new Integer(11));
i1.query(new Integer(11), OQLLexerTokenTypes.TOK_LT, results, keysToRemove, context);
assertEquals(10, results.size());
for (int i = 0; i < 11; ) {
if (i != 8) {
assertTrue(results.contains(region.get(new Integer(i))));
}
++i;
}
keysToRemove.clear();
results.clear();
keysToRemove.add(new Integer(8));
keysToRemove.add(new Integer(11));
i1.query(new Integer(11), OQLLexerTokenTypes.TOK_LE, results, keysToRemove, context);
assertEquals(10, results.size());
for (int i = 0; i < 11; ) {
if (i != 8) {
assertTrue(results.contains(region.get(new Integer(i))));
}
++i;
}
keysToRemove.clear();
results.clear();
keysToRemove.add(new Integer(1));
keysToRemove.add(new Integer(10));
i1.query(new Integer(1), OQLLexerTokenTypes.TOK_GT, results, keysToRemove, context);
assertEquals(9, results.size());
for (int i = 2; i < 12; ) {
if (i != 10) {
assertTrue(results.contains(region.get(new Integer(i))));
}
++i;
}
}
Aggregations