Search in sources :

Example 26 with TypeMismatchException

use of org.apache.geode.cache.query.TypeMismatchException 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)

Example 27 with TypeMismatchException

use of org.apache.geode.cache.query.TypeMismatchException in project geode by apache.

the class ExecutionContext method resolve.

public CompiledValue resolve(String name) throws TypeMismatchException, AmbiguousNameException {
    CompiledValue value = resolveAsVariable(name);
    if (value != null)
        return value;
    // attribute name or operation name (no args) of a variable in the current scope when there is
    // no ambiguity, i.e. this property name belongs to only one variable in the scope
    value = resolveImplicitPath(name);
    if (value == null)
        // cannot be resolved
        throw new TypeMismatchException(LocalizedStrings.ExecutionContext_THE_ATTRIBUTE_OR_METHOD_NAME_0_COULD_NOT_BE_RESOLVED.toLocalizedString(name));
    return value;
}
Also used : TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException)

Example 28 with TypeMismatchException

use of org.apache.geode.cache.query.TypeMismatchException in project geode by apache.

the class GroupByQueryDUnitTest method runQuery.

private void runQuery(VM queryVM) throws Exception {
    // createIndex(vm0, "compactRangeIndex", "entry.value",
    // "/region.entrySet entry");
    // Do Puts
    queryVM.invoke(new SerializableRunnable("putting data") {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion("portfolio");
            for (int i = 1; i < 200; ++i) {
                Portfolio pf = new Portfolio(i);
                pf.shortID = (short) ((short) i / 5);
                region.put("" + i, pf);
            }
        }
    });
    queryVM.invoke(new SerializableRunnable("query") {

        public void run() {
            try {
                QueryService qs = getCache().getQueryService();
                String queryStr = "select  p.shortID as short_id  from /portfolio p where p.ID >= 0 group by short_id ";
                Query query = qs.newQuery(queryStr);
                SelectResults<Struct> results = (SelectResults<Struct>) query.execute();
                Iterator<Struct> iter = results.iterator();
                int counter = 0;
                while (iter.hasNext()) {
                    Struct str = iter.next();
                    assertEquals(counter++, ((Short) str.get("short_id")).intValue());
                }
                assertEquals(39, counter - 1);
            } catch (QueryInvocationTargetException e) {
                fail(e.toString());
            } catch (NameResolutionException e) {
                fail(e.toString());
            } catch (TypeMismatchException e) {
                fail(e.toString());
            } catch (FunctionDomainException e) {
                fail(e.toString());
            }
        }
    });
}
Also used : Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) Struct(org.apache.geode.cache.query.Struct) SelectResults(org.apache.geode.cache.query.SelectResults) QueryService(org.apache.geode.cache.query.QueryService) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache)

Example 29 with TypeMismatchException

use of org.apache.geode.cache.query.TypeMismatchException in project geode by apache.

the class IndexOperatorJUnitTest method testWithNULL.

@Test
public void testWithNULL() throws Exception {
    runQuery(null, 0);
    runQuery(null, null);
    Object[] objectArray = { "a", "b" };
    try {
        runQuery(objectArray, null);
        fail();
    } catch (TypeMismatchException e) {
    }
    HashMap map = new HashMap();
    map.put("0", new Integer(11));
    map.put("1", new Integer(12));
    Object result = runQuery(map, null);
    if (result != null)
        fail();
}
Also used : HashMap(java.util.HashMap) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 30 with TypeMismatchException

use of org.apache.geode.cache.query.TypeMismatchException in project geode by apache.

the class GetDeliveredOrders method execute.

public void execute(FunctionContext context) {
    Cache c = null;
    ArrayList<Object> vals = new ArrayList<Object>();
    try {
        c = CacheFactory.getAnyInstance();
    } catch (CacheClosedException ex) {
        vals.add("NoCacheFoundResult");
        context.getResultSender().lastResult(vals);
    }
    String oql = "SELECT o.purchaseOrderNo, o.deliveryDate  FROM /orders o WHERE o.deliveryDate != NULL";
    final Query query = c.getQueryService().newQuery(oql);
    SelectResults result = null;
    try {
        result = (SelectResults) query.execute();
        int resultSize = result.size();
        if (result instanceof Collection<?>)
            for (Object item : result) {
                vals.add(item);
            }
    } catch (FunctionDomainException e) {
        if (c != null)
            c.getLogger().info("Caught FunctionDomainException while executing function GetDeliveredOrders: " + e.getMessage());
    } catch (TypeMismatchException e) {
        if (c != null)
            c.getLogger().info("Caught TypeMismatchException while executing function GetDeliveredOrders: " + e.getMessage());
    } catch (NameResolutionException e) {
        if (c != null)
            c.getLogger().info("Caught NameResolutionException while executing function GetDeliveredOrders: " + e.getMessage());
    } catch (QueryInvocationTargetException e) {
        if (c != null)
            c.getLogger().info("Caught QueryInvocationTargetException while executing function GetDeliveredOrders: " + e.getMessage());
    }
    context.getResultSender().lastResult(vals);
}
Also used : Query(org.apache.geode.cache.query.Query) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) ArrayList(java.util.ArrayList) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) CacheClosedException(org.apache.geode.cache.CacheClosedException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) SelectResults(org.apache.geode.cache.query.SelectResults) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) Collection(java.util.Collection) Cache(org.apache.geode.cache.Cache)

Aggregations

TypeMismatchException (org.apache.geode.cache.query.TypeMismatchException)36 NameResolutionException (org.apache.geode.cache.query.NameResolutionException)17 FunctionDomainException (org.apache.geode.cache.query.FunctionDomainException)16 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)16 SelectResults (org.apache.geode.cache.query.SelectResults)15 Query (org.apache.geode.cache.query.Query)12 Iterator (java.util.Iterator)11 ArrayList (java.util.ArrayList)9 QueryService (org.apache.geode.cache.query.QueryService)9 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)9 Collection (java.util.Collection)7 List (java.util.List)6 QueryException (org.apache.geode.cache.query.QueryException)6 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)6 Host (org.apache.geode.test.dunit.Host)6 VM (org.apache.geode.test.dunit.VM)6 Map (java.util.Map)5 QueryExecutionTimeoutException (org.apache.geode.cache.query.QueryExecutionTimeoutException)5 ObjectType (org.apache.geode.cache.query.types.ObjectType)5 HashSet (java.util.HashSet)4