Search in sources :

Example 1 with JoinedTuple

use of org.bboxdb.storage.entity.JoinedTuple in project bboxdb by jnidzwetzki.

the class ContinuousBoundingBoxClientQuery method fetchAndSendNextTuples.

@Override
public void fetchAndSendNextTuples(final short packageSequence) throws IOException, PackageEncodeException {
    try {
        long sendTuplesInThisPage = 0;
        clientConnectionHandler.writeResultPackage(new MultipleTupleStartResponse(packageSequence));
        while (queryActive) {
            if (sendTuplesInThisPage >= tuplesPerPage) {
                clientConnectionHandler.writeResultPackage(new PageEndResponse(packageSequence));
                clientConnectionHandler.flushPendingCompressionPackages();
                return;
            }
            // Send next tuple or wait
            final Tuple tuple = tupleQueue.take();
            final JoinedTuple joinedTuple = new JoinedTuple(tuple, requestTable.getFullname());
            clientConnectionHandler.writeResultTuple(packageSequence, joinedTuple);
            totalSendTuples++;
            sendTuplesInThisPage++;
        }
        // All tuples are send
        clientConnectionHandler.writeResultPackage(new MultipleTupleEndResponse(packageSequence));
        clientConnectionHandler.flushPendingCompressionPackages();
    } catch (InterruptedException e) {
        logger.debug("Got interrupted excetion");
        close();
        Thread.currentThread().interrupt();
    }
}
Also used : PageEndResponse(org.bboxdb.network.packages.response.PageEndResponse) MultipleTupleEndResponse(org.bboxdb.network.packages.response.MultipleTupleEndResponse) MultipleTupleStartResponse(org.bboxdb.network.packages.response.MultipleTupleStartResponse) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple)

Example 2 with JoinedTuple

use of org.bboxdb.storage.entity.JoinedTuple in project bboxdb by jnidzwetzki.

the class StreamClientQuery method fetchAndSendNextTuples.

/* (non-Javadoc)
	 * @see org.bboxdb.network.server.ClientQuery#fetchAndSendNextTuples(short)
	 */
@Override
public void fetchAndSendNextTuples(final short packageSequence) throws IOException, PackageEncodeException {
    long sendTuplesInThisPage = 0;
    clientConnectionHandler.writeResultPackage(new MultipleTupleStartResponse(packageSequence));
    while (!isDataExhausted()) {
        if (activeOperatorIterator == null) {
            setupNewIterator();
        }
        // Unable to set up a new iterator
        if (activeOperatorIterator == null) {
            break;
        }
        while (activeOperatorIterator.hasNext()) {
            // Handle page end
            if (pageResult == true && sendTuplesInThisPage >= tuplesPerPage) {
                clientConnectionHandler.writeResultPackage(new PageEndResponse(packageSequence));
                clientConnectionHandler.flushPendingCompressionPackages();
                return;
            }
            // Send next tuple
            final JoinedTuple tuple = activeOperatorIterator.next();
            clientConnectionHandler.writeResultTuple(packageSequence, tuple);
            totalSendTuples++;
            sendTuplesInThisPage++;
        }
        closeIteratorNE();
    }
    // All tuples are send
    clientConnectionHandler.writeResultPackage(new MultipleTupleEndResponse(packageSequence));
    clientConnectionHandler.flushPendingCompressionPackages();
}
Also used : PageEndResponse(org.bboxdb.network.packages.response.PageEndResponse) MultipleTupleEndResponse(org.bboxdb.network.packages.response.MultipleTupleEndResponse) MultipleTupleStartResponse(org.bboxdb.network.packages.response.MultipleTupleStartResponse) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple)

Example 3 with JoinedTuple

use of org.bboxdb.storage.entity.JoinedTuple in project bboxdb by jnidzwetzki.

the class JoinedTupleResponse method decodePackage.

/**
 * Decode the encoded package into a object
 *
 * @param encodedPackage
 * @return
 * @throws PackageEncodeException
 */
public static JoinedTupleResponse decodePackage(final ByteBuffer encodedPackage) throws PackageEncodeException {
    final short requestId = NetworkPackageDecoder.getRequestIDFromResponsePackage(encodedPackage);
    final boolean decodeResult = NetworkPackageDecoder.validateResponsePackageHeader(encodedPackage, NetworkConst.RESPONSE_TYPE_JOINED_TUPLE);
    if (decodeResult == false) {
        throw new PackageEncodeException("Unable to decode package");
    }
    final List<String> tupleStoreNames = new ArrayList<>();
    final List<Tuple> tuples = new ArrayList<>();
    final int numberOfTuples = encodedPackage.getInt();
    for (int i = 0; i < numberOfTuples; i++) {
        final TupleAndTable tupleAndTable = NetworkTupleEncoderDecoder.decode(encodedPackage);
        tupleStoreNames.add(tupleAndTable.getTable());
        tuples.add(tupleAndTable.getTuple());
    }
    final JoinedTuple joinedTuple = new JoinedTuple(tuples, tupleStoreNames);
    if (encodedPackage.remaining() != 0) {
        throw new PackageEncodeException("Some bytes are left after encoding: " + encodedPackage.remaining());
    }
    return new JoinedTupleResponse(requestId, joinedTuple);
}
Also used : PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) ArrayList(java.util.ArrayList) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) TupleAndTable(org.bboxdb.storage.entity.TupleAndTable) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple)

Example 4 with JoinedTuple

use of org.bboxdb.storage.entity.JoinedTuple in project bboxdb by jnidzwetzki.

