use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.
the class CustomerOptimizationsJUnitTest method testProjectionEvaluationDuringIndexResultsWithComplexWhereClause_UNIMPLEMENTED_1.
@Ignore
@Test
public void testProjectionEvaluationDuringIndexResultsWithComplexWhereClause_UNIMPLEMENTED_1() 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) OR (p.ID IN SET( 20,30,110,120) AND p.createTime > 7l)" };
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 = { true };
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(expectedIntersectionCallback[i], actualIntersectionCallback[i]);
assertEquals(expectedProjectionCallabck[i], actualProjectionCallback[i]);
}
CacheUtils.compareResultsOfWithAndWithoutIndex(sr, this);
}
use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.
the class CountStarJUnitTest method testCountStarWithDuplicateValues.
@Test
public void testCountStarWithDuplicateValues() throws Exception {
Cache cache = CacheUtils.getCache();
createLocalRegion();
assertNotNull(cache.getRegion(regionName));
assertEquals(numElem, cache.getRegion(regionName).size());
HashMap<String, Integer> countStarDistinctQueries = new HashMap<String, Integer>();
countStarDistinctQueries.put("select distinct COUNT(*) from /" + regionName, 100);
countStarDistinctQueries.put("select distinct COUNT(*) from /" + regionName + " where ID > 0", 100);
countStarDistinctQueries.put("select distinct COUNT(*) from /" + regionName + " where ID < 0", 0);
countStarDistinctQueries.put("select distinct COUNT(*) from /" + regionName + " where ID > 0 LIMIT 50", 50);
countStarDistinctQueries.put("select distinct COUNT(*) from /" + regionName + " where ID > 0 AND status='active'", 50);
countStarDistinctQueries.put("select distinct COUNT(*) from /" + regionName + " where ID > 0 OR status='active'", 100);
countStarDistinctQueries.put("select distinct COUNT(*) from /" + regionName + " where ID > 0 AND status LIKE 'act%'", 50);
countStarDistinctQueries.put("select distinct COUNT(*) from /" + regionName + " where ID > 0 OR status LIKE 'ina%'", 100);
countStarDistinctQueries.put("select distinct COUNT(*) from /" + regionName + " where ID IN SET(1, 2, 3, 4, 5)", 5);
countStarDistinctQueries.put("select distinct COUNT(*) from /" + regionName + " where NOT (ID > 5)", 5);
QueryService queryService = cache.getQueryService();
// Run queries
Query query1 = null;
Query query2 = null;
// Populate the region.
Region region = cache.getRegion(regionName);
for (int i = 1; i <= 100; i++) {
region.put(i, new Portfolio(i, i));
}
// Duplicate values
for (int i = 1; i <= 100; i++) {
region.put(i + 100, new Portfolio(i, i));
}
// Without Indexes
for (String queryStr : countStarDistinctQueries.keySet()) {
query1 = queryService.newQuery(queryStr);
query2 = queryService.newQuery(queryStr.replace("COUNT(*)", "*"));
SelectResults result1 = (SelectResults) query1.execute();
SelectResults result2 = (SelectResults) query2.execute();
assertEquals(queryStr, 1, result1.size());
assertTrue(result1.asList().get(0) instanceof Integer);
int count = ((Integer) result1.asList().get(0)).intValue();
// Also verify with size of result2 to count
assertEquals("COUNT(*) query result is wrong for query: " + queryStr, result2.size(), count);
// assertIndexDetailsEquals("Query: "+ queryStr,
// countStarDistinctQueries.get(queryStr).intValue(), count);
}
// CReate Index on status and ID
queryService.createIndex("sampleIndex-1", IndexType.FUNCTIONAL, "p.ID", "/" + regionName + " p");
queryService.createIndex("sampleIndex-2", IndexType.FUNCTIONAL, "p.status", "/" + regionName + " p");
queryService.createIndex("sampleIndex-3", IndexType.FUNCTIONAL, "pos.secId", "/" + regionName + " p, p.positions.values pos");
// Verify Index Creation
assertNotNull(queryService.getIndex(region, "sampleIndex-1"));
assertNotNull(queryService.getIndex(region, "sampleIndex-2"));
assertEquals(3, queryService.getIndexes().size());
// Without Indexes
for (String queryStr : countStarDistinctQueries.keySet()) {
query1 = queryService.newQuery(queryStr);
query2 = queryService.newQuery(queryStr.replace("COUNT(*)", "*"));
SelectResults result1 = (SelectResults) query1.execute();
SelectResults result2 = (SelectResults) query2.execute();
assertEquals(queryStr, 1, result1.size());
assertTrue(result1.asList().get(0) instanceof Integer);
int count = ((Integer) result1.asList().get(0)).intValue();
// Also verify with size of result2 to count
assertEquals("COUNT(*) query result is wrong for query: " + queryStr, result2.size(), count);
// assertIndexDetailsEquals("Query: "+ queryStr,
// countStarDistinctQueries.get(queryStr).intValue(), count);
}
}
use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.
the class ComparisonOperatorsJUnitTest method testCompareWithInt.
@Test
public void testCompareWithInt() throws Exception {
String var = "ID";
int value = 2;
QueryService qs = CacheUtils.getQueryService();
for (int i = 0; i < operators.length; i++) {
Query query = qs.newQuery("SELECT DISTINCT * FROM /Portfolios where " + var + operators[i] + value);
Object result = query.execute();
if (result instanceof Collection) {
Iterator iter = ((Collection) result).iterator();
while (iter.hasNext()) {
boolean isPassed = false;
Portfolio p = (Portfolio) iter.next();
switch(i) {
case 0:
isPassed = (p.getID() == value);
break;
case 1:
isPassed = (p.getID() != value);
break;
case 2:
isPassed = (p.getID() != value);
break;
case 3:
isPassed = (p.getID() < value);
break;
case 4:
isPassed = (p.getID() <= value);
break;
case 5:
isPassed = (p.getID() > value);
break;
case 6:
isPassed = (p.getID() >= value);
break;
}
if (!isPassed)
fail(this.getName() + " failed for operator " + operators[i]);
}
} else {
fail(this.getName() + " failed for operator " + operators[i]);
}
}
}
use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.
the class ConstantsJUnitTest method setUp.
@Before
public void setUp() throws java.lang.Exception {
CacheUtils.startCache();
Region region = CacheUtils.createRegion("Portfolios", Portfolio.class);
region.put("0", new Portfolio(0));
region.put("1", new Portfolio(1));
region.put("2", new Portfolio(2));
region.put("3", new Portfolio(3));
}
use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.
the class QRegionInterfaceJUnitTest method testGetValues.
@Test
public void testGetValues() throws Exception {
Query query = CacheUtils.getQueryService().newQuery("select distinct * from /Portfolios.values where ID = 1");
Collection result = (Collection) query.execute();
Portfolio p = (Portfolio) result.iterator().next();
if (p.getID() != 1)
fail(query.getQueryString());
}
Aggregations