Search in sources :

Example 66 with Tuple

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

the class NetworkQueryHelper method testInsertAndDeleteTuple.

/**
 * Insert and delete tuple
 * @param bboxDBConnection
 * @throws BBoxDBException
 * @throws InterruptedException
 */
public static void testInsertAndDeleteTuple(final BBoxDB bboxDBClient, final String distributionGroup) throws BBoxDBException, InterruptedException {
    System.out.println("=== Running testInsertAndDelete");
    final String table = distributionGroup + "_relation4";
    final String key = "key12";
    // Create table
    final EmptyResultFuture resultCreateTable = bboxDBClient.createTable(table, new TupleStoreConfiguration());
    resultCreateTable.waitForAll();
    Assert.assertFalse(resultCreateTable.isFailed());
    System.out.println("Delete tuple");
    final EmptyResultFuture deleteResult1 = bboxDBClient.deleteTuple(table, key);
    deleteResult1.waitForAll();
    Assert.assertFalse(deleteResult1.isFailed());
    Assert.assertTrue(deleteResult1.isDone());
    System.out.println("Query key");
    final TupleListFuture getResult = bboxDBClient.queryKey(table, key);
    getResult.waitForAll();
    Assert.assertFalse(getResult.isFailed());
    Assert.assertTrue(getResult.isDone());
    System.out.println("Insert tuple");
    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 key 2");
    final TupleListFuture getResult2 = bboxDBClient.queryKey(table, key);
    getResult2.waitForAll();
    final List<Tuple> resultList = Lists.newArrayList(getResult2.iterator());
    Assert.assertEquals(tuple, resultList.get(0));
    System.out.println("Delete tuple 2");
    final EmptyResultFuture deleteResult2 = bboxDBClient.deleteTuple(table, key, System.currentTimeMillis());
    deleteResult2.waitForAll();
    Assert.assertFalse(deleteResult2.isFailed());
    Assert.assertTrue(deleteResult2.isDone());
    System.out.println("Query key 3");
    final TupleListFuture getResult3 = bboxDBClient.queryKey(table, key);
    getResult3.waitForAll();
    Assert.assertFalse(getResult3.isFailed());
    Assert.assertTrue(getResult3.isDone());
    bboxDBClient.disconnect();
    System.out.println("=== End testInsertAndDelete");
}
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 67 with Tuple

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

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

the class TupleStoreManager method getVersionsForTuple.

/**
 * Get the most recent version of the tuple
 * e.g. Memtables can contain multiple versions of the key
 * The iterator can return an outdated version
 *
 * @param tuple
 * @return
 * @throws StorageManagerException
 */
public List<Tuple> getVersionsForTuple(final String key) throws StorageManagerException {
    final List<Tuple> resultTuples = getAllTupleVersionsForKey(key);
    final TupleStoreConfiguration tupleStoreConfiguration = getTupleStoreConfiguration();
    final DuplicateResolver<Tuple> resolver = TupleDuplicateResolverFactory.build(tupleStoreConfiguration);
    // Removed unwanted tuples for key
    resolver.removeDuplicates(resultTuples);
    return resultTuples;
}
Also used : TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) Tuple(org.bboxdb.storage.entity.Tuple)

Example 69 with Tuple

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

the class TupleStoreManager method getAllTupleVersionsForKey.

/**
 * Get all tuples for a given key
 * @param tuple
 * @param activeStorage
 * @return
 * @throws StorageManagerException
 */
public List<Tuple> getAllTupleVersionsForKey(final String key) throws StorageManagerException {
    List<ReadOnlyTupleStore> aquiredStorages = null;
    try {
        aquiredStorages = aquireStorage();
        final List<Tuple> resultTuples = new ArrayList<>();
        for (final ReadOnlyTupleStore readOnlyTupleStorage : aquiredStorages) {
            final List<Tuple> possibleTuples = readOnlyTupleStorage.get(key);
            resultTuples.addAll(possibleTuples);
        }
        return resultTuples;
    } catch (Exception e) {
        throw e;
    } finally {
        releaseStorage(aquiredStorages);
    }
}
Also used : ArrayList(java.util.ArrayList) ReadOnlyTupleStore(org.bboxdb.storage.tuplestore.ReadOnlyTupleStore) Tuple(org.bboxdb.storage.entity.Tuple) RejectedException(org.bboxdb.commons.RejectedException) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) StorageManagerException(org.bboxdb.storage.StorageManagerException) IOException(java.io.IOException) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Example 70 with Tuple

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

the class DistributedSelftest method queryForExistingTuplesByKey.

/**
 * Query for the stored tuples
 * @param bboxdbClient
 * @param random
 * @throws InterruptedException
 * @throws ExecutionException
 * @throws BBoxDBException
 */
private static void queryForExistingTuplesByKey(final BBoxDBCluster bboxdbClient) throws InterruptedException, ExecutionException, BBoxDBException {
    logger.info("Query for tuples");
    for (int i = 0; i < NUMBER_OF_OPERATIONS; i++) {
        final int nextInt = ThreadLocalRandom.current().nextInt(NUMBER_OF_OPERATIONS);
        final String key = Integer.toString(nextInt);
        final TupleListFuture queryResult = bboxdbClient.queryKey(TABLE, key);
        queryResult.waitForAll();
        if (queryResult.isFailed()) {
            logger.error("Query {} : Got failed future, when query for: {}", i, key);
            logger.error(queryResult.getAllMessages());
            System.exit(-1);
        }
        boolean tupleFound = false;
        for (final Tuple tuple : queryResult) {
            if (!tuple.getKey().equals(key)) {
                logger.error("Query {}: Got tuple with wrong key.", i);
                logger.error("Expected: {} but got: {}", i, tuple.getKey());
                System.exit(-1);
            }
            tupleFound = true;
        }
        if (tupleFound == false) {
            logger.error("Query {}: Key {} not found", i, key);
            System.exit(-1);
        }
    }
}
Also used : TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) Tuple(org.bboxdb.storage.entity.Tuple)

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