the class JoinedTupleListFuture method createSimpleIterator.

@Override
protected Iterator<JoinedTuple> createSimpleIterator() {
    final List<JoinedTuple> allTuples = getListWithAllResults();
    final EntityDuplicateTracker entityDuplicateTracker = new EntityDuplicateTracker();
    final Iterator<JoinedTuple> iterator = allTuples.iterator();
    while (iterator.hasNext()) {
        final JoinedTuple nextElement = iterator.next();
        if (entityDuplicateTracker.isElementAlreadySeen(nextElement)) {
            iterator.remove();
        }
    }
    return allTuples.iterator();
}
Also used : JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) EntityDuplicateTracker(org.bboxdb.storage.util.EntityDuplicateTracker)

Example 5 with JoinedTuple

use of org.bboxdb.storage.entity.JoinedTuple in project bboxdb by jnidzwetzki.

the class TestQueryProcessing method testBBoxQuery3.

/**
 * Simple BBox query - across multiple tables on disk
 * @throws StorageManagerException
 * @throws InterruptedException
 * @throws RejectedException
 * @throws IOException
 */
@Test(timeout = 60000)
public void testBBoxQuery3() throws StorageManagerException, InterruptedException, RejectedException, IOException {
    final TupleStoreManager storageManager = storageRegistry.getTupleStoreManager(TABLE_1);
    final Tuple tuple1 = new Tuple("1", new BoundingBox(1.0, 2.0, 1.0, 2.0), "value".getBytes());
    final Tuple tuple2 = new Tuple("2", new BoundingBox(1.5, 2.5, 1.5, 2.5), "value2".getBytes());
    final Tuple tuple3 = new Tuple("1", new BoundingBox(1.0, 2.0, 1.0, 2.0), "value1".getBytes());
    storageManager.put(tuple1);
    storageManager.flush();
    storageManager.put(tuple2);
    storageManager.flush();
    storageManager.put(tuple3);
    storageManager.flush();
    final BoundingBox queryBoundingBox = new BoundingBox(0.0, 5.0, 0.0, 5.0);
    final Operator spatialIndexReadOperator = new FullTablescanOperator(storageManager);
    final Operator queryPlan = new BoundingBoxSelectOperator(queryBoundingBox, spatialIndexReadOperator);
    final Iterator<JoinedTuple> iterator = queryPlan.iterator();
    final List<JoinedTuple> resultList = Lists.newArrayList(iterator);
    final List<Tuple> resultTupleList = resultList.stream().map(t -> t.convertToSingleTupleIfPossible()).collect(Collectors.toList());
    queryPlan.close();
    Assert.assertEquals(2, resultList.size());
    Assert.assertFalse(resultTupleList.contains(tuple1));
    Assert.assertTrue(resultTupleList.contains(tuple2));
    Assert.assertTrue(resultTupleList.contains(tuple3));
}
Also used : FullTablescanOperator(org.bboxdb.storage.queryprocessor.operator.FullTablescanOperator) IndexedSpatialJoinOperator(org.bboxdb.storage.queryprocessor.operator.IndexedSpatialJoinOperator) Operator(org.bboxdb.storage.queryprocessor.operator.Operator) SpatialIndexReadOperator(org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator) BoundingBoxSelectOperator(org.bboxdb.storage.queryprocessor.operator.BoundingBoxSelectOperator) AfterClass(org.junit.AfterClass) Iterator(java.util.Iterator) BeforeClass(org.junit.BeforeClass) RejectedException(org.bboxdb.commons.RejectedException) FullTablescanOperator(org.bboxdb.storage.queryprocessor.operator.FullTablescanOperator) Tuple(org.bboxdb.storage.entity.Tuple) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) BoundingBox(org.bboxdb.commons.math.BoundingBox) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) List(java.util.List) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager) IndexedSpatialJoinOperator(org.bboxdb.storage.queryprocessor.operator.IndexedSpatialJoinOperator) Lists(com.google.common.collect.Lists) Operator(org.bboxdb.storage.queryprocessor.operator.Operator) BBoxDBException(org.bboxdb.misc.BBoxDBException) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) Assert(org.junit.Assert) SpatialIndexReadOperator(org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator) BoundingBoxSelectOperator(org.bboxdb.storage.queryprocessor.operator.BoundingBoxSelectOperator) Before(org.junit.Before) BoundingBoxSelectOperator(org.bboxdb.storage.queryprocessor.operator.BoundingBoxSelectOperator) BoundingBox(org.bboxdb.commons.math.BoundingBox) FullTablescanOperator(org.bboxdb.storage.queryprocessor.operator.FullTablescanOperator) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager) Test(org.junit.Test)

Aggregations

JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)22 Tuple (org.bboxdb.storage.entity.Tuple)17 BoundingBox (org.bboxdb.commons.math.BoundingBox)13 Test (org.junit.Test)13 IndexedSpatialJoinOperator (org.bboxdb.storage.queryprocessor.operator.IndexedSpatialJoinOperator)8 SpatialIndexReadOperator (org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator)8 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)8 List (java.util.List)5 BBoxDBException (org.bboxdb.misc.BBoxDBException)5 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)5 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 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)4 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)4 BoundingBoxSelectOperator (org.bboxdb.storage.queryprocessor.operator.BoundingBoxSelectOperator)4 FullTablescanOperator (org.bboxdb.storage.queryprocessor.operator.FullTablescanOperator)4 Operator (org.bboxdb.storage.queryprocessor.operator.Operator)4