Search in sources :

Example 11 with CompiledSortCriterion

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);
        }
    }
}
Also used : CompiledSortCriterion(org.apache.geode.cache.query.internal.CompiledSortCriterion) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) NavigableMap(java.util.NavigableMap) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 12 with CompiledSortCriterion

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);
        }
    }
}
Also used : CompiledSortCriterion(org.apache.geode.cache.query.internal.CompiledSortCriterion) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) NavigableMap(java.util.NavigableMap) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException)

Aggregations

CompiledSortCriterion (org.apache.geode.cache.query.internal.CompiledSortCriterion)12 ArrayList (java.util.ArrayList)6 List (java.util.List)6 HashSet (java.util.HashSet)5 NavigableMap (java.util.NavigableMap)4 ConcurrentNavigableMap (java.util.concurrent.ConcurrentNavigableMap)4 TypeMismatchException (org.apache.geode.cache.query.TypeMismatchException)4 Struct (org.apache.geode.cache.query.Struct)3 CompiledSelect (org.apache.geode.cache.query.internal.CompiledSelect)3 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)3 Region (org.apache.geode.cache.Region)2 Query (org.apache.geode.cache.query.Query)2 QueryService (org.apache.geode.cache.query.QueryService)2 SelectResults (org.apache.geode.cache.query.SelectResults)2 Portfolio (org.apache.geode.cache.query.data.Portfolio)2 IndexStoreEntry (org.apache.geode.cache.query.internal.index.IndexStore.IndexStoreEntry)2 MemoryIndexStoreEntry (org.apache.geode.cache.query.internal.index.MemoryIndexStore.MemoryIndexStoreEntry)2 Test (org.junit.Test)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1