Search in sources :

Example 21 with QueryInvalidException

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

the class AbstractExecution method handleException.

private void handleException(Throwable functionException, final Function fn, final FunctionContext cx, final ResultSender sender, DM dm) {
    FunctionStats stats = FunctionStats.getFunctionStats(fn.getId(), dm.getSystem());
    if (logger.isDebugEnabled()) {
        logger.debug("Exception occurred on local node while executing Function: {}", fn.getId(), functionException);
    }
    stats.endFunctionExecutionWithException(fn.hasResult());
    if (fn.hasResult()) {
        if (waitOnException || forwardExceptions) {
            if (functionException instanceof FunctionException && functionException.getCause() instanceof QueryInvalidException) {
                // Handle this exception differently since it can contain
                // non-serializable objects.
                // java.io.NotSerializableException: antlr.CommonToken
                // create a new FunctionException on the original one's message (not cause).
                functionException = new FunctionException(functionException.getLocalizedMessage());
            }
            sender.lastResult(functionException);
        } else {
            ((InternalResultSender) sender).setException(functionException);
        }
    } else {
        logger.warn(LocalizedMessage.create(LocalizedStrings.FunctionService_EXCEPTION_ON_LOCAL_NODE), functionException);
    }
}
Also used : QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) FunctionException(org.apache.geode.cache.execute.FunctionException)

Example 22 with QueryInvalidException

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

the class IndexCreationInternalsJUnitTest method testLoneProjectionAttributes.

@Test
public void testLoneProjectionAttributes() throws Exception {
    // compileProjectionAttributes returns a List or null.
    // null if '*', or a List<Object[2]>.
    // The two-element Object arrays are:
    // 0: a String, the field name, or null if no identifier provided
    // 1: The CompiledValue for the projection expression.
    QCompiler compiler = new QCompiler();
    List list = compiler.compileProjectionAttributes("*");
    assertNull(list);
    compiler = new QCompiler();
    list = compiler.compileProjectionAttributes("ID, status");
    assertEquals(2, list.size());
    Object[] firstProj = (Object[]) list.get(0);
    assertEquals(2, firstProj.length);
    // no field name
    assertNull(firstProj[0]);
    CompiledID id1 = (CompiledID) firstProj[1];
    assertEquals("ID", id1.getId());
    Object[] secondProj = (Object[]) list.get(1);
    assertEquals(2, secondProj.length);
    // no field name
    assertNull(secondProj[0]);
    CompiledID id2 = (CompiledID) secondProj[1];
    assertEquals("status", id2.getId());
    // test two ways of specifying the field names
    compiler = new QCompiler();
    list = compiler.compileProjectionAttributes("x: ID, y: status");
    assertEquals(2, list.size());
    firstProj = (Object[]) list.get(0);
    assertEquals(2, firstProj.length);
    assertEquals("x", firstProj[0]);
    id1 = (CompiledID) firstProj[1];
    assertEquals("ID", id1.getId());
    secondProj = (Object[]) list.get(1);
    assertEquals(2, secondProj.length);
    assertEquals("y", secondProj[0]);
    id2 = (CompiledID) secondProj[1];
    assertEquals("status", id2.getId());
    // the following is invalid
    try {
        compiler = new QCompiler();
        list = compiler.compileProjectionAttributes("ID x, status y");
        fail("Should have thrown a QueryInvalidException");
    } catch (QueryInvalidException e) {
    // pass
    }
    // test three ways of specifying the field names
    compiler = new QCompiler();
    list = compiler.compileProjectionAttributes("ID AS x, status as y");
    assertEquals(2, list.size());
    firstProj = (Object[]) list.get(0);
    assertEquals(2, firstProj.length);
    assertEquals("x", firstProj[0]);
    id1 = (CompiledID) firstProj[1];
    assertEquals("ID", id1.getId());
    secondProj = (Object[]) list.get(1);
    assertEquals(2, secondProj.length);
    assertEquals("y", secondProj[0]);
    id2 = (CompiledID) secondProj[1];
    assertEquals("status", id2.getId());
}
Also used : CompiledID(org.apache.geode.cache.query.internal.CompiledID) QCompiler(org.apache.geode.cache.query.internal.QCompiler) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) List(java.util.List) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 23 with QueryInvalidException

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

the class QCompiler method compileFromClause.

/** Returns List<CompiledIteratorDef> */
public List compileFromClause(String fromClause) {
    try {
        OQLLexer lexer = new OQLLexer(new StringReader(fromClause));
        OQLParser parser = new OQLParser(lexer);
        // by default use Unsupported AST class, overridden for supported
        // operators in the grammer proper
        parser.setASTNodeClass("org.apache.geode.cache.query.internal.parse.ASTUnsupported");
        parser.loneFromClause();
        GemFireAST n = (GemFireAST) parser.getAST();
        n.compile(this);
    } catch (Exception ex) {
        // GemFire Exception.
        throw new QueryInvalidException(LocalizedStrings.QCompiler_SYNTAX_ERROR_IN_QUERY_0.toLocalizedString(ex.getMessage()), ex);
    }
    Assert.assertTrue(stackSize() == 1, "stack size = " + stackSize());
    return (List) pop();
}
Also used : OQLLexer(org.apache.geode.cache.query.internal.parse.OQLLexer) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) StringReader(java.io.StringReader) GemFireAST(org.apache.geode.cache.query.internal.parse.GemFireAST) ArrayList(java.util.ArrayList) List(java.util.List) OQLParser(org.apache.geode.cache.query.internal.parse.OQLParser) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException)

