Search in sources :

Example 1 with ExecutionContext

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

the class FunctionJUnitTest method testCanonicalization.

@Test
public void testCanonicalization() throws Exception {
    CompiledValue cv1 = new CompiledLiteral("str1");
    CompiledValue cv2 = new CompiledLiteral("str2");
    CompiledValue cv3 = new CompiledLiteral(null);
    CompiledValue cv4 = new CompiledLiteral(null);
    CompiledValue cv5 = new CompiledLiteral(new Integer(10));
    CompiledValue cv6 = new CompiledLiteral(new Integer(5));
    CompiledValue[][] cvArr = new CompiledValue[][] { { cv1, cv2, cv3, cv4, cv5, cv6 }, { cv6, cv5, cv3, cv4, cv2, cv1 }, { cv1, cv3, cv5, cv2, cv4, cv6 }, { cv1 }, { cv3 }, { cv5 } };
    String[] canonicalizedArgs = { "('str1','str2',null,null,10,5)", "(5,10,null,null,'str2','str1')", "('str1',null,10,'str2',null,5)", "('str1')", "(null)", "(10)" };
    ExecutionContext context = null;
    for (int i = 0; i < 6; i++) {
        CompiledValue cf = new CompiledFunction(cvArr[i], OQLLexerTokenTypes.LITERAL_nvl);
        StringBuilder clauseBuffer = new StringBuilder();
        cf.generateCanonicalizedExpression(clauseBuffer, context);
        if (!clauseBuffer.toString().equals("NVL" + canonicalizedArgs[i])) {
            fail("Canonicalization not done properly");
        }
        cf = new CompiledFunction(cvArr[i], OQLLexerTokenTypes.LITERAL_element);
        clauseBuffer = new StringBuilder();
        cf.generateCanonicalizedExpression(clauseBuffer, context);
        if (!clauseBuffer.toString().equals("ELEMENT" + canonicalizedArgs[i])) {
            fail("Canonicalization not done properly");
        }
    }
}
Also used : CompiledFunction(org.apache.geode.cache.query.internal.CompiledFunction) ExecutionContext(org.apache.geode.cache.query.internal.ExecutionContext) CompiledValue(org.apache.geode.cache.query.internal.CompiledValue) CompiledLiteral(org.apache.geode.cache.query.internal.CompiledLiteral) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with ExecutionContext

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

the class RangeIndexAPIJUnitTest method testQueryMethod_3.

/**
   * Tests the query method of RangeIndex with takes a bound defined ( lower as well as upper) & may
   * contain NotEqaul Keys
   */
