Search in sources :

Example 41 with QueryObserverAdapter

use of org.apache.geode.cache.query.internal.QueryObserverAdapter in project geode by apache.

the class LimitClauseJUnitTest method testLimitDistinctIterEvaluatedQueryForResultBagWithIndex.

// Asif:Test the index results behaviour also
// Shobhit: Testing the Limit behavior now with indexes for all above test cases.
/**
   * Tests the limit functionality for Iter evaluated query with distinct clause This tests the
   * basic limit functionality for ResultBag wrapped by a SelectResults
   * 
   * Tests ResultBag behaviour
   */
@Test
public void testLimitDistinctIterEvaluatedQueryForResultBagWithIndex() {
    try {
        Query query;
        SelectResults result;
        String queryString = "SELECT DISTINCT * FROM /portfolios pf WHERE pf.ID > 0 limit 5";
        query = qs.newQuery(queryString);
        MyQueryObserverAdapter observer = new MyQueryObserverAdapter();
        QueryObserver old = QueryObserverHolder.setInstance(observer);
        Index index = qs.createIndex("idIndex", "pf.ID", "/portfolios pf");
        assertNotNull(index);
        result = (SelectResults) query.execute();
        assertTrue(result instanceof SelectResults);
        assertEquals(5, result.size());
        SelectResults wrapper = (SelectResults) result;
        assertEquals(5, wrapper.asSet().size());
        assertTrue(observer.limitAppliedAtIndex);
    } catch (Exception e) {
        CacheUtils.getLogger().error(e);
        fail(e.toString());
    } finally {
        QueryObserverHolder.setInstance(new QueryObserverAdapter());
    }
}
Also used : QueryObserver(org.apache.geode.cache.query.internal.QueryObserver) SelectResults(org.apache.geode.cache.query.SelectResults) Query(org.apache.geode.cache.query.Query) QueryObserverAdapter(org.apache.geode.cache.query.internal.QueryObserverAdapter) Index(org.apache.geode.cache.query.Index) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 42 with QueryObserverAdapter

use of org.apache.geode.cache.query.internal.QueryObserverAdapter in project geode by apache.

the class LimitClauseJUnitTest method testLimitDistinctIterEvaluatedQueryForStructBagWithIndex.

/**
   * Tests the limit functionality for Iter evaluated query with distinct clause This tests the
   * basic limit functionality for StructBag wrapped by a SelectResults
   * 
   * Tests StructBag behaviour
   */
@Test
public void testLimitDistinctIterEvaluatedQueryForStructBagWithIndex() {
    try {
        Query query;
        SelectResults result;
        String queryString = "SELECT DISTINCT * FROM /portfolios pf, pf.positions.values WHERE pf.ID > 0 limit 5";
        query = qs.newQuery(queryString);
        MyQueryObserverAdapter observer = new MyQueryObserverAdapter();
        QueryObserver old = QueryObserverHolder.setInstance(observer);
        Index index = qs.createIndex("idIndex", "pf.ID", "/portfolios pf, pf.positions.values");
        assertNotNull(index);
        result = (SelectResults) query.execute();
        assertTrue(result instanceof SelectResults);
        assertEquals(5, result.size());
        SelectResults wrapper = (SelectResults) result;
        assertEquals(5, wrapper.asSet().size());
        // currently this is false because we disabled limit application at the range index level
        assertFalse(observer.limitAppliedAtIndex);
    } catch (Exception e) {
        CacheUtils.getLogger().error(e);
        fail(e.toString());
    } finally {
        QueryObserverHolder.setInstance(new QueryObserverAdapter());
    }
}
Also used : QueryObserver(org.apache.geode.cache.query.internal.QueryObserver) SelectResults(org.apache.geode.cache.query.SelectResults) Query(org.apache.geode.cache.query.Query) QueryObserverAdapter(org.apache.geode.cache.query.internal.QueryObserverAdapter) Index(org.apache.geode.cache.query.Index) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 43 with QueryObserverAdapter

use of org.apache.geode.cache.query.internal.QueryObserverAdapter in project geode by apache.

the class LimitClauseJUnitTest method testLimitQueryForStructBagWithRangeIndex.

/**
   * Tests the limit functionality for Iter evaluated query with distinct clause This tests the
   * basic limit functionality for StructBag wrapped by a SelectResults
   * 
   * Tests StructBag behaviour
   */
@Ignore
@Test
public void testLimitQueryForStructBagWithRangeIndex() {
    try {
        Query query;
        SelectResults result;
        String queryString = "SELECT * FROM /portfolios pf, pf.positions.values pos WHERE pf.ID > 1  AND pos.secId = 'GOOG' limit 1";
        query = qs.newQuery(queryString);
        MyQueryObserverAdapter observer = new MyQueryObserverAdapter();
        QueryObserver old = QueryObserverHolder.setInstance(observer);
        Index index = qs.createIndex("idIndex", "pf.ID", "/portfolios pf");
        Index posindex = qs.createIndex("posIndex", "pos.secId", "/portfolios pf, pf.positions.values pos");
        assertNotNull(index);
        assertNotNull(posindex);
        result = (SelectResults) query.execute();
        assertEquals(1, result.size());
        assertFalse(observer.limitAppliedAtIndex);
    } catch (Exception e) {
        CacheUtils.getLogger().error(e);
        fail(e.toString());
    } finally {
        QueryObserverHolder.setInstance(new QueryObserverAdapter());
    }
}
Also used : QueryObserver(org.apache.geode.cache.query.internal.QueryObserver) SelectResults(org.apache.geode.cache.query.SelectResults) Query(org.apache.geode.cache.query.Query) QueryObserverAdapter(org.apache.geode.cache.query.internal.QueryObserverAdapter) Index(org.apache.geode.cache.query.Index) Ignore(org.junit.Ignore) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 44 with QueryObserverAdapter

