Search in sources :

Example 6 with StructSetOrResultsSet

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>" });
}
Also used : DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) StructSetOrResultsSet(org.apache.geode.cache.query.functional.StructSetOrResultsSet) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 7 with StructSetOrResultsSet

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>" });
}
Also used : DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) StructSetOrResultsSet(org.apache.geode.cache.query.functional.StructSetOrResultsSet) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 8 with StructSetOrResultsSet

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>" });
}
Also used : DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) StructSetOrResultsSet(org.apache.geode.cache.query.functional.StructSetOrResultsSet) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 9 with StructSetOrResultsSet

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>" });
}
Also used : DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) StructSetOrResultsSet(org.apache.geode.cache.query.functional.StructSetOrResultsSet) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 10 with StructSetOrResultsSet

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);
        }
    }
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) StructSetOrResultsSet(org.apache.geode.cache.query.functional.StructSetOrResultsSet)

Aggregations

StructSetOrResultsSet (org.apache.geode.cache.query.functional.StructSetOrResultsSet)35 QueryService (org.apache.geode.cache.query.QueryService)23 Test (org.junit.Test)23 SelectResults (org.apache.geode.cache.query.SelectResults)19 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)17 Query (org.apache.geode.cache.query.Query)16 LocalRegion (org.apache.geode.internal.cache.LocalRegion)16 Region (org.apache.geode.cache.Region)15 Index (org.apache.geode.cache.query.Index)13 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)13 Cache (org.apache.geode.cache.Cache)12 QueryException (org.apache.geode.cache.query.QueryException)12 Iterator (java.util.Iterator)9 CancelException (org.apache.geode.CancelException)8 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)8 QueryInvalidException (org.apache.geode.cache.query.QueryInvalidException)8 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)8 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)8 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)8 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)8