@Test
public void testQueryMethod_3() throws Exception {
    QueryService qs;
    qs = CacheUtils.getQueryService();
    AbstractIndex i1 = (AbstractIndex) qs.createIndex("idIndex", IndexType.FUNCTIONAL, "ID", "/portfolios");
    AbstractIndex i2 = (AbstractIndex) qs.createIndex("statusIndex", IndexType.FUNCTIONAL, "status", "/portfolios");
    AbstractIndex i3 = (AbstractIndex) qs.createIndex("status.toString()", IndexType.FUNCTIONAL, "status.toString", "/portfolios");
    Set results = new HashSet();
    DefaultQuery q = new DefaultQuery("select * from /portfolios", CacheUtils.getCache(), false);
    q.setRemoteQuery(false);
    ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache(), q);
    bindIterators(context, "/portfolios");
    Set keysToRemove = new HashSet();
    i1.query(new Integer(5), OQLLexerTokenTypes.TOK_GT, new Integer(10), OQLLexerTokenTypes.TOK_LT, results, null, context);
    assertEquals(4, results.size());
    for (int i = 6; i < 10; ) {
        assertTrue(results.contains(region.get(new Integer(i))));
        ++i;
    }
    results.clear();
    keysToRemove.clear();
    keysToRemove.add(new Integer(10));
    keysToRemove.add(new Integer(9));
    i1.query(new Integer(5), OQLLexerTokenTypes.TOK_GT, new Integer(10), OQLLexerTokenTypes.TOK_LT, results, keysToRemove, context);
    assertEquals(3, results.size());
    for (int i = 6; i < 9; ) {
        assertTrue(results.contains(region.get(new Integer(i))));
        ++i;
    }
    results.clear();
    keysToRemove.clear();
    keysToRemove.add(new Integer(10));
    i1.query(new Integer(5), OQLLexerTokenTypes.TOK_GT, new Integer(10), OQLLexerTokenTypes.TOK_LE, results, keysToRemove, context);
    assertEquals(4, results.size());
    for (int i = 6; i < 10; ) {
        assertTrue(results.contains(region.get(new Integer(i))));
        ++i;
    }
    results.clear();
    keysToRemove.clear();
    i1.query(new Integer(5), OQLLexerTokenTypes.TOK_GT, new Integer(10), OQLLexerTokenTypes.TOK_LE, results, null, context);
    assertEquals(5, results.size());
    for (int i = 6; i < 11; ) {
        assertTrue(results.contains(region.get(new Integer(i))));
        ++i;
    }
    results.clear();
    keysToRemove.clear();
    i1.query(new Integer(5), OQLLexerTokenTypes.TOK_GE, new Integer(10), OQLLexerTokenTypes.TOK_LE, results, null, context);
    assertEquals(6, results.size());
    for (int i = 5; i < 11; ) {
        assertTrue(results.contains(region.get(new Integer(i))));
        ++i;
    }
    results.clear();
    keysToRemove.clear();
    keysToRemove.add(new Integer(5));
    i1.query(new Integer(5), OQLLexerTokenTypes.TOK_GE, new Integer(10), OQLLexerTokenTypes.TOK_LE, results, keysToRemove, context);
    assertEquals(5, results.size());
    for (int i = 6; i < 11; ) {
        assertTrue(results.contains(region.get(new Integer(i))));
        ++i;
    }
    results.clear();
    keysToRemove.clear();
    keysToRemove.add(new Integer(5));
    keysToRemove.add(new Integer(10));
    keysToRemove.add(new Integer(7));
    i1.query(new Integer(5), OQLLexerTokenTypes.TOK_GE, new Integer(10), OQLLexerTokenTypes.TOK_LE, results, keysToRemove, context);
    assertEquals(3, results.size());
    assertTrue(results.contains(region.get(new Integer(6))));
    assertTrue(results.contains(region.get(new Integer(8))));
    assertTrue(results.contains(region.get(new Integer(9))));
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) ExecutionContext(org.apache.geode.cache.query.internal.ExecutionContext) QueryExecutionContext(org.apache.geode.cache.query.internal.QueryExecutionContext) QueryService(org.apache.geode.cache.query.QueryService) QueryExecutionContext(org.apache.geode.cache.query.internal.QueryExecutionContext) HashSet(java.util.HashSet) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with ExecutionContext

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

the class RangeIndexAPIJUnitTest method testQueryMethod_1.

