Search in sources :

Example 1 with CompiledComparison

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

the class FunctionalIndexCreationHelper method prepareIndexExpression.

/**
   * This function is modified so that if the indexed expression has any dependency on the 0th
   * iterator, then it needs to modified by using the missing link so that it is derivable from the
   * 0th iterator.
   * <p>
   * TODO: refactor large method prepareIndexExpression
   */
private void prepareIndexExpression(String indexedExpression) throws IndexInvalidException {
    CompiledValue expr = this.compiler.compileQuery(indexedExpression);
    if (expr == null) {
        throw new IndexInvalidException(LocalizedStrings.FunctionalIndexCreationHelper_INVALID_INDEXED_EXPRESSION_0.toLocalizedString(indexedExpression));
    }
    if (expr instanceof CompiledUndefined || expr instanceof CompiledLiteral || expr instanceof CompiledComparison || expr instanceof CompiledBindArgument || expr instanceof CompiledNegation) {
        throw new IndexInvalidException(LocalizedStrings.FunctionalIndexCreationHelper_INVALID_INDEXED_EXPRESSION_0.toLocalizedString(indexedExpression));
    }
    try {
        StringBuilder sb = new StringBuilder();
        if (expr instanceof MapIndexable) {
            MapIndexable mi = (MapIndexable) expr;
            List<CompiledValue> indexingKeys = mi.getIndexingKeys();
            if (indexingKeys.size() == 1 && indexingKeys.get(0) == CompiledValue.MAP_INDEX_ALL_KEYS) {
                this.isMapTypeIndex = true;
                this.isAllKeys = true;
                // Strip the index operator
                expr = mi.getRecieverSansIndexArgs();
                expr.generateCanonicalizedExpression(sb, this.context);
                sb.append('[').append('*').append(']');
            } else if (indexingKeys.size() == 1) {
                expr.generateCanonicalizedExpression(sb, this.context);
            } else {
                this.isMapTypeIndex = true;
                this.multiIndexKeysPattern = new String[indexingKeys.size()];
                this.mapKeys = new Object[indexingKeys.size()];
                expr = mi.getRecieverSansIndexArgs();
                expr.generateCanonicalizedExpression(sb, this.context);
                sb.append('[');
                String prefixStr = sb.toString();
                StringBuilder sb2 = new StringBuilder();
                int size = indexingKeys.size();
                for (int j = 0; j < size; ++j) {
                    CompiledValue cv = indexingKeys.get(size - j - 1);
                    this.mapKeys[size - j - 1] = cv.evaluate(this.context);
                    StringBuilder sb3 = new StringBuilder();
                    cv.generateCanonicalizedExpression(sb3, this.context);
                    sb3.insert(0, prefixStr);
                    sb3.append(']');
                    this.multiIndexKeysPattern[j] = sb3.toString();
                    cv.generateCanonicalizedExpression(sb2, this.context);
                    sb2.insert(0, ',');
                }
                sb2.deleteCharAt(0);
                sb.append(sb2);
                sb.append(']');
            }
        } else {
            expr.generateCanonicalizedExpression(sb, this.context);
        }
        this.indexedExpression = sb.toString();
        this.modifiedIndexExpr = expr;
        if (!this.isFirstIteratorRegionEntry && this.indexedExpression.contains(this.canonicalizedIteratorNames[0])) {
            this.modifiedIndexExpr = getModifiedDependentCompiledValue(this.context, -1, expr, true);
        }
    } catch (Exception e) {
        throw new IndexInvalidException(LocalizedStrings.FunctionalIndexCreationHelper_INVALID_INDEXED_EXPRESSION_0.toLocalizedString(indexedExpression), e);
    }
    this.indexedExpr = expr;
}
Also used : CompiledValue(org.apache.geode.cache.query.internal.CompiledValue) CompiledUndefined(org.apache.geode.cache.query.internal.CompiledUndefined) CompiledComparison(org.apache.geode.cache.query.internal.CompiledComparison) CompiledLiteral(org.apache.geode.cache.query.internal.CompiledLiteral) 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) CompiledNegation(org.apache.geode.cache.query.internal.CompiledNegation) IndexInvalidException(org.apache.geode.cache.query.IndexInvalidException) MapIndexable(org.apache.geode.cache.query.internal.MapIndexable)

Aggregations

AmbiguousNameException (org.apache.geode.cache.query.AmbiguousNameException)1 IndexInvalidException (org.apache.geode.cache.query.IndexInvalidException)1 NameResolutionException (org.apache.geode.cache.query.NameResolutionException)1 TypeMismatchException (org.apache.geode.cache.query.TypeMismatchException)1 CompiledBindArgument (org.apache.geode.cache.query.internal.CompiledBindArgument)1 CompiledComparison (org.apache.geode.cache.query.internal.CompiledComparison)1 CompiledLiteral (org.apache.geode.cache.query.internal.CompiledLiteral)1 CompiledNegation (org.apache.geode.cache.query.internal.CompiledNegation)1 CompiledUndefined (org.apache.geode.cache.query.internal.CompiledUndefined)1 CompiledValue (org.apache.geode.cache.query.internal.CompiledValue)1 MapIndexable (org.apache.geode.cache.query.internal.MapIndexable)1