MCPcopy Create free account
hub / github.com/crate/crate / bulkExec

Method bulkExec

server/src/main/java/io/crate/session/Session.java:717–782  ·  view source on GitHub ↗
(List<DeferredExecution> toExec)

Source from the content-addressed store, hash-verified

715 }
716
717 private CompletableFuture<?> bulkExec(List<DeferredExecution> toExec) {
718 assert !toExec.isEmpty() : "Must have at least 1 deferred execution for bulk exec";
719 mostRecentJobID = UUIDs.dirtyUUID();
720 final UUID jobId = mostRecentJobID;
721 var routingProvider = new RoutingProvider(Randomness.get().nextInt(), planner.getAwarenessAttributes());
722 var txnCtx = new CoordinatorTxnCtx(sessionSettings);
723 PreparedStmt firstPreparedStatement = toExec.get(0).portal().preparedStmt();
724 TimeoutToken timeoutToken = firstPreparedStatement.timeoutToken();
725 timeoutToken.enable();
726
727 var plannerContext = planner.createContext(
728 routingProvider,
729 jobId,
730 txnCtx,
731 0,
732 null,
733 cursors,
734 currentTransactionState,
735 timeoutToken
736 );
737
738
739 AnalyzedStatement analyzedStatement = firstPreparedStatement.analyzedStatement();
740 lastStmt = firstPreparedStatement.rawStatement();
741
742 Plan plan;
743 try {
744 plan = planner.plan(analyzedStatement, plannerContext);
745 timeoutToken.check("bulkExec:plan");
746 } catch (Throwable t) {
747 jobsLogs.logPreExecutionFailure(
748 jobId,
749 id,
750 firstPreparedStatement.rawStatement(),
751 SQLExceptions.messageOf(t),
752 sessionSettings.sessionUser());
753 throw t;
754 }
755 jobsLogs.logExecutionStart(
756 jobId,
757 id,
758 firstPreparedStatement.rawStatement(),
759 sessionSettings.sessionUser(),
760 StatementClassifier.classify(plan)
761 );
762
763 var bulkArgs = Lists.map(toExec, x -> (Row) new RowN(x.portal().params().toArray()));
764 CompletableFuture<BulkResponse> result = plan.executeBulk(
765 executor,
766 plannerContext,
767 bulkArgs,
768 SubQueryResults.EMPTY
769 );
770 List<CompletableFuture<?>> resultReceiverFutures = Lists.map(toExec, x -> x.resultReceiver().completionFuture());
771 CompletableFuture<Void> allResultReceivers = CompletableFuture.allOf(resultReceiverFutures.toArray(new CompletableFuture[0]));
772
773 result
774 .thenAccept(bulkResp -> emitRowCountsToResultReceivers(jobId, jobsLogs, toExec, bulkResp, 0, 0))

Callers 1

execMethod · 0.95

Calls 15

dirtyUUIDMethod · 0.95
getMethod · 0.95
timeoutTokenMethod · 0.95
enableMethod · 0.95
analyzedStatementMethod · 0.95
rawStatementMethod · 0.95
checkMethod · 0.95
messageOfMethod · 0.95
classifyMethod · 0.95
mapMethod · 0.95
executeBulkMethod · 0.95

Tested by

no test coverage detected