use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.
the class KeepAliveRequest method decodeTuple.
/**
* Decode the encoded package into a object
*
* @param encodedPackage
* @return
* @throws PackageEncodeException
*/
public static KeepAliveRequest decodeTuple(final ByteBuffer encodedPackage) throws PackageEncodeException {
final short sequenceNumber = NetworkPackageDecoder.getRequestIDFromRequestPackage(encodedPackage);
final boolean decodeResult = NetworkPackageDecoder.validateRequestPackageHeader(encodedPackage, NetworkConst.REQUEST_TYPE_KEEP_ALIVE);
if (decodeResult == false) {
throw new PackageEncodeException("Unable to decode package");
}
final List<Tuple> tuples = new ArrayList<>();
final short tableLength = encodedPackage.getShort();
// Unused
encodedPackage.get();
// Unused
encodedPackage.get();
final int elements = encodedPackage.getInt();
final byte[] tableNameBytes = new byte[tableLength];
encodedPackage.get(tableNameBytes, 0, tableNameBytes.length);
final String tableName = new String(tableNameBytes);
for (int i = 0; i < elements; i++) {
final int keyLength = encodedPackage.getInt();
final byte[] keyBytes = new byte[keyLength];
encodedPackage.get(keyBytes, 0, keyBytes.length);
final String key = new String(keyBytes);
final int boundingBoxLength = encodedPackage.getInt();
final byte[] boundingBoxBytes = new byte[boundingBoxLength];
encodedPackage.get(boundingBoxBytes, 0, boundingBoxBytes.length);
final BoundingBox boundingBox = BoundingBox.fromByteArray(boundingBoxBytes);
final long version = encodedPackage.getLong();
final Tuple tuple = new Tuple(key, boundingBox, "".getBytes(), version);
tuples.add(tuple);
}
if (encodedPackage.remaining() != 0) {
throw new PackageEncodeException("Some bytes are left after decoding: " + encodedPackage.remaining());
}
return new KeepAliveRequest(sequenceNumber, tableName, tuples);
}
use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.
the class TestPredicates method boundingAndPredicate.
/**
* Test the and predicate
* @throws Exception
*/
@Test(timeout = 60000)
public void boundingAndPredicate() {
final Tuple tuple1 = new Tuple("1", new BoundingBox(1.0, 10.0, 1.0, 10.9), "abc".getBytes(), 50);
final Tuple tuple2 = new Tuple("2", new BoundingBox(-11.0, 0.0, -11.0, 0.9), "def".getBytes(), 1234);
final List<Tuple> tupleList = new ArrayList<>();
tupleList.add(tuple1);
tupleList.add(tuple2);
final Predicate predicate1 = new OverlapsBoundingBoxPredicate(new BoundingBox(2.0, 100.0, 2.0, 100.0));
final Predicate predicate2 = new NewerAsVersionTimePredicate(51);
final Predicate predicate = new AndPredicate(predicate1, predicate2);
final Collection<Tuple> tuples = getTuplesFromPredicate(tupleList, predicate);
Assert.assertTrue(tuples.isEmpty());
}
use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.
the class TestPredicates method boundingBoxPredicate.
/**
* Test the bounding box predicate
* @throws Exception
*/
@Test(timeout = 60000)
public void boundingBoxPredicate() {
final Tuple tuple1 = new Tuple("1", new BoundingBox(1.0, 10.0, 1.0, 10.9), "abc".getBytes(), 50);
final Tuple tuple2 = new Tuple("2", new BoundingBox(-11.0, 0.0, -11.0, 0.9), "def".getBytes(), 1234);
final List<Tuple> tupleList = new ArrayList<>();
tupleList.add(tuple1);
tupleList.add(tuple2);
final Predicate predicate1 = new OverlapsBoundingBoxPredicate(new BoundingBox(-100.0, 100.0, -100.0, 100.0));
final Collection<Tuple> tuples1 = getTuplesFromPredicate(tupleList, predicate1);
Assert.assertEquals(2, tuples1.size());
Assert.assertTrue(tuples1.contains(tuple1));
Assert.assertTrue(tuples1.contains(tuple2));
final Predicate predicate2 = new OverlapsBoundingBoxPredicate(new BoundingBox(2.0, 100.0, 2.0, 100.0));
final Collection<Tuple> tuples2 = getTuplesFromPredicate(tupleList, predicate2);
Assert.assertEquals(1, tuples2.size());
Assert.assertTrue(tuples2.contains(tuple1));
Assert.assertFalse(tuples2.contains(tuple2));
}
use of org.bboxdb.commons.math.BoundingBox 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));
}
use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.
the class TestQueryProcessing method testBBoxQuery1.
/**
* Simple BBox query
* @throws StorageManagerException
* @throws RejectedException
* @throws IOException
*/
@Test(timeout = 60000)
public void testBBoxQuery1() throws StorageManagerException, 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.put(tuple2);
storageManager.put(tuple3);
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));
// Reopen
final Iterator<JoinedTuple> iterator2 = queryPlan.iterator();
final List<JoinedTuple> resultList2 = Lists.newArrayList(iterator2);
final List<Tuple> resultTupleList2 = resultList2.stream().map(t -> t.convertToSingleTupleIfPossible()).collect(Collectors.toList());
queryPlan.close();
Assert.assertEquals(2, resultList2.size());
Assert.assertFalse(resultTupleList2.contains(tuple1));
Assert.assertTrue(resultTupleList2.contains(tuple2));
Assert.assertTrue(resultTupleList2.contains(tuple3));
}
Aggregations