Search in sources :

Example 11 with JoinedTuple

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

the class TestTupleHelper method testConvertMultiTuple.

/**
 * Test the convert method of multiple tuples
 */
@Test(expected = IllegalArgumentException.class)
public void testConvertMultiTuple() {
    final Tuple tuple1 = new Tuple("abc", new BoundingBox(1d, 2d), "".getBytes());
    final Tuple tuple2 = new Tuple("def", new BoundingBox(1d, 2d), "".getBytes());
    final JoinedTuple joinedTuple1 = new JoinedTuple(Arrays.asList(tuple1, tuple2), Arrays.asList("abc", "def"));
    joinedTuple1.convertToSingleTupleIfPossible();
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 12 with JoinedTuple

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

the class PredicateJoinedTupleFilterIterator method next.

@Override
public JoinedTuple next() {
    if (nextTuple == null) {
        throw new IllegalArgumentException("Invalid state, did you really called hasNext()?");
    }
    final JoinedTuple resultTuple = nextTuple;
    nextTuple = null;
    return resultTuple;
}
Also used : JoinedTuple(org.bboxdb.storage.entity.JoinedTuple)

Example 13 with JoinedTuple

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

the class KeyClientQuery method fetchAndSendNextTuples.

@Override
public void fetchAndSendNextTuples(final short packageSequence) throws IOException, PackageEncodeException {
    long sendTuplesInThisPage = 0;
    clientConnectionHandler.writeResultPackage(new MultipleTupleStartResponse(packageSequence));
    final Iterator<Tuple> tupleListIterator = tuplesForKey.iterator();
    while (tupleListIterator.hasNext()) {
        if (pageResult == true && sendTuplesInThisPage >= tuplesPerPage) {
            clientConnectionHandler.writeResultPackage(new PageEndResponse(packageSequence));
            clientConnectionHandler.flushPendingCompressionPackages();
            return;
        }
        // Send next tuple
        final Tuple tuple = tupleListIterator.next();
        tupleListIterator.remove();
        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();
}
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 14 with JoinedTuple

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

the class ResponseHandlerHelper method castAndSetFutureResult.

/**
 * Cast the content on the result list according to the future type
 * @param future
 * @param resultList
 * @param completeResult
 * @throws PackageEncodeException
 */
public static void castAndSetFutureResult(final NetworkOperationFuture future, final List<PagedTransferableEntity> resultList, final boolean completeResult) throws PackageEncodeException {
    if (resultList.isEmpty()) {
        future.setCompleteResult(completeResult);
        future.setOperationResult(new ArrayList<>());
        future.fireCompleteEvent();
        return;
    }
    final PagedTransferableEntity firstElement = resultList.get(0);
    if (firstElement instanceof Tuple) {
        final List<Tuple> tupleList = new ArrayList<>();
        for (final PagedTransferableEntity entity : resultList) {
            tupleList.add((Tuple) entity);
        }
        future.setCompleteResult(completeResult);
        future.setOperationResult(tupleList);
        future.fireCompleteEvent();
    } else if (firstElement instanceof JoinedTuple) {
        final List<JoinedTuple> tupleList = new ArrayList<>();
        for (final PagedTransferableEntity entity : resultList) {
            tupleList.add((JoinedTuple) entity);
        }
        future.setCompleteResult(completeResult);
        future.setOperationResult(tupleList);
        future.fireCompleteEvent();
    } else {
        throw new PackageEncodeException("Unknown future type: " + firstElement);
    }
}
Also used : PagedTransferableEntity(org.bboxdb.storage.entity.PagedTransferableEntity) ArrayList(java.util.ArrayList) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) List(java.util.List) ArrayList(java.util.ArrayList) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple)

Example 15 with JoinedTuple

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

the class TestNetworkClasses method encodeAndDecodeJoinedTuple.

/**
 * Test the decoding and the encoding of a joined tuple
 * @throws PackageEncodeException
 * @throws IOException
 */
@Test(timeout = 60000)
public void encodeAndDecodeJoinedTuple() throws IOException, PackageEncodeException {
    final Tuple tuple1 = new Tuple("key1", new BoundingBox(1.3244343224, 232.232333343, 34324.343, 343243.0), "abc".getBytes(), 12);
    final Tuple tuple2 = new Tuple("key2", new BoundingBox(1.32443453224, 545334.03, 34324.343, 343243.0), "abc".getBytes(), 12);
    final Tuple tuple3 = new Tuple("key3", new BoundingBox(1.35433224, 5453.43, 34324.343, 343243.0), "abc".getBytes(), 12);
    final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
    final List<Tuple> tupleList = Arrays.asList(tuple1, tuple2, tuple3);
    final List<String> tableNames = Arrays.asList("abc", "def", "geh");
    final JoinedTuple joinedTuple = new JoinedTuple(tupleList, tableNames);
    final JoinedTupleResponse joinedResponse = new JoinedTupleResponse(sequenceNumber, joinedTuple);
    byte[] encodedVersion = networkPackageToByte(joinedResponse);
    Assert.assertNotNull(encodedVersion);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
    final JoinedTupleResponse decodedPackage = JoinedTupleResponse.decodePackage(bb);
    final JoinedTuple decodedJoinedTuple = decodedPackage.getJoinedTuple();
    Assert.assertEquals(3, decodedJoinedTuple.getNumberOfTuples());
    for (int i = 0; i < 3; i++) {
        Assert.assertEquals(tupleList.get(i), decodedJoinedTuple.getTuple(i));
        Assert.assertEquals(tableNames.get(i), decodedJoinedTuple.getTupleStoreName(i));
    }
    Assert.assertTrue(joinedResponse.toString().length() > 10);
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) JoinedTupleResponse(org.bboxdb.network.packages.response.JoinedTupleResponse) ByteBuffer(java.nio.ByteBuffer) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) 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