use of org.apache.geode.cache.query.internal.types.ObjectTypeImpl in project geode by apache.
the class CustomerOptimizationsJUnitTest method testProjectionEvaluationDuringIndexResults_UNIMPLEMENTED.
@Ignore
@Test
public void testProjectionEvaluationDuringIndexResults_UNIMPLEMENTED() throws QueryException {
QueryService qs = CacheUtils.getQueryService();
String[] queries = new String[] { "select p.status from /pos p, p.positions pos where p.ID > 0 ", "select p.status as sts, p as pos from /pos p where ( p.ID IN SET( 0,1,2,3) and p.createTime > 0L) OR (p.ID IN SET( 2,3) and p.createTime > 5L)", "select p.status as sts, p as pos from /pos p where p.ID IN SET( 0,1,2,3) and p.createTime > 0L" };
SelectResults[][] sr = new SelectResults[queries.length][2];
for (int i = 0; i < queries.length; ++i) {
Query q = qs.newQuery(queries[i]);
sr[i][0] = (SelectResults) q.execute();
}
qs.createIndex("PortFolioID", IndexType.FUNCTIONAL, "ID", "/pos");
qs.createIndex("CreateTime", IndexType.FUNCTIONAL, "createTime", "/pos");
ObjectType[] expectedTypes = new ObjectType[] { new ObjectTypeImpl(String.class), new StructTypeImpl(new String[] { "sts", "pos" }, new ObjectType[] { new ObjectTypeImpl(String.class), new ObjectTypeImpl(Portfolio.class) }), new StructTypeImpl(new String[] { "sts", "pos" }, new ObjectType[] { new ObjectTypeImpl(String.class), new ObjectTypeImpl(Portfolio.class) }) };
final boolean[] expectedCallback = { false, false, false };
final boolean[] actualCallback = new boolean[queries.length];
QueryObserverHolder.setInstance(new QueryObserverAdapter() {
private int i = 0;
public void beforeApplyingProjectionOnFilterEvaluatedResults(Object preProjectionApplied) {
actualCallback[i] = true;
}
public void afterQueryEvaluation(Object result) {
++i;
}
});
for (int i = 0; i < queries.length; ++i) {
Query q = qs.newQuery(queries[i]);
sr[i][1] = (SelectResults) q.execute();
assertEquals(expectedCallback[i], actualCallback[i]);
assertEquals(expectedTypes[i], sr[i][1].getCollectionType().getElementType());
}
CacheUtils.compareResultsOfWithAndWithoutIndex(sr, this);
}
use of org.apache.geode.cache.query.internal.types.ObjectTypeImpl in project geode by apache.
the class CustomerOptimizationsJUnitTest method testInAndEqualityCombination.
@Test
public void testInAndEqualityCombination() throws Exception {
QueryService qs = CacheUtils.getQueryService();
Region rgn = CacheUtils.getRegion("/pos");
for (int i = 100; i < 200; ++i) {
Portfolio pf = new Portfolio(i);
pf.setCreateTime(10l);
rgn.put("" + i, pf);
}
String[] queries = new String[] { "select distinct p.status from /pos p where p.ID = 11 AND p.createTime IN SET( 10L) " };
SelectResults[][] sr = new SelectResults[queries.length][2];
for (int i = 0; i < queries.length; ++i) {
Query q = qs.newQuery(queries[i]);
sr[i][0] = (SelectResults) q.execute();
}
qs.createIndex("PortFolioID", IndexType.FUNCTIONAL, "ID", "/pos");
qs.createIndex("CreateTime", IndexType.FUNCTIONAL, "createTime", "/pos");
qs.createIndex("Status", IndexType.FUNCTIONAL, "status", "/pos");
qs.createIndex("Type", IndexType.FUNCTIONAL, "\"type\"", "/pos");
final boolean[] expectedIndexUsed = new boolean[] { true };
final boolean[] actualIndexUsed = new boolean[] { false };
final boolean[] expectedProjectionCallabck = new boolean[] { false };
final boolean[] actualProjectionCallback = new boolean[] { false };
final boolean[] expectedUnionCallback = { false };
final boolean[] actualUnionCallback = new boolean[queries.length];
final List indexesUsed = new ArrayList();
final boolean[] expectedIntersectionCallback = { false };
final boolean[] actualIntersectionCallback = new boolean[queries.length];
ObjectType[] expectedTypes = new ObjectType[] { new ObjectTypeImpl(String.class) };
QueryObserverHolder.setInstance(new QueryObserverAdapter() {
private int i = 0;
public void invokedQueryUtilsUnion(SelectResults r1, SelectResults r2) {
actualUnionCallback[i] = true;
}
public void invokedQueryUtilsIntersection(SelectResults r1, SelectResults r2) {
actualIntersectionCallback[i] = true;
}
public void beforeIndexLookup(Index index, int oper, Object key) {
actualIndexUsed[i] = true;
indexesUsed.add(index);
}
public void beforeApplyingProjectionOnFilterEvaluatedResults(Object preProjectionApplied) {
actualProjectionCallback[i] = true;
}
public void afterQueryEvaluation(Object result) {
++i;
}
});
for (int i = 0; i < queries.length; ++i) {
Query q = qs.newQuery(queries[i]);
sr[i][1] = (SelectResults) q.execute();
assertEquals(expectedUnionCallback[i], actualUnionCallback[i]);
assertEquals(expectedTypes[i], sr[i][1].getCollectionType().getElementType());
assertEquals(expectedIndexUsed[i], actualIndexUsed[i]);
assertEquals(expectedIntersectionCallback[i], actualIntersectionCallback[i]);
assertEquals(expectedProjectionCallabck[i], actualProjectionCallback[i]);
}
assertEquals(indexesUsed.size(), 1);
assertEquals(((Index) indexesUsed.iterator().next()).getName(), "PortFolioID");
CacheUtils.compareResultsOfWithAndWithoutIndex(sr, this);
}
use of org.apache.geode.cache.query.internal.types.ObjectTypeImpl in project geode by apache.
the class ResultsCollectionWrapperLimitJUnitTest method testToArray.
@Test
public void testToArray() {
List ordered = new ArrayList();
for (int i = 1; i < 11; ++i) {
ordered.add(new Integer(i));
}
ResultsCollectionWrapper wrapper = new ResultsCollectionWrapper(new ObjectTypeImpl(Object.class), ordered, 5);
Object[] toArray = wrapper.toArray();
assertEquals(wrapper.size(), toArray.length);
Iterator itr = wrapper.iterator();
for (int i = 1; i < 6; ++i) {
assertEquals(toArray[i - 1], itr.next());
}
assertFalse(itr.hasNext());
}
use of org.apache.geode.cache.query.internal.types.ObjectTypeImpl in project geode by apache.
the class ResultsCollectionWrapperLimitJUnitTest method testLimitIterator.
@Test
public void testLimitIterator() {
Collection ordered = new TreeSet();
for (int i = 1; i < 11; ++i) {
ordered.add(new Integer(i));
}
ResultsCollectionWrapper wrapper = new ResultsCollectionWrapper(new ObjectTypeImpl(Object.class), ordered, 5);
Iterator itr = wrapper.iterator();
assertEquals(5, wrapper.size());
while (itr.hasNext()) {
itr.next();
itr.remove();
}
assertEquals(0, wrapper.size());
assertFalse(wrapper.iterator().hasNext());
try {
wrapper.iterator().next();
fail("Should have failed as the wrapper size is 0");
} catch (NoSuchElementException nsee) {
// Ok
}
assertTrue(wrapper.isEmpty());
}
use of org.apache.geode.cache.query.internal.types.ObjectTypeImpl in project geode by apache.
the class StructBagLimitBehaviourJUnitTest method getBagObject.
public ResultsBag getBagObject(Class clazz) {
ObjectType[] types = new ObjectType[] { new ObjectTypeImpl(clazz), new ObjectTypeImpl(clazz) };
StructType type = new StructTypeImpl(new String[] { "field1", "field2" }, types);
return new StructBag(type, null);
}
Aggregations