use of org.apache.geode.cache.query.functional.StructSetOrResultsSet in project geode by apache.
the class IndexHintJUnitTest method testIndexWithCompiledInSet.
@Test
public void testIndexWithCompiledInSet() throws Exception {
createRegion();
populateData(1000);
// create index
createIndex("IDIndex", "p.ID", "/Portfolios p");
createIndex("SecIndex", "p.status", "/Portfolios p");
createIndex("DescriptionIndex", "p.description", "/Portfolios p");
// set observer
QueryObserverImpl observer = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer);
// execute query
SelectResults[][] results = new SelectResults[1][2];
QueryService qs = CacheUtils.getQueryService();
Query query = qs.newQuery("<hint 'IDIndex'>select * from /Portfolios p where p.ID > 10 and p.ID < 200 and p.status = 'inactive' and p.description IN SET ('XXXX', 'XXXY')");
results[0][0] = (SelectResults) query.execute();
// verify index usage
assertTrue(observer.wasIndexUsed("IDIndex"));
observer.reset();
query = qs.newQuery("<hint 'SecIndex'>select * from /Portfolios p where p.ID > 10 and p.ID < 200 and p.status = 'inactive' and p.description IN SET ('XXXX', 'XXXY')");
results[0][1] = (SelectResults) query.execute();
// verify index usage
assertTrue(observer.wasIndexUsed("SecIndex"));
observer.reset();
// Compare results with the first two index queries
StructSetOrResultsSet ssOrrs = new StructSetOrResultsSet();
assertEquals(95, results[0][1].size());
// Not really with and without index but we can use this method to verify they are the same
// results
// regardless of which index used
ssOrrs.CompareQueryResultsWithoutAndWithIndexes(results, 1, new String[] { "<query with hints>" });
query = qs.newQuery("<hint 'DescriptionIndex'>select * from /Portfolios p where p.ID > 10 and p.ID < 200 and p.status = 'inactive' and p.description IN SET ('XXXX', 'XXXY')");
results[0][1] = (SelectResults) query.execute();
// verify index usage
assertTrue(observer.wasIndexUsed("DescriptionIndex"));
// Compare results with the final index result
ssOrrs.CompareQueryResultsWithoutAndWithIndexes(results, 1, new String[] { "<query with hints>" });
}
use of org.apache.geode.cache.query.functional.StructSetOrResultsSet in project geode by apache.
the class IndexHintJUnitTest method testHintNestedCompiledIn.
// Hints inside of a nested query will trigger index usage for that query only
// Unusable hints should behave the same for nested queries in that they are not used if
// unapplicable to the query
@Test
public void testHintNestedCompiledIn() throws Exception {
createRegion();
populateData(1000);
// create index
createIndex("IDIndex", "p.ID", "/Portfolios p");
createIndex("SecIndex", "p.status", "/Portfolios p");
createIndex("DescriptionIndex", "p.description", "/Portfolios p");
// set observer
QueryObserverImpl observer = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer);
// execute query
SelectResults[][] results = new SelectResults[1][2];
QueryService qs = CacheUtils.getQueryService();
Query query = qs.newQuery("select * from /Portfolios p where p.ID > 10 and p.ID < 200 and p.status = 'inactive' and p.description IN (<hint 'IDIndex', 'SecIndex', 'DescriptionIndex'>select p.description from /Portfolios p where p.ID > 10)");
results[0][0] = (SelectResults) query.execute();
// verify index usage
assertTrue(observer.wasIndexUsed("IDIndex"));
assertTrue(observer.wasIndexUsed("SecIndex"));
// Because it was a hint for the inner query, it was an unuseable hint for that query
assertFalse(observer.wasIndexUsed("DescriptionIndex"));
observer.reset();
// query again with no hints for a "bare" comparison
query = qs.newQuery("select * from /Portfolios p where p.ID > 10 and p.ID < 200 and p.status = 'inactive' and p.description IN (select p.description from /Portfolios p where p.ID > 10)");
results[0][1] = (SelectResults) query.execute();
observer.reset();
// Compare results with the first two index queries
StructSetOrResultsSet ssOrrs = new StructSetOrResultsSet();
assertEquals(95, results[0][1].size());
// Not really with and without index but we can use this method to verify they are the same
// results
// regardless of which index used
ssOrrs.CompareQueryResultsWithoutAndWithIndexes(results, 1, new String[] { "<query with hints>" });
}
use of org.apache.geode.cache.query.functional.StructSetOrResultsSet in project geode by apache.
the class IndexHintJUnitTest method testHintMultiIndexWithCompiledIn.
@Test
public void testHintMultiIndexWithCompiledIn() throws Exception {
createRegion();
populateData(1000);
// create index
createIndex("IDIndex", "p.ID", "/Portfolios p");
createIndex("SecIndex", "p.status", "/Portfolios p");
createIndex("DescriptionIndex", "p.description", "/Portfolios p");
// set observer
QueryObserverImpl observer = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer);
// execute query
SelectResults[][] results = new SelectResults[1][2];
QueryService qs = CacheUtils.getQueryService();
Query query = qs.newQuery("select * from /Portfolios p where p.ID > 10 and p.ID < 200 and p.status = 'inactive' and p.description IN (<hint 'IDIndex', 'SecIndex', 'DescriptionIndex'>select p.description from /Portfolios p where p.ID > 10)");
results[0][0] = (SelectResults) query.execute();
// verify index usage
assertTrue(observer.wasIndexUsed("IDIndex"));
assertTrue(observer.wasIndexUsed("SecIndex"));
observer.reset();
query = qs.newQuery("select * from /Portfolios p where p.ID > 10 and p.ID < 200 and p.status = 'inactive' and p.description IN (select p.description from /Portfolios p where p.ID > 10)");
results[0][1] = (SelectResults) query.execute();
// verify index usage
assertTrue(observer.wasIndexUsed("SecIndex"));
assertFalse(observer.wasIndexUsed("DescriptionIndex"));
// We end up using IDIndex for this case.
observer.reset();
// Compare results with the first two index queries
StructSetOrResultsSet ssOrrs = new StructSetOrResultsSet();
assertEquals(95, results[0][1].size());
// Not really with and without index but we can use this method to verify they are the same
// results
// regardless of which index used
ssOrrs.CompareQueryResultsWithoutAndWithIndexes(results, 1, new String[] { "<query with hints>" });
query = qs.newQuery("select * from /Portfolios p where p.ID > 10 and p.ID < 200 and p.status = 'inactive' and p.description IN (<hint 'DescriptionIndex'>select p.description from /Portfolios p where p.ID > 10)");
results[0][1] = (SelectResults) query.execute();
// verify index usage
assertTrue(observer.wasIndexUsed("DescriptionIndex"));
assertFalse(observer.wasIndexUsed("SecIndex"));
// We end up using IDIndex for this case also
// Compare results with the final index result
ssOrrs.CompareQueryResultsWithoutAndWithIndexes(results, 1, new String[] { "<query with hints>" });
}
use of org.apache.geode.cache.query.functional.StructSetOrResultsSet in project geode by apache.
the class IndexHintJUnitTest method testHintSingleIndexWithCompiledIn.
@Test
public void testHintSingleIndexWithCompiledIn() throws Exception {
createRegion();
populateData(1000);
// create index
createIndex("IDIndex", "p.ID", "/Portfolios p");
createIndex("SecIndex", "p.status", "/Portfolios p");
createIndex("DescriptionIndex", "p.description", "/Portfolios p");
// set observer
QueryObserverImpl observer = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer);
// execute query
SelectResults[][] results = new SelectResults[1][2];
QueryService qs = CacheUtils.getQueryService();
Query query = qs.newQuery("<hint 'IDIndex'>select * from /Portfolios p where p.ID > 10 and p.ID < 200 and p.status = 'inactive' and p.description IN (select p.description from /Portfolios p where p.ID > 10)");
results[0][0] = (SelectResults) query.execute();
// verify index usage
assertTrue(observer.wasIndexUsed("IDIndex"));
observer.reset();
query = qs.newQuery("<hint 'SecIndex'>select * from /Portfolios p where p.ID > 10 and p.ID < 200 and p.status = 'inactive' and p.description IN (select p.description from /Portfolios p where p.ID > 10)");
results[0][1] = (SelectResults) query.execute();
// verify index usage
assertTrue(observer.wasIndexUsed("SecIndex"));
observer.reset();
// Compare results with the first two index queries
StructSetOrResultsSet ssOrrs = new StructSetOrResultsSet();
assertEquals(95, results[0][1].size());
// Not really with and without index but we can use this method to verify they are the same
// results
// regardless of which index used
ssOrrs.CompareQueryResultsWithoutAndWithIndexes(results, 1, new String[] { "<query with hints>" });
query = qs.newQuery("<hint 'DescriptionIndex'>select * from /Portfolios p where p.ID > 10 and p.ID < 200 and p.status = 'inactive' and p.description IN (select p.description from /Portfolios p where p.ID > 10) ");
results[0][1] = (SelectResults) query.execute();
// verify index usage
assertTrue(observer.wasIndexUsed("DescriptionIndex"));
// Compare results with the final index result
ssOrrs.CompareQueryResultsWithoutAndWithIndexes(results, 1, new String[] { "<query with hints>" });
}
use of org.apache.geode.cache.query.functional.StructSetOrResultsSet in project geode by apache.
the class EquiJoinIntegrationTest method compareResults.
private void compareResults(Object[] nonIndexedResults, Object[] indexedResults, String[] queries, boolean sizeOnly) {
if (sizeOnly) {
for (int i = 0; i < queries.length; i++) {
assertTrue(((SelectResults) nonIndexedResults[i]).size() == ((SelectResults) indexedResults[i]).size());
assertTrue(((SelectResults) nonIndexedResults[i]).size() > 0);
}
} else {
StructSetOrResultsSet util = new StructSetOrResultsSet();
for (int i = 0; i < queries.length; i++) {
Object[][] resultsToCompare = new Object[1][2];
resultsToCompare[0][0] = nonIndexedResults[i];
resultsToCompare[0][1] = indexedResults[i];
util.CompareQueryResultsWithoutAndWithIndexes(resultsToCompare, 1, new String[] { queries[i] });
assertTrue(((SelectResults) nonIndexedResults[i]).size() > 0);
}
}
}
Aggregations