Example 24 with QueryInvalidException

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

the class QCompiler method resolveType.

public ObjectType resolveType(String typeName) {
    if (typeName == null) {
        if (logger.isTraceEnabled()) {
            logger.trace("QCompiler.resolveType= {}", Object.class.getName());
        }
        return TypeUtils.OBJECT_TYPE;
    }
    // resolve with imports
    String as = null;
    if (this.imports != null) {
        as = (String) this.imports.get(typeName);
    }
    if (as != null)
        typeName = as;
    Class resultClass;
    try {
        resultClass = InternalDataSerializer.getCachedClass(typeName);
    } catch (ClassNotFoundException e) {
        throw new QueryInvalidException(LocalizedStrings.QCompiler_TYPE_NOT_FOUND_0.toLocalizedString(typeName), e);
    }
    if (logger.isTraceEnabled()) {
        logger.trace("QCompiler.resolveType= {}", resultClass.getName());
    }
    return new ObjectTypeImpl(resultClass);
}
Also used : QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) ObjectTypeImpl(org.apache.geode.cache.query.internal.types.ObjectTypeImpl)

Example 25 with QueryInvalidException

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

the class RegionProvider method getOrCreateRegion0.

private Region<?, ?> getOrCreateRegion0(ByteArrayWrapper key, RedisDataType type, ExecutionHandlerContext context, boolean addToMeta) {
    checkDataType(key, type);
    Region<?, ?> r = this.regions.get(key);
    if (r != null && r.isDestroyed()) {
        removeKey(key, type);
        r = null;
    }
    if (r == null) {
        String stringKey = key.toString();
        Lock lock = this.locks.get(stringKey);
        if (lock == null) {
            this.locks.putIfAbsent(stringKey, new ReentrantLock());
            lock = this.locks.get(stringKey);
        }
        try {
            lock.lock();
            r = regions.get(key);
            if (r == null) {
                // Can create
                boolean hasTransaction = context != null && context.hasTransaction();
                // without context
                CacheTransactionManager txm = null;
                TransactionId transactionId = null;
                try {
                    if (hasTransaction) {
                        txm = cache.getCacheTransactionManager();
                        transactionId = txm.suspend();
                    }
                    Exception concurrentCreateDestroyException = null;
                    do {
                        concurrentCreateDestroyException = null;
                        r = createRegionGlobally(stringKey);
                        try {
                            if (type == RedisDataType.REDIS_LIST) {
                                doInitializeList(key, r);
                            } else if (type == RedisDataType.REDIS_SORTEDSET) {
                                try {
                                    doInitializeSortedSet(key, r);
                                } catch (RegionNotFoundException | IndexInvalidException e) {
                                    concurrentCreateDestroyException = e;
                                }
                            }
                        } catch (QueryInvalidException e) {
                            if (e.getCause() instanceof RegionNotFoundException) {
                                concurrentCreateDestroyException = e;
                            }
                        }
                    } while (concurrentCreateDestroyException != null);
                    this.regions.put(key, r);
                    if (addToMeta) {
                        RedisDataType existingType = metaPutIfAbsent(key, type);
                        if (existingType != null && existingType != type)
                            throw new RedisDataTypeMismatchException("The key name \"" + key + "\" is already used by a " + existingType.toString());
                    }
                } finally {
                    if (hasTransaction)
                        txm.resume(transactionId);
                }
            }
        } finally {
            lock.unlock();
        }
    }
    return r;
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) IndexInvalidException(org.apache.geode.cache.query.IndexInvalidException) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) IndexExistsException(org.apache.geode.cache.query.IndexExistsException) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) TransactionId(org.apache.geode.cache.TransactionId)

Aggregations

QueryInvalidException (org.apache.geode.cache.query.QueryInvalidException)36 Test (org.junit.Test)12 QueryService (org.apache.geode.cache.query.QueryService)11 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)11 List (java.util.List)7 TypeMismatchException (org.apache.geode.cache.query.TypeMismatchException)7 ArrayList (java.util.ArrayList)6 FunctionDomainException (org.apache.geode.cache.query.FunctionDomainException)6 NameResolutionException (org.apache.geode.cache.query.NameResolutionException)6 Query (org.apache.geode.cache.query.Query)6 AttributesFactory (org.apache.geode.cache.AttributesFactory)5 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)5 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)5 StringReader (java.io.StringReader)4 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)4 Region (org.apache.geode.cache.Region)4 SelectResults (org.apache.geode.cache.query.SelectResults)4 Portfolio (org.apache.geode.cache.query.data.Portfolio)4 Set (java.util.Set)3 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)3