use of org.apache.geode.cache.query.internal.CompiledNegation 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;
}
Aggregations