use of org.apache.geode.cache.query.SelectResults in project geode by apache.
the class LimitClauseJUnitTest method testLimitOnEqualsCompactRangeIndexedFieldWithAndClauseCompactRangeIndexedField.
// This is one where the old code could apply limit but we do not. Should investigate... index
// being used is on ShortId
@Test
public void testLimitOnEqualsCompactRangeIndexedFieldWithAndClauseCompactRangeIndexedField() throws Exception {
Query query;
SelectResults result;
Region region = CacheUtils.createRegion("portfolios1", Portfolio.class);
for (int i = 0; i <= 15; i++) {
Portfolio p = new Portfolio(10);
p.shortID = 1;
p.positions.clear();
p.positions.put("IBM", new Position("IBM", i));
region.put("KEY" + i, p);
}
for (int i = 16; i < 20; i++) {
Portfolio p = new Portfolio(10);
p.shortID = 2;
p.positions.clear();
p.positions.put("VMW", new Position("VMW", i));
region.put("KEY" + i, p);
}
for (int i = 20; i < 24; i++) {
Portfolio p = new Portfolio(11);
p.shortID = 2;
p.positions.clear();
p.positions.put("VMW", new Position("VMW", i));
region.put("KEY" + i, p);
}
for (int i = 24; i < 28; i++) {
Portfolio p = new Portfolio(10);
p.shortID = (short) (i % 3);
p.positions.clear();
p.positions.put("VMW", new Position("VMW", i));
region.put("KEY" + i, p);
}
for (int i = 100; i < 200; i++) {
Portfolio p = new Portfolio(10);
p.shortID = 0;
p.positions.clear();
p.positions.put("VMW", new Position("VMW", i));
region.put("KEY" + i, p);
}
// MyQueryObserverAdapter observer = new MyQueryObserverAdapter();
// QueryObserver old = QueryObserverHolder.setInstance(observer);
// Create Index on ID
Index idIndex = qs.createIndex("idIndex", "P.ID", "/portfolios1 P");
Index shortIdIndex = qs.createIndex("shortIdIndex", "P.shortID", "/portfolios1 P");
String queryString = "<trace>SELECT * FROM /portfolios1 P WHERE P.ID = 10 AND P.shortID = 2 LIMIT 5";
query = qs.newQuery(queryString);
assertNotNull(idIndex);
SelectResults resultsWithIndex = (SelectResults) query.execute();
// assertFalse(observer.limitAppliedAtIndex);
assertEquals(5, resultsWithIndex.size());
}
use of org.apache.geode.cache.query.SelectResults in project geode by apache.
the class LimitClauseJUnitTest method testDistinctLimitWithParameter.
@Test
public void testDistinctLimitWithParameter() throws Exception {
String queryString = "SELECT DISTINCT entry FROM $1 entry LIMIT $2 ";
SelectResults result;
Region region = CacheUtils.createRegion("portfolios1", Portfolio.class);
for (int i = 0; i < 100; i++) {
region.put(i, new Portfolio(i));
}
Object[] params = new Object[2];
params[0] = region;
params[1] = 5;
SelectResults results = (SelectResults) qs.newQuery(queryString).execute(params);
assertEquals(5, results.size());
}
use of org.apache.geode.cache.query.SelectResults in project geode by apache.
the class LimitClauseJUnitTest method testNotLimitAtIndexLevelForMultiSingleIndexOrClauseUsage.
@Test
public void testNotLimitAtIndexLevelForMultiSingleIndexOrClauseUsage() throws Exception {
// try {
Query query;
SelectResults result;
Region region = CacheUtils.createRegion("portfolios1", Portfolio.class);
for (int i = 15; i > 0; i--) {
Portfolio p = new Portfolio(i);
// CacheUtils.log(p);
p.positions.clear();
p.positions.put("IBM", new Position("IBM", i));
region.put("KEY" + i, p);
}
String queryString = "<trace>SELECT * FROM /portfolios1 P, P.positions.values POS WHERE P.ID < 4 OR P.ID > 11 AND P.ID != 13 LIMIT 5";
query = qs.newQuery(queryString);
SelectResults resultsNoIndex = (SelectResults) query.execute();
// Create Index on ID and secId
Index secIndex = qs.createIndex("secIdIndex", "pos.secId", "/portfolios1 p, p.positions.values pos");
Index idIndex = qs.createIndex("idIndex", IndexType.FUNCTIONAL, "P.ID", "/portfolios1 P, P.positions.values pos");
// assertNotNull(secIndex);
assertNotNull(idIndex);
SelectResults resultsWithIndex = (SelectResults) query.execute();
assertEquals(resultsNoIndex.size(), resultsWithIndex.size());
}
use of org.apache.geode.cache.query.SelectResults in project geode by apache.
the class LimitClauseJUnitTest method helpTestIndexForQuery.
/*
* helper method to test against a compact range index
*
* @param query
*
* @throws Exception
*/
private SelectResults helpTestIndexForQuery(String query, String indexedExpression, String regionPath, Object[] params) throws Exception {
QueryService qs = CacheUtils.getQueryService();
MyQueryObserverAdapter observer = new MyQueryObserverAdapter();
QueryObserverHolder.setInstance(observer);
SelectResults nonIndexedResults = (SelectResults) qs.newQuery(query).execute(params);
assertFalse(observer.indexUsed);
qs.createIndex("newIndex", indexedExpression, regionPath);
SelectResults indexedResults = (SelectResults) qs.newQuery(query).execute(params);
assertEquals(nonIndexedResults.size(), indexedResults.size());
assertTrue(observer.indexUsed);
return indexedResults;
}
use of org.apache.geode.cache.query.SelectResults in project geode by apache.
the class LimitClauseJUnitTest method testLimitDistinctIterEvaluatedQueryForResultBagWithProjectionAttributeWithIndex.
/**
* Tests the limit functionality for Iter evaluated query with distinct clause This tests the
* basic limit functionality for ResultBag wrapped by a SelectResults . This test contains
* projection attributes. Since the attribute is unique every time, the limit will be satisfied
* with first 5 iterations
*
* Tests ResultBag behaviour
*
*/
@Test
public void testLimitDistinctIterEvaluatedQueryForResultBagWithProjectionAttributeWithIndex() {
try {
Query query;
SelectResults result;
String queryString = "SELECT DISTINCT pf.ID FROM /portfolios pf WHERE pf.ID > 0 limit 5";
query = qs.newQuery(queryString);
MyQueryObserverAdapter observer = new MyQueryObserverAdapter();
QueryObserver old = QueryObserverHolder.setInstance(observer);
Index index = qs.createIndex("idIndex", "pf.ID", "/portfolios pf");
assertNotNull(index);
result = (SelectResults) query.execute();
assertTrue(result instanceof SelectResults);
assertEquals(5, result.size());
SelectResults wrapper = (SelectResults) result;
assertEquals(5, wrapper.asSet().size());
assertTrue(observer.limitAppliedAtIndex);
} catch (Exception e) {
CacheUtils.getLogger().error(e);
fail(e.toString());
} finally {
QueryObserverHolder.setInstance(new QueryObserverAdapter());
}
}
Aggregations