Source:
<code>private CompletableFuture<?> bulkExec(Statement statement, List<DeferredExecution> toExec) { assert toExec.size() >= 1 : "Must have at least 1 deferred execution for bulk exec"; var jobId = UUID.randomUUID(); var routingProvider = new RoutingProvider(Randomness.get().nextInt(), planner.getAwarenessAttributes()); var clusterState = executor.clusterService().state(); var txnCtx = new CoordinatorTxnCtx(sessionContext); var plannerContext = new PlannerContext( clusterState, routingProvider, jobId, executor.functions(), txnCtx, 0, null); <START> var analyzedStatement = analyzer.unboundAnalyze( <END> statement, sessionContext, ParamTypeHints.EMPTY); Plan plan; PreparedStmt firstPreparedStatement = toExec.get(0).portal().preparedStmt(); try { plan = planner.plan(analyzedStatement, plannerContext); } catch (Throwable t) { jobsLogs.logPreExecutionFailure( jobId, firstPreparedStatement.rawStatement(), SQLExceptions.messageOf(t), sessionContext.user()); throw t; } jobsLogs.logExecutionStart( jobId, firstPreparedStatement.rawStatement(), sessionContext.user(), StatementClassifier.classify(plan) ); var bulkArgs = Lists2.map(toExec, x -> (Row) new RowN(x.portal().params().toArray())); List<CompletableFuture<Long>> rowCounts = plan.executeBulk( executor, plannerContext, bulkArgs, SubQueryResults.EMPTY ); CompletableFuture<Void> allRowCounts = CompletableFuture.allOf(rowCounts.toArray(new CompletableFuture[0])); List<CompletableFuture<?>> resultReceiverFutures = Lists2.map(toExec, x -> x.resultReceiver().completionFuture()); CompletableFuture<Void> allResultReceivers = CompletableFuture.allOf(resultReceiverFutures.toArray(new CompletableFuture[0])); return allRowCounts .exceptionally(t -> null) .thenAccept(ignored -> emitRowCountsToResultReceivers(jobId, jobsLogs, toExec, rowCounts)) .runAfterBoth(allResultReceivers, () -> {}); }</code><technical_language>Similar here, this point analyzed statement able utilize a existing analyzed statement. E.g. firstPreparedStatement.unbound... (Maybe assertion making analyzed statements of prepared statements equal - case grouping Statement)</technical_language>

Target:
private CompletableFuture<?> bulkExec(Statement statement, List<DeferredExecution> toExec) { assert toExec.size() >= 1 : "Must have at least 1 deferred execution for bulk exec"; var jobId = UUID.randomUUID(); var routingProvider = new RoutingProvider(Randomness.get().nextInt(), planner.getAwarenessAttributes()); var clusterState = executor.clusterService().state(); var txnCtx = new CoordinatorTxnCtx(sessionContext); var plannerContext = new PlannerContext( clusterState, routingProvider, jobId, executor.functions(), txnCtx, 0, null); PreparedStmt firstPreparedStatement = toExec.get(0).portal().preparedStmt(); var unboundStatement = firstPreparedStatement.unboundStatement(); AnalyzedStatement analyzedStatement; if (unboundStatement == null) { analyzedStatement = analyzer.unboundAnalyze( statement, sessionContext, firstPreparedStatement.paramTypes()); } else { analyzedStatement = unboundStatement; } Plan plan; try { plan = planner.plan(analyzedStatement, plannerContext); } catch (Throwable t) { jobsLogs.logPreExecutionFailure( jobId, firstPreparedStatement.rawStatement(), SQLExceptions.messageOf(t), sessionContext.user()); throw t; } jobsLogs.logExecutionStart( jobId, firstPreparedStatement.rawStatement(), sessionContext.user(), StatementClassifier.classify(plan) ); var bulkArgs = Lists2.map(toExec, x -> (Row) new RowN(x.portal().params().toArray())); List<CompletableFuture<Long>> rowCounts = plan.executeBulk( executor, plannerContext, bulkArgs, SubQueryResults.EMPTY ); CompletableFuture<Void> allRowCounts = CompletableFuture.allOf(rowCounts.toArray(new CompletableFuture[0])); List<CompletableFuture<?>> resultReceiverFutures = Lists2.map(toExec, x -> x.resultReceiver().completionFuture()); CompletableFuture<Void> allResultReceivers = CompletableFuture.allOf(resultReceiverFutures.toArray(new CompletableFuture[0])); return allRowCounts .exceptionally(t -> null) .thenAccept(ignored -> emitRowCountsToResultReceivers(jobId, jobsLogs, toExec, rowCounts)) .runAfterBoth(allResultReceivers, () -> {}); }