This is an automated email from the ASF dual-hosted git repository.

apkhmv pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new fedb9267f5 IGNITE-19038 sql command does not enter repl (#1940)
fedb9267f5 is described below

commit fedb9267f522de5c8a96ab2bbde450ff6d1139d5
Author: Vadim Pakhnushev <[email protected]>
AuthorDate: Mon Apr 17 20:15:29 2023 +0300

    IGNITE-19038 sql command does not enter repl (#1940)
---
 .../org/apache/ignite/internal/cli/call/sql/SqlQueryCall.java    | 9 ++++++++-
 .../apache/ignite/internal/cli/commands/sql/SqlReplCommand.java  | 9 ++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/call/sql/SqlQueryCall.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/call/sql/SqlQueryCall.java
index 1101383b8d..98fbb45c05 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/call/sql/SqlQueryCall.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/call/sql/SqlQueryCall.java
@@ -45,10 +45,17 @@ public class SqlQueryCall implements Call<StringCallInput, 
SqlQueryResult> {
     @Override
     public CallOutput<SqlQueryResult> execute(StringCallInput input) {
         try {
-            SqlQueryResult result = sqlManager.execute(input.getString());
+            SqlQueryResult result = 
sqlManager.execute(trimQuotes(input.getString()));
             return DefaultCallOutput.success(result);
         } catch (SQLException e) {
             return DefaultCallOutput.failure(e);
         }
     }
+
+    private static String trimQuotes(String input) {
+        if (input.startsWith("\"") && input.endsWith("\"") && input.length() > 
2) {
+            return input.substring(1, input.length() - 1);
+        }
+        return input;
+    }
 }
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/sql/SqlReplCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/sql/SqlReplCommand.java
index a4f6194acc..b3acb5465f 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/sql/SqlReplCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/sql/SqlReplCommand.java
@@ -50,6 +50,7 @@ import 
org.apache.ignite.internal.cli.core.style.AnsiStringSupport.Color;
 import org.apache.ignite.internal.cli.decorators.SqlQueryResultDecorator;
 import org.apache.ignite.internal.cli.sql.SqlManager;
 import org.apache.ignite.internal.cli.sql.SqlSchemaProvider;
+import org.apache.ignite.internal.util.StringUtils;
 import org.jline.reader.impl.completer.AggregateCompleter;
 import picocli.CommandLine.ArgGroup;
 import picocli.CommandLine.Command;
@@ -72,7 +73,7 @@ public class SqlReplCommand extends BaseCommand implements 
Runnable {
     private ExecOptions execOptions;
 
     private static class ExecOptions {
-        @Parameters(index = "0", description = "SQL query to execute")
+        @Parameters(index = "0", description = "SQL query to execute", 
defaultValue = Option.NULL_VALUE)
         private String command;
 
         @Option(names = {SCRIPT_FILE_OPTION, SCRIPT_FILE_OPTION_SHORT}, 
description = SCRIPT_FILE_OPTION_SHORT)
@@ -97,7 +98,7 @@ public class SqlReplCommand extends BaseCommand implements 
Runnable {
     public void run() {
         try (SqlManager sqlManager = new SqlManager(jdbc)) {
             // When passing white space to this command, picocli will treat it 
as a positional argument
-            if (execOptions == null || (execOptions.command != null && 
execOptions.command.isBlank())) {
+            if (execOptions == null || 
(StringUtils.nullOrBlank(execOptions.command) && execOptions.file == null)) {
                 SqlSchemaProvider schemaProvider = new 
SqlSchemaProvider(sqlManager::getMetadata);
                 schemaProvider.initStateAsync();
 
@@ -113,7 +114,9 @@ public class SqlReplCommand extends BaseCommand implements 
Runnable {
                         .build());
             } else {
                 String executeCommand = execOptions.file != null ? 
extract(execOptions.file) : execOptions.command;
-                createSqlExecPipeline(sqlManager, 
executeCommand).runPipeline();
+                if (executeCommand != null) {
+                    createSqlExecPipeline(sqlManager, 
executeCommand).runPipeline();
+                }
             }
         } catch (SQLException e) {
             new 
SqlExceptionHandler().handle(ExceptionWriter.fromPrintWriter(spec.commandLine().getErr()),
 e);

Reply via email to