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");
}
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");
}
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;
}
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);
}
}
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);
}
}
}
Aggregations