Search in sources :

Example 6 with CompiledValue

use of org.apache.geode.cache.query.internal.CompiledValue 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 7 with CompiledValue

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

the class AbstractMapIndex method isMatchingWithIndexExpression.

@Override
public boolean isMatchingWithIndexExpression(CompiledValue condnExpr, String conditionExprStr, ExecutionContext context) throws AmbiguousNameException, TypeMismatchException, NameResolutionException {
    if (this.isAllKeys) {
        // stripped of the index arg & see if it matches.
        if (condnExpr instanceof MapIndexable) {
            MapIndexable mi = (MapIndexable) condnExpr;
            CompiledValue recvr = mi.getRecieverSansIndexArgs();
            StringBuilder sb = new StringBuilder();
            recvr.generateCanonicalizedExpression(sb, context);
            sb.append('[').append(']');
            return sb.toString().equals(this.patternStr[0]);
        } else {
            return false;
        }
    } else {
        for (String expr : this.patternStr) {
            if (expr.equals(conditionExprStr)) {
                return true;
            }
        }
        return false;
    }
}
Also used : CompiledValue(org.apache.geode.cache.query.internal.CompiledValue) MapIndexable(org.apache.geode.cache.query.internal.MapIndexable)

Example 8 with CompiledValue

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

the class AbstractIndex method applyProjection.

void applyProjection(List projAttrib, ExecutionContext context, Collection result, Object iterValue, SelectResults intermediateResults, boolean isIntersection) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
    if (projAttrib == null) {
        iterValue = deserializePdxForLocalDistinctQuery(context, iterValue);
        this.addToResultsWithUnionOrIntersection(result, intermediateResults, isIntersection, iterValue);
    } else {
        boolean isStruct = result instanceof SelectResults && ((SelectResults) result).getCollectionType().getElementType() != null && ((SelectResults) result).getCollectionType().getElementType().isStructType();
        if (isStruct) {
            int projCount = projAttrib.size();
            Object[] values = new Object[projCount];
            Iterator projIter = projAttrib.iterator();
            int i = 0;
            while (projIter.hasNext()) {
                Object[] projDef = (Object[]) projIter.next();
                values[i] = deserializePdxForLocalDistinctQuery(context, ((CompiledValue) projDef[1]).evaluate(context));
                i++;
            }
            this.addToStructsWithUnionOrIntersection(result, intermediateResults, isIntersection, values);
        } else {
            Object[] temp = (Object[]) projAttrib.get(0);
            Object val = deserializePdxForLocalDistinctQuery(context, ((CompiledValue) temp[1]).evaluate(context));
            this.addToResultsWithUnionOrIntersection(result, intermediateResults, isIntersection, val);
        }
    }
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) CompiledValue(org.apache.geode.cache.query.internal.CompiledValue) RuntimeIterator(org.apache.geode.cache.query.internal.RuntimeIterator) CloseableIterator(org.apache.geode.internal.cache.persistence.query.CloseableIterator) Iterator(java.util.Iterator)

Example 9 with CompiledValue

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

the class HashIndex method evaluateEntry.

/**
   * This evaluates the left and right side of a where condition for which this Index was used.
   * Like, if condition is "ID > 1", {@link IndexInfo} will contain Left as ID, Right as '1' and
   * operator as TOK_GT. This method will evaluate ID from region entry value and verify the ID > 1.
   *
   * Note: IndexInfo is created for each query separately based on the condition being evaluated
   * using the Index.
   *
   * @return true if RegionEntry value satisfies the where condition (contained in IndexInfo).
   */
private boolean evaluateEntry(IndexInfo indexInfo, ExecutionContext context, Object keyVal) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
    CompiledValue path = ((IndexInfo) indexInfo)._path();
    Object left = path.evaluate(context);
    CompiledValue key = ((IndexInfo) indexInfo)._key();
    Object right = null;
    // For CompiledUndefined indexInfo has null key.
    if (keyVal == null && key == null) {
        if (left == QueryService.UNDEFINED) {
            return true;
        } else {
            return false;
        }
    }
    if (key != null) {
        right = key.evaluate(context);
    } else {
        right = keyVal;
    }
    int operator = indexInfo._operator();
    if (left == null && right == null) {
        return Boolean.TRUE;
    } else {
        return (Boolean) TypeUtils.compare(left, right, operator);
    }
}
Also used : CompiledValue(org.apache.geode.cache.query.internal.CompiledValue) StoredObject(org.apache.geode.internal.offheap.StoredObject) IndexInfo(org.apache.geode.cache.query.internal.IndexInfo)

Example 10 with CompiledValue

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

the class QueryDataFunction method compileQuery.

/**
   * Compile the query and return a set of regions involved in the query It throws an
   * QueryInvalidException if the query is not proper
   *
   * @param cache current cache
   * @param query input query
   *
   * @return a set of regions involved in the query
   */
private static Set<String> compileQuery(final InternalCache cache, final String query) throws QueryInvalidException {
    QCompiler compiler = new QCompiler();
    Set<String> regionsInQuery;
    try {
        CompiledValue compiledQuery = compiler.compileQuery(query);
        Set<String> regions = new HashSet<>();
        compiledQuery.getRegionsInQuery(regions, null);
        regionsInQuery = Collections.unmodifiableSet(regions);
        return regionsInQuery;
    } catch (QueryInvalidException qe) {
        logger.error("{} Failed, Error {}", query, qe.getMessage(), qe);
        throw qe;
    }
}
Also used : QCompiler(org.apache.geode.cache.query.internal.QCompiler) CompiledValue(org.apache.geode.cache.query.internal.CompiledValue) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) HashSet(java.util.HashSet)

Aggregations

CompiledValue (org.apache.geode.cache.query.internal.CompiledValue)21 HashSet (java.util.HashSet)7 List (java.util.List)6 Set (java.util.Set)6 Region (org.apache.geode.cache.Region)5 SelectResults (org.apache.geode.cache.query.SelectResults)5 QueryObserverAdapter (org.apache.geode.cache.query.internal.QueryObserverAdapter)5 RuntimeIterator (org.apache.geode.cache.query.internal.RuntimeIterator)5 LocalRegion (org.apache.geode.internal.cache.LocalRegion)5 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 IndexInvalidException (org.apache.geode.cache.query.IndexInvalidException)4 Query (org.apache.geode.cache.query.Query)4 Portfolio (org.apache.geode.cache.query.data.Portfolio)4 CompiledIteratorDef (org.apache.geode.cache.query.internal.CompiledIteratorDef)4 CompiledPath (org.apache.geode.cache.query.internal.CompiledPath)4 QueryObserver (org.apache.geode.cache.query.internal.QueryObserver)4 AmbiguousNameException (org.apache.geode.cache.query.AmbiguousNameException)3 NameResolutionException (org.apache.geode.cache.query.NameResolutionException)3