Search in sources :

Example 6 with CompiledIteratorDef

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

the class PrimaryKeyIndexCreationHelper method prepareFromClause.

private void prepareFromClause(IndexManager imgr) throws IndexInvalidException {
    List list = this.compiler.compileFromClause(fromClause);
    if (list.size() > 1) {
        throw new IndexInvalidException(LocalizedStrings.PrimaryKeyIndexCreationHelper_THE_FROMCLAUSE_FOR_A_PRIMARY_KEY_INDEX_SHOULD_ONLY_HAVE_ONE_ITERATOR_AND_THE_COLLECTION_MUST_BE_A_REGION_PATH_ONLY.toLocalizedString());
    }
    try {
        CompiledIteratorDef iterDef = (CompiledIteratorDef) list.get(0);
        if (iterDef.getCollectionExpr().getType() != OQLLexerTokenTypes.RegionPath) {
            throw new IndexInvalidException(LocalizedStrings.PrimaryKeyIndexCreationHelper_THE_FROMCLAUSE_FOR_A_PRIMARY_KEY_INDEX_SHOULD_BE_A_REGION_PATH_ONLY.toLocalizedString());
        }
        iterDef.computeDependencies(this.context);
        RuntimeIterator rIter = (iterDef.getRuntimeIterator(this.context));
        String definition = rIter.getDefinition();
        this.canonicalizedIteratorDefinitions = new String[1];
        this.canonicalizedIteratorDefinitions[0] = definition;
        // Bind the Index_Internal_ID to the RuntimeIterator
        PartitionedRegion pr = this.context.getPartitionedRegion();
        this.canonicalizedIteratorNames = new String[1];
        String name = null;
        if (pr != null) {
            name = pr.getIndexManager().putCanonicalizedIteratorNameIfAbsent(definition);
        } else {
            name = imgr.putCanonicalizedIteratorNameIfAbsent(definition);
        }
        rIter.setIndexInternalID(name);
        this.canonicalizedIteratorNames = new String[1];
        this.canonicalizedIteratorNames[0] = name;
        this.fromClause = new StringBuilder(definition).append(' ').append(name).toString();
        context.bindIterator(rIter);
    } catch (IndexInvalidException e) {
        // propagate
        throw e;
    } catch (Exception e) {
        // wrap any other exceptions
        throw new IndexInvalidException(e);
    }
}
Also used : CompiledIteratorDef(org.apache.geode.cache.query.internal.CompiledIteratorDef) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) List(java.util.List) IndexInvalidException(org.apache.geode.cache.query.IndexInvalidException) IndexInvalidException(org.apache.geode.cache.query.IndexInvalidException) RuntimeIterator(org.apache.geode.cache.query.internal.RuntimeIterator)

Example 7 with CompiledIteratorDef

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

the class IndexCreationInternalsJUnitTest method testLoneFromClause.

@Test
public void testLoneFromClause() throws Exception {
    // compileFromClause returns a List<CompiledIteratorDef>
    QCompiler compiler = new QCompiler();
    List list = compiler.compileFromClause("/pos p, p.positions");
    assertEquals(2, list.size());
    CompiledIteratorDef first = (CompiledIteratorDef) list.get(0);
    assertEquals("p", first.getName());
    assertEquals("/pos", ((CompiledRegion) first.getCollectionExpr()).getRegionPath());
    assertEquals(TypeUtils.OBJECT_TYPE, first.getElementType());
    CompiledIteratorDef second = (CompiledIteratorDef) list.get(1);
    assertNull(second.getName());
    CompiledPath path = (CompiledPath) second.getCollectionExpr();
    assertEquals("p", ((CompiledID) path.getReceiver()).getId());
    assertEquals("positions", path.getTailID());
    assertEquals(TypeUtils.OBJECT_TYPE, second.getElementType());
}
Also used : CompiledIteratorDef(org.apache.geode.cache.query.internal.CompiledIteratorDef) QCompiler(org.apache.geode.cache.query.internal.QCompiler) List(java.util.List) CompiledPath(org.apache.geode.cache.query.internal.CompiledPath) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 8 with CompiledIteratorDef

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

the class ServerCQImpl method constructServerSideQuery.

/**
   * Returns parameterized query used by the server. This method replaces Region name with $1 and if
   * type is not specified in the query, looks for type from cqattributes and appends into the
   * query.
   * 
   * @return String modified query.
   */
private Query constructServerSideQuery() throws QueryException {
    InternalCache cache = cqService.getInternalCache();
    DefaultQuery locQuery = (DefaultQuery) cache.getLocalQueryService().newQuery(this.queryString);
    CompiledSelect select = locQuery.getSimpleSelect();
    CompiledIteratorDef from = (CompiledIteratorDef) select.getIterators().get(0);
    // WARNING: ASSUMES QUERY WAS ALREADY VALIDATED FOR PROPER "FORM" ON CLIENT;
    // THIS VALIDATION WILL NEED TO BE DONE ON THE SERVER FOR NATIVE CLIENTS,
    // BUT IS NOT DONE HERE FOR JAVA CLIENTS.
    // The query was already checked on the client that the sole iterator is a
    // CompiledRegion
    this.regionName = ((CompiledRegion) from.getCollectionExpr()).getRegionPath();
    from.setCollectionExpr(new CompiledBindArgument(1));
    return locQuery;
}
Also used : CompiledIteratorDef(org.apache.geode.cache.query.internal.CompiledIteratorDef) CompiledBindArgument(org.apache.geode.cache.query.internal.CompiledBindArgument) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) CompiledSelect(org.apache.geode.cache.query.internal.CompiledSelect) InternalCache(org.apache.geode.internal.cache.InternalCache)

Aggregations

CompiledIteratorDef (org.apache.geode.cache.query.internal.CompiledIteratorDef)8 List (java.util.List)7 CompiledPath (org.apache.geode.cache.query.internal.CompiledPath)4 CompiledValue (org.apache.geode.cache.query.internal.CompiledValue)4 RuntimeIterator (org.apache.geode.cache.query.internal.RuntimeIterator)4 ArrayList (java.util.ArrayList)3 IndexInvalidException (org.apache.geode.cache.query.IndexInvalidException)3 CompiledBindArgument (org.apache.geode.cache.query.internal.CompiledBindArgument)3 CompiledIndexOperation (org.apache.geode.cache.query.internal.CompiledIndexOperation)3 CompiledOperation (org.apache.geode.cache.query.internal.CompiledOperation)3 CompiledRegion (org.apache.geode.cache.query.internal.CompiledRegion)3 AmbiguousNameException (org.apache.geode.cache.query.AmbiguousNameException)2 NameResolutionException (org.apache.geode.cache.query.NameResolutionException)2 TypeMismatchException (org.apache.geode.cache.query.TypeMismatchException)2 CompiledID (org.apache.geode.cache.query.internal.CompiledID)2 CompiledSelect (org.apache.geode.cache.query.internal.CompiledSelect)2 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)2 QCompiler (org.apache.geode.cache.query.internal.QCompiler)2 InternalCache (org.apache.geode.internal.cache.InternalCache)2 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)2