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();
}
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;
}
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();
}
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);
}
}
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);
}
Aggregations