Search in sources :

Example 1 with NewerAsVersionTimeSelectionOperator

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

the class HandleVersionTimeQuery method handleQuery.

@Override
public /**
 * Handle a time query
 */
void handleQuery(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
    try {
        if (clientConnectionHandler.getActiveQueries().containsKey(packageSequence)) {
            logger.error("Query sequence {} is allready known, please close old query first", packageSequence);
            return;
        }
        final QueryVersionTimeRequest queryRequest = QueryVersionTimeRequest.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 FullTablescanOperator tablescanOperator = new FullTablescanOperator(storageManager.get(0));
                final long timestamp = queryRequest.getTimestamp();
                final Operator opeator = new NewerAsVersionTimeSelectionOperator(timestamp, tablescanOperator);
                return opeator;
            }
        };
        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.writeResultPackage(new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION));
    }
    return;
}
Also used : FullTablescanOperator(org.bboxdb.storage.queryprocessor.operator.FullTablescanOperator) NewerAsVersionTimeSelectionOperator(org.bboxdb.storage.queryprocessor.operator.NewerAsVersionTimeSelectionOperator) Operator(org.bboxdb.storage.queryprocessor.operator.Operator) NewerAsVersionTimeSelectionOperator(org.bboxdb.storage.queryprocessor.operator.NewerAsVersionTimeSelectionOperator) QueryVersionTimeRequest(org.bboxdb.network.packages.request.QueryVersionTimeRequest) FullTablescanOperator(org.bboxdb.storage.queryprocessor.operator.FullTablescanOperator) 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) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Aggregations

List (java.util.List)1 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)1 QueryVersionTimeRequest (org.bboxdb.network.packages.request.QueryVersionTimeRequest)1 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)1 StreamClientQuery (org.bboxdb.network.server.StreamClientQuery)1 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)1 OperatorTreeBuilder (org.bboxdb.storage.queryprocessor.OperatorTreeBuilder)1 FullTablescanOperator (org.bboxdb.storage.queryprocessor.operator.FullTablescanOperator)1 NewerAsVersionTimeSelectionOperator (org.bboxdb.storage.queryprocessor.operator.NewerAsVersionTimeSelectionOperator)1 Operator (org.bboxdb.storage.queryprocessor.operator.Operator)1