use of org.bboxdb.storage.entity.Tuple 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.storage.entity.Tuple 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.storage.entity.Tuple 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));
}
use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.
the class TestQueryProcessing method testBBoxQuery2.
/**
* Simple BBox query - across multiple tables
* @throws StorageManagerException
* @throws RejectedException
* @throws IOException
*/
@Test(timeout = 60000)
public void testBBoxQuery2() 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.initNewMemtable();
storageManager.put(tuple2);
storageManager.initNewMemtable();
storageManager.put(tuple3);
storageManager.initNewMemtable();
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.storage.entity.Tuple 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());
}
Aggregations