Search in sources :

Example 6 with JoinedTuple

use of org.bboxdb.storage.entity.JoinedTuple 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));
}
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)

Example 7 with JoinedTuple

use of org.bboxdb.storage.entity.JoinedTuple 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));
}
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)

Example 8 with JoinedTuple

use of org.bboxdb.storage.entity.JoinedTuple 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());
}
Also used : SpatialIndexReadOperator(org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator) BoundingBox(org.bboxdb.commons.math.BoundingBox) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) IndexedSpatialJoinOperator(org.bboxdb.storage.queryprocessor.operator.IndexedSpatialJoinOperator) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager) Test(org.junit.Test)

Example 9 with JoinedTuple

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

the class NetworkQueryHelper method executeJoinQuery.

/**
 * Execute a join
 * @param bboxDBConnection
 * @throws InterruptedException
 * @throws BBoxDBException
 */
public static void executeJoinQuery(final BBoxDB bboxDBClient, final String distributionGroup) throws InterruptedException, BBoxDBException {
    System.out.println("=== Execute join");
    final String table1 = distributionGroup + "_table1";
    final String table2 = distributionGroup + "_table2";
    // Create table1
    System.out.println("Create table 1");
    final EmptyResultFuture resultCreateTable1 = bboxDBClient.createTable(table1, new TupleStoreConfiguration());
    resultCreateTable1.waitForAll();
    Assert.assertFalse(resultCreateTable1.isFailed());
    System.out.println("Create table 2");
    final EmptyResultFuture resultCreateTable2 = bboxDBClient.createTable(table2, new TupleStoreConfiguration());
    resultCreateTable2.waitForAll();
    Assert.assertFalse(resultCreateTable2.isFailed());
    // Insert tuples
    System.out.println("Insert tuple 1");
    final Tuple tuple1 = new Tuple("abc", new BoundingBox(1.0, 2.0, 1.0, 2.0), "abc".getBytes());
    final EmptyResultFuture insertResult1 = bboxDBClient.insertTuple(table1, tuple1);
    insertResult1.waitForAll();
    Assert.assertFalse(insertResult1.isFailed());
    Assert.assertTrue(insertResult1.isDone());
    System.out.println("Insert tuple 2");
    final Tuple tuple2 = new Tuple("def", new BoundingBox(1.5, 2.5, 1.5, 2.5), "abc".getBytes());
    final EmptyResultFuture insertResult2 = bboxDBClient.insertTuple(table1, tuple2);
    insertResult2.waitForAll();
    Assert.assertFalse(insertResult2.isFailed());
    Assert.assertTrue(insertResult2.isDone());
    System.out.println("Insert tuple 3");
    final Tuple tuple3 = new Tuple("123", new BoundingBox(0.0, 5.0, 0.0, 5.0), "abc".getBytes());
    final EmptyResultFuture insertResult3 = bboxDBClient.insertTuple(table2, tuple3);
    insertResult3.waitForAll();
    Assert.assertFalse(insertResult3.isFailed());
    Assert.assertTrue(insertResult3.isDone());
    // Execute the join
    final JoinedTupleListFuture joinResult = bboxDBClient.queryJoin(Arrays.asList(table1, table2), new BoundingBox(0.0, 10.0, 0.0, 10.0));
    joinResult.waitForAll();
    final List<JoinedTuple> resultList = Lists.newArrayList(joinResult.iterator());
    System.out.println(resultList);
    Assert.assertEquals(2, resultList.size());
    Assert.assertEquals(2, resultList.get(0).getNumberOfTuples());
    Assert.assertEquals(table1, resultList.get(0).getTupleStoreName(0));
    Assert.assertEquals(table2, resultList.get(0).getTupleStoreName(1));
    Assert.assertEquals(new BoundingBox(1.0, 2.0, 1.0, 2.0), resultList.get(0).getBoundingBox());
    Assert.assertEquals(2, resultList.get(1).getNumberOfTuples());
    Assert.assertEquals(table1, resultList.get(1).getTupleStoreName(0));
    Assert.assertEquals(table2, resultList.get(1).getTupleStoreName(1));
    Assert.assertEquals(new BoundingBox(1.5, 2.5, 1.5, 2.5), resultList.get(1).getBoundingBox());
    System.out.println("=== End Execute join");
}
Also used : JoinedTupleListFuture(org.bboxdb.network.client.future.JoinedTupleListFuture) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) BoundingBox(org.bboxdb.commons.math.BoundingBox) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 10 with JoinedTuple

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

the class TestTupleHelper method testCreateWithDifferentSizes.

/**
 * Test the creation with different sizes
 */
@Test(expected = IllegalArgumentException.class)
public void testCreateWithDifferentSizes() {
    final Tuple tuple1 = new Tuple("abc", new BoundingBox(1d, 2d), "".getBytes());
    final Tuple tuple2 = new Tuple("def", new BoundingBox(1d, 2d), "".getBytes());
    new JoinedTuple(Arrays.asList(tuple1, tuple2), Arrays.asList("abc"));
}
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)

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