@Test
public void testQueryMethod_1() throws Exception {
    QueryService qs;
    qs = CacheUtils.getQueryService();
    AbstractIndex i1 = (AbstractIndex) qs.createIndex("idIndex", IndexType.FUNCTIONAL, "ID", "/portfolios");
    AbstractIndex i2 = (AbstractIndex) qs.createIndex("statusIndex", IndexType.FUNCTIONAL, "status", "/portfolios");
    AbstractIndex i3 = (AbstractIndex) qs.createIndex("status.toString()", IndexType.FUNCTIONAL, "status.toString", "/portfolios");
    Set results = new HashSet();
    DefaultQuery q = new DefaultQuery("select * from /portfolios", CacheUtils.getCache(), false);
    q.setRemoteQuery(false);
    ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache(), q);
    bindIterators(context, "/portfolios");
    i1.query(new Integer(1), OQLLexerTokenTypes.TOK_EQ, results, context);
    assertEquals(1, results.size());
    assertTrue(results.iterator().next() == region.get(new Integer(1)));
    results.clear();
    i1.query(new Integer(1), OQLLexerTokenTypes.TOK_GT, results, context);
    assertEquals(10, results.size());
    for (int i = 2; i < 12; ++i) {
        assertTrue(results.contains(region.get(new Integer(i))));
    }
    results.clear();
    i2.query(new String("active"), OQLLexerTokenTypes.TOK_NE, results, context);
    assertEquals(7, results.size());
    for (int i = 1; i < 12; ) {
        assertTrue(results.contains(region.get(new Integer(i))));
        if (i >= 9) {
            ++i;
        } else {
            i += 2;
        }
    }
    results.clear();
    i3.query(QueryService.UNDEFINED, OQLLexerTokenTypes.TOK_EQ, results, context);
    assertEquals(2, results.size());
    assertTrue(results.contains(region.get(new Integer(11))));
    assertTrue(results.contains(region.get(new Integer(10))));
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) ExecutionContext(org.apache.geode.cache.query.internal.ExecutionContext) QueryExecutionContext(org.apache.geode.cache.query.internal.QueryExecutionContext) QueryService(org.apache.geode.cache.query.QueryService) QueryExecutionContext(org.apache.geode.cache.query.internal.QueryExecutionContext) HashSet(java.util.HashSet) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with ExecutionContext

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

the class RangeIndexAPIJUnitTest method testQueryMethod_2.

/**
   * The keysToRemove set will never contain null or UNDEFINED as those conditions never form part
   * of RangeJunctionCondnEvaluator. Such null or undefined conditions are treated as separate
   * filter operands. This test checks the query method of Index which takes a set of keys which
   * need to be removed from the set
   */
@Test
public void testQueryMethod_2() throws Exception {
    QueryService qs;
    qs = CacheUtils.getQueryService();
    AbstractIndex i1 = (AbstractIndex) qs.createIndex("idIndex", IndexType.FUNCTIONAL, "ID", "/portfolios");
    AbstractIndex i2 = (AbstractIndex) qs.createIndex("statusIndex", IndexType.FUNCTIONAL, "status", "/portfolios");
    AbstractIndex i3 = (AbstractIndex) qs.createIndex("status.toString()", IndexType.FUNCTIONAL, "status.toString", "/portfolios");
    Set results = new HashSet();
    DefaultQuery q = new DefaultQuery("select * from /portfolios  ", CacheUtils.getCache(), false);
    q.setRemoteQuery(false);
    ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache(), q);
    bindIterators(context, "/portfolios");
    Set keysToRemove = new HashSet();
    i1.query(new Integer(1), OQLLexerTokenTypes.TOK_EQ, results, context);
    assertEquals(1, results.size());
    assertTrue(results.iterator().next() == region.get(new Integer(1)));
    results.clear();
    keysToRemove.clear();
    keysToRemove.add(new Integer(1));
    try {
        i1.query(new Integer(1), OQLLexerTokenTypes.TOK_EQ, results, keysToRemove, context);
        fail("A condition having an  equal will be identified at RangeJunction level itself, so this type of condition should throw error in RangeIndex where along with an equal there happens not equal conditions");
    } catch (AssertionError error) {
    // pass
    }
    keysToRemove.clear();
    results.clear();
    keysToRemove.add(new Integer(9));
    i1.query(new Integer(1), OQLLexerTokenTypes.TOK_GT, results, keysToRemove, context);
    assertEquals(9, results.size());
    for (int i = 2; i < 12; ) {
        if (i != 9) {
            assertTrue(results.contains(region.get(new Integer(i))));
        }
        ++i;
    }
    keysToRemove.clear();
    results.clear();
    keysToRemove.add(new Integer(1));
    keysToRemove.add(new Integer(10));
    i1.query(new Integer(1), OQLLexerTokenTypes.TOK_GE, results, keysToRemove, context);
    assertEquals(9, results.size());
    for (int i = 2; i < 12; ) {
        if (i != 10) {
            assertTrue(results.contains(region.get(new Integer(i))));
        }
        ++i;
    }
    keysToRemove.clear();
    results.clear();
    keysToRemove.add(new Integer(8));
    keysToRemove.add(new Integer(11));
    i1.query(new Integer(11), OQLLexerTokenTypes.TOK_LT, results, keysToRemove, context);
    assertEquals(10, results.size());
    for (int i = 0; i < 11; ) {
        if (i != 8) {
            assertTrue(results.contains(region.get(new Integer(i))));
        }
        ++i;
    }
    keysToRemove.clear();
    results.clear();
    keysToRemove.add(new Integer(8));
    keysToRemove.add(new Integer(11));
    i1.query(new Integer(11), OQLLexerTokenTypes.TOK_LE, results, keysToRemove, context);
    assertEquals(10, results.size());
    for (int i = 0; i < 11; ) {
        if (i != 8) {
            assertTrue(results.contains(region.get(new Integer(i))));
        }
        ++i;
    }
    keysToRemove.clear();
    results.clear();
    keysToRemove.add(new Integer(1));
    keysToRemove.add(new Integer(10));
    i1.query(new Integer(1), OQLLexerTokenTypes.TOK_GT, results, keysToRemove, context);
    assertEquals(9, results.size());
    for (int i = 2; i < 12; ) {
        if (i != 10) {
            assertTrue(results.contains(region.get(new Integer(i))));
        }
        ++i;
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) ExecutionContext(org.apache.geode.cache.query.internal.ExecutionContext) QueryExecutionContext(org.apache.geode.cache.query.internal.QueryExecutionContext) QueryService(org.apache.geode.cache.query.QueryService) QueryExecutionContext(org.apache.geode.cache.query.internal.QueryExecutionContext) HashSet(java.util.HashSet) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 5 with ExecutionContext

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

