Search in sources :

Example 1 with JoinedTupleListFuture

use of org.bboxdb.network.client.future.JoinedTupleListFuture in project bboxdb by jnidzwetzki.

the class NetworkQueryHelper method executeJoinQuery.

/**
 * Execute a join
 * @param bboxDBConnection
 * @throws InterruptedException
 * @throws BBoxDBException
 */
public static void executeJoinQuery(final BBoxDB bboxDBClient, final String distributionGroup) throws InterruptedException, BBoxDBException {
    System.out.println("=== Execute join");
    final String table1 = distributionGroup + "_table1";
    final String table2 = distributionGroup + "_table2";
    // Create table1
    System.out.println("Create table 1");
    final EmptyResultFuture resultCreateTable1 = bboxDBClient.createTable(table1, new TupleStoreConfiguration());
    resultCreateTable1.waitForAll();
    Assert.assertFalse(resultCreateTable1.isFailed());
    System.out.println("Create table 2");
    final EmptyResultFuture resultCreateTable2 = bboxDBClient.createTable(table2, new TupleStoreConfiguration());
    resultCreateTable2.waitForAll();
    Assert.assertFalse(resultCreateTable2.isFailed());
    // Insert tuples
    System.out.println("Insert tuple 1");
    final Tuple tuple1 = new Tuple("abc", new BoundingBox(1.0, 2.0, 1.0, 2.0), "abc".getBytes());
    final EmptyResultFuture insertResult1 = bboxDBClient.insertTuple(table1, tuple1);
    insertResult1.waitForAll();
    Assert.assertFalse(insertResult1.isFailed());
    Assert.assertTrue(insertResult1.isDone());
    System.out.println("Insert tuple 2");
    final Tuple tuple2 = new Tuple("def", new BoundingBox(1.5, 2.5, 1.5, 2.5), "abc".getBytes());
    final EmptyResultFuture insertResult2 = bboxDBClient.insertTuple(table1, tuple2);
    insertResult2.waitForAll();
    Assert.assertFalse(insertResult2.isFailed());
    Assert.assertTrue(insertResult2.isDone());
    System.out.println("Insert tuple 3");
    final Tuple tuple3 = new Tuple("123", new BoundingBox(0.0, 5.0, 0.0, 5.0), "abc".getBytes());
    final EmptyResultFuture insertResult3 = bboxDBClient.insertTuple(table2, tuple3);
    insertResult3.waitForAll();
    Assert.assertFalse(insertResult3.isFailed());
    Assert.assertTrue(insertResult3.isDone());
    // Execute the join
    final JoinedTupleListFuture joinResult = bboxDBClient.queryJoin(Arrays.asList(table1, table2), new BoundingBox(0.0, 10.0, 0.0, 10.0));
    joinResult.waitForAll();
    final List<JoinedTuple> resultList = Lists.newArrayList(joinResult.iterator());
    System.out.println(resultList);
    Assert.assertEquals(2, resultList.size());
    Assert.assertEquals(2, resultList.get(0).getNumberOfTuples());
    Assert.assertEquals(table1, resultList.get(0).getTupleStoreName(0));
    Assert.assertEquals(table2, resultList.get(0).getTupleStoreName(1));
    Assert.assertEquals(new BoundingBox(1.0, 2.0, 1.0, 2.0), resultList.get(0).getBoundingBox());
    Assert.assertEquals(2, resultList.get(1).getNumberOfTuples());
    Assert.assertEquals(table1, resultList.get(1).getTupleStoreName(0));
    Assert.assertEquals(table2, resultList.get(1).getTupleStoreName(1));
    Assert.assertEquals(new BoundingBox(1.5, 2.5, 1.5, 2.5), resultList.get(1).getBoundingBox());
    System.out.println("=== End Execute join");
}
Also used : JoinedTupleListFuture(org.bboxdb.network.client.future.JoinedTupleListFuture) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) BoundingBox(org.bboxdb.commons.math.BoundingBox) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 2 with JoinedTupleListFuture

use of org.bboxdb.network.client.future.JoinedTupleListFuture in project bboxdb by jnidzwetzki.

the class BBoxDBClient method queryJoin.

/* (non-Javadoc)
	 * @see org.bboxdb.network.client.BBoxDB#queryJoin
	 */
