korlov42 commented on code in PR #817:
URL: https://github.com/apache/ignite-3/pull/817#discussion_r883327115


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/SqlQueryProcessor.java:
##########
@@ -228,6 +230,77 @@ public 
List<CompletableFuture<AsyncSqlCursor<List<Object>>>> queryAsync(QueryCon
         }
     }
 
+    /** {@inheritDoc} */
+    @Override
+    public CompletableFuture<AsyncSqlCursor<List<Object>>> 
querySingleAsync(QueryContext context, String schemaName, String qry,
+            Object... params) {
+        if (!busyLock.enterBusy()) {
+            throw new IgniteInternalException(new NodeStoppingException());
+        }
+
+        try {
+            return querySingle0(context, schemaName, qry, params);
+        } finally {
+            busyLock.leaveBusy();
+        }
+    }
+
+    private CompletableFuture<AsyncSqlCursor<List<Object>>> querySingle0(
+            QueryContext context,
+            String schemaName,
+            String sql,
+            Object... params) {
+        SchemaPlus schema = schemaManager.schema(schemaName);
+
+        if (schema == null) {
+            return CompletableFuture.failedFuture(new 
IgniteInternalException(format("Schema not found [schemaName={}]", 
schemaName)));
+        }
+
+        final BaseQueryContext ctx = BaseQueryContext.builder()
+                .cancel(new QueryCancel())
+                .frameworkConfig(
+                        Frameworks.newConfigBuilder(FRAMEWORK_CONFIG)
+                                .defaultSchema(schema)
+                                .build()
+                )
+                .logger(LOG)
+                .parameters(params)
+                .build();
+
+        CompletableFuture<SqlNode> parseFut = CompletableFuture.supplyAsync(
+                        () -> Commons.parse(sql, 
FRAMEWORK_CONFIG.getParserConfig()),
+                        taskExecutor
+                )
+                .thenApply(nodes -> {
+                    if (nodes.size() > 1) {
+                        throw new IgniteSqlException("Multiple statements 
aren't allowed.");
+                    }
+
+                    return nodes.get(0);
+                });
+
+        CompletableFuture<AsyncSqlCursor<List<Object>>> stage = parseFut
+                .thenCompose(sqlNode -> prepareSvc.prepareAsync(sqlNode, ctx))
+                .thenApply(plan -> {
+                    context.maybeUnwrap(QueryValidator.class)
+                            .ifPresent(queryValidator -> 
queryValidator.validatePlan(plan));
+
+                    return new AsyncSqlCursorImpl<>(
+                            SqlQueryType.mapPlanTypeToSqlType(plan.type()),
+                            plan.metadata(),
+                            executionSrvc.executePlan(plan, ctx)
+                    );
+                });
+
+        stage.whenComplete((cur, ex) -> {
+            if (ex instanceof CancellationException) {
+                ctx.cancel().cancel();

Review Comment:
   QueryCancel currently is not used 



-- 
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]

Reply via email to