Search in sources :

Example 91 with CompletableFuture

use of java.util.concurrent.CompletableFuture in project voltdb by VoltDB.

the class AdHocNTBase method processExplainDefaultProc.

/**
     * Explain Proc for a default proc is routed through the regular Explain
     * path using ad hoc planning and all. Take the result from that async
     * process and format it like other explains for procedures.
     */
static CompletableFuture<ClientResponse> processExplainDefaultProc(AdHocPlannedStmtBatch planBatch) {
    Database db = VoltDB.instance().getCatalogContext().database;
    // from a default procedure
    assert (planBatch.getPlannedStatementCount() == 1);
    AdHocPlannedStatement ahps = planBatch.getPlannedStatement(0);
    String sql = new String(ahps.sql, StandardCharsets.UTF_8);
    String explain = planBatch.explainStatement(0, db);
    VoltTable vt = new VoltTable(new VoltTable.ColumnInfo("SQL_STATEMENT", VoltType.STRING), new VoltTable.ColumnInfo("EXECUTION_PLAN", VoltType.STRING));
    vt.addRow(sql, explain);
    ClientResponseImpl response = new ClientResponseImpl(ClientResponseImpl.SUCCESS, ClientResponse.UNINITIALIZED_APP_STATUS_CODE, null, new VoltTable[] { vt }, null);
    CompletableFuture<ClientResponse> fut = new CompletableFuture<>();
    fut.complete(response);
    return fut;
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) CompletableFuture(java.util.concurrent.CompletableFuture) AdHocPlannedStatement(org.voltdb.compiler.AdHocPlannedStatement) Database(org.voltdb.catalog.Database) ClientResponseImpl(org.voltdb.ClientResponseImpl) VoltTable(org.voltdb.VoltTable)

Example 92 with CompletableFuture

use of java.util.concurrent.CompletableFuture in project voltdb by VoltDB.

the class ExplainProc method run.

