use of org.apache.geode.cache.query.internal.CompiledSortCriterion in project geode by apache.
the class RangeIndex method evaluate.
private void evaluate(Object key, int operator, Collection results, Set keysToRemove, int limit, ExecutionContext context) throws TypeMismatchException {
key = TypeUtils.indexKeyFor(key);
Boolean orderByClause = (Boolean) context.cacheGet(CompiledValue.CAN_APPLY_ORDER_BY_AT_INDEX);
boolean multiColOrderBy = false;
boolean asc = true;
List orderByAttrs = null;
if (orderByClause != null && orderByClause) {
orderByAttrs = (List) context.cacheGet(CompiledValue.ORDERBY_ATTRIB);
CompiledSortCriterion csc = (CompiledSortCriterion) orderByAttrs.get(0);
asc = !csc.getCriterion();
multiColOrderBy = orderByAttrs.size() > 1;
}
limit = multiColOrderBy ? -1 : limit;
try {
switch(operator) {
case OQLLexerTokenTypes.TOK_EQ:
{
assert keysToRemove == null;
addValuesToResult(this.valueToEntriesMap.get(key), results, keysToRemove, limit, context);
break;
}
case OQLLexerTokenTypes.TOK_LT:
{
NavigableMap sm = this.valueToEntriesMap.headMap(key, false);
sm = asc ? sm : sm.descendingMap();
addValuesToResult(sm, results, keysToRemove, limit, context);
break;
}
case OQLLexerTokenTypes.TOK_LE:
{
NavigableMap sm = this.valueToEntriesMap.headMap(key, true);
sm = asc ? sm : sm.descendingMap();
addValuesToResult(sm, results, keysToRemove, limit, context);
break;
}
case OQLLexerTokenTypes.TOK_GT:
{
// Asif:As tail Map returns the SortedMap vie which is greater than or
// equal to the key passed, the equal to key needs to be removed.
// However if the boundtary key is already part of the keysToRemove set
// then we do not have to remove it as it is already taken care of
NavigableMap sm = this.valueToEntriesMap.tailMap(key, false);
sm = asc ? sm : sm.descendingMap();
addValuesToResult(sm, results, keysToRemove, limit, context);
break;
}
case OQLLexerTokenTypes.TOK_GE:
{
NavigableMap sm = this.valueToEntriesMap.tailMap(key, true);
sm = asc ? sm : sm.descendingMap();
addValuesToResult(sm, results, keysToRemove, limit, context);
break;
}
case OQLLexerTokenTypes.TOK_NE_ALT:
case OQLLexerTokenTypes.TOK_NE:
{
NavigableMap sm = this.valueToEntriesMap;
if (!asc) {
sm = sm.descendingMap();
}
if (keysToRemove == null) {
addValuesToResultSingleKeyToRemove(sm, results, key, limit, context);
} else {
// TODO:Asif Somehow avoid this removal & then addition
keysToRemove.add(key);
addValuesToResult(sm, results, keysToRemove, limit, context);
}
nullMappedEntries.addValuesToCollection(results, limit, context);
undefinedMappedEntries.addValuesToCollection(results, limit, context);
break;
}
default:
{
throw new IllegalArgumentException(LocalizedStrings.RangeIndex_OPERATOR_0.toLocalizedString(valueOf(operator)));
}
}
// end switch
} catch (ClassCastException ex) {
if (operator == OQLLexerTokenTypes.TOK_EQ) {
// result is empty set
return;
} else if (operator == OQLLexerTokenTypes.TOK_NE || operator == OQLLexerTokenTypes.TOK_NE_ALT) {
// put
// all
// in
// result
NavigableMap sm = this.valueToEntriesMap;
if (!asc) {
sm = sm.descendingMap();
}
addValuesToResult(sm, results, keysToRemove, limit, context);
nullMappedEntries.addValuesToCollection(results, limit, context);
undefinedMappedEntries.addValuesToCollection(results, limit, context);
} else {
// otherwise throw exception
throw new TypeMismatchException("", ex);
}
}
}
use of org.apache.geode.cache.query.internal.CompiledSortCriterion in project geode by apache.
the class RangeIndex method evaluate.
private void evaluate(Object key, int operator, Collection results, CompiledValue iterOps, RuntimeIterator runtimeItr, ExecutionContext context, List projAttrib, SelectResults intermediateResults, boolean isIntersection, int limit, boolean applyOrderBy, List orderByAttribs) throws TypeMismatchException, FunctionDomainException, NameResolutionException, QueryInvocationTargetException {
key = TypeUtils.indexKeyFor(key);
boolean multiColOrderBy = false;
boolean asc = true;
if (applyOrderBy) {
CompiledSortCriterion csc = (CompiledSortCriterion) orderByAttribs.get(0);
asc = !csc.getCriterion();
multiColOrderBy = orderByAttribs.size() > 1;
}
limit = multiColOrderBy ? -1 : limit;
try {
switch(operator) {
case OQLLexerTokenTypes.TOK_EQ:
{
addValuesToResult(this.valueToEntriesMap.get(key), results, null, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
break;
}
case OQLLexerTokenTypes.TOK_LT:
{
NavigableMap sm = this.valueToEntriesMap.headMap(key, false);
sm = asc ? sm : sm.descendingMap();
addValuesToResult(sm, results, null, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
break;
}
case OQLLexerTokenTypes.TOK_LE:
{
NavigableMap sm = this.valueToEntriesMap.headMap(key, true);
sm = asc ? sm : sm.descendingMap();
addValuesToResult(sm, results, null, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
break;
}
case OQLLexerTokenTypes.TOK_GT:
{
// Asif:As tail Map returns the SortedMap vie which is greater
// than or equal
// to the key passed, the equal to key needs to be removed.
// However if the boundary key is already part of the
// keysToRemove set
// then we do not have to remove it as it is already taken care
// of
NavigableMap sm = this.valueToEntriesMap.tailMap(key, false);
sm = asc ? sm : sm.descendingMap();
addValuesToResult(sm, results, null, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
break;
}
case OQLLexerTokenTypes.TOK_GE:
{
NavigableMap sm = this.valueToEntriesMap.tailMap(key, true);
sm = asc ? sm : sm.descendingMap();
addValuesToResult(sm, results, null, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
break;
}
case OQLLexerTokenTypes.TOK_NE_ALT:
case OQLLexerTokenTypes.TOK_NE:
{
NavigableMap sm = this.valueToEntriesMap;
if (!asc) {
sm = sm.descendingMap();
}
addValuesToResult(sm, results, key, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
nullMappedEntries.addValuesToCollection(results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
undefinedMappedEntries.addValuesToCollection(results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
break;
}
default:
{
throw new IllegalArgumentException("Operator = " + operator);
}
}
// end switch
} catch (ClassCastException ex) {
if (operator == OQLLexerTokenTypes.TOK_EQ) {
// set
return;
} else if (operator == OQLLexerTokenTypes.TOK_NE || operator == OQLLexerTokenTypes.TOK_NE_ALT) {
// put
// all
// in
// result
NavigableMap sm = this.valueToEntriesMap;
if (!asc) {
sm = sm.descendingMap();
}
addValuesToResult(sm, results, key, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
nullMappedEntries.addValuesToCollection(results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
undefinedMappedEntries.addValuesToCollection(results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
} else {
// otherwise throw exception
throw new TypeMismatchException("", ex);
}
}
}
Aggregations