use of org.apache.geode.cache.query.internal.QueryObserverAdapter in project geode by apache.

the class LimitClauseJUnitTest method testLimitDistinctIterEvaluatedQueryForStructBag.

/**
   * Tests the limit functionality for Iter evaluated query with distinct clause This tests the
   * basic limit functionality for StructBag wrapped by a SelectResults
   * 
   * Tests StructBag behaviour
   */
@Test
public void testLimitDistinctIterEvaluatedQueryForStructBag() {
    try {
        Query query;
        SelectResults result;
        String queryString = "SELECT DISTINCT * FROM /portfolios pf, pf.positions.values WHERE pf.ID > 0 limit 5";
        query = qs.newQuery(queryString);
        final int[] num = new int[1];
        num[0] = 0;
        QueryObserver old = QueryObserverHolder.setInstance(new QueryObserverAdapter() {

            public void afterIterationEvaluation(Object result) {
                num[0] += 1;
            }
        });
        result = (SelectResults) query.execute();
        assertEquals(5, num[0]);
        assertTrue(result instanceof SelectResults);
        assertEquals(5, result.size());
        SelectResults wrapper = (SelectResults) result;
        assertEquals(5, wrapper.asSet().size());
    } catch (Exception e) {
        CacheUtils.getLogger().error(e);
        fail(e.toString());
    } finally {
        QueryObserverHolder.setInstance(new QueryObserverAdapter());
    }
}
Also used : QueryObserver(org.apache.geode.cache.query.internal.QueryObserver) SelectResults(org.apache.geode.cache.query.SelectResults) Query(org.apache.geode.cache.query.Query) QueryObserverAdapter(org.apache.geode.cache.query.internal.QueryObserverAdapter) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 45 with QueryObserverAdapter

use of org.apache.geode.cache.query.internal.QueryObserverAdapter in project geode by apache.

the class LimitClauseJUnitTest method testLimitDistinctIterEvaluatedQueryForResultBagWithProjectionAttribute.

/**
   * Tests the limit functionality for Iter evaluated query with distinct clause This tests the
   * basic limit functionality for ResultBag wrapped by a SelectResults . This test contains
   * projection attributes. Since the attribute is unique every time, the limit will be satisfied
   * with first 5 iterations
   * 
   * Tests ResultBag behaviour
   * 
   */
@Test
public void testLimitDistinctIterEvaluatedQueryForResultBagWithProjectionAttribute() {
    try {
        Query query;
        SelectResults result;
        String queryString = "SELECT DISTINCT pf.ID FROM /portfolios pf WHERE pf.ID > 0 limit 5";
        query = qs.newQuery(queryString);
        final int[] num = new int[1];
        num[0] = 0;
        QueryObserver old = QueryObserverHolder.setInstance(new QueryObserverAdapter() {

            public void afterIterationEvaluation(Object result) {
                num[0] += 1;
            }
        });
        result = (SelectResults) query.execute();
        assertEquals(5, num[0]);
        assertTrue(result instanceof SelectResults);
        assertEquals(5, result.size());
        SelectResults wrapper = (SelectResults) result;
        assertEquals(5, wrapper.asSet().size());
    } catch (Exception e) {
        CacheUtils.getLogger().error(e);
        fail(e.toString());
    } finally {
        QueryObserverHolder.setInstance(new QueryObserverAdapter());
    }
}
Also used : QueryObserver(org.apache.geode.cache.query.internal.QueryObserver) SelectResults(org.apache.geode.cache.query.SelectResults) Query(org.apache.geode.cache.query.Query) QueryObserverAdapter(org.apache.geode.cache.query.internal.QueryObserverAdapter) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

QueryObserverAdapter (org.apache.geode.cache.query.internal.QueryObserverAdapter)63 SelectResults (org.apache.geode.cache.query.SelectResults)59 Test (org.junit.Test)55 Query (org.apache.geode.cache.query.Query)54 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)51 Portfolio (org.apache.geode.cache.query.data.Portfolio)49 Region (org.apache.geode.cache.Region)48 QueryObserver (org.apache.geode.cache.query.internal.QueryObserver)38 Index (org.apache.geode.cache.query.Index)36 QueryService (org.apache.geode.cache.query.QueryService)35 ObjectTypeImpl (org.apache.geode.cache.query.internal.types.ObjectTypeImpl)23 Collection (java.util.Collection)18 ObjectType (org.apache.geode.cache.query.types.ObjectType)18 LocalRegion (org.apache.geode.internal.cache.LocalRegion)14 AttributesFactory (org.apache.geode.cache.AttributesFactory)12 Cache (org.apache.geode.cache.Cache)11 List (java.util.List)10 ArrayList (java.util.ArrayList)9 RegionAttributes (org.apache.geode.cache.RegionAttributes)9 StructTypeImpl (org.apache.geode.cache.query.internal.types.StructTypeImpl)7