the class PartitionedIndex method verifyAndCreateMissingIndex.

/**
   * Verify if the index is available of the buckets. If not create index on the bucket.
   */
public void verifyAndCreateMissingIndex(List buckets) throws QueryInvocationTargetException {
    PartitionedRegion pr = (PartitionedRegion) this.getRegion();
    PartitionedRegionDataStore prds = pr.getDataStore();
    for (Object bId : buckets) {
        // create index
        BucketRegion bukRegion = (BucketRegion) prds.getLocalBucketById((Integer) bId);
        if (bukRegion == null) {
            throw new QueryInvocationTargetException("Bucket not found for the id :" + bId);
        }
        IndexManager im = IndexUtils.getIndexManager(bukRegion, true);
        if (im != null && im.getIndex(indexName) == null) {
            try {
                if (pr.getCache().getLogger().fineEnabled()) {
                    pr.getCache().getLogger().fine("Verifying index presence on bucket region. " + " Found index " + this.indexName + " not present on the bucket region " + bukRegion.getFullPath() + ", index will be created on this region.");
                }
                ExecutionContext externalContext = new ExecutionContext(null, bukRegion.getCache());
                externalContext.setBucketRegion(pr, bukRegion);
                im.createIndex(this.indexName, this.type, this.originalIndexedExpression, this.fromClause, this.imports, externalContext, this, true);
            } catch (IndexExistsException iee) {
            // Index exists.
            } catch (IndexNameConflictException ince) {
            // ignore.
            }
        }
    }
}
Also used : ExecutionContext(org.apache.geode.cache.query.internal.ExecutionContext) IndexExistsException(org.apache.geode.cache.query.IndexExistsException) BucketRegion(org.apache.geode.internal.cache.BucketRegion) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore)

Aggregations

ExecutionContext (org.apache.geode.cache.query.internal.ExecutionContext)11 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)6 QueryExecutionContext (org.apache.geode.cache.query.internal.QueryExecutionContext)6 HashSet (java.util.HashSet)5 Set (java.util.Set)4 CompiledSelect (org.apache.geode.cache.query.internal.CompiledSelect)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 Test (org.junit.Test)4 QueryService (org.apache.geode.cache.query.QueryService)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 InternalGemFireException (org.apache.geode.InternalGemFireException)2 QueryException (org.apache.geode.cache.query.QueryException)2 IOException (java.io.IOException)1 Integer (java.lang.Integer)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1