Search in sources :

Example 1 with CompiledIteratorDef

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

the class FunctionalIndexCreationHelper method getModifiedDependentCompiledValue.

/**
   * This function is used to correct the complied value's dependency , in case the compiledValue is
   * dependent on the 0th RuntimeIterator in some way. Thus the dependent compiled value is prefixed
   * with the missing link so that it is derivable from the 0th iterator.
   */
private CompiledValue getModifiedDependentCompiledValue(ExecutionContext context, int currItrID, CompiledValue cv, boolean isDependent) throws AmbiguousNameException, TypeMismatchException, NameResolutionException {
    if (cv instanceof CompiledIteratorDef) {
        CompiledIteratorDef iterDef = (CompiledIteratorDef) cv;
        RuntimeIterator rItr = (RuntimeIterator) context.getCurrentIterators().get(currItrID);
        String canonFrmClause = rItr.getDefinition();
        // TODO: original value of isDependent is always ignored
        isDependent = canonFrmClause.startsWith(this.canonicalizedIteratorNames[0]);
        return new CompiledIteratorDef(iterDef.getName(), rItr.getElementType(), getModifiedDependentCompiledValue(context, currItrID, iterDef.getCollectionExpr(), isDependent));
    } else if (cv instanceof CompiledPath) {
        CompiledPath path = (CompiledPath) cv;
        return new CompiledPath(getModifiedDependentCompiledValue(context, currItrID, path.getReceiver(), isDependent), path.getTailID());
    } else if (cv instanceof CompiledOperation) {
        CompiledOperation oper = (CompiledOperation) cv;
        List list = oper.getArguments();
        List newList = new ArrayList();
        for (Object aList : list) {
            CompiledValue cv1 = (CompiledValue) aList;
            StringBuilder sb = new StringBuilder();
            cv1.generateCanonicalizedExpression(sb, context);
            if (sb.toString().startsWith(this.canonicalizedIteratorNames[0])) {
                newList.add(getModifiedDependentCompiledValue(context, currItrID, cv1, true));
            } else {
                newList.add(getModifiedDependentCompiledValue(context, currItrID, cv1, false));
            }
        }
        // What if the receiver is null?
        CompiledValue rec = oper.getReceiver(context);
        if (rec == null) {
            if (isDependent) {
                rec = this.missingLink;
            }
            return new CompiledOperation(rec, oper.getMethodName(), newList);
        } else {
            return new CompiledOperation(getModifiedDependentCompiledValue(context, currItrID, rec, isDependent), oper.getMethodName(), newList);
        }
    } else if (cv instanceof CompiledFunction) {
        CompiledFunction cf = (CompiledFunction) cv;
        CompiledValue[] cvArray = cf.getArguments();
        int function = cf.getFunction();
        int len = cvArray.length;
        CompiledValue[] newCvArray = new CompiledValue[len];
        for (int i = 0; i < len; ++i) {
            CompiledValue cv1 = cvArray[i];
            StringBuilder sb = new StringBuilder();
            cv1.generateCanonicalizedExpression(sb, context);
            if (sb.toString().startsWith(this.canonicalizedIteratorNames[0])) {
                newCvArray[i] = getModifiedDependentCompiledValue(context, currItrID, cv1, true);
            } else {
                newCvArray[i] = getModifiedDependentCompiledValue(context, currItrID, cv1, false);
            }
        }
        return new CompiledFunction(newCvArray, function);
    } else if (cv instanceof CompiledID) {
        CompiledID id = (CompiledID) cv;
        RuntimeIterator rItr0 = (RuntimeIterator) context.getCurrentIterators().get(0);
        if (isDependent) {
            String name;
            if ((name = rItr0.getName()) != null && name.equals(id.getId())) {
                // The CompiledID is a RuneTimeIterator & so it needs to be replaced by the missing link
                return this.missingLink;
            } else {
                // The compiledID is a compiledPath
                return new CompiledPath(this.missingLink, id.getId());
            }
        } else {
            return cv;
        }
    } else if (cv instanceof CompiledIndexOperation) {
        CompiledIndexOperation co = (CompiledIndexOperation) cv;
        CompiledValue cv1 = co.getExpression();
        StringBuilder sb = new StringBuilder();
        cv1.generateCanonicalizedExpression(sb, context);
        if (sb.toString().startsWith(this.canonicalizedIteratorNames[0])) {
            cv1 = getModifiedDependentCompiledValue(context, currItrID, cv1, true);
        } else {
            cv1 = getModifiedDependentCompiledValue(context, currItrID, cv1, false);
        }
        return new CompiledIndexOperation(getModifiedDependentCompiledValue(context, currItrID, co.getReceiver(), isDependent), cv1);
    } else {
        return cv;
    }
}
Also used : CompiledIteratorDef(org.apache.geode.cache.query.internal.CompiledIteratorDef) CompiledID(org.apache.geode.cache.query.internal.CompiledID) CompiledFunction(org.apache.geode.cache.query.internal.CompiledFunction) CompiledValue(org.apache.geode.cache.query.internal.CompiledValue) ArrayList(java.util.ArrayList) CompiledPath(org.apache.geode.cache.query.internal.CompiledPath) CompiledIndexOperation(org.apache.geode.cache.query.internal.CompiledIndexOperation) CompiledOperation(org.apache.geode.cache.query.internal.CompiledOperation) ArrayList(java.util.ArrayList) List(java.util.List) RuntimeIterator(org.apache.geode.cache.query.internal.RuntimeIterator)

