use of org.apache.geode.cache.query.SelectResults in project geode by apache.
the class LimitClauseJUnitTest method testLimitDistinctIterEvaluatedQueryWithDuplicatesInIterationWithProjectionAttributeForResultBagWithIndex.
/**
* Tests the limit functionality for Iter evaluated query with distinct clause This tests the
* basic limit functionality for ResultBag wrapped by a SelectResults if the iteration included
* duplicate elements. If the distinct clause is present then duplicate elements even if
* satisfying the where clause should not be considered as part as distinct will eliminate them.
* This test validates the above behaviour if projection sttribute is present and the projection
* attribute may be duplicate
*
* Tests ResultBag behaviour
*/
@Test
public void testLimitDistinctIterEvaluatedQueryWithDuplicatesInIterationWithProjectionAttributeForResultBagWithIndex() {
try {
Region region1 = CacheUtils.createRegion("portfolios1", Portfolio.class);
// Add 5 pairs of same Object starting from 11 to 20
for (int i = 11; i < 21; ) {
region1.put(Integer.toString(i), new Portfolio(i));
region1.put(Integer.toString(i + 1), new Portfolio(i));
i += 2;
}
Query query;
SelectResults result;
MyQueryObserverAdapter observer = new MyQueryObserverAdapter();
QueryObserver old = QueryObserverHolder.setInstance(observer);
Index index = qs.createIndex("idIndex", "pf.ID", "/portfolios1 pf");
assertNotNull(index);
String queryString = "SELECT DISTINCT pf.ID FROM /portfolios1 pf WHERE pf.ID > 10 limit 5";
query = qs.newQuery(queryString);
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());
}
}
use of org.apache.geode.cache.query.SelectResults in project geode by apache.
the class LimitClauseJUnitTest method testLimitDistinctIterEvaluatedQueryWithDuplicatesInIterationForResultBagWithIndex.
/**
* Tests the limit functionality for Iter evaluated query with distinct clause This tests the
* basic limit functionality for ResultBag wrapped by a SelectResults if the iteration included
* duplicate elements. If the distinct clause is present then duplicate elements even if
* satisfying the where clause should not be considered as part of the resultset as distinct will
* eliminate them
*
* Tests ResultBag behaviour
*/
@Test
public void testLimitDistinctIterEvaluatedQueryWithDuplicatesInIterationForResultBagWithIndex() {
try {
Region region1 = CacheUtils.createRegion("portfolios1", Portfolio.class);
// Add 5 pairs of same Object starting from 11 to 20
for (int i = 11; i < 21; ) {
region1.put(Integer.toString(i), new Portfolio(i));
region1.put(Integer.toString(i + 1), new Portfolio(i));
i += 2;
}
Query query;
SelectResults result;
MyQueryObserverAdapter observer = new MyQueryObserverAdapter();
QueryObserver old = QueryObserverHolder.setInstance(observer);
Index index = qs.createIndex("idIndex", "pf.ID", "/portfolios1 pf");
assertNotNull(index);
String queryString = "SELECT DISTINCT * FROM /portfolios1 pf WHERE pf.ID > 10 limit 5";
query = qs.newQuery(queryString);
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());
}
}
use of org.apache.geode.cache.query.SelectResults in project geode by apache.
the class LimitClauseJUnitTest method testLimitOnJunctionWithCompactRangeIndexedFieldWithAndClauseJunctionCompactRangeIndexedField.
// This is one where we do not apply limit at index but old code does
@Test
public void testLimitOnJunctionWithCompactRangeIndexedFieldWithAndClauseJunctionCompactRangeIndexedField() 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 < 21; 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);
}
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 = "SELECT * FROM /portfolios1 P WHERE P.ID > 9 AND P.ID < 20 AND P.shortID > 1 AND P.shortID < 3 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 testLimitNonDistinctQueryWithTwoRangeCondTwoIndex.
@Test
public void testLimitNonDistinctQueryWithTwoRangeCondTwoIndex() {
try {
Query query;
SelectResults result;
Region region = CacheUtils.createRegion("portfolios1", Portfolio.class);
for (int i = 1; i < 100; i++) {
Portfolio p = new Portfolio(i);
if (i < 50)
p.status = "active";
region.put(Integer.toString(i), p);
}
MyQueryObserverAdapter observer = new MyQueryObserverAdapter();
QueryObserver old = QueryObserverHolder.setInstance(observer);
// Create Index on ID
Index index = qs.createIndex("idIndex", "ID", "/portfolios1");
assertNotNull(index);
index = qs.createIndex("statusIndex", "status", "/portfolios1");
assertNotNull(index);
String[] queryString = new String[] { "select * from /portfolios1 where (status > 'inactiva' AND status < 'xyz') AND (ID > 70 AND ID < 100) limit 10", "select * from /portfolios1 where (status > 'inactiva' AND status < 'xyz') AND (ID > 60 AND ID < 100) AND (\"type\"='type1' OR \"type\"='type2') limit 10" };
for (String qstr : queryString) {
query = qs.newQuery(qstr);
result = (SelectResults) query.execute();
assertEquals(10, result.size());
assertFalse(observer.limitAppliedAtIndex);
}
} catch (Exception e) {
CacheUtils.getLogger().error(e);
fail(e.toString());
} finally {
QueryObserverHolder.setInstance(new QueryObserverAdapter());
}
}
use of org.apache.geode.cache.query.SelectResults in project geode by apache.
the class LimitClauseJUnitTest method testLimitWithParameterForNonAndIndexedQuery.
// Test to see if bind argument limit is applied correctly for indexed and non indexed
// queries.
@Test
public void testLimitWithParameterForNonAndIndexedQuery() throws Exception {
String queryString = "SELECT * from /portfolios1 WHERE shortID = $1 LIMIT $2 ";
SelectResults result;
Region region = CacheUtils.createRegion("portfolios1", Portfolio.class);
for (int i = 0; i < 100; i++) {
Portfolio p = new Portfolio(i);
p.shortID = Integer.valueOf(i % 10).shortValue();
region.put(i, p);
}
Object[] params = new Object[2];
params[0] = 5;
int[] limits = { 1, 5, 0, 10 };
for (int i = 0; i < limits.length; i++) {
params[1] = limits[i];
SelectResults results = helpTestIndexForQuery(queryString, "shortID", "/portfolios1", params);
assertEquals(limits[i], results.size());
// clear out indexes for next query.
qs.removeIndexes();
}
}
Aggregations