Search in sources :

Example 16 with QueryInvalidException

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

the class QCompiler method compileProjectionAttributes.

/** Returns List<CompiledIteratorDef> or null if projectionAttrs is '*' */
public List compileProjectionAttributes(String projectionAttributes) {
    try {
        OQLLexer lexer = new OQLLexer(new StringReader(projectionAttributes));
        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.loneProjectionAttributes();
        GemFireAST n = (GemFireAST) parser.getAST();
        // don't compile TOK_STAR
        if (n.getType() == TOK_STAR) {
            return null;
        }
        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() + ";stack=" + this.stack);
    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 17 with QueryInvalidException

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

the class CompiledGroupBySelectJUnitTest method testInvalidQuery.

@Test
public void testInvalidQuery() throws Exception {
    String queryStr = "select count(*) , pf.shortID from /portfolio pf where pf.ID > 0 ";
    QueryService qs = CacheUtils.getQueryService();
    try {
        DefaultQuery query = (DefaultQuery) qs.newQuery(queryStr);
        fail("query creation should have failed");
    } catch (QueryInvalidException qie) {
        assertTrue(qie.toString().indexOf(LocalizedStrings.DefaultQuery_PROJ_COL_ABSENT_IN_GROUP_BY.toLocalizedString()) != -1);
    }
    queryStr = "select * from /portfolio pf where pf.ID > 0 group by pf.ID";
    try {
        DefaultQuery query = (DefaultQuery) qs.newQuery(queryStr);
        fail("query creation should have failed");
    } catch (QueryInvalidException qie) {
        assertTrue(qie.toString().indexOf(LocalizedStrings.DefaultQuery_PROJ_COL_ABSENT_IN_GROUP_BY.toLocalizedString()) != -1);
    }
    queryStr = "select * from /portfolio pf, pf.positions pos where pf.ID > 0 group by pf";
    try {
        DefaultQuery query = (DefaultQuery) qs.newQuery(queryStr);
        fail("query creation should have failed");
    } catch (QueryInvalidException qie) {
        assertTrue(qie.toString().indexOf("Query contains projected column not present in group by clause") != -1);
    }
}
Also used : QueryService(org.apache.geode.cache.query.QueryService) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 18 with QueryInvalidException

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

the class ServerToClientFunctionResultSender65 method writeFunctionExceptionResponse.

@Override
protected void writeFunctionExceptionResponse(ChunkedMessage message, String errormessage, Throwable e) throws IOException {
    if (logger.isDebugEnabled()) {
        logger.debug(" ServerToClientFunctionResultSender sending Function Error Response : {}", errormessage);
    }
    int numParts = 0;
    message.clear();
    if (e instanceof FunctionException && e.getCause() instanceof InternalFunctionInvocationTargetException) {
        message.setNumberOfParts(3);
        message.addObjPart(e);
        message.addStringPart(BaseCommand.getExceptionTrace(e));
        InternalFunctionInvocationTargetException fe = (InternalFunctionInvocationTargetException) e.getCause();
        message.addObjPart(fe.getFailedNodeSet());
        numParts = 3;
    } else {
        if (e instanceof FunctionException && e.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).
            e = new FunctionException(e.getLocalizedMessage());
        }
        message.setNumberOfParts(2);
        message.addObjPart(e);
        message.addStringPart(BaseCommand.getExceptionTrace(e));
        numParts = 2;
    }
    message.setServerConnection(this.sc);
    message.setLastChunkAndNumParts(true, numParts);
    // message.setLastChunk(true);
    message.sendChunk(this.sc);
    this.sc.setAsTrue(Command.RESPONDED);
}
Also used : QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) FunctionException(org.apache.geode.cache.execute.FunctionException)

Example 19 with QueryInvalidException

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

the class LocalRegion method constructRegionQueryString.

private String constructRegionQueryString(final String predicate) throws QueryInvalidException {
    // send it as is to the server
    boolean matches = false;
    for (Pattern queryPattern : QUERY_PATTERNS) {
        if (queryPattern.matcher(predicate).matches()) {
            if (!predicate.contains(getName())) {
                throw new QueryInvalidException("Should not execute region.query with a different region in the from clause: " + getName() + " was not present in:" + predicate);
            }
            matches = true;
            break;
        }
    }
    // Compare the query patterns to the 'predicate'. If one matches,
    final String queryString;
    if (matches) {
        queryString = predicate;
    } else {
        queryString = "select * from " + getFullPath() + " this where " + predicate;
    }
    return queryString;
}
Also used : Pattern(java.util.regex.Pattern) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException)

Example 20 with QueryInvalidException

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

the class LocalRegion method query.

@Override
public SelectResults query(String predicate) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
    if (predicate == null) {
        throw new IllegalArgumentException("The input query predicate is null. A null predicate is not allowed.");
    }
    predicate = predicate.trim();
    SelectResults results;
    if (hasServerProxy()) {
        // Trim whitespace
        String queryString = constructRegionQueryString(predicate.trim());
        try {
            results = getServerProxy().query(queryString, null);
        } catch (Exception e) {
            Throwable cause = e.getCause();
            if (cause == null) {
                cause = e;
            }
            throw new QueryInvocationTargetException(e.getMessage(), cause);
        }
    } else {
        // TODO: params size is always zero so this whole block is wasted
        Object[] params = new Object[0];
        QueryService qs = getGemFireCache().getLocalQueryService();
        String queryStr = constructRegionQueryString(predicate.trim());
        DefaultQuery query = (DefaultQuery) qs.newQuery(queryStr);
        if (query.getRegionsInQuery(params).size() != 1) {
            throw new QueryInvalidException("Prevent multiple region query from being executed through region.query()");
        }
        results = (SelectResults) query.execute(params);
    }
    return results;
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) StoredObject(org.apache.geode.internal.offheap.StoredObject) TimeoutException(org.apache.geode.cache.TimeoutException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) InternalGemFireException(org.apache.geode.InternalGemFireException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) CacheRuntimeException(org.apache.geode.cache.CacheRuntimeException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) ExecutionException(java.util.concurrent.ExecutionException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) EntryExistsException(org.apache.geode.cache.EntryExistsException) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) StatisticsDisabledException(org.apache.geode.cache.StatisticsDisabledException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) FailedSynchronizationException(org.apache.geode.cache.FailedSynchronizationException) NoSuchElementException(java.util.NoSuchElementException) QueryException(org.apache.geode.cache.query.QueryException) RedundancyAlreadyMetException(org.apache.geode.internal.cache.partitioned.RedundancyAlreadyMetException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) LowMemoryException(org.apache.geode.cache.LowMemoryException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) SystemException(javax.transaction.SystemException) SubscriptionNotEnabledException(org.apache.geode.cache.client.SubscriptionNotEnabledException) RegionExistsException(org.apache.geode.cache.RegionExistsException) RegionReinitializedException(org.apache.geode.cache.RegionReinitializedException) CancelException(org.apache.geode.CancelException) DiskAccessException(org.apache.geode.cache.DiskAccessException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IndexMaintenanceException(org.apache.geode.cache.query.IndexMaintenanceException) TransactionException(org.apache.geode.cache.TransactionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) RollbackException(javax.transaction.RollbackException) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) DeltaSerializationException(org.apache.geode.DeltaSerializationException)

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