Search in sources :

Example 31 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class NetworkQueryHelper method executeBoudingboxAndTimeQuery.

/**
 * Execute a bounding box and time query
 * @param bboxDBConnection
 * @throws BBoxDBException
 * @throws InterruptedException
 */
public static void executeBoudingboxAndTimeQuery(final BBoxDB bboxDBClient, final String distributionGroup) throws BBoxDBException, InterruptedException {
    final String table = distributionGroup + "_relation9990";
    // Create table
    final EmptyResultFuture resultCreateTable = bboxDBClient.createTable(table, new TupleStoreConfiguration());
    resultCreateTable.waitForAll();
    Assert.assertFalse(resultCreateTable.isFailed());
    // Inside our bbox query
    final Tuple tuple1 = new Tuple("abc", new BoundingBox(0d, 1d, 0d, 1d), "abc".getBytes(), 4);
    final EmptyResultFuture result1 = bboxDBClient.insertTuple(table, tuple1);
    final Tuple tuple2 = new Tuple("def", new BoundingBox(0d, 0.5d, 0d, 0.5d), "def".getBytes(), 4);
    final EmptyResultFuture result2 = bboxDBClient.insertTuple(table, tuple2);
    final Tuple tuple3 = new Tuple("geh", new BoundingBox(0.5d, 1.5d, 0.5d, 1.5d), "geh".getBytes(), 1);
    final EmptyResultFuture result3 = bboxDBClient.insertTuple(table, tuple3);
    // Outside our bbox query
    final Tuple tuple4 = new Tuple("ijk", new BoundingBox(-10d, -9d, -10d, -9d), "ijk".getBytes());
    final EmptyResultFuture result4 = bboxDBClient.insertTuple(table, tuple4);
    final Tuple tuple5 = new Tuple("lmn", new BoundingBox(1000d, 1001d, 1000d, 1001d), "lmn".getBytes());
    final EmptyResultFuture result5 = bboxDBClient.insertTuple(table, tuple5);
    result1.waitForAll();
    result2.waitForAll();
    result3.waitForAll();
    result4.waitForAll();
    result5.waitForAll();
    final TupleListFuture future = bboxDBClient.queryBoundingBoxAndTime(table, new BoundingBox(-1d, 2d, -1d, 2d), 2);
    future.waitForAll();
    final List<Tuple> resultList = Lists.newArrayList(future.iterator());
    Assert.assertEquals(3, resultList.size());
    Assert.assertTrue(resultList.contains(tuple1));
    Assert.assertTrue(resultList.contains(tuple2));
    Assert.assertTrue(resultList.contains(tuple3));
    Assert.assertFalse(resultList.contains(tuple4));
    Assert.assertFalse(resultList.contains(tuple5));
}
Also used : TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) BoundingBox(org.bboxdb.commons.math.BoundingBox) TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) JoinedTupleListFuture(org.bboxdb.network.client.future.JoinedTupleListFuture) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 32 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class NetworkQueryHelper method testBoundingBoxQuery.

/**
 * Test a bounding box query
 * @param bboxDBConnection
 * @return
 * @throws BBoxDBException
 * @throws InterruptedException
 */
public static TupleListFuture testBoundingBoxQuery(final BBoxDB bboxDBClient, final String distributionGroup, final boolean withTupes) throws BBoxDBException, InterruptedException {
    System.out.println("=== Running testInsertAndBoundingBoxQuery");
    final String table = distributionGroup + "_relation9991";
    // Create table
    final EmptyResultFuture resultCreateTable = bboxDBClient.createTable(table, new TupleStoreConfiguration());
    resultCreateTable.waitForAll();
    Assert.assertFalse(resultCreateTable.isFailed());
    // Inside our bbox query
    final Tuple tuple1 = new Tuple("abc", new BoundingBox(0d, 1d, 0d, 1d), "abc".getBytes());
    final Tuple tuple2 = new Tuple("def", new BoundingBox(0d, 0.5d, 0d, 0.5d), "def".getBytes());
    final Tuple tuple3 = new Tuple("geh", new BoundingBox(0.5d, 1.5d, 0.5d, 1.5d), "geh".getBytes());
    // Outside our bbox query
    final Tuple tuple4 = new Tuple("ijk", new BoundingBox(-10d, -9d, -10d, -9d), "ijk".getBytes());
    final Tuple tuple5 = new Tuple("lmn", new BoundingBox(1000d, 1001d, 1000d, 1001d), "lmn".getBytes());
    if (withTupes) {
        final EmptyResultFuture result1 = bboxDBClient.insertTuple(table, tuple1);
        final EmptyResultFuture result2 = bboxDBClient.insertTuple(table, tuple2);
        final EmptyResultFuture result3 = bboxDBClient.insertTuple(table, tuple3);
        final EmptyResultFuture result4 = bboxDBClient.insertTuple(table, tuple4);
        final EmptyResultFuture result5 = bboxDBClient.insertTuple(table, tuple5);
        result1.waitForAll();
        result2.waitForAll();
        result3.waitForAll();
        result4.waitForAll();
        result5.waitForAll();
    }
    System.out.println("=== Executing query");
    final TupleListFuture future = bboxDBClient.queryBoundingBox(table, new BoundingBox(-1d, 2d, -1d, 2d));
    future.waitForAll();
    System.out.println("=== Query DONE");
    Assert.assertFalse(future.isFailed());
    final List<Tuple> resultList = Lists.newArrayList(future.iterator());
    if (!withTupes) {
        Assert.assertEquals(0, resultList.size());
    } else {
        Assert.assertEquals(3, resultList.size());
        Assert.assertTrue(resultList.contains(tuple1));
        Assert.assertTrue(resultList.contains(tuple2));
        Assert.assertTrue(resultList.contains(tuple3));
        Assert.assertFalse(resultList.contains(tuple4));
        Assert.assertFalse(resultList.contains(tuple5));
    }
    System.out.println("=== End testInsertAndBoundingBoxQuery");
    return future;
}
Also used : TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) BoundingBox(org.bboxdb.commons.math.BoundingBox) TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) JoinedTupleListFuture(org.bboxdb.network.client.future.JoinedTupleListFuture) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 33 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class NetworkQueryHelper method testBoundingBoxQueryContinous.