Example 2 with CompiledIteratorDef

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

the class FunctionalIndexCreationHelper method modifyIterDefToSuiteIMQ.

private Object[] modifyIterDefToSuiteIMQ(CompiledIteratorDef iterDef) throws IndexInvalidException {
    Object[] retValues = { null, null };
    try {
        CompiledValue def = iterDef.getCollectionExpr();
        if (def instanceof CompiledRegion) {
            CompiledBindArgument bindArg = new CompiledBindArgument(1);
            CompiledIteratorDef newDef = new CompiledIteratorDef(iterDef.getName(), null, bindArg);
            retValues[0] = def.evaluate(this.context);
            retValues[1] = newDef;
            return retValues;
        }
        if (def instanceof CompiledPath || def instanceof CompiledOperation || def instanceof CompiledIndexOperation) {
            CompiledValue cv = def;
            List reconstruct = new ArrayList();
            while (!(cv instanceof CompiledRegion)) {
                CompiledValue prevCV = cv;
                if (cv instanceof CompiledOperation) {
                    reconstruct.add(0, ((CompiledOperation) cv).getArguments());
                    reconstruct.add(0, ((CompiledOperation) cv).getMethodName());
                    cv = ((CompiledOperation) cv).getReceiver(this.context);
                } else if (cv instanceof CompiledPath) {
                    reconstruct.add(0, ((CompiledPath) cv).getTailID());
                    cv = ((CompiledPath) cv).getReceiver();
                } else if (cv instanceof CompiledIndexOperation) {
                    reconstruct.add(0, ((CompiledIndexOperation) cv).getExpression());
                    cv = ((CompiledIndexOperation) cv).getReceiver();
                } else {
                    throw new IndexInvalidException(LocalizedStrings.FunctionalIndexCreationHelper_FUNCTIONALINDEXCREATIONHELPERPREPAREFROMCLAUSEFROM_CLAUSE_IS_NEITHER_A_COMPILEDPATH_NOR_COMPILEDOPERATION.toLocalizedString());
                }
                reconstruct.add(0, prevCV.getType());
            }
            CompiledValue v = cv;
            cv = new CompiledBindArgument(1);
            int len = reconstruct.size();
            for (int j = 0; j < len; ++j) {
                Object obj = reconstruct.get(j);
                if (obj instanceof Integer) {
                    int tokenType = (Integer) obj;
                    if (tokenType == CompiledValue.PATH) {
                        cv = new CompiledPath(cv, (String) reconstruct.get(++j));
                    } else if (tokenType == OQLLexerTokenTypes.TOK_LBRACK) {
                        cv = new CompiledIndexOperation(cv, (CompiledValue) reconstruct.get(++j));
                    } else if (tokenType == OQLLexerTokenTypes.METHOD_INV) {
                        cv = new CompiledOperation(cv, (String) reconstruct.get(++j), (List) reconstruct.get(++j));
                    }
                }
            }
            CompiledIteratorDef newDef = new CompiledIteratorDef(iterDef.getName(), null, cv);
            retValues[0] = v.evaluate(this.context);
            retValues[1] = newDef;
            return retValues;
        }
    } catch (Exception e) {
        throw new IndexInvalidException(e);
    }
    return retValues;
}
Also used : CompiledIteratorDef(org.apache.geode.cache.query.internal.CompiledIteratorDef) CompiledValue(org.apache.geode.cache.query.internal.CompiledValue) ArrayList(java.util.ArrayList) CompiledPath(org.apache.geode.cache.query.internal.CompiledPath) CompiledIndexOperation(org.apache.geode.cache.query.internal.CompiledIndexOperation) AmbiguousNameException(org.apache.geode.cache.query.AmbiguousNameException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) IndexInvalidException(org.apache.geode.cache.query.IndexInvalidException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) CompiledBindArgument(org.apache.geode.cache.query.internal.CompiledBindArgument) CompiledOperation(org.apache.geode.cache.query.internal.CompiledOperation) ArrayList(java.util.ArrayList) List(java.util.List) CompiledRegion(org.apache.geode.cache.query.internal.CompiledRegion) IndexInvalidException(org.apache.geode.cache.query.IndexInvalidException)

