Search in sources :

Example 1 with SelectRequest

use of io.arlas.server.core.impl.jdbi.model.SelectRequest in project ARLAS-server by gisaia.

the class JdbiExploreService method count.

@Override
public Hits count(CollectionReference collectionReference, FluidSearchService fluidSearch) throws ArlasException {
    SelectRequest req = ((JdbiFluidSearch) fluidSearch).getRequest();
    Hits hits = new Hits(collectionReference.collectionName);
    hits.totalnb = dao.count(collectionReference.params.indexName, req.getWhereClause(), getParamMap(collectionReference, req.getWhereParams()));
    hits.nbhits = hits.totalnb;
    return hits;
}
Also used : SelectRequest(io.arlas.server.core.impl.jdbi.model.SelectRequest)

Example 2 with SelectRequest

use of io.arlas.server.core.impl.jdbi.model.SelectRequest in project ARLAS-server by gisaia.

the class JdbiExploreService method compute.

@Override
public ComputationResponse compute(CollectionReference collectionReference, FluidSearchService fluidSearch, String field, ComputationEnum metric) throws ArlasException {
    SelectRequest req = ((JdbiFluidSearch) fluidSearch).getRequest();
    ComputationResponse computationResponse = new ComputationResponse();
    computationResponse.field = field;
    computationResponse.metric = metric;
    try (ResultIterator<Map<String, Object>> iter = dao.select(collectionReference.params.indexName, req.getSelectClause(), req.getWhereClause(), req.getGroupClause(), req.getOrderClause(), req.getLimitClause(), getParamMap(collectionReference, req.getWhereParams()))) {
        long startQueryTimestamp = System.nanoTime();
        computationResponse.value = null;
        computationResponse.geometry = null;
        Map<String, Object> response = ResultIterable.of(iter).first();
        computationResponse.totalnb = (Long) response.get(COUNT);
        if (computationResponse.totalnb > 0) {
            switch(metric) {
                case AVG:
                    computationResponse.value = Double.parseDouble(response.get(AVG).toString());
                    break;
                case CARDINALITY:
                    computationResponse.value = Double.parseDouble(response.get(COUNT).toString());
                    break;
                case MAX:
                    computationResponse.value = Double.parseDouble(response.get(MAX).toString());
                    break;
                case MIN:
                    computationResponse.value = Double.parseDouble(response.get(MIN).toString());
                    break;
                case SPANNING:
                    computationResponse.value = Double.parseDouble(response.get(MAX).toString()) - Double.parseDouble(response.get(MIN).toString());
                    break;
                case SUM:
                    computationResponse.value = Double.parseDouble(response.get(SUM).toString());
                    break;
                case GEOBBOX:
                    computationResponse.geometry = createGeoJsonObject((String) response.get(GEOBBOX.value()));
                    break;
                case GEOCENTROID:
                    computationResponse.geometry = createGeoJsonObject((String) response.get(GEOCENTROID.value()));
                    break;
            }
        }
        computationResponse.queryTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startQueryTimestamp);
    }
    return computationResponse;
}
Also used : SelectRequest(io.arlas.server.core.impl.jdbi.model.SelectRequest)

Example 3 with SelectRequest

use of io.arlas.server.core.impl.jdbi.model.SelectRequest in project ARLAS-server by gisaia.

the class JdbiExploreService method getFeatures.

@Override
public FeatureCollection getFeatures(MixedRequest request, CollectionReference collectionReference, FluidSearchService fluidSearch, boolean flat, UriInfo uriInfo, String method, HashMap<String, Object> context) throws ArlasException {
    SelectRequest req = ((JdbiFluidSearch) fluidSearch).getRequest(true);
    Search searchRequest = (Search) request.basicRequest;
    FeatureCollection fc = new FeatureCollection();
    try (ResultIterator<Map<String, Object>> iter = dao.select(collectionReference.params.indexName, req.getSelectClause(), req.getWhereClause(), req.getGroupClause(), req.getOrderClause(), req.getLimitClause(), getParamMap(collectionReference, req.getWhereParams()))) {
        while (iter.hasNext()) {
            Map<String, Object> source = iter.next();
            Hit arlasHit = new Hit(collectionReference, source, searchRequest.returned_geometries, flat, true);
            if (searchRequest.returned_geometries != null) {
                for (String path : searchRequest.returned_geometries.split(",")) {
                    GeoJsonObject g = arlasHit.getGeometry(path);
                    if (g != null) {
                        fc.add(getFeatureFromHit(arlasHit, path, g));
                    }
                }
            } else {
                // Apply geometry or centroid to geo json feature
                if (arlasHit.md.geometry != null) {
                    fc.add(getFeatureFromHit(arlasHit, collectionReference.params.geometryPath, arlasHit.md.geometry));
                } else if (arlasHit.md.centroid != null) {
                    fc.add(getFeatureFromHit(arlasHit, collectionReference.params.centroidPath, arlasHit.md.centroid));
                }
            }
        }
    }
    if (searchRequest.page != null && searchRequest.page.before != null) {
        Collections.reverse(fc.getFeatures());
    }
    return fc;
}
Also used : Search(io.arlas.server.core.model.request.Search) SelectRequest(io.arlas.server.core.impl.jdbi.model.SelectRequest)

Example 4 with SelectRequest

use of io.arlas.server.core.impl.jdbi.model.SelectRequest in project ARLAS-server by gisaia.

the class JdbiExploreService method aggregate.

@Override
protected AggregationResponse aggregate(CollectionReference collectionReference, List<Aggregation> aggregationsRequests, int aggTreeDepth, Long startQuery, FluidSearchService fluidSearch) throws ArlasException {
    SelectRequest req = ((JdbiFluidSearch) fluidSearch).getRequest();
    AggregationResponse aggregationResponse = new AggregationResponse();
    try (ResultIterator<Map<String, Object>> iter = dao.select(collectionReference.params.indexName, req.getSelectClause(), req.getWhereClause(), req.getGroupClause(), req.getOrderClause(), req.getLimitClause(), getParamMap(collectionReference, req.getWhereParams()))) {
        aggregationResponse.queryTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startQuery);
        JdbiAggregationResult aggResult = new JdbiAggregationResult(aggregationsRequests.size(), ResultIterable.of(iter));
        aggregationResponse = formatAggregationResult(aggResult.getResults(), aggregationResponse, collectionReference, aggregationsRequests, aggTreeDepth);
    }
    return aggregationResponse;
}
Also used : JdbiAggregationResult(io.arlas.server.core.impl.jdbi.model.JdbiAggregationResult) SelectRequest(io.arlas.server.core.impl.jdbi.model.SelectRequest)

Aggregations

SelectRequest (io.arlas.server.core.impl.jdbi.model.SelectRequest)4 JdbiAggregationResult (io.arlas.server.core.impl.jdbi.model.JdbiAggregationResult)1 Search (io.arlas.server.core.model.request.Search)1