Search in sources :

Example 6 with CompactRangeIndex

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

the class QueryTraceJUnitTest method testTraceOnLocalRegionWithSmallTracePrefixNoComments.

@Test
public void testTraceOnLocalRegionWithSmallTracePrefixNoComments() throws Exception {
    String prefix = "<trace> ";
    // Create Partition Region
    AttributesFactory af = new AttributesFactory();
    af.setScope(Scope.LOCAL);
    region = CacheUtils.createRegion("portfolio", af.create(), false);
    if (region.size() == 0) {
        for (int i = 1; i <= 100; i++) {
            region.put(Integer.toString(i), new Portfolio(i, i));
        }
    }
    assertEquals(100, region.size());
    qs = CacheUtils.getQueryService();
    keyIndex1 = (IndexProtocol) qs.createIndex(INDEX_NAME, IndexType.FUNCTIONAL, "ID", "/portfolio ");
    assertTrue(keyIndex1 instanceof CompactRangeIndex);
    Query query = qs.newQuery(prefix + queryStr);
    assertTrue(((DefaultQuery) query).isTraced());
    SelectResults results = (SelectResults) query.execute();
    assertTrue(QueryObserverHolder.getInstance() instanceof IndexTrackingQueryObserver);
    // The query should return all elements in region.
    assertEquals(region.size(), results.size());
    QueryObserverHolder.reset();
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) SelectResults(org.apache.geode.cache.query.SelectResults) Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 7 with CompactRangeIndex

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

the class IndexCreationJUnitTest method testBug36591.

/**
   * The Index maintenance has a bug as it does not re-evaluate the index maintenance collection in
   * the IMQEvaluator when an entry gets modified & so the index resultset is messed up
   */
@Test
public void testBug36591() throws Exception {
    QueryService qs;
    qs = CacheUtils.getQueryService();
    Index i1 = qs.createIndex("keyIndex", IndexType.FUNCTIONAL, "ks.hashCode", "/portfolios.keys ks");
    Region rgn = CacheUtils.getRegion("/portfolios");
    rgn.put("4", new Portfolio(4));
    rgn.put("5", new Portfolio(5));
    CacheUtils.log(((CompactRangeIndex) i1).dump());
    Query qr = qs.newQuery("Select distinct * from /portfolios.keys keys where keys.hashCode >= $1");
    SelectResults sr = (SelectResults) qr.execute(new Object[] { new Integer(-1) });
    assertEquals(6, sr.size());
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) Query(org.apache.geode.cache.query.Query) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) Portfolio(org.apache.geode.cache.query.data.Portfolio) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) RangeIndex(org.apache.geode.cache.query.internal.index.RangeIndex) CompactMapRangeIndex(org.apache.geode.cache.query.internal.index.CompactMapRangeIndex) Index(org.apache.geode.cache.query.Index) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 8 with CompactRangeIndex

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

the class IndexCreationJUnitTest method testIMQFailureAsMethodKeysNAInDummyQRegion.

/**
   * Test the Index maiantenance as it may use the method keys() of QRegion instead of DummyQRegion
   * while running an IndexMaintenanceQuery
   */
@Test
public void testIMQFailureAsMethodKeysNAInDummyQRegion() throws Exception {
    QueryService qs;
    qs = CacheUtils.getQueryService();
    Index i1 = qs.createIndex("keyIndex", IndexType.FUNCTIONAL, "ks.hashCode", "/portfolios.keys() ks");
    Region rgn = CacheUtils.getRegion("/portfolios");
    rgn.put("4", new Portfolio(4));
    rgn.put("5", new Portfolio(5));
    CacheUtils.log(((CompactRangeIndex) i1).dump());
    Query qr = qs.newQuery("Select distinct keys.hashCode  from /portfolios.keys() keys where keys.hashCode >= $1");
    SelectResults sr = (SelectResults) qr.execute(new Object[] { new Integer(-1) });
    assertEquals(6, sr.size());
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) Query(org.apache.geode.cache.query.Query) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) Portfolio(org.apache.geode.cache.query.data.Portfolio) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) RangeIndex(org.apache.geode.cache.query.internal.index.RangeIndex) CompactMapRangeIndex(org.apache.geode.cache.query.internal.index.CompactMapRangeIndex) Index(org.apache.geode.cache.query.Index) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 9 with CompactRangeIndex

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