Example 3 with CompiledIteratorDef

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

the class RangeIndexAPIJUnitTest method bindIterators.

private void bindIterators(ExecutionContext context, String string) throws AmbiguousNameException, TypeMismatchException, NameResolutionException {
    QCompiler compiler = new QCompiler();
    List compilerItrDefs = compiler.compileFromClause(string);
    context.newScope(0);
    for (Object itrDef : compilerItrDefs) {
        CompiledIteratorDef iterDef = (CompiledIteratorDef) itrDef;
        RuntimeIterator rIter = iterDef.getRuntimeIterator(context);
        context.bindIterator(rIter);
    }
}
Also used : CompiledIteratorDef(org.apache.geode.cache.query.internal.CompiledIteratorDef) QCompiler(org.apache.geode.cache.query.internal.QCompiler) List(java.util.List) RuntimeIterator(org.apache.geode.cache.query.internal.RuntimeIterator)

Example 4 with CompiledIteratorDef

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

the class CqQueryImpl method validateCq.

/**
   * Validates the CQ. Checks for cq constraints. Also sets the base region name.
   */
void validateCq() {
    InternalCache cache = cqService.getInternalCache();
    DefaultQuery locQuery = (DefaultQuery) cache.getLocalQueryService().newQuery(this.queryString);
    this.query = locQuery;
    // assert locQuery != null;
    // validate Query.
    // parameters are not permitted
    Object[] parameters = new Object[0];
    // check that it is only a SELECT statement (possibly with IMPORTs)
    CompiledSelect select = locQuery.getSimpleSelect();
    if (select == null) {
        throw new UnsupportedOperationException(LocalizedStrings.CqQueryImpl_CQ_QUERIES_MUST_BE_A_SELECT_STATEMENT_ONLY.toLocalizedString());
    }
    // must not be a DISTINCT select
    if (select.isDistinct()) {
        throw new UnsupportedOperationException(LocalizedStrings.CqQueryImpl_SELECT_DISTINCT_QUERIES_NOT_SUPPORTED_IN_CQ.toLocalizedString());
    }
    // get the regions referenced in this query
    Set regionsInQuery = locQuery.getRegionsInQuery(parameters);
    // (though it could still be one region referenced multiple times)
    if (regionsInQuery.size() > 1 || regionsInQuery.size() < 1) {
        throw new UnsupportedOperationException(LocalizedStrings.CqQueryImpl_CQ_QUERIES_MUST_REFERENCE_ONE_AND_ONLY_ONE_REGION.toLocalizedString());
    }
    this.regionName = (String) regionsInQuery.iterator().next();
    // make sure the where clause references no regions
    Set regions = new HashSet();
    CompiledValue whereClause = select.getWhereClause();
    if (whereClause != null) {
        whereClause.getRegionsInQuery(regions, parameters);
        if (!regions.isEmpty()) {
            throw new UnsupportedOperationException(LocalizedStrings.CqQueryImpl_THE_WHERE_CLAUSE_IN_CQ_QUERIES_CANNOT_REFER_TO_A_REGION.toLocalizedString());
        }
    }
    List fromClause = select.getIterators();
    // cannot have more than one iterator in FROM clause
    if (fromClause.size() > 1) {
        throw new UnsupportedOperationException(LocalizedStrings.CqQueryImpl_CQ_QUERIES_CANNOT_HAVE_MORE_THAN_ONE_ITERATOR_IN_THE_FROM_CLAUSE.toLocalizedString());
    }
    // the first iterator in the FROM clause must be just a CompiledRegion
    CompiledIteratorDef itrDef = (CompiledIteratorDef) fromClause.get(0);
    // to the region. Check to make sure it is only a CompiledRegion
    if (!(itrDef.getCollectionExpr() instanceof CompiledRegion)) {
        throw new UnsupportedOperationException(LocalizedStrings.CqQueryImpl_CQ_QUERIES_MUST_HAVE_A_REGION_PATH_ONLY_AS_THE_FIRST_ITERATOR_IN_THE_FROM_CLAUSE.toLocalizedString());
    }
    // must not have any projections
    List projs = select.getProjectionAttributes();
    if (projs != null) {
        throw new UnsupportedOperationException(LocalizedStrings.CqQueryImpl_CQ_QUERIES_DO_NOT_SUPPORT_PROJECTIONS.toLocalizedString());
    }
    // check the orderByAttrs, not supported
    List orderBys = select.getOrderByAttrs();
    if (orderBys != null) {
        throw new UnsupportedOperationException(LocalizedStrings.CqQueryImpl_CQ_QUERIES_DO_NOT_SUPPORT_ORDER_BY.toLocalizedString());
    }
    // Set Query ExecutionContext, that will be used in later execution.
    this.setQueryExecutionContext(new QueryExecutionContext(null, (InternalCache) this.cqService.getCache()));
}
Also used : CompiledIteratorDef(org.apache.geode.cache.query.internal.CompiledIteratorDef) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) HashSet(java.util.HashSet) Set(java.util.Set) QueryExecutionContext(org.apache.geode.cache.query.internal.QueryExecutionContext) CompiledValue(org.apache.geode.cache.query.internal.CompiledValue) InternalCache(org.apache.geode.internal.cache.InternalCache) CompiledSelect(org.apache.geode.cache.query.internal.CompiledSelect) List(java.util.List) CompiledRegion(org.apache.geode.cache.query.internal.CompiledRegion) HashSet(java.util.HashSet)

