Search in sources :

Example 1 with BatchConsumerToResultReceiver

use of io.crate.action.sql.BatchConsumerToResultReceiver in project crate by crate.

the class BatchPortal method sync.

@Override
public CompletableFuture<Void> sync(Planner planner, JobsLogs jobsLogs) {
    CountdownFutureCallback completionCallback = new CountdownFutureCallback(analysis.size());
    for (int i = 0; i < analysis.size(); i++) {
        UUID jobId = UUID.randomUUID();
        Plan plan;
        String stmt = queries.get(i);
        try {
            plan = planner.plan(analysis.get(i), jobId, 0, 0);
        } catch (Throwable t) {
            jobsLogs.logPreExecutionFailure(jobId, stmt, SQLExceptions.messageOf(t));
            throw t;
        }
        ResultReceiver resultReceiver = resultReceivers.get(i);
        jobsLogs.logExecutionStart(jobId, stmt);
        JobsLogsUpdateListener jobsLogsUpdateListener = new JobsLogsUpdateListener(jobId, jobsLogs);
        resultReceiver.completionFuture().whenComplete(jobsLogsUpdateListener).whenComplete(completionCallback);
        BatchConsumer consumer = new BatchConsumerToResultReceiver(resultReceiver, 0);
        portalContext.getExecutor().execute(plan, consumer, new RowN(batchParams.toArray()));
    }
    synced = true;
    return completionCallback;
}
Also used : RowN(io.crate.data.RowN) CountdownFutureCallback(io.crate.concurrent.CountdownFutureCallback) BatchConsumerToResultReceiver(io.crate.action.sql.BatchConsumerToResultReceiver) UUID(java.util.UUID) Plan(io.crate.planner.Plan) BatchConsumerToResultReceiver(io.crate.action.sql.BatchConsumerToResultReceiver) ResultReceiver(io.crate.action.sql.ResultReceiver) BatchConsumer(io.crate.data.BatchConsumer)

Example 2 with BatchConsumerToResultReceiver

use of io.crate.action.sql.BatchConsumerToResultReceiver in project crate by crate.

the class SimplePortal method sync.

@Override
public CompletableFuture<?> sync(Planner planner, JobsLogs jobsLogs) {
    UUID jobId = UUID.randomUUID();
    Plan plan;
    try {
        plan = planner.plan(analysis, jobId, defaultLimit, maxRows);
    } catch (Throwable t) {
        jobsLogs.logPreExecutionFailure(jobId, query, SQLExceptions.messageOf(t));
        throw t;
    }
    if (!analysis.analyzedStatement().isWriteOperation()) {
        resultReceiver = new ResultReceiverRetryWrapper(resultReceiver, this, portalContext.getAnalyzer(), planner, portalContext.getExecutor(), jobId, sessionContext);
    }
    jobsLogs.logExecutionStart(jobId, query);
    JobsLogsUpdateListener jobsLogsUpdateListener = new JobsLogsUpdateListener(jobId, jobsLogs);
    CompletableFuture completableFuture = resultReceiver.completionFuture().whenComplete(jobsLogsUpdateListener);
    if (!resumeIfSuspended()) {
        consumer = new BatchConsumerToResultReceiver(resultReceiver, maxRows);
        portalContext.getExecutor().execute(plan, consumer, this.rowParams);
    }
    synced = true;
    return completableFuture;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) BatchConsumerToResultReceiver(io.crate.action.sql.BatchConsumerToResultReceiver) UUID(java.util.UUID) Plan(io.crate.planner.Plan)

Aggregations

BatchConsumerToResultReceiver (io.crate.action.sql.BatchConsumerToResultReceiver)2 Plan (io.crate.planner.Plan)2 UUID (java.util.UUID)2 ResultReceiver (io.crate.action.sql.ResultReceiver)1 CountdownFutureCallback (io.crate.concurrent.CountdownFutureCallback)1 BatchConsumer (io.crate.data.BatchConsumer)1 RowN (io.crate.data.RowN)1 CompletableFuture (java.util.concurrent.CompletableFuture)1