the class IndexCreationJUnitTest method testIndexCreationOnKeys.

@Test
public void testIndexCreationOnKeys() throws Exception {
    // Task ID : ICM 9
    QueryService qs;
    qs = CacheUtils.getQueryService();
    Index i1 = qs.createIndex("kIndex", IndexType.FUNCTIONAL, "pf", "/portfolios.keys pf");
    Index i2 = qs.createIndex("k1Index", IndexType.FUNCTIONAL, "key", "/portfolios.entries");
    Index i3 = qs.createIndex("k2Index", IndexType.FUNCTIONAL, "pf", "/portfolios.keys.toArray pf");
    // Index i4 = qs.createIndex("k3Index", IndexType.FUNCTIONAL,
    // "pf","/portfolios.keys().toArray() pf");
    Index i5 = qs.createIndex("k4Index", IndexType.FUNCTIONAL, "pf", "/portfolios.getKeys.asList pf");
    // Index i5 = qs.createIndex("k5Index", IndexType.FUNCTIONAL,
    // "pf","/portfolios.getKeys.asList() pf");
    Index i6 = qs.createIndex("k5Index", IndexType.FUNCTIONAL, "pf", "/portfolios.getKeys.asSet() pf");
    // Index i5 = qs.createIndex("k5Index", IndexType.FUNCTIONAL,
    // "pf","/portfolios.getKeys.asSet pf");
    CacheUtils.log(((CompactRangeIndex) i1).dump());
    CacheUtils.log(((CompactRangeIndex) i2).dump());
    CacheUtils.log(((CompactRangeIndex) i3).dump());
    CacheUtils.log(((CompactRangeIndex) i5).dump());
    CacheUtils.log(((CompactRangeIndex) i6).dump());
}
Also used : DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) RangeIndex(org.apache.geode.cache.query.internal.index.RangeIndex) CompactMapRangeIndex(org.apache.geode.cache.query.internal.index.CompactMapRangeIndex) Index(org.apache.geode.cache.query.Index) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 10 with CompactRangeIndex

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

the class IndexCreationJUnitTest method testIndexCreationOnRegionEntry.

@Test
public void testIndexCreationOnRegionEntry() throws Exception {
    // Task ID : ICM11
    QueryService qs;
    qs = CacheUtils.getQueryService();
    Index i1 = qs.createIndex("r1Index", IndexType.FUNCTIONAL, "secId", "/portfolios.values['1'].positions.values");
    qs.createIndex("r12Index", IndexType.FUNCTIONAL, "secId", "/portfolios['1'].positions.values");
    CacheUtils.log(((CompactRangeIndex) i1).dump());
// CacheUtils.log(((RangeIndex)i2).dump());
}
Also used : DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) RangeIndex(org.apache.geode.cache.query.internal.index.RangeIndex) CompactMapRangeIndex(org.apache.geode.cache.query.internal.index.CompactMapRangeIndex) Index(org.apache.geode.cache.query.Index) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

CompactRangeIndex (org.apache.geode.cache.query.internal.index.CompactRangeIndex)18 Test (org.junit.Test)18 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)15 Query (org.apache.geode.cache.query.Query)12 SelectResults (org.apache.geode.cache.query.SelectResults)11 Portfolio (org.apache.geode.cache.query.data.Portfolio)11 RangeIndex (org.apache.geode.cache.query.internal.index.RangeIndex)11 Index (org.apache.geode.cache.query.Index)10 QueryService (org.apache.geode.cache.query.QueryService)10 AttributesFactory (org.apache.geode.cache.AttributesFactory)9 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)9 Region (org.apache.geode.cache.Region)6 DefaultQueryService (org.apache.geode.cache.query.internal.DefaultQueryService)6 CompactMapRangeIndex (org.apache.geode.cache.query.internal.index.CompactMapRangeIndex)6 PdxString (org.apache.geode.pdx.internal.PdxString)5 IOException (java.io.IOException)3 CacheException (org.apache.geode.cache.CacheException)3 PortfolioPdx (org.apache.geode.cache.query.data.PortfolioPdx)3 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)3 PartitionedIndex (org.apache.geode.cache.query.internal.index.PartitionedIndex)3