Example 5 with CompiledIteratorDef

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

the class FunctionalIndexCreationHelper method prepareFromClause.

/**
   * The function is modified to optimize the index creation code. If the 0th iterator of from
   * clause is not on Entries, then the 0th iterator is replaced with that of entries & the value
   * corresponding to original iterator is derived from the 0th iterator as additional projection
   * attribute. All the other iterators & index expression if were dependent on 0th iterator are
   * also appropriately modified such that they are correctly derived on the modified 0th iterator.
   * <p>
   * TODO: method is too complex for IDE to analyze -- refactor prepareFromClause
   */
private void prepareFromClause(IndexManager imgr) throws IndexInvalidException {
    if (this.imports != null) {
        this.compiler.compileImports(this.imports);
    }
    List list = this.compiler.compileFromClause(this.fromClause);
    if (list == null) {
        throw new IndexInvalidException(LocalizedStrings.FunctionalIndexCreationHelper_INVALID_FROM_CLAUSE_0.toLocalizedString(this.fromClause));
    }
    int size = list.size();
    this.canonicalizedIteratorNames = new String[size];
    this.canonicalizedIteratorDefinitions = new String[size];
    StringBuilder tempBuff = new StringBuilder();
    boolean isFromClauseNull = true;
    try {
        PartitionedRegion pr = this.context.getPartitionedRegion();
        for (int i = 0; i < size; i++) {
            CompiledIteratorDef iterDef = (CompiledIteratorDef) list.get(i);
            iterDef.computeDependencies(this.context);
            RuntimeIterator rIter = iterDef.getRuntimeIterator(this.context);
            this.context.addToIndependentRuntimeItrMapForIndexCreation(iterDef);
            this.context.bindIterator(rIter);
            if (i != 0 && !iterDef.isDependentOnCurrentScope(this.context)) {
                throw new IndexInvalidException(LocalizedStrings.FunctionalIndexCreationHelper_INVALID_FROM_CLAUSE_0_SUBSEQUENT_ITERATOR_EXPRESSIONS_IN_FROM_CLAUSE_MUST_BE_DEPENDENT_ON_PREVIOUS_ITERATORS.toLocalizedString(this.fromClause));
            }
            String definition = rIter.getDefinition();
            this.canonicalizedIteratorDefinitions[i] = definition;
            // Bind the Index_Internal_ID to the RuntimeIterator
            this.canonicalizedIteratorNames[i] = imgr.putCanonicalizedIteratorNameIfAbsent(definition);
            if (pr != null) {
                this.canonicalizedIteratorNames[i] = pr.getIndexManager().putCanonicalizedIteratorNameIfAbsent(definition);
            } else {
                this.canonicalizedIteratorNames[i] = imgr.putCanonicalizedIteratorNameIfAbsent(definition);
            }
            rIter.setIndexInternalID(this.canonicalizedIteratorNames[i]);
            tempBuff.append(definition).append(' ').append(this.canonicalizedIteratorNames[i]).append(", ");
            isFromClauseNull = false;
            CompiledIteratorDef newItr;
            if (i == 0) {
                CompiledValue cv = iterDef.getCollectionExpr();
                this.addnlProjType = rIter.getElementType();
                String name = iterDef.getName();
                if (isEmpty(name)) {
                    // In case the name of iterator is null or blank set it to index_internal_id
                    name = this.canonicalizedIteratorNames[i];
                }
                CompiledValue newCollExpr = new CompiledPath(new CompiledBindArgument(1), "entries");
                // TODO: What if cv is not an instance of CompiledRegion
                if (cv instanceof CompiledRegion) {
                    this.missingLink = new CompiledPath(new CompiledID(name), "value");
                    this.additionalProj = this.missingLink;
                } else if (cv instanceof CompiledOperation || cv instanceof CompiledPath || cv instanceof CompiledIndexOperation) {
                    CompiledValue prevCV;
                    List reconstruct = new ArrayList();
                    while (!(cv instanceof CompiledRegion)) {
                        prevCV = cv;
                        if (cv instanceof CompiledOperation) {
                            reconstruct.add(0, ((CompiledOperation) cv).getArguments());
                            reconstruct.add(0, ((CompiledOperation) cv).getMethodName());
                            cv = ((CompiledOperation) cv).getReceiver(this.context);
                        } else if (cv instanceof CompiledPath) {
                            reconstruct.add(0, ((CompiledPath) cv).getTailID());
                            cv = cv.getReceiver();
                        } else if (cv instanceof CompiledIndexOperation) {
                            reconstruct.add(0, ((CompiledIndexOperation) cv).getExpression());
                            cv = cv.getReceiver();
                        } else {
                            throw new IndexInvalidException(LocalizedStrings.FunctionalIndexCreationHelper_FUNCTIONALINDEXCREATIONHELPERPREPAREFROMCLAUSEFROM_CLAUSE_IS_NEITHER_A_COMPILEDPATH_NOR_COMPILEDOPERATION.toLocalizedString());
                        }
                        reconstruct.add(0, prevCV.getType());
                    }
                    int firstTokenType = (Integer) reconstruct.get(0);
                    if (firstTokenType == CompiledValue.PATH) {
                        String tailID = (String) reconstruct.get(1);
                        if (tailID.equals("asList") || tailID.equals("asSet") || tailID.equals("values") || tailID.equals("toArray") || tailID.equals("getValues")) {
                            this.missingLink = new CompiledPath(new CompiledID(name), "value");
                        } else if (tailID.equals("keys") || tailID.equals("getKeys") || tailID.equals("keySet")) {
                            this.missingLink = new CompiledPath(new CompiledID(name), "key");
                            this.isFirstIteratorRegionKey = true;
                        } else if (tailID.equals("entries") || tailID.equals("getEntries") || tailID.equals("entrySet")) {
                            this.isFirstIteratorRegionEntry = true;
                        } else {
                            throw new IndexInvalidException(LocalizedStrings.FunctionalIndexCreationHelper_FUNCTIONALINDEXCREATIONHELPERPREPAREFROMCLAUSEFROM_CLAUSE_DOES_NOT_EVALUATE_TO_VALID_COLLECTION.toLocalizedString());
                        }
                        remove(reconstruct, 2, 0);
                        int secondTokenType = reconstruct.size() > 1 ? (Integer) reconstruct.get(0) : -1;
                        if (!this.isFirstIteratorRegionEntry && secondTokenType == OQLLexerTokenTypes.TOK_LBRACK) {
                            // should be thrown as IndexOpn on set is not defined.
                            if (tailID.equals("values") || tailID.equals("getValues")) {
                                boolean returnEntryForRegionCollection = true;
                                this.additionalProj = new CompiledIndexOperation(new CompiledBindArgument(1), (CompiledValue) reconstruct.get(1), returnEntryForRegionCollection);
                                this.isFirstIteratorRegionEntry = true;
                            } else if (tailID.equals("toList") || tailID.equals("toArray")) {
                                // TODO: add support for toList and toArray
                                throw new IndexInvalidException(LocalizedStrings.FunctionalIndexCreationHelper_FUNCTIONALINDEXCREATIONHELPERPREPAREFROMCLAUSETOLIST_TOARRAY_NOT_SUPPORTED.toLocalizedString());
                            } else {
                                throw new IndexInvalidException(LocalizedStrings.FunctionalIndexCreationHelper_FUNCTIONALINDEXCREATIONHELPERPREPAREFROMCLAUSETOLIST_TOARRAY_NOT_SUPPORTED.toLocalizedString());
                            }
                            remove(reconstruct, 2, 0);
                        } else if (!this.isFirstIteratorRegionEntry && (secondTokenType == OQLLexerTokenTypes.METHOD_INV || secondTokenType == CompiledValue.PATH) && (tailID.equals("values") || tailID.equals("getValues") || tailID.equals("keySet") || tailID.equals("keys") || tailID.equals("getKeys"))) {
                            // Check if the second token name is toList or toArray or asSet.We need to remove
                            // those
                            String secTokName = (String) reconstruct.get(1);
                            if (secTokName.equals("asList") || secTokName.equals("asSet") || secTokName.equals("toArray")) {
                                remove(reconstruct, secondTokenType == OQLLexerTokenTypes.METHOD_INV ? 3 : 2, 0);
                            }
                        }
                    } else if (firstTokenType == OQLLexerTokenTypes.TOK_LBRACK) {
                        boolean returnEntryForRegionCollection = true;
                        this.additionalProj = new CompiledIndexOperation(new CompiledBindArgument(1), (CompiledValue) reconstruct.get(1), returnEntryForRegionCollection);
                        this.isFirstIteratorRegionEntry = true;
                    } else if (firstTokenType == OQLLexerTokenTypes.METHOD_INV) {
                        String methodName = (String) reconstruct.get(1);
                        if (methodName.equals("asList") || methodName.equals("asSet") || methodName.equals("values") || methodName.equals("toArray") || methodName.equals("getValues")) {
                            this.missingLink = new CompiledPath(new CompiledID(name), "value");
                        } else if (methodName.equals("keys") || methodName.equals("getKeys") || methodName.equals("keySet")) {
                            this.missingLink = new CompiledPath(new CompiledID(name), "key");
                            this.isFirstIteratorRegionKey = true;
                        } else if (methodName.equals("entries") || methodName.equals("getEntries") || methodName.equals("entrySet")) {
                            this.isFirstIteratorRegionEntry = true;
                            List args = (List) reconstruct.get(2);
                            if (args != null && args.size() == 1) {
                                Object obj = args.get(0);
                                if (obj instanceof CompiledBindArgument) {
                                    throw new IndexInvalidException(LocalizedStrings.FunctionalIndexCreationHelper_FUNCTIONALINDEXCREATIONHELPERPREPAREFROMCLAUSEENTRIES_METHOD_CALLED_WITH_COMPILEDBINDARGUMENT.toLocalizedString());
                                }
                            }
                        }
                        remove(reconstruct, 3, 0);
                        int secondTokenType = reconstruct.size() > 1 ? (Integer) reconstruct.get(0) : -1;
                        if (!this.isFirstIteratorRegionEntry && secondTokenType == OQLLexerTokenTypes.TOK_LBRACK) {
                            if (methodName.equals("values") || methodName.equals("getValues")) {
                                boolean returnEntryForRegionCollection = true;
                                newCollExpr = new CompiledIndexOperation(new CompiledBindArgument(1), (CompiledValue) reconstruct.get(1), returnEntryForRegionCollection);
                            } else if (methodName.equals("toList") || methodName.equals("toArray")) {
                                // TODO: add support for toList and toArray
                                throw new IndexInvalidException(LocalizedStrings.FunctionalIndexCreationHelper_FUNCTIONALINDEXCREATIONHELPERPREPAREFROMCLAUSETOLIST_TOARRAY_NOT_SUPPORTED_YET.toLocalizedString());
                            } else {
                                throw new IndexInvalidException(LocalizedStrings.FunctionalIndexCreationHelper_FUNCTIONALINDEXCREATIONHELPERPREPAREFROMCLAUSETOLIST_TOARRAY_NOT_SUPPORTED_YET.toLocalizedString());
                            }
                            remove(reconstruct, 2, 0);
                        } else if (!this.isFirstIteratorRegionEntry && (secondTokenType == OQLLexerTokenTypes.METHOD_INV || secondTokenType == CompiledValue.PATH) && (methodName.equals("values") || methodName.equals("getValues") || methodName.equals("keys") || methodName.equals("getKeys") || methodName.equals("keySet"))) {
                            // Check if the second token name is toList or toArray or asSet.We need to remove
                            // those
                            String secTokName = (String) reconstruct.get(1);
                            if (secTokName.equals("asList") || secTokName.equals("asSet") || secTokName.equals("toArray")) {
                                remove(reconstruct, secondTokenType == OQLLexerTokenTypes.METHOD_INV ? 3 : 2, 0);
                            }
                        }
                    }
                    if (!this.isFirstIteratorRegionEntry) {
                        this.additionalProj = this.missingLink;
                        int len = reconstruct.size();
                        for (int j = 0; j < len; ++j) {
                            Object obj = reconstruct.get(j);
                            if (obj instanceof Integer) {
                                int tokenType = (Integer) obj;
                                if (tokenType == CompiledValue.PATH) {
                                    this.additionalProj = new CompiledPath(this.additionalProj, (String) reconstruct.get(++j));
                                } else if (tokenType == OQLLexerTokenTypes.TOK_LBRACK) {
                                    this.additionalProj = new CompiledIndexOperation(this.additionalProj, (CompiledValue) reconstruct.get(++j));
                                } else if (tokenType == OQLLexerTokenTypes.METHOD_INV) {
                                    this.additionalProj = new CompiledOperation(this.additionalProj, (String) reconstruct.get(++j), (List) reconstruct.get(++j));
                                }
                            }
                        }
                    }
                } else {
                    throw new IndexInvalidException(LocalizedStrings.FunctionalIndexCreationHelper_FUNCTIONALINDEXCREATIONHELPERPREPAREFROMCLAUSEFROM_CLAUSE_IS_NEITHER_A_COMPILEDPATH_NOR_COMPILEDOPERATION.toLocalizedString());
                }
                if (!this.isFirstIteratorRegionEntry) {
                    newItr = new CompiledIteratorDef(name, null, newCollExpr);
                    this.indexInitIterators = new ArrayList();
                    this.indexInitIterators.add(newItr);
                }
            } else if (!this.isFirstIteratorRegionEntry) {
                newItr = iterDef;
                if (rIter.getDefinition().contains(this.canonicalizedIteratorNames[0])) {
                    newItr = (CompiledIteratorDef) getModifiedDependentCompiledValue(this.context, i, iterDef, true);
                }
                this.indexInitIterators.add(newItr);
            }
        }
    } catch (IndexInvalidException e) {
        throw e;
    } catch (Exception e) {
        throw new IndexInvalidException(e);
    }
    if (isFromClauseNull)
        throw new IndexInvalidException(LocalizedStrings.FunctionalIndexCreationHelper_INVALID_FROM_CLAUSE_0.toLocalizedString(this.fromClause));
    this.fromClause = tempBuff.substring(0, tempBuff.length() - 2);
    this.fromClauseIterators = list;
}
Also used : CompiledIteratorDef(org.apache.geode.cache.query.internal.CompiledIteratorDef) CompiledID(org.apache.geode.cache.query.internal.CompiledID) CompiledValue(org.apache.geode.cache.query.internal.CompiledValue) ArrayList(java.util.ArrayList) CompiledPath(org.apache.geode.cache.query.internal.CompiledPath) CompiledIndexOperation(org.apache.geode.cache.query.internal.CompiledIndexOperation) AmbiguousNameException(org.apache.geode.cache.query.AmbiguousNameException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) IndexInvalidException(org.apache.geode.cache.query.IndexInvalidException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) CompiledBindArgument(org.apache.geode.cache.query.internal.CompiledBindArgument) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) CompiledOperation(org.apache.geode.cache.query.internal.CompiledOperation) ArrayList(java.util.ArrayList) List(java.util.List) CompiledRegion(org.apache.geode.cache.query.internal.CompiledRegion) IndexInvalidException(org.apache.geode.cache.query.IndexInvalidException) RuntimeIterator(org.apache.geode.cache.query.internal.RuntimeIterator)

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