Search in sources :

Example 6 with TupleStoreName

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));
    }
}
Also used : FullTablescanOperator(org.bboxdb.storage.queryprocessor.operator.FullTablescanOperator) NewerAsInsertTimeSeclectionOperator(org.bboxdb.storage.queryprocessor.operator.NewerAsInsertTimeSeclectionOperator) Operator(org.bboxdb.storage.queryprocessor.operator.Operator) QueryInsertTimeRequest(org.bboxdb.network.packages.request.QueryInsertTimeRequest) FullTablescanOperator(org.bboxdb.storage.queryprocessor.operator.FullTablescanOperator) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) OperatorTreeBuilder(org.bboxdb.storage.queryprocessor.OperatorTreeBuilder) StreamClientQuery(org.bboxdb.network.server.StreamClientQuery) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) List(java.util.List) NewerAsInsertTimeSeclectionOperator(org.bboxdb.storage.queryprocessor.operator.NewerAsInsertTimeSeclectionOperator) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 7 with TupleStoreName

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));
    }
}
Also used : IndexedSpatialJoinOperator(org.bboxdb.storage.queryprocessor.operator.IndexedSpatialJoinOperator) Operator(org.bboxdb.storage.queryprocessor.operator.Operator) SpatialIndexReadOperator(org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator) StreamClientQuery(org.bboxdb.network.server.StreamClientQuery) IndexedSpatialJoinOperator(org.bboxdb.storage.queryprocessor.operator.IndexedSpatialJoinOperator) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse) QueryJoinRequest(org.bboxdb.network.packages.request.QueryJoinRequest) SpatialIndexReadOperator(org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator) BoundingBox(org.bboxdb.commons.math.BoundingBox) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) OperatorTreeBuilder(org.bboxdb.storage.queryprocessor.OperatorTreeBuilder) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) List(java.util.List)

Example 8 with TupleStoreName

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);
}
Also used : PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) ArrayList(java.util.ArrayList) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName)

Example 9 with TupleStoreName

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);
}
Also used : TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) Tuple(org.bboxdb.storage.entity.Tuple) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager) Test(org.junit.Test)

Example 10 with TupleStoreName

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);
}
Also used : TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) Test(org.junit.Test)

Aggregations

TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)77 Test (org.junit.Test)25 Tuple (org.bboxdb.storage.entity.Tuple)18 StorageManagerException (org.bboxdb.storage.StorageManagerException)15 ArrayList (java.util.ArrayList)14 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)14 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)13 ByteBuffer (java.nio.ByteBuffer)12 BoundingBox (org.bboxdb.commons.math.BoundingBox)12 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)12 BBoxDBException (org.bboxdb.misc.BBoxDBException)12 InsertTupleRequest (org.bboxdb.network.packages.request.InsertTupleRequest)12 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)12 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)12 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)11 List (java.util.List)10 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)10 TupleStoreManagerRegistry (org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry)10 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)9 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)9