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;
}
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;
}
}
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);
}
}
}
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);
}
}
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;
}
}
Aggregations