use of org.bboxdb.storage.queryprocessor.operator.Operator 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.queryprocessor.operator.Operator 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.queryprocessor.operator.Operator in project bboxdb by jnidzwetzki.
the class TestQueryProcessing method testBBoxQuery3.
/**
* Simple BBox query - across multiple tables on disk
* @throws StorageManagerException
* @throws InterruptedException
* @throws RejectedException
* @throws IOException
*/
@Test(timeout = 60000)
public void testBBoxQuery3() throws StorageManagerException, InterruptedException, RejectedException, IOException {
final TupleStoreManager storageManager = storageRegistry.getTupleStoreManager(TABLE_1);
final Tuple tuple1 = new Tuple("1", new BoundingBox(1.0, 2.0, 1.0, 2.0), "value".getBytes());
final Tuple tuple2 = new Tuple("2", new BoundingBox(1.5, 2.5, 1.5, 2.5), "value2".getBytes());
final Tuple tuple3 = new Tuple("1", new BoundingBox(1.0, 2.0, 1.0, 2.0), "value1".getBytes());
storageManager.put(tuple1);
storageManager.flush();
storageManager.put(tuple2);
storageManager.flush();
storageManager.put(tuple3);
storageManager.flush();
final BoundingBox queryBoundingBox = new BoundingBox(0.0, 5.0, 0.0, 5.0);
final Operator spatialIndexReadOperator = new FullTablescanOperator(storageManager);
final Operator queryPlan = new BoundingBoxSelectOperator(queryBoundingBox, spatialIndexReadOperator);
final Iterator<JoinedTuple> iterator = queryPlan.iterator();
final List<JoinedTuple> resultList = Lists.newArrayList(iterator);
final List<Tuple> resultTupleList = resultList.stream().map(t -> t.convertToSingleTupleIfPossible()).collect(Collectors.toList());
queryPlan.close();
Assert.assertEquals(2, resultList.size());
Assert.assertFalse(resultTupleList.contains(tuple1));
Assert.assertTrue(resultTupleList.contains(tuple2));
Assert.assertTrue(resultTupleList.contains(tuple3));
}
use of org.bboxdb.storage.queryprocessor.operator.Operator in project bboxdb by jnidzwetzki.
the class TestQueryProcessing method testBBoxQuery1.
/**
* Simple BBox query
* @throws StorageManagerException
* @throws RejectedException
* @throws IOException
*/
@Test(timeout = 60000)
public void testBBoxQuery1() throws StorageManagerException, RejectedException, IOException {
final TupleStoreManager storageManager = storageRegistry.getTupleStoreManager(TABLE_1);
final Tuple tuple1 = new Tuple("1", new BoundingBox(1.0, 2.0, 1.0, 2.0), "value".getBytes());
final Tuple tuple2 = new Tuple("2", new BoundingBox(1.5, 2.5, 1.5, 2.5), "value2".getBytes());
final Tuple tuple3 = new Tuple("1", new BoundingBox(1.0, 2.0, 1.0, 2.0), "value1".getBytes());
storageManager.put(tuple1);
storageManager.put(tuple2);
storageManager.put(tuple3);
final BoundingBox queryBoundingBox = new BoundingBox(0.0, 5.0, 0.0, 5.0);
final Operator spatialIndexReadOperator = new FullTablescanOperator(storageManager);
final Operator queryPlan = new BoundingBoxSelectOperator(queryBoundingBox, spatialIndexReadOperator);
final Iterator<JoinedTuple> iterator = queryPlan.iterator();
final List<JoinedTuple> resultList = Lists.newArrayList(iterator);
final List<Tuple> resultTupleList = resultList.stream().map(t -> t.convertToSingleTupleIfPossible()).collect(Collectors.toList());
queryPlan.close();
Assert.assertEquals(2, resultList.size());
Assert.assertFalse(resultTupleList.contains(tuple1));
Assert.assertTrue(resultTupleList.contains(tuple2));
Assert.assertTrue(resultTupleList.contains(tuple3));
// Reopen
final Iterator<JoinedTuple> iterator2 = queryPlan.iterator();
final List<JoinedTuple> resultList2 = Lists.newArrayList(iterator2);
final List<Tuple> resultTupleList2 = resultList2.stream().map(t -> t.convertToSingleTupleIfPossible()).collect(Collectors.toList());
queryPlan.close();
Assert.assertEquals(2, resultList2.size());
Assert.assertFalse(resultTupleList2.contains(tuple1));
Assert.assertTrue(resultTupleList2.contains(tuple2));
Assert.assertTrue(resultTupleList2.contains(tuple3));
}
use of org.bboxdb.storage.queryprocessor.operator.Operator in project bboxdb by jnidzwetzki.
the class TestQueryProcessing method testBBoxQuery2.
/**
* Simple BBox query - across multiple tables
* @throws StorageManagerException
* @throws RejectedException
* @throws IOException
*/
@Test(timeout = 60000)
public void testBBoxQuery2() throws StorageManagerException, RejectedException, IOException {
final TupleStoreManager storageManager = storageRegistry.getTupleStoreManager(TABLE_1);
final Tuple tuple1 = new Tuple("1", new BoundingBox(1.0, 2.0, 1.0, 2.0), "value".getBytes());
final Tuple tuple2 = new Tuple("2", new BoundingBox(1.5, 2.5, 1.5, 2.5), "value2".getBytes());
final Tuple tuple3 = new Tuple("1", new BoundingBox(1.0, 2.0, 1.0, 2.0), "value1".getBytes());
storageManager.put(tuple1);
storageManager.initNewMemtable();
storageManager.put(tuple2);
storageManager.initNewMemtable();
storageManager.put(tuple3);
storageManager.initNewMemtable();
final BoundingBox queryBoundingBox = new BoundingBox(0.0, 5.0, 0.0, 5.0);
final Operator spatialIndexReadOperator = new FullTablescanOperator(storageManager);
final Operator queryPlan = new BoundingBoxSelectOperator(queryBoundingBox, spatialIndexReadOperator);
final Iterator<JoinedTuple> iterator = queryPlan.iterator();
final List<JoinedTuple> resultList = Lists.newArrayList(iterator);
final List<Tuple> resultTupleList = resultList.stream().map(t -> t.convertToSingleTupleIfPossible()).collect(Collectors.toList());
queryPlan.close();
Assert.assertEquals(2, resultList.size());
Assert.assertFalse(resultTupleList.contains(tuple1));
Assert.assertTrue(resultTupleList.contains(tuple2));
Assert.assertTrue(resultTupleList.contains(tuple3));
}
Aggregations