Search in sources :

Example 11 with SpatialIndexReadOperator

use of org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator in project bboxdb by jnidzwetzki.

the class HandleBoundingBoxTimeQuery method handleQuery.

@Override
public /**
 * Handle the bounding box time query
 */
void handleQuery(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException {
    try {
        if (clientConnectionHandler.getActiveQueries().containsKey(packageSequence)) {
            logger.error("Query sequence {} is allready known, please close old query first", packageSequence);
        }
        final QueryBoundingBoxTimeRequest queryRequest = QueryBoundingBoxTimeRequest.decodeTuple(encodedPackage);
        final TupleStoreName requestTable = queryRequest.getTable();
        if (!QueryHelper.handleNonExstingTable(requestTable, packageSequence, clientConnectionHandler)) {
            return;
        }
        final OperatorTreeBuilder operatorTreeBuilder = new OperatorTreeBuilder() {

            @Override
            public Operator buildOperatorTree(final List<TupleStoreManager> storageManager) {
                if (storageManager.size() != 1) {
                    throw new IllegalArgumentException("This operator tree needs 1 storage manager");
                }
                final BoundingBox boundingBox = queryRequest.getBoundingBox();
                final SpatialIndexReadOperator operator = new SpatialIndexReadOperator(storageManager.get(0), boundingBox);
                final Operator operator1 = new NewerAsInsertTimeSeclectionOperator(queryRequest.getTimestamp(), operator);
                return operator1;
            }
        };
        final StreamClientQuery clientQuery = new StreamClientQuery(operatorTreeBuilder, queryRequest.isPagingEnabled(), queryRequest.getTuplesPerPage(), clientConnectionHandler, packageSequence, Arrays.asList(requestTable));
        clientConnectionHandler.getActiveQueries().put(packageSequence, clientQuery);
        clientConnectionHandler.sendNextResultsForQuery(packageSequence, packageSequence);
    } catch (PackageEncodeException e) {
        logger.warn("Got exception while decoding package", e);
        clientConnectionHandler.writeResultPackageNE(new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION));
    }
}
Also used : NewerAsInsertTimeSeclectionOperator(org.bboxdb.storage.queryprocessor.operator.NewerAsInsertTimeSeclectionOperator) Operator(org.bboxdb.storage.queryprocessor.operator.Operator) SpatialIndexReadOperator(org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator) QueryBoundingBoxTimeRequest(org.bboxdb.network.packages.request.QueryBoundingBoxTimeRequest) SpatialIndexReadOperator(org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator) BoundingBox(org.bboxdb.commons.math.BoundingBox) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) OperatorTreeBuilder(org.bboxdb.storage.queryprocessor.OperatorTreeBuilder) StreamClientQuery(org.bboxdb.network.server.StreamClientQuery) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) List(java.util.List) NewerAsInsertTimeSeclectionOperator(org.bboxdb.storage.queryprocessor.operator.NewerAsInsertTimeSeclectionOperator) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Aggregations

SpatialIndexReadOperator (org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator)11 BoundingBox (org.bboxdb.commons.math.BoundingBox)10 IndexedSpatialJoinOperator (org.bboxdb.storage.queryprocessor.operator.IndexedSpatialJoinOperator)9 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)8 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)8 Test (org.junit.Test)8 List (java.util.List)7 Tuple (org.bboxdb.storage.entity.Tuple)7 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)7 Operator (org.bboxdb.storage.queryprocessor.operator.Operator)6 Lists (com.google.common.collect.Lists)4 IOException (java.io.IOException)4 Iterator (java.util.Iterator)4 Collectors (java.util.stream.Collectors)4 RejectedException (org.bboxdb.commons.RejectedException)4 BBoxDBException (org.bboxdb.misc.BBoxDBException)4 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)4 BoundingBoxSelectOperator (org.bboxdb.storage.queryprocessor.operator.BoundingBoxSelectOperator)4 FullTablescanOperator (org.bboxdb.storage.queryprocessor.operator.FullTablescanOperator)4 TupleStoreManagerRegistry (org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry)4