use of org.apache.geode.cache.query.internal.QueryObserverAdapter in project geode by apache.
the class LimitClauseJUnitTest method testLimitDistinctIterEvaluatedQueryForResultBagWithIndex.
// Asif:Test the index results behaviour also
// Shobhit: Testing the Limit behavior now with indexes for all above test cases.
/**
* Tests the limit functionality for Iter evaluated query with distinct clause This tests the
* basic limit functionality for ResultBag wrapped by a SelectResults
*
* Tests ResultBag behaviour
*/
@Test
public void testLimitDistinctIterEvaluatedQueryForResultBagWithIndex() {
try {
Query query;
SelectResults result;
String queryString = "SELECT DISTINCT * 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());
}
}
use of org.apache.geode.cache.query.internal.QueryObserverAdapter in project geode by apache.
the class LimitClauseJUnitTest method testLimitDistinctIterEvaluatedQueryForStructBagWithIndex.
/**
* Tests the limit functionality for Iter evaluated query with distinct clause This tests the
* basic limit functionality for StructBag wrapped by a SelectResults
*
* Tests StructBag behaviour
*/
@Test
public void testLimitDistinctIterEvaluatedQueryForStructBagWithIndex() {
try {
Query query;
SelectResults result;
String queryString = "SELECT DISTINCT * FROM /portfolios pf, pf.positions.values 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, pf.positions.values");
assertNotNull(index);
result = (SelectResults) query.execute();
assertTrue(result instanceof SelectResults);
assertEquals(5, result.size());
SelectResults wrapper = (SelectResults) result;
assertEquals(5, wrapper.asSet().size());
// currently this is false because we disabled limit application at the range index level
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.internal.QueryObserverAdapter in project geode by apache.
the class LimitClauseJUnitTest method testLimitQueryForStructBagWithRangeIndex.
/**
* Tests the limit functionality for Iter evaluated query with distinct clause This tests the
* basic limit functionality for StructBag wrapped by a SelectResults
*
* Tests StructBag behaviour
*/
@Ignore
@Test
public void testLimitQueryForStructBagWithRangeIndex() {
try {
Query query;
SelectResults result;
String queryString = "SELECT * FROM /portfolios pf, pf.positions.values pos WHERE pf.ID > 1 AND pos.secId = 'GOOG' limit 1";
query = qs.newQuery(queryString);
MyQueryObserverAdapter observer = new MyQueryObserverAdapter();
QueryObserver old = QueryObserverHolder.setInstance(observer);
Index index = qs.createIndex("idIndex", "pf.ID", "/portfolios pf");
Index posindex = qs.createIndex("posIndex", "pos.secId", "/portfolios pf, pf.positions.values pos");
assertNotNull(index);
assertNotNull(posindex);
result = (SelectResults) query.execute();
assertEquals(1, 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.internal.QueryObserverAdapter in project geode by apache.
the class LimitClauseJUnitTest method testLimitDistinctIterEvaluatedQueryForStructBag.
/**
* Tests the limit functionality for Iter evaluated query with distinct clause This tests the
* basic limit functionality for StructBag wrapped by a SelectResults
*
* Tests StructBag behaviour
*/
@Test
public void testLimitDistinctIterEvaluatedQueryForStructBag() {
try {
Query query;
SelectResults result;
String queryString = "SELECT DISTINCT * FROM /portfolios pf, pf.positions.values WHERE pf.ID > 0 limit 5";
query = qs.newQuery(queryString);
final int[] num = new int[1];
num[0] = 0;
QueryObserver old = QueryObserverHolder.setInstance(new QueryObserverAdapter() {
public void afterIterationEvaluation(Object result) {
num[0] += 1;
}
});
result = (SelectResults) query.execute();
assertEquals(5, num[0]);
assertTrue(result instanceof SelectResults);
assertEquals(5, result.size());
SelectResults wrapper = (SelectResults) result;
assertEquals(5, wrapper.asSet().size());
} catch (Exception e) {
CacheUtils.getLogger().error(e);
fail(e.toString());
} finally {
QueryObserverHolder.setInstance(new QueryObserverAdapter());
}
}
use of org.apache.geode.cache.query.internal.QueryObserverAdapter in project geode by apache.
the class LimitClauseJUnitTest method testLimitDistinctIterEvaluatedQueryForResultBagWithProjectionAttribute.
/**
* 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 testLimitDistinctIterEvaluatedQueryForResultBagWithProjectionAttribute() {
try {
Query query;
SelectResults result;
String queryString = "SELECT DISTINCT pf.ID FROM /portfolios pf WHERE pf.ID > 0 limit 5";
query = qs.newQuery(queryString);
final int[] num = new int[1];
num[0] = 0;
QueryObserver old = QueryObserverHolder.setInstance(new QueryObserverAdapter() {
public void afterIterationEvaluation(Object result) {
num[0] += 1;
}
});
result = (SelectResults) query.execute();
assertEquals(5, num[0]);
assertTrue(result instanceof SelectResults);
assertEquals(5, result.size());
SelectResults wrapper = (SelectResults) result;
assertEquals(5, wrapper.asSet().size());
} catch (Exception e) {
CacheUtils.getLogger().error(e);
fail(e.toString());
} finally {
QueryObserverHolder.setInstance(new QueryObserverAdapter());
}
}
Aggregations