Search in sources :

Example 11 with FunctionDomainException

use of org.apache.geode.cache.query.FunctionDomainException 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 12 with FunctionDomainException

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

Example 13 with FunctionDomainException

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

the class FunctionJUnitTest method testELEMENT.

@Test
public void testELEMENT() throws Exception {
    Query query = CacheUtils.getQueryService().newQuery("ELEMENT(SELECT DISTINCT * FROM /Portfolios where ID =1).status");
    Object result = query.execute();
    if (!result.equals("inactive"))
        fail(query.getQueryString());
    try {
        query = CacheUtils.getQueryService().newQuery("ELEMENT(SELECT DISTINCT * FROM /Portfolios where ID <= 1).status");
        result = query.execute();
        fail(query.getQueryString());
    } catch (FunctionDomainException e) {
    }
}
Also used : Query(org.apache.geode.cache.query.Query) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 14 with FunctionDomainException

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

the class QueryAccessController method runAdhocQuery.

/**
   * Run an adhoc Query specified in a query string
   * 
   * @param oql OQL query string to be executed
   * @return query result as a JSON document
   */
@RequestMapping(method = RequestMethod.GET, value = "/adhoc", produces = { MediaType.APPLICATION_JSON_UTF8_VALUE })
@ApiOperation(value = "run an adhoc query", notes = "Run an unnamed (unidentified), ad-hoc query passed as a URL parameter", response = void.class)
@ApiResponses({ @ApiResponse(code = 200, message = "OK."), @ApiResponse(code = 401, message = "Invalid Username or Password."), @ApiResponse(code = 403, message = "Insufficient privileges for operation."), @ApiResponse(code = 500, message = "GemFire throws an error or exception") })
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@PreAuthorize("@securityService.authorize('DATA', 'READ')")
public ResponseEntity<String> runAdhocQuery(@RequestParam("q") String oql) {
    logger.debug("Running an adhoc Query ({})...", oql);
    oql = decode(oql);
    final Query query = getQueryService().newQuery(oql);
    // and handle the Exceptions appropriately (500 Server Error)!
    try {
        Object queryResult = query.execute();
        return processQueryResponse(query, null, queryResult);
    } catch (FunctionDomainException fde) {
        throw new GemfireRestException("A function was applied to a parameter that is improper for that function!", fde);
    } catch (TypeMismatchException tme) {
        throw new GemfireRestException("Bind parameter is not of the expected type!", tme);
    } catch (NameResolutionException nre) {
        throw new GemfireRestException("Name in the query cannot be resolved!", nre);
    } catch (IllegalArgumentException iae) {
        throw new GemfireRestException(" The number of bound parameters does not match the number of placeholders!", iae);
    } catch (IllegalStateException ise) {
        throw new GemfireRestException("Query is not permitted on this type of region!", ise);
    } catch (QueryExecutionTimeoutException qete) {
        throw new GemfireRestException("Query execution time is exceeded max query execution time (gemfire.Cache.MAX_QUERY_EXECUTION_TIME) configured! ", qete);
    } catch (QueryInvocationTargetException qite) {
        throw new GemfireRestException("Data referenced in from clause is not available for querying!", qite);
    } catch (QueryExecutionLowMemoryException qelme) {
        throw new GemfireRestException("Query execution gets canceled due to low memory conditions and the resource manager critical heap percentage has been set!", qelme);
    } catch (Exception e) {
        throw new GemfireRestException("Server has encountered while executing Adhoc query!", e);
    }
}
Also used : GemfireRestException(org.apache.geode.rest.internal.web.exception.GemfireRestException) Query(org.apache.geode.cache.query.Query) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) QueryExecutionLowMemoryException(org.apache.geode.cache.query.QueryExecutionLowMemoryException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) QueryExecutionTimeoutException(org.apache.geode.cache.query.QueryExecutionTimeoutException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) QueryExecutionTimeoutException(org.apache.geode.cache.query.QueryExecutionTimeoutException) ResourceNotFoundException(org.apache.geode.rest.internal.web.exception.ResourceNotFoundException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) QueryExecutionLowMemoryException(org.apache.geode.cache.query.QueryExecutionLowMemoryException) GemfireRestException(org.apache.geode.rest.internal.web.exception.GemfireRestException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 15 with FunctionDomainException

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

the class PartitionedRegionQueryDUnitTest method testReevaluationDueToUpdateInProgress.

@Test
public void testReevaluationDueToUpdateInProgress() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    // VM vm2 = host.getVM(2);
    createPR(vm0);
    createPR(vm1);
    createIndex(vm0, "compactRangeIndex", "entry.value", "/region.entrySet entry");
    // Do Puts
    vm0.invoke(new SerializableRunnable("putting data") {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion("region");
            for (int i = 0; i < 100; i++) {
                region.put(i, new TestObject(i));
            }
        }
    });
    vm0.invoke(new SerializableRunnable("resetting sqt") {

        public void run() {
            IndexManager.setIndexBufferTime(Long.MAX_VALUE, Long.MAX_VALUE);
        }
    });
    vm1.invoke(new SerializableRunnable("resetting sqt") {

        public void run() {
            IndexManager.setIndexBufferTime(Long.MAX_VALUE, Long.MAX_VALUE);
        }
    });
    vm0.invoke(new SerializableRunnable("query") {

        public void run() {
            try {
                QueryService qs = getCache().getQueryService();
                qs.newQuery("SELECT DISTINCT entry.key, entry.value FROM /region.entrySet entry WHERE entry.value.score >= 5 AND entry.value.score <= 10 ORDER BY value asc").execute();
            } catch (QueryInvocationTargetException e) {
                e.printStackTrace();
                fail(e.toString());
            } catch (NameResolutionException e) {
                fail(e.toString());
            } catch (TypeMismatchException e) {
                fail(e.toString());
            } catch (FunctionDomainException e) {
                fail(e.toString());
            }
        }
    });
}
Also used : QueryService(org.apache.geode.cache.query.QueryService) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) VM(org.apache.geode.test.dunit.VM) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Region(org.apache.geode.cache.Region) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) Host(org.apache.geode.test.dunit.Host) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Aggregations

FunctionDomainException (org.apache.geode.cache.query.FunctionDomainException)15 NameResolutionException (org.apache.geode.cache.query.NameResolutionException)14 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)14 TypeMismatchException (org.apache.geode.cache.query.TypeMismatchException)14 Query (org.apache.geode.cache.query.Query)12 SelectResults (org.apache.geode.cache.query.SelectResults)11 QueryService (org.apache.geode.cache.query.QueryService)9 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)9 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)6 Host (org.apache.geode.test.dunit.Host)6 VM (org.apache.geode.test.dunit.VM)6 QueryException (org.apache.geode.cache.query.QueryException)4 QueryExecutionLowMemoryException (org.apache.geode.cache.query.QueryExecutionLowMemoryException)4 QueryExecutionTimeoutException (org.apache.geode.cache.query.QueryExecutionTimeoutException)4 ArrayList (java.util.ArrayList)3 Cache (org.apache.geode.cache.Cache)3 CacheClosedException (org.apache.geode.cache.CacheClosedException)3 CacheException (org.apache.geode.cache.CacheException)3 ServerOperationException (org.apache.geode.cache.client.ServerOperationException)3 QueryInvalidException (org.apache.geode.cache.query.QueryInvalidException)3