Search in sources :

Example 1 with IndexedSpatialJoinOperator

use of org.bboxdb.storage.queryprocessor.operator.IndexedSpatialJoinOperator 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 IndexedSpatialJoinOperator

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

the class TestQueryProcessing method testJoinWithChangedTuple1.

/**
 * Simple Join
 * @throws StorageManagerException
 * @throws RejectedException
 */
@Test(timeout = 60000)
public void testJoinWithChangedTuple1() throws StorageManagerException, RejectedException {
    final TupleStoreManager storageManager1 = storageRegistry.getTupleStoreManager(TABLE_1);
    final TupleStoreManager storageManager2 = storageRegistry.getTupleStoreManager(TABLE_2);
    final Tuple tuple1 = new Tuple("1a", new BoundingBox(1.0, 2.0, 1.0, 2.0), "value1".getBytes());
    final Tuple tuple2 = new Tuple("2a", new BoundingBox(4.0, 5.0, 4.0, 5.0), "value2".getBytes());
    // Tuple 3 and tuple 4 have the same key
    final Tuple tuple3 = new Tuple("1b", new BoundingBox(1.5, 2.5, 1.5, 2.5), "value3".getBytes());
    final Tuple tuple4 = new Tuple("1b", new BoundingBox(2.5, 5.5, 2.5, 5.5), "value4".getBytes());
    // Table1
    storageManager1.put(tuple1);
    storageManager1.put(tuple2);
    // Table2
    storageManager2.put(tuple3);
    storageManager2.put(tuple4);
    final SpatialIndexReadOperator operator1 = new SpatialIndexReadOperator(storageManager1, BoundingBox.FULL_SPACE);
    final SpatialIndexReadOperator operator2 = new SpatialIndexReadOperator(storageManager2, BoundingBox.FULL_SPACE);
    final IndexedSpatialJoinOperator joinQueryProcessor1 = new IndexedSpatialJoinOperator(operator1, operator2);
    final Iterator<JoinedTuple> iterator = joinQueryProcessor1.iterator();
    final List<JoinedTuple> resultList = Lists.newArrayList(iterator);
    joinQueryProcessor1.close();
    Assert.assertEquals(1, resultList.size());
    Assert.assertEquals(2, resultList.get(0).getNumberOfTuples());
    Assert.assertEquals(2, resultList.get(0).getBoundingBox().getDimension());
    Assert.assertEquals(new BoundingBox(4.0d, 5.0d, 4.0d, 5.0d), resultList.get(0).getBoundingBox());
}
Also used : SpatialIndexReadOperator(org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator) BoundingBox(org.bboxdb.commons.math.BoundingBox) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) IndexedSpatialJoinOperator(org.bboxdb.storage.queryprocessor.operator.IndexedSpatialJoinOperator) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager) Test(org.junit.Test)

Example 3 with IndexedSpatialJoinOperator

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

the class TestQueryProcessing method testJoin3.

/**
 * Simple Join
 * @throws StorageManagerException
 * @throws RejectedException
 */
@Test(timeout = 60000)
public void testJoin3() throws StorageManagerException, RejectedException {
    final TupleStoreManager storageManager1 = storageRegistry.getTupleStoreManager(TABLE_1);
    final TupleStoreManager storageManager2 = storageRegistry.getTupleStoreManager(TABLE_2);
    final Tuple tuple1 = new Tuple("1a", new BoundingBox(1.0, 2.0, 1.0, 2.0), "value1".getBytes());
    final Tuple tuple2 = new Tuple("2a", new BoundingBox(4.0, 5.0, 4.0, 5.0), "value2".getBytes());
    final Tuple tuple3 = new Tuple("1b", new BoundingBox(1.5, 2.5, 1.5, 2.5), "value3".getBytes());
    final Tuple tuple4 = new Tuple("2b", new BoundingBox(2.5, 5.5, 2.5, 5.5), "value4".getBytes());
    // Table1
    storageManager1.put(tuple1);
    storageManager1.put(tuple2);
    // Table2
    storageManager2.put(tuple3);
    storageManager2.put(tuple4);
    final BoundingBox queryBox = new BoundingBox(3.0, 10.0, 3.0, 10.0);
    final SpatialIndexReadOperator operator1 = new SpatialIndexReadOperator(storageManager1, queryBox);
    final SpatialIndexReadOperator operator2 = new SpatialIndexReadOperator(storageManager2, queryBox);
    final IndexedSpatialJoinOperator joinQueryProcessor = new IndexedSpatialJoinOperator(operator1, operator2);
    final Iterator<JoinedTuple> iterator = joinQueryProcessor.iterator();
    final List<JoinedTuple> resultList = Lists.newArrayList(iterator);
    joinQueryProcessor.close();
    Assert.assertEquals(1, resultList.size());
    Assert.assertEquals(2, resultList.get(0).getNumberOfTuples());
    Assert.assertEquals(2, resultList.get(0).getBoundingBox().getDimension());
    Assert.assertEquals(new BoundingBox(4.0d, 5.0d, 4.0d, 5.0d), resultList.get(0).getBoundingBox());
}
Also used : SpatialIndexReadOperator(org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator) BoundingBox(org.bboxdb.commons.math.BoundingBox) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) IndexedSpatialJoinOperator(org.bboxdb.storage.queryprocessor.operator.IndexedSpatialJoinOperator) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager) Test(org.junit.Test)

