use of org.apache.geode.cache.query.types.ObjectType in project geode by apache.
the class ResultsBagLimitBehaviourJUnitTest method testAddAndGetOccurence.
// Internal method AddAndGetOccurence used for iter evaluating
// only up till the limit
@Test
public void testAddAndGetOccurence() {
ResultsBag bag = getBagObject(String.class);
bag = getBagObject(String.class);
ObjectType elementType = bag.getCollectionType().getElementType();
assertEquals(1, bag.addAndGetOccurence(elementType instanceof StructType ? ((Struct) wrap("one", elementType)).getFieldValues() : wrap("one", elementType)));
bag.add(wrap("two", elementType));
assertEquals(2, bag.addAndGetOccurence(elementType instanceof StructType ? ((Struct) wrap("two", elementType)).getFieldValues() : wrap("two", bag.getCollectionType().getElementType())));
bag.add(wrap("three", bag.getCollectionType().getElementType()));
bag.add(wrap("three", bag.getCollectionType().getElementType()));
assertEquals(3, bag.addAndGetOccurence(elementType instanceof StructType ? ((Struct) wrap("three", elementType)).getFieldValues() : wrap("three", elementType)));
bag.add(wrap(null, bag.getCollectionType().getElementType()));
bag.add(wrap(null, bag.getCollectionType().getElementType()));
assertEquals(3, bag.addAndGetOccurence(elementType instanceof StructType ? ((Struct) wrap(null, elementType)).getFieldValues() : wrap(null, elementType)));
}
use of org.apache.geode.cache.query.types.ObjectType in project geode by apache.
the class StructSetJUnitTest method testIntersectionAndRetainAll.
@Test
public void testIntersectionAndRetainAll() {
String[] names = { "p", "pos" };
ObjectType[] types = { TypeUtils.OBJECT_TYPE, TypeUtils.OBJECT_TYPE };
StructTypeImpl sType = new StructTypeImpl(names, types);
StructSet set1 = new StructSet(sType);
Portfolio ptf = new Portfolio(0);
Iterator pIter = ptf.positions.values().iterator();
while (pIter.hasNext()) {
Object[] arr = { ptf, pIter.next() };
set1.addFieldValues(arr);
}
StructSet set2 = new StructSet(sType);
pIter = ptf.positions.values().iterator();
while (pIter.hasNext()) {
Object[] arr = { ptf, pIter.next() };
set2.addFieldValues(arr);
}
assertEquals(2, set1.size());
assertEquals(2, set2.size());
// tests that retainAll does not modify set1
assertTrue(!set1.retainAll(set2));
assertEquals(2, set1.size());
assertEquals(2, set2.size());
SelectResults sr = QueryUtils.intersection(set1, set2, null);
assertEquals(2, sr.size());
}
use of org.apache.geode.cache.query.types.ObjectType in project geode by apache.
the class QueryUsingPoolDUnitTest method compareQueryResultsWithoutAndWithIndexes.
/**
* Creates a new instance of StructSetOrResultsSet
*/
private void compareQueryResultsWithoutAndWithIndexes(Object[][] r, int len) {
Set set1 = null;
Set set2 = null;
Iterator itert1 = null;
Iterator itert2 = null;
ObjectType type1, type2;
for (int j = 0; j < len; j++) {
type1 = ((SelectResults) r[j][0]).getCollectionType().getElementType();
type2 = ((SelectResults) r[j][1]).getCollectionType().getElementType();
if ((type1.getClass().getName()).equals(type2.getClass().getName())) {
logger.info("Both SelectResults are of the same Type i.e.--> " + ((SelectResults) r[j][0]).getCollectionType().getElementType());
} else {
logger.info("Classes are : " + type1.getClass().getName() + " " + type2.getClass().getName());
fail("FAILED:Select result Type is different in both the cases");
}
if (((SelectResults) r[j][0]).size() == ((SelectResults) r[j][1]).size()) {
logger.info("Both SelectResults are of Same Size i.e. Size= " + ((SelectResults) r[j][1]).size());
} else {
fail("FAILED:SelectResults size is different in both the cases. Size1=" + ((SelectResults) r[j][0]).size() + " Size2 = " + ((SelectResults) r[j][1]).size());
}
set2 = (((SelectResults) r[j][1]).asSet());
set1 = (((SelectResults) r[j][0]).asSet());
logger.info(" SIZE1 = " + set1.size() + " SIZE2 = " + set2.size());
// boolean pass = true;
itert1 = set1.iterator();
while (itert1.hasNext()) {
Object p1 = itert1.next();
itert2 = set2.iterator();
boolean exactMatch = false;
while (itert2.hasNext()) {
logger.info("### Comparing results..");
Object p2 = itert2.next();
if (p1 instanceof Struct) {
logger.info("ITS a Set");
Object[] values1 = ((Struct) p1).getFieldValues();
Object[] values2 = ((Struct) p2).getFieldValues();
assertEquals(values1.length, values2.length);
boolean elementEqual = true;
for (int i = 0; i < values1.length; ++i) {
elementEqual = elementEqual && ((values1[i] == values2[i]) || values1[i].equals(values2[i]));
}
exactMatch = elementEqual;
} else {
logger.info("Not a Set p2:" + p2 + " p1: " + p1);
if (p2 instanceof TestObject) {
logger.info("An instance of TestObject");
exactMatch = p2.equals(p1);
} else {
logger.info("Not an instance of TestObject" + p2.getClass().getCanonicalName());
exactMatch = p2.equals(p1);
}
}
if (exactMatch) {
logger.info("Exact MATCH");
break;
}
}
if (!exactMatch) {
logger.info("NOT A MATCH");
fail("Atleast one element in the pair of SelectResults supposedly identical, is not equal ");
}
}
logger.info("### Done Comparing results..");
}
}
use of org.apache.geode.cache.query.types.ObjectType in project geode by apache.
the class CustomerOptimizationsJUnitTest method testUnionDuringIndexEvaluationWithMultipleFilters.
@Test
public void testUnionDuringIndexEvaluationWithMultipleFilters() throws QueryException {
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 p.status as sts, p as pos from /pos p where p.ID IN SET( 0,1,2,3,4,5,101,102,103,104,105) AND p.createTime > 9l" };
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");
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 boolean[] expectedIntersectionCallback = { false };
final boolean[] actualIntersectionCallback = new boolean[queries.length];
ObjectType[] expectedTypes = new ObjectType[] { new StructTypeImpl(new String[] { "sts", "pos" }, new ObjectType[] { new ObjectTypeImpl(String.class), new ObjectTypeImpl(Portfolio.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;
}
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(expectedProjectionCallabck[i], actualProjectionCallback[i]);
assertEquals(expectedIntersectionCallback[i], actualIntersectionCallback[i]);
}
CacheUtils.compareResultsOfWithAndWithoutIndex(sr, this);
}
use of org.apache.geode.cache.query.types.ObjectType in project geode by apache.
the class CustomerOptimizationsJUnitTest method testNestedJunction.
@Test
public void testNestedJunction() throws Exception {
QueryService qs = CacheUtils.getQueryService();
Region rgn = CacheUtils.getRegion("/pos");
for (int i = 100; i < 10000; ++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.createTime IN SET( 10l ) OR p.status IN SET( 'active') )AND p.ID > 0 " };
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();
}
final List indexUsed = new ArrayList();
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[] { true };
final boolean[] actualProjectionCallback = new boolean[] { false };
final boolean[] expectedUnionCallback = { false };
final boolean[] actualUnionCallback = new boolean[queries.length];
final boolean[] expectedIntersectionCallback = { true };
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;
indexUsed.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(indexUsed.size(), 3);
CacheUtils.compareResultsOfWithAndWithoutIndex(sr, this);
}
Aggregations