@Override
public JoinedTupleListFuture queryJoin(final List<String> tableNames, final BoundingBox boundingBox) {
    final RoutingHeader routingHeader = RoutingHeaderHelper.getRoutingHeaderForLocalSystemReadNE(tableNames.get(0), boundingBox, true, connection.getServerAddress());
    final NetworkOperationFuture future = getJoinFuture(tableNames, boundingBox, routingHeader);
    return new JoinedTupleListFuture(future);
}
Also used : JoinedTupleListFuture(org.bboxdb.network.client.future.JoinedTupleListFuture) NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) RoutingHeader(org.bboxdb.network.routing.RoutingHeader)

Example 3 with JoinedTupleListFuture

use of org.bboxdb.network.client.future.JoinedTupleListFuture in project bboxdb by jnidzwetzki.

the class BBoxDBCluster method queryJoin.

/* (non-Javadoc)
	 * @see org.bboxdb.network.client.BBoxDB#queryJoin
	 */
@Override
public JoinedTupleListFuture queryJoin(final List<String> tableNames, final BoundingBox boundingBox) throws BBoxDBException {
    if (membershipConnectionService.getNumberOfConnections() == 0) {
        throw new BBoxDBException("queryJoin called, but connection list is empty");
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Query by for join {} on tables {}", boundingBox, tableNames);
    }
    final String fullname = tableNames.get(0);
    final DistributionRegion distributionRegion = getRootNode(fullname);
    final Supplier<List<NetworkOperationFuture>> futureProvider = () -> {
        final List<RoutingHop> hops = RoutingHopHelper.getRoutingHopsForRead(distributionRegion, boundingBox);
        final List<NetworkOperationFuture> futures = new ArrayList<>();
        for (final RoutingHop hop : hops) {
            final BBoxDBInstance instance = hop.getDistributedInstance();
            final BBoxDBConnection connection = membershipConnectionService.getConnectionForInstance(instance);
            final RoutingHeader routingHeader = new RoutingHeader((short) 0, Arrays.asList(hop));
            final NetworkOperationFuture future = connection.getBboxDBClient().getJoinFuture(tableNames, boundingBox, routingHeader);
            futures.add(future);
        }
        return futures;
    };
    return new JoinedTupleListFuture(futureProvider);
}
Also used : JoinedTupleListFuture(org.bboxdb.network.client.future.JoinedTupleListFuture) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) ArrayList(java.util.ArrayList) List(java.util.List) RoutingHop(org.bboxdb.network.routing.RoutingHop) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Example 4 with JoinedTupleListFuture

use of org.bboxdb.network.client.future.JoinedTupleListFuture in project bboxdb by jnidzwetzki.

the class CLI method actionExecuteJoin.

/**
 * Execute the given query
 * @param line
 */
protected void actionExecuteJoin(final CommandLine line) {
    if (!line.hasOption(CLIParameter.TABLE)) {
        System.err.println("Query should be performed, but no table was specified");
        printHelpAndExit();
    }
    if (!line.hasOption(CLIParameter.BOUNDING_BOX)) {
        System.err.println("Bounding box is not given");
        System.exit(-1);
    }
    try {
        final String tables = line.getOptionValue(CLIParameter.TABLE);
        final List<String> tableList = Arrays.asList(tables.split(":"));
        System.out.println("Executing join query...");
        final BoundingBox boundingBox = getBoundingBoxFromArgs(line);
        final JoinedTupleListFuture resultFuture = bboxDbConnection.queryJoin(tableList, boundingBox);
        if (resultFuture == null) {
            System.err.println("Unable to get query");
            System.exit(-1);
        }
        resultFuture.waitForAll();
        if (resultFuture.isFailed()) {
            System.err.println("Unable to execute query: " + resultFuture.getAllMessages());
            System.exit(-1);
        }
        for (final JoinedTuple tuple : resultFuture) {
            printJoinedTuple(tuple);
        }
        System.out.println("Join done");
    } catch (BBoxDBException e) {
        System.err.println("Got an exception while performing query: " + e);
        System.exit(-1);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return;
    }
}
Also used : JoinedTupleListFuture(org.bboxdb.network.client.future.JoinedTupleListFuture) BoundingBox(org.bboxdb.commons.math.BoundingBox) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Aggregations

JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)4 BoundingBox (org.bboxdb.commons.math.BoundingBox)2 BBoxDBException (org.bboxdb.misc.BBoxDBException)2 NetworkOperationFuture (org.bboxdb.network.client.future.NetworkOperationFuture)2 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)2 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)1 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)1 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)1 RoutingHop (org.bboxdb.network.routing.RoutingHop)1 Tuple (org.bboxdb.storage.entity.Tuple)1 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)1