public CompletableFuture<ClientResponse> run(String procedureNames) {
    // Go to the catalog and fetch all the "explain plan" strings of the queries in the procedure.
    CatalogContext context = VoltDB.instance().getCatalogContext();
    /*
         * TODO: We don't actually support multiple proc names in an ExplainProc call,
         * so I THINK that the string is always a single procname symbol and all this
         * splitting and iterating is a no-op.
         */
    List<String> procNames = SQLLexer.splitStatements(procedureNames);
    int size = procNames.size();
    VoltTable[] vt = new VoltTable[size];
    for (int i = 0; i < size; i++) {
        String procName = procNames.get(i);
        // look in the catalog
        Procedure proc = context.procedures.get(procName);
        if (proc == null) {
            // check default procs and send them off to be explained using the regular
            // adhoc explain process
            proc = context.m_defaultProcs.checkForDefaultProcedure(procName);
            if (proc != null) {
                String sql = DefaultProcedureManager.sqlForDefaultProc(proc);
                List<String> sqlStatements = new ArrayList<>(1);
                sqlStatements.add(sql);
                return runNonDDLAdHoc(context, sqlStatements, true, null, ExplainMode.EXPLAIN_DEFAULT_PROC, false, new Object[0]);
            }
            return makeQuickResponse(ClientResponse.GRACEFUL_FAILURE, "Procedure " + procName + " not in catalog");
        }
        vt[i] = new VoltTable(new VoltTable.ColumnInfo("SQL_STATEMENT", VoltType.STRING), new VoltTable.ColumnInfo("EXECUTION_PLAN", VoltType.STRING));
        for (Statement stmt : proc.getStatements()) {
            vt[i].addRow(stmt.getSqltext(), Encoder.hexDecodeToString(stmt.getExplainplan()));
        }
    }
    ClientResponseImpl response = new ClientResponseImpl(ClientResponseImpl.SUCCESS, ClientResponse.UNINITIALIZED_APP_STATUS_CODE, null, vt, null);
    CompletableFuture<ClientResponse> fut = new CompletableFuture<>();
    fut.complete(response);
    return fut;
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Statement(org.voltdb.catalog.Statement) ArrayList(java.util.ArrayList) VoltTable(org.voltdb.VoltTable) CompletableFuture(java.util.concurrent.CompletableFuture) Procedure(org.voltdb.catalog.Procedure) ClientResponseImpl(org.voltdb.ClientResponseImpl) CatalogContext(org.voltdb.CatalogContext)

Example 93 with CompletableFuture

use of java.util.concurrent.CompletableFuture in project voltdb by VoltDB.

the class ExplainView method run.

public CompletableFuture<ClientResponse> run(String fullViewNames) {
    CatalogContext context = VoltDB.instance().getCatalogContext();
    /*
         * TODO: We don't actually support multiple view names in an ExplainView call,
         * so I THINK that the string is always a single view symbol and all this
         * splitting and iterating is a no-op.
         */
    List<String> viewNames = SQLLexer.splitStatements(fullViewNames);
    int size = viewNames.size();
    VoltTable[] vt = new VoltTable[size];
    CatalogMap<Table> tables = context.database.getTables();
    for (int i = 0; i < size; i++) {
        String viewName = viewNames.get(i);
        // look in the catalog
        // get the view table from the catalog
        Table viewTable = tables.getIgnoreCase(viewName);
        if (viewTable == null) {
            return makeQuickResponse(ClientResponse.GRACEFUL_FAILURE, "View " + viewName + " does not exist.");
        }
        vt[i] = new VoltTable(new VoltTable.ColumnInfo("TASK", VoltType.STRING), new VoltTable.ColumnInfo("EXECUTION_PLAN", VoltType.STRING));
        try {
            ArrayList<String[]> viewExplanation = ViewExplainer.explain(viewTable);
            for (String[] row : viewExplanation) {
                vt[i].addRow(row[0], row[1]);
            }
        } catch (Exception e) {
            return makeQuickResponse(ClientResponse.GRACEFUL_FAILURE, e.getMessage());
        }
    }
    ClientResponseImpl response = new ClientResponseImpl(ClientResponseImpl.SUCCESS, ClientResponse.UNINITIALIZED_APP_STATUS_CODE, null, vt, null);
    CompletableFuture<ClientResponse> fut = new CompletableFuture<>();
    fut.complete(response);
    return fut;
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Table(org.voltdb.catalog.Table) VoltTable(org.voltdb.VoltTable) VoltTable(org.voltdb.VoltTable) CompletableFuture(java.util.concurrent.CompletableFuture) ClientResponseImpl(org.voltdb.ClientResponseImpl) CatalogContext(org.voltdb.CatalogContext)

Example 94 with CompletableFuture

use of java.util.concurrent.CompletableFuture in project EnrichmentMapApp by BaderLab.

the class GSEALeadingEdgeRankingOption method computeRanking.

@Override
public CompletableFuture<Optional<Map<Integer, RankValue>>> computeRanking(Collection<Integer> genes) {
    initializeLeadingEdge();
    int topRank = getTopRank();
    boolean isNegative = isNegativeGS();
    Map<Integer, GeneExpression> expressions = dataset.getExpressionSets().getExpressionMatrix();
    Ranking ranking = dataset.getExpressionSets().getRanksByName(rankingName);
    Integer[] ranksSubset = new Integer[expressions.size()];
    HashMap<Integer, ArrayList<Integer>> rank2keys = new HashMap<Integer, ArrayList<Integer>>();
    int n = 0;
    Map<Integer, Rank> currentRanks = ranking.getRanking();
    for (Integer key : expressions.keySet()) {
        if (currentRanks.containsKey(key)) {
            ranksSubset[n] = currentRanks.get(key).getRank();
        } else {
            ranksSubset[n] = -1;
        }
        rank2keys.computeIfAbsent(ranksSubset[n], k -> new ArrayList<>()).add(key);
        n++;
    }
    Map<Integer, RankValue> result = new HashMap<>();
    int previous = -1;
    boolean significant = false;
    for (int m = 0; m < ranksSubset.length; m++) {
        //if the current gene doesn't have a rank then don't show it
        if (ranksSubset[m] == -1)
            continue;
        if (ranksSubset[m] == previous)
            continue;
        previous = ranksSubset[m];
        significant = false;
        if (ranksSubset[m] <= topRank && !isNegative && topRank != 0 && topRank != -1)
            significant = true;
        else if (ranksSubset[m] >= topRank && isNegative && topRank != 0 && topRank != -1)
            significant = true;
        List<Integer> keys = rank2keys.get(ranksSubset[m]);
        for (Integer key : keys) {
            Rank rank = currentRanks.get(key);
            result.put(key, new RankValue(rank.getRank(), rank.getScore(), significant));
        }
    }
    // Remove genes that we don't need
    result.keySet().retainAll(genes);
    BasicRankingOption.normalizeRanks(result);
    return CompletableFuture.completedFuture(Optional.of(result));
}
Also used : Method(org.baderlab.csplugins.enrichmentmap.model.EMDataSet.Method) GeneExpression(org.baderlab.csplugins.enrichmentmap.model.GeneExpression) DetermineEnrichmentResultFileReader(org.baderlab.csplugins.enrichmentmap.parsers.DetermineEnrichmentResultFileReader) Collection(java.util.Collection) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Ranking(org.baderlab.csplugins.enrichmentmap.model.Ranking) GSEAResult(org.baderlab.csplugins.enrichmentmap.model.GSEAResult) ArrayList(java.util.ArrayList) List(java.util.List) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) SwingUtil(org.baderlab.csplugins.enrichmentmap.view.util.SwingUtil) Map(java.util.Map) Rank(org.baderlab.csplugins.enrichmentmap.model.Rank) Optional(java.util.Optional) RankValue(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankValue) EnrichmentResult(org.baderlab.csplugins.enrichmentmap.model.EnrichmentResult) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Rank(org.baderlab.csplugins.enrichmentmap.model.Rank) RankValue(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankValue) Ranking(org.baderlab.csplugins.enrichmentmap.model.Ranking) GeneExpression(org.baderlab.csplugins.enrichmentmap.model.GeneExpression)

Example 95 with CompletableFuture

use of java.util.concurrent.CompletableFuture in project azure-iot-sdk-java by Azure.

the class RegistryManagerTest method removeDeviceAsync_future_return_ok.

// Tests_SRS_SERVICE_SDK_JAVA_REGISTRYMANAGER_12_053: [The function shall create an async wrapper around the removeDevice() function call, handle the return value or delegate exception]
@Test
public void removeDeviceAsync_future_return_ok() throws Exception {
    String connectionString = "HostName=aaa.bbb.ccc;SharedAccessKeyName=XXX;SharedAccessKey=YYY";
    String deviceId = "somedevice";
    commonExpectations(connectionString, deviceId);
    RegistryManager registryManager = RegistryManager.createFromConnectionString(connectionString);
    CompletableFuture completableFuture = registryManager.removeDeviceAsync(deviceId);
    completableFuture.get();
    new VerificationsInOrder() {

        {
            iotHubConnectionString.getUrlDevice(deviceId);
            times = 1;
            new HttpRequest(mockUrl, HttpMethod.DELETE, new byte[0]);
            times = 1;
            mockHttpRequest.setReadTimeoutMillis(anyInt);
            mockHttpRequest.setHeaderField("authorization", anyString);
            mockHttpRequest.setHeaderField("If-Match", "*");
        }
    };
}
Also used : HttpRequest(com.microsoft.azure.sdk.iot.service.transport.http.HttpRequest) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)490 Test (org.junit.Test)152 ArrayList (java.util.ArrayList)88 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)77 List (java.util.List)75 UUID (java.util.UUID)62 Futures (io.pravega.common.concurrent.Futures)60 Map (java.util.Map)59 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)57 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)53 HashMap (java.util.HashMap)52 TimeUnit (java.util.concurrent.TimeUnit)52 Cleanup (lombok.Cleanup)49 Exceptions (io.pravega.common.Exceptions)48 Collectors (java.util.stream.Collectors)48 lombok.val (lombok.val)47 IOException (java.io.IOException)46 Duration (java.time.Duration)46 Slf4j (lombok.extern.slf4j.Slf4j)46 AtomicReference (java.util.concurrent.atomic.AtomicReference)45