AMashenkov commented on code in PR #2846:
URL: https://github.com/apache/ignite-3/pull/2846#discussion_r1400391085
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/SqlQueryProcessor.java:
##########
@@ -615,49 +586,63 @@ private static void validateDynamicParameters(int
expectedParamsCount, Object[]
private class MultiStatementHandler {
private final String schemaName;
- private final IgniteTransactions transactions;
- private final @Nullable InternalTransaction explicitTransaction;
+ private final QueryTransactionHandler transactionHandler;
private final Queue<ScriptStatementParameters> statements;
MultiStatementHandler(
String schemaName,
- IgniteTransactions transactions,
- @Nullable InternalTransaction explicitTransaction,
+ QueryTransactionHandler transactionHandler,
List<ParsedResult> parsedResults,
Object[] params
) {
this.schemaName = schemaName;
- this.transactions = transactions;
- this.explicitTransaction = explicitTransaction;
+ this.transactionHandler = transactionHandler;
this.statements = prepareStatementsQueue(parsedResults, params);
}
- CompletableFuture<AsyncSqlCursor<List<Object>>> processNext() {
- if (statements == null) {
- // TODO https://issues.apache.org/jira/browse/IGNITE-20463
Each tx control statement must return an empty cursor.
- return CompletableFuture.completedFuture(null);
+ /**
+ * Returns a queue. each element of which represents parameters
required to execute a single statement of the script.
+ */
+ private Queue<ScriptStatementParameters>
prepareStatementsQueue(List<ParsedResult> parsedResults0, Object[] params) {
+ assert !parsedResults0.isEmpty();
+
+ int paramsCount =
parsedResults0.stream().mapToInt(ParsedResult::dynamicParamsCount).sum();
+
+ validateDynamicParameters(paramsCount, params);
+
+ ScriptStatementParameters[] results = new
ScriptStatementParameters[parsedResults0.size()];
+
+ // We fill parameters in reverse order, because each script
statement
+ // requires a reference to the future of the next statement.
+ for (int i = parsedResults0.size(); i > 0; i--) {
+ ParsedResult result = parsedResults0.get(i - 1);
+
+ Object[] params0 = Arrays.copyOfRange(params, paramsCount -
result.dynamicParamsCount(), paramsCount);
+ paramsCount -= result.dynamicParamsCount();
+
+ results[i - 1] = new ScriptStatementParameters(result, params0,
+ i < parsedResults0.size() ? results[i].cursorFuture :
null);
Review Comment:
```suggestion
// We fill parameters in reverse order, because each script
statement
// requires a reference to the future of the next statement.
Future prevCursorFuture = null;
for (int i = parsedResults0.size() - 1; i >= 0; i--) {
ParsedResult result = parsedResults0.get(i);
Object[] params0 = Arrays.copyOfRange(params, paramsCount -
result.dynamicParamsCount(), paramsCount);
paramsCount -= result.dynamicParamsCount();
results[i] = new ScriptStatementParameters(result, params0,
prevCursorFuture);
prevCursorFuture = results[i].cursorFuture
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]