Example 4 with IndexedSpatialJoinOperator

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

the class TestQueryProcessing method testDoubleJoin1.

/**
 * Simple Join
 * @throws StorageManagerException
 * @throws RejectedException
 */
@Test(timeout = 60000)
public void testDoubleJoin1() throws StorageManagerException, RejectedException {
    final TupleStoreManager storageManager1 = storageRegistry.getTupleStoreManager(TABLE_1);
    final TupleStoreManager storageManager2 = storageRegistry.getTupleStoreManager(TABLE_2);
    final TupleStoreManager storageManager3 = storageRegistry.getTupleStoreManager(TABLE_3);
    final Tuple tuple1 = new Tuple("1a", new BoundingBox(1.0, 2.0, 1.0, 2.0), "value1".getBytes());
    final Tuple tuple2 = new Tuple("2a", new BoundingBox(4.0, 5.0, 4.0, 5.0), "value2".getBytes());
    final Tuple tuple3 = new Tuple("1b", new BoundingBox(1.5, 2.5, 1.5, 2.5), "value3".getBytes());
    final Tuple tuple4 = new Tuple("2b", new BoundingBox(2.5, 5.5, 2.5, 5.5), "value4".getBytes());
    final Tuple tuple5 = new Tuple("1c", new BoundingBox(2.5, 5.5, 2.5, 5.5), "value4".getBytes());
    // Table1
    storageManager1.put(tuple1);
    storageManager1.put(tuple2);
    // Table2
    storageManager2.put(tuple3);
    storageManager2.put(tuple4);
    // Table3
    storageManager3.put(tuple5);
    final SpatialIndexReadOperator operator1 = new SpatialIndexReadOperator(storageManager1, BoundingBox.FULL_SPACE);
    final SpatialIndexReadOperator operator2 = new SpatialIndexReadOperator(storageManager2, BoundingBox.FULL_SPACE);
    final SpatialIndexReadOperator operator3 = new SpatialIndexReadOperator(storageManager3, BoundingBox.FULL_SPACE);
    final IndexedSpatialJoinOperator joinQueryProcessor1 = new IndexedSpatialJoinOperator(operator1, operator2);
    final IndexedSpatialJoinOperator joinQueryProcessor2 = new IndexedSpatialJoinOperator(joinQueryProcessor1, operator3);
    final Iterator<JoinedTuple> iterator = joinQueryProcessor2.iterator();
    final List<JoinedTuple> resultList = Lists.newArrayList(iterator);
    joinQueryProcessor2.close();
    Assert.assertEquals(1, resultList.size());
    Assert.assertEquals(3, resultList.get(0).getNumberOfTuples());
    Assert.assertEquals(2, resultList.get(0).getBoundingBox().getDimension());
    Assert.assertEquals(new BoundingBox(4.0d, 5.0d, 4.0d, 5.0d), resultList.get(0).getBoundingBox());
}
Also used : SpatialIndexReadOperator(org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator) BoundingBox(org.bboxdb.commons.math.BoundingBox) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) IndexedSpatialJoinOperator(org.bboxdb.storage.queryprocessor.operator.IndexedSpatialJoinOperator) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager) Test(org.junit.Test)

Example 5 with IndexedSpatialJoinOperator

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

the class TestQueryProcessing method testJoin1.

/**
 * Simple Join
 * @throws StorageManagerException
 * @throws RejectedException
 */
@Test(timeout = 60000)
public void testJoin1() throws StorageManagerException, RejectedException {
    final TupleStoreManager storageManager1 = storageRegistry.getTupleStoreManager(TABLE_1);
    final TupleStoreManager storageManager2 = storageRegistry.getTupleStoreManager(TABLE_2);
    final SpatialIndexReadOperator operator1 = new SpatialIndexReadOperator(storageManager1, BoundingBox.FULL_SPACE);
    final SpatialIndexReadOperator operator2 = new SpatialIndexReadOperator(storageManager2, BoundingBox.FULL_SPACE);
    final IndexedSpatialJoinOperator joinQueryProcessor = new IndexedSpatialJoinOperator(operator1, operator2);
    final Iterator<JoinedTuple> iterator = joinQueryProcessor.iterator();
    final List<JoinedTuple> resultList = Lists.newArrayList(iterator);
    joinQueryProcessor.close();
    Assert.assertEquals(0, resultList.size());
}
Also used : SpatialIndexReadOperator(org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) IndexedSpatialJoinOperator(org.bboxdb.storage.queryprocessor.operator.IndexedSpatialJoinOperator) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager) Test(org.junit.Test)

Aggregations

IndexedSpatialJoinOperator (org.bboxdb.storage.queryprocessor.operator.IndexedSpatialJoinOperator)5 SpatialIndexReadOperator (org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator)5 BoundingBox (org.bboxdb.commons.math.BoundingBox)4 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)4 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)4 Test (org.junit.Test)4 Tuple (org.bboxdb.storage.entity.Tuple)3 List (java.util.List)1 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)1 QueryJoinRequest (org.bboxdb.network.packages.request.QueryJoinRequest)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 Operator (org.bboxdb.storage.queryprocessor.operator.Operator)1