/**
 * Test a bounding box query
 * @param bboxDBConnection
 * @throws BBoxDBException
 * @throws InterruptedException
 */
public static void testBoundingBoxQueryContinous(final BBoxDBClient bboxDBClient, final String distributionGroup) throws BBoxDBException, InterruptedException {
    System.out.println("=== Running testBoundingBoxQueryContinous");
    final String table = distributionGroup + "_relation9991";
    // Create table
    final EmptyResultFuture resultCreateTable = bboxDBClient.createTable(table, new TupleStoreConfiguration());
    resultCreateTable.waitForAll();
    Assert.assertFalse(resultCreateTable.isFailed());
    final TupleListFuture future = bboxDBClient.queryBoundingBoxContinuous(table, new BoundingBox(-1d, 2d, -1d, 2d));
    Thread.sleep(1000);
    System.out.println("=== Tuples per page is: " + bboxDBClient.getTuplesPerPage());
    if (bboxDBClient.getTuplesPerPage() > 0) {
        for (int i = 0; i <= bboxDBClient.getTuplesPerPage(); i++) {
            bboxDBClient.insertTuple(table, new Tuple("1", new BoundingBox(0d, 1d, 0d, 1d), "".getBytes()));
        }
    }
    System.out.println("=== Wait for query result");
    future.waitForAll();
    Assert.assertTrue(future.iterator().hasNext());
    final short queryId = future.getRequestId(0);
    System.out.println("Canceling query: " + queryId);
    final EmptyResultFuture cancelResult = bboxDBClient.cancelQuery(queryId);
    cancelResult.waitForAll();
    Assert.assertTrue(cancelResult.isDone());
    Assert.assertFalse(cancelResult.isFailed());
    System.out.println("=== End testBoundingBoxQueryContinous");
}
Also used : TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) JoinedTupleListFuture(org.bboxdb.network.client.future.JoinedTupleListFuture) BoundingBox(org.bboxdb.commons.math.BoundingBox) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 34 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class TestBBoxDBCluster method testInsertAndBoundingBoxContinousQuery.

/**
 * Insert some tuples and start a bounding box query afterwards
 * @throws ExecutionException
 * @throws InterruptedException
 * @throws BBoxDBException
 */
@Test(timeout = 60000)
public void testInsertAndBoundingBoxContinousQuery() throws InterruptedException, ExecutionException, BBoxDBException {
    final BBoxDB bboxDBClient = connectToServer();
    final String table = DISTRIBUTION_GROUP + "_relation9991";
    // Create table
    final EmptyResultFuture resultCreateTable = bboxDBClient.createTable(table, new TupleStoreConfiguration());
    resultCreateTable.waitForAll();
    Assert.assertFalse(resultCreateTable.isFailed());
    // Execute query
    final TupleListFuture result = bboxDBClient.queryBoundingBoxContinuous(table, new BoundingBox(-1d, 2d, -1d, 2d));
    Assert.assertFalse(result.isFailed());
    disconnect(bboxDBClient);
}
Also used : BBoxDB(org.bboxdb.network.client.BBoxDB) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) BoundingBox(org.bboxdb.commons.math.BoundingBox) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture) Test(org.junit.Test)

Example 35 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class DistributedSelftest method insertNewTuples.

/**
 * Insert new tuples
 * @param bboxdbClient
 * @throws InterruptedException
 * @throws ExecutionException
 * @throws BBoxDBException
 */
private static void insertNewTuples(final BBoxDBCluster bboxdbClient) throws InterruptedException, ExecutionException, BBoxDBException {
    logger.info("Inserting new tuples");
    for (int i = 0; i < NUMBER_OF_OPERATIONS; i++) {
        final String key = Integer.toString(i);
        final Tuple myTuple = new Tuple(key, new BoundingBox(1.0d, 2.0d, 1.0d, 2.0d), "test".getBytes());
        final EmptyResultFuture insertResult = bboxdbClient.insertTuple(TABLE, myTuple);
        insertResult.waitForAll();
        if (insertResult.isFailed()) {
            logger.error("Got an error during tuple insert: ", insertResult.getAllMessages());
            System.exit(-1);
        }
    }
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) Tuple(org.bboxdb.storage.entity.Tuple) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Aggregations

BoundingBox (org.bboxdb.commons.math.BoundingBox)194 Test (org.junit.Test)113 Tuple (org.bboxdb.storage.entity.Tuple)61 ArrayList (java.util.ArrayList)25 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)24 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)23 BBoxDBException (org.bboxdb.misc.BBoxDBException)22 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)20 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)16 List (java.util.List)15 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)13 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)13 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)13 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)12 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)11 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)11 IOException (java.io.IOException)10 Date (java.util.Date)10 DoubleInterval (org.bboxdb.commons.math.DoubleInterval)10 SpatialIndexReadOperator (org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator)10