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

sk0x50 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 b67150d45 IGNITE-17209 Allow passing sql query as a parameter. Fixes 
#899
b67150d45 is described below

commit b67150d450680eb7bb9ece2a3b02dcc6126e5b05
Author: Vadim Pakhnushev <[email protected]>
AuthorDate: Wed Jun 29 15:11:45 2022 +0300

    IGNITE-17209 Allow passing sql query as a parameter. Fixes #899
    
    Signed-off-by: Slava Koptilin <[email protected]>
---
 .../java/org/apache/ignite/cli/commands/sql/ItSqlCommandTest.java   | 6 +++---
 .../main/java/org/apache/ignite/cli/commands/sql/SqlCommand.java    | 5 +++--
 .../java/org/apache/ignite/cli/commands/sql/SqlReplCommand.java     | 5 +++--
 .../java/org/apache/ignite/cli/commands/sql/SqlCommandTest.java     | 6 +++---
 4 files changed, 12 insertions(+), 10 deletions(-)

diff --git 
a/modules/cli/src/integrationTest/java/org/apache/ignite/cli/commands/sql/ItSqlCommandTest.java
 
b/modules/cli/src/integrationTest/java/org/apache/ignite/cli/commands/sql/ItSqlCommandTest.java
index 68933cbe3..5cb924b30 100644
--- 
a/modules/cli/src/integrationTest/java/org/apache/ignite/cli/commands/sql/ItSqlCommandTest.java
+++ 
b/modules/cli/src/integrationTest/java/org/apache/ignite/cli/commands/sql/ItSqlCommandTest.java
@@ -46,7 +46,7 @@ class ItSqlCommandTest extends CliCommandTestIntegrationBase {
     @Test
     @DisplayName("Should execute select * from table and display table when 
jdbc-url is correct")
     void selectFromTable() {
-        execute("sql", "--execute", "select * from person", "--jdbc-url", 
JDBC_URL);
+        execute("sql", "select * from person", "--jdbc-url", JDBC_URL);
 
         assertAll(
                 this::assertExitCodeIsZero,
@@ -58,7 +58,7 @@ class ItSqlCommandTest extends CliCommandTestIntegrationBase {
     @Test
     @DisplayName("Should display readable error when wrong jdbc is given")
     void wrongJdbcUrl() {
-        execute("sql", "--execute", "select * from person", "--jdbc-url", 
"jdbc:ignite:thin://no-such-host.com:10800");
+        execute("sql", "select * from person", "--jdbc-url", 
"jdbc:ignite:thin://no-such-host.com:10800");
 
         assertAll(
                 () -> assertExitCodeIs(1),
@@ -71,7 +71,7 @@ class ItSqlCommandTest extends CliCommandTestIntegrationBase {
     @Test
     @DisplayName("Should display readable error when wrong query is given")
     void incorrectQueryTest() {
-        execute("sql", "--execute", "select", "--jdbc-url", JDBC_URL);
+        execute("sql", "select", "--jdbc-url", JDBC_URL);
 
         assertAll(
                 () -> assertExitCodeIs(1),
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/cli/commands/sql/SqlCommand.java 
b/modules/cli/src/main/java/org/apache/ignite/cli/commands/sql/SqlCommand.java
index 8b68f8323..bd968e93a 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/cli/commands/sql/SqlCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/cli/commands/sql/SqlCommand.java
@@ -35,6 +35,7 @@ import org.apache.ignite.cli.sql.SqlManager;
 import picocli.CommandLine.ArgGroup;
 import picocli.CommandLine.Command;
 import picocli.CommandLine.Option;
+import picocli.CommandLine.Parameters;
 
 /**
  * Command for sql execution.
@@ -50,10 +51,10 @@ public class SqlCommand extends BaseCommand implements 
Callable<Integer> {
     private ExecOptions execOptions;
 
     private static class ExecOptions {
-        @Option(names = {"-e", "--execute", "--exec"}) //todo: can be passed 
as parameter, not option (see IGNITE-17209)
+        @Parameters(index = "0", description = "SQL query to execute.")
         private String command;
 
-        @Option(names = {"-f", "--script-file"})
+        @Option(names = {"-f", "--script-file"}, description = "Path to file 
with SQL commands to execute.")
         private File file;
     }
 
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/cli/commands/sql/SqlReplCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/cli/commands/sql/SqlReplCommand.java
index 14bd83dba..5f6aa702b 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/cli/commands/sql/SqlReplCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/cli/commands/sql/SqlReplCommand.java
@@ -41,6 +41,7 @@ import org.apache.ignite.cli.sql.SqlSchemaProvider;
 import picocli.CommandLine.ArgGroup;
 import picocli.CommandLine.Command;
 import picocli.CommandLine.Option;
+import picocli.CommandLine.Parameters;
 
 /**
  * Command for sql execution in REPL mode.
@@ -57,10 +58,10 @@ public class SqlReplCommand extends BaseCommand implements 
Runnable {
     private ExecOptions execOptions;
 
     private static class ExecOptions {
-        @Option(names = {"-e", "--execute", "--exec"}) //todo: can be passed 
as parameter, not option (see IEP-88)
+        @Parameters(index = "0", description = "SQL query to execute.")
         private String command;
 
-        @Option(names = {"-f", "--script-file"})
+        @Option(names = {"-f", "--script-file"}, description = "Path to file 
with SQL commands to execute.")
         private File file;
     }
 
diff --git 
a/modules/cli/src/test/java/org/apache/ignite/cli/commands/sql/SqlCommandTest.java
 
b/modules/cli/src/test/java/org/apache/ignite/cli/commands/sql/SqlCommandTest.java
index 5093a5fb2..4c78135da 100644
--- 
a/modules/cli/src/test/java/org/apache/ignite/cli/commands/sql/SqlCommandTest.java
+++ 
b/modules/cli/src/test/java/org/apache/ignite/cli/commands/sql/SqlCommandTest.java
@@ -38,19 +38,19 @@ class SqlCommandTest extends CliCommandTestBase {
         assertAll(
                 () -> assertExitCodeIs(2),
                 this::assertOutputIsEmpty,
-                () -> assertErrOutputContains("Missing required argument 
(specify one of these): (-e=<command> | -f=<file>)")
+                () -> assertErrOutputContains("Missing required argument 
(specify one of these): (<command> | -f=<file>)")
         );
     }
 
     @Test
     @DisplayName("Should throw error if both --execute or --script-file 
options are present")
     void mutuallyExclusiveOptions() {
-        execute("--jdbc-url=", "--execute=", "--script-file=");
+        execute("--jdbc-url=", "select", "--script-file=");
 
         assertAll(
                 () -> assertExitCodeIs(2),
                 this::assertOutputIsEmpty,
-                () -> assertErrOutputContains("--execute=<command>, 
--script-file=<file> are mutually exclusive (specify only one)")
+                () -> assertErrOutputContains("<command>, --script-file=<file> 
are mutually exclusive (specify only one)")
         );
     }
 }

Reply via email to