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;
}
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;
}
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;
}
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));
}
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", "*");
}
};
}
Aggregations