use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class HandleInsertTimeQuery method handleQuery.
@Override
public /**
* Handle a time query
*/
void handleQuery(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
try {
if (clientConnectionHandler.getActiveQueries().containsKey(packageSequence)) {
logger.error("Query sequence {} is allready known, please close old query first", packageSequence);
return;
}
final QueryInsertTimeRequest queryRequest = QueryInsertTimeRequest.decodeTuple(encodedPackage);
final TupleStoreName requestTable = queryRequest.getTable();
if (!QueryHelper.handleNonExstingTable(requestTable, packageSequence, clientConnectionHandler)) {
return;
}
final OperatorTreeBuilder operatorTreeBuilder = new OperatorTreeBuilder() {
@Override
public Operator buildOperatorTree(final List<TupleStoreManager> storageManager) {
if (storageManager.size() != 1) {
throw new IllegalArgumentException("This operator tree needs 1 storage manager");
}
final FullTablescanOperator tablescanOperator = new FullTablescanOperator(storageManager.get(0));
final long timestamp = queryRequest.getTimestamp();
final Operator opeator = new NewerAsInsertTimeSeclectionOperator(timestamp, tablescanOperator);
return opeator;
}
};
final StreamClientQuery clientQuery = new StreamClientQuery(operatorTreeBuilder, queryRequest.isPagingEnabled(), queryRequest.getTuplesPerPage(), clientConnectionHandler, packageSequence, Arrays.asList(requestTable));
clientConnectionHandler.getActiveQueries().put(packageSequence, clientQuery);
clientConnectionHandler.sendNextResultsForQuery(packageSequence, packageSequence);
} catch (PackageEncodeException e) {
logger.warn("Got exception while decoding package", e);
clientConnectionHandler.writeResultPackage(new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION));
}
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class HandleJoinQuery method handleQuery.
@Override
public /**
* Handle a bounding box query
*/
void handleQuery(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
try {
if (clientConnectionHandler.getActiveQueries().containsKey(packageSequence)) {
logger.error("Query sequence {} is allready known, please close old query first", packageSequence);
return;
}
final QueryJoinRequest queryRequest = QueryJoinRequest.decodeTuple(encodedPackage);
final List<TupleStoreName> requestTables = queryRequest.getTables();
final BoundingBox boundingBox = queryRequest.getBoundingBox();
for (final TupleStoreName requestTable : requestTables) {
if (!QueryHelper.handleNonExstingTable(requestTable, packageSequence, clientConnectionHandler)) {
return;
}
}
final OperatorTreeBuilder operatorTreeBuilder = new OperatorTreeBuilder() {
@Override
public Operator buildOperatorTree(final List<TupleStoreManager> storageManager) {
if (storageManager.size() <= 1) {
throw new IllegalArgumentException("This operator tree needs more than one storage manager");
}
Operator operator1 = new SpatialIndexReadOperator(storageManager.get(0), boundingBox);
SpatialIndexReadOperator indexReader = new SpatialIndexReadOperator(storageManager.get(1));
operator1 = new IndexedSpatialJoinOperator(operator1, indexReader);
for (int i = 3; i < storageManager.size(); i++) {
indexReader = new SpatialIndexReadOperator(storageManager.get(i));
operator1 = new IndexedSpatialJoinOperator(operator1, indexReader);
}
return operator1;
}
};
final StreamClientQuery clientQuery = new StreamClientQuery(operatorTreeBuilder, queryRequest.isPagingEnabled(), queryRequest.getTuplesPerPage(), clientConnectionHandler, packageSequence, requestTables);
clientConnectionHandler.getActiveQueries().put(packageSequence, clientQuery);
clientConnectionHandler.sendNextResultsForQuery(packageSequence, packageSequence);
} catch (PackageEncodeException e) {
logger.warn("Got exception while decoding package", e);
clientConnectionHandler.writeResultPackage(new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION));
}
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class ListTablesResponse method decodePackage.
/**
* Decode the encoded package into a object
*
* @param encodedPackage
* @return
* @throws PackageEncodeException
*/
public static ListTablesResponse decodePackage(final ByteBuffer encodedPackage) throws PackageEncodeException {
final short requestId = NetworkPackageDecoder.getRequestIDFromResponsePackage(encodedPackage);
final boolean decodeResult = NetworkPackageDecoder.validateResponsePackageHeader(encodedPackage, NetworkConst.RESPONSE_TYPE_LIST_TABLES);
if (decodeResult == false) {
throw new PackageEncodeException("Unable to decode package");
}
// Read the total amount of tables
final int totalTables = encodedPackage.getInt();
final List<TupleStoreName> tables = new ArrayList<TupleStoreName>(totalTables);
// Read and decode tables
for (short readTables = 0; readTables < totalTables; readTables++) {
// Read table name length
final short tableNameLength = encodedPackage.getShort();
final byte[] tablenameBytes = new byte[tableNameLength];
// Read table name and decode
encodedPackage.get(tablenameBytes, 0, tablenameBytes.length);
final String tablename = new String(tablenameBytes);
final TupleStoreName sstableName = new TupleStoreName(tablename);
tables.add(sstableName);
}
if (encodedPackage.remaining() != 0) {
throw new PackageEncodeException("Some bytes are left after decoding: " + encodedPackage.remaining());
}
return new ListTablesResponse(requestId, tables);
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class TestStorageRegistry method testCalculateSize.
/**
* Calculate the size of a distribution group
* @throws StorageManagerException
* @throws InterruptedException
* @throws RejectedException
*/
@Test(timeout = 60000)
public void testCalculateSize() throws StorageManagerException, InterruptedException, RejectedException {
storageRegistry.deleteTable(RELATION_NAME, true);
Assert.assertFalse(storageRegistry.isStorageManagerActive(RELATION_NAME));
storageRegistry.createTable(RELATION_NAME, new TupleStoreConfiguration());
final TupleStoreManager storageManager = storageRegistry.getTupleStoreManager(RELATION_NAME);
for (int i = 0; i < 50000; i++) {
final Tuple createdTuple = new Tuple(Integer.toString(i), BoundingBox.FULL_SPACE, Integer.toString(i).getBytes());
storageManager.put(createdTuple);
}
// Wait for requests to settle
storageManager.flush();
final List<TupleStoreName> tablesBeforeDelete = storageRegistry.getAllTables();
System.out.println(tablesBeforeDelete);
Assert.assertTrue(tablesBeforeDelete.contains(RELATION_NAME));
final long size1 = TupleStoreUtil.getSizeOfDistributionGroupAndRegionId(storageRegistry, RELATION_NAME.getDistributionGroup(), 2);
Assert.assertTrue(size1 > 0);
storageRegistry.deleteTable(RELATION_NAME, true);
final List<TupleStoreName> tablesAfterDelete = storageRegistry.getAllTables();
System.out.println(tablesAfterDelete);
Assert.assertFalse(tablesAfterDelete.contains(RELATION_NAME));
final long size2 = TupleStoreUtil.getSizeOfDistributionGroupAndRegionId(storageRegistry, RELATION_NAME.getDistributionGroup(), 2);
Assert.assertTrue(size2 == 0);
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class TestTablenameParser method testCompareTo.
/**
* Test the compare to method
*/
@Test(timeout = 60000)
public void testCompareTo() {
final TupleStoreName tupleStoreName1 = new TupleStoreName("abc_def_1");
final TupleStoreName tupleStoreName2 = new TupleStoreName("def_def_2");
Assert.assertTrue(tupleStoreName1.getRegionId().isPresent());
Assert.assertTrue(tupleStoreName2.getRegionId().isPresent());
Assert.assertTrue(tupleStoreName1.compareTo(tupleStoreName1) == 0);
Assert.assertTrue(tupleStoreName1.compareTo(tupleStoreName2) < 0);
Assert.assertTrue(tupleStoreName2.compareTo(tupleStoreName1) > 0);
}
Aggregations