Search in sources :

Example 61 with Tuple

use of org.bboxdb.storage.entity.Tuple 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 62 with Tuple

use of org.bboxdb.storage.entity.Tuple 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 63 with Tuple

use of org.bboxdb.storage.entity.Tuple 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 64 with Tuple

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

the class NetworkQueryHelper method testInsertedTimeQuery.

/**
 * Test the version time query
 * @param bboxDBConnection
 * @param distributionGroup
 * @throws InterruptedException
 * @throws BBoxDBException
 */
public static void testInsertedTimeQuery(final BBoxDB bboxDBClient, final String distributionGroup) throws InterruptedException, BBoxDBException {
    final String table = distributionGroup + "_relationit";
    final String key = "key12";
    System.out.println("== Executing testInsertedTimeQuery");
    // Create table
    final EmptyResultFuture resultCreateTable = bboxDBClient.createTable(table, new TupleStoreConfiguration());
    resultCreateTable.waitForAll();
    Assert.assertFalse(resultCreateTable.isFailed());
    final Tuple tuple = new Tuple(key, BoundingBox.FULL_SPACE, "abc".getBytes());
    final EmptyResultFuture insertResult = bboxDBClient.insertTuple(table, tuple);
    insertResult.waitForAll();
    Assert.assertFalse(insertResult.isFailed());
    Assert.assertTrue(insertResult.isDone());
    System.out.println("Query all versions");
    final TupleListFuture getResult1 = bboxDBClient.queryInsertedTime(table, 0);
    getResult1.waitForAll();
    final List<Tuple> resultList1 = Lists.newArrayList(getResult1.iterator());
    Assert.assertEquals(1, resultList1.size());
    Assert.assertEquals(tuple, resultList1.get(0));
    System.out.println("Query newest versions");
    final TupleListFuture getResult2 = bboxDBClient.queryInsertedTime(table, Long.MAX_VALUE);
    getResult2.waitForAll();
    final List<Tuple> resultList2 = Lists.newArrayList(getResult2.iterator());
    Assert.assertTrue(resultList2.isEmpty());
}
Also used : TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) 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 65 with Tuple

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

the class NetworkQueryHelper method testVersionTimeQuery.

/**
 * Test the version time query
 * @param bboxDBConnection
 * @param distributionGroup
 * @throws InterruptedException
 * @throws BBoxDBException
 */
public static void testVersionTimeQuery(final BBoxDB bboxDBClient, final String distributionGroup) throws InterruptedException, BBoxDBException {
    final String table = distributionGroup + "_relationqt";
    final String key = "key12";
    System.out.println("== Executing testVersionTimeQuery");
    // Create table
    final EmptyResultFuture resultCreateTable = bboxDBClient.createTable(table, new TupleStoreConfiguration());
    resultCreateTable.waitForAll();
    Assert.assertFalse(resultCreateTable.isFailed());
    final Tuple tuple = new Tuple(key, BoundingBox.FULL_SPACE, "abc".getBytes());
    final EmptyResultFuture insertResult = bboxDBClient.insertTuple(table, tuple);
    insertResult.waitForAll();
    Assert.assertFalse(insertResult.isFailed());
    Assert.assertTrue(insertResult.isDone());
    System.out.println("Query all versions");
    final TupleListFuture getResult1 = bboxDBClient.queryVersionTime(table, 0);
    getResult1.waitForAll();
    final List<Tuple> resultList1 = Lists.newArrayList(getResult1.iterator());
    Assert.assertEquals(1, resultList1.size());
    Assert.assertEquals(tuple, resultList1.get(0));
    System.out.println("Query newest versions");
    final TupleListFuture getResult2 = bboxDBClient.queryVersionTime(table, Long.MAX_VALUE);
    getResult2.waitForAll();
    final List<Tuple> resultList2 = Lists.newArrayList(getResult2.iterator());
    Assert.assertTrue(resultList2.isEmpty());
}
Also used : TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) 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)

Aggregations

Tuple (org.bboxdb.storage.entity.Tuple)198 Test (org.junit.Test)123 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)104 BoundingBox (org.bboxdb.commons.math.BoundingBox)62 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)58 ArrayList (java.util.ArrayList)41 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)25 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)24 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)18 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)18 ByteBuffer (java.nio.ByteBuffer)17 BBoxDBException (org.bboxdb.misc.BBoxDBException)16 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)15 SSTableKeyIndexReader (org.bboxdb.storage.sstable.reader.SSTableKeyIndexReader)13 IOException (java.io.IOException)11 List (java.util.List)11 JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)11 InsertTupleRequest (org.bboxdb.network.packages.request.InsertTupleRequest)11 StorageManagerException (org.bboxdb.storage.StorageManagerException)11 TupleBuilder (org.bboxdb.tools.converter.tuple.TupleBuilder)11