Search in sources :

Example 1 with QueryJoinRequest

use of org.bboxdb.network.packages.request.QueryJoinRequest in project bboxdb by jnidzwetzki.

the class HandleJoinQuery method handleQuery.

@Override
public /**
 * Handle a bounding box 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 QueryJoinRequest queryRequest = QueryJoinRequest.decodeTuple(encodedPackage);
        final List<TupleStoreName> requestTables = queryRequest.getTables();
        final BoundingBox boundingBox = queryRequest.getBoundingBox();
        for (final TupleStoreName requestTable : requestTables) {
            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 more than one storage manager");
                }
                Operator operator1 = new SpatialIndexReadOperator(storageManager.get(0), boundingBox);
                SpatialIndexReadOperator indexReader = new SpatialIndexReadOperator(storageManager.get(1));
                operator1 = new IndexedSpatialJoinOperator(operator1, indexReader);
                for (int i = 3; i < storageManager.size(); i++) {
                    indexReader = new SpatialIndexReadOperator(storageManager.get(i));
                    operator1 = new IndexedSpatialJoinOperator(operator1, indexReader);
                }
                return operator1;
            }
        };
        final StreamClientQuery clientQuery = new StreamClientQuery(operatorTreeBuilder, queryRequest.isPagingEnabled(), queryRequest.getTuplesPerPage(), clientConnectionHandler, packageSequence, requestTables);
        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));
    }
}
Also used : IndexedSpatialJoinOperator(org.bboxdb.storage.queryprocessor.operator.IndexedSpatialJoinOperator) Operator(org.bboxdb.storage.queryprocessor.operator.Operator) SpatialIndexReadOperator(org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator) StreamClientQuery(org.bboxdb.network.server.StreamClientQuery) IndexedSpatialJoinOperator(org.bboxdb.storage.queryprocessor.operator.IndexedSpatialJoinOperator) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse) QueryJoinRequest(org.bboxdb.network.packages.request.QueryJoinRequest) 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) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) List(java.util.List)

Example 2 with QueryJoinRequest

use of org.bboxdb.network.packages.request.QueryJoinRequest in project bboxdb by jnidzwetzki.

the class TestNetworkClasses method testDecodeJoinQuery.

/**
 * Test decode bounding box query
 * @throws IOException
 * @throws PackageEncodeException
 */
@Test(timeout = 60000)
public void testDecodeJoinQuery() throws IOException, PackageEncodeException {
    final List<TupleStoreName> tables = Arrays.asList(new TupleStoreName("3dgroup_table1"), new TupleStoreName("3dgroup_table2"), new TupleStoreName("3dgroup_table3"));
    final BoundingBox boundingBox = new BoundingBox(10d, 20d);
    final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
    final QueryJoinRequest queryRequest = new QueryJoinRequest(sequenceNumber, ROUTING_HEADER_ROUTED, tables, boundingBox, false, (short) 10);
    byte[] encodedPackage = networkPackageToByte(queryRequest);
    Assert.assertNotNull(encodedPackage);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
    boolean result = NetworkPackageDecoder.validateRequestPackageHeader(bb, NetworkConst.REQUEST_TYPE_QUERY);
    Assert.assertTrue(result);
    final QueryJoinRequest decodedPackage = QueryJoinRequest.decodeTuple(bb);
    Assert.assertEquals(queryRequest.getBoundingBox(), decodedPackage.getBoundingBox());
    Assert.assertEquals(tables, decodedPackage.getTables());
    Assert.assertEquals(queryRequest.isPagingEnabled(), decodedPackage.isPagingEnabled());
    Assert.assertEquals(queryRequest.getTuplesPerPage(), decodedPackage.getTuplesPerPage());
    Assert.assertEquals(NetworkConst.REQUEST_QUERY_JOIN, NetworkPackageDecoder.getQueryTypeFromRequest(bb));
    Assert.assertEquals(queryRequest.toString(), decodedPackage.toString());
}
Also used : QueryJoinRequest(org.bboxdb.network.packages.request.QueryJoinRequest) BoundingBox(org.bboxdb.commons.math.BoundingBox) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

BoundingBox (org.bboxdb.commons.math.BoundingBox)2 QueryJoinRequest (org.bboxdb.network.packages.request.QueryJoinRequest)2 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)2 ByteBuffer (java.nio.ByteBuffer)1 List (java.util.List)1 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)1 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)1 StreamClientQuery (org.bboxdb.network.server.StreamClientQuery)1 OperatorTreeBuilder (org.bboxdb.storage.queryprocessor.OperatorTreeBuilder)1 IndexedSpatialJoinOperator (org.bboxdb.storage.queryprocessor.operator.IndexedSpatialJoinOperator)1 Operator (org.bboxdb.storage.queryprocessor.operator.Operator)1 SpatialIndexReadOperator (org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator)1 Test (org.junit.Test)1