You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ap...@apache.org on 2024/02/06 20:15:41 UTC
(ignite-3) branch main updated: IGNITE-21322 Add tests for multiline sql execution from file (#3164)
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 65b5e41c16 IGNITE-21322 Add tests for multiline sql execution from file (#3164)
65b5e41c16 is described below
commit 65b5e41c161e37ee559fbd750b2f9fc85b9c97f1
Author: Aleksandr Pakhomov <ap...@gmail.com>
AuthorDate: Tue Feb 6 23:15:34 2024 +0300
IGNITE-21322 Add tests for multiline sql execution from file (#3164)
* There is no support for multiline strings in interactive mode. It requires implementing our own parser for jline 3 [1] that can be done but not now.
[1] - https://github.com/jline/jline3/issues/36
---
.../cli/commands/sql/ItSqlCommandTest.java | 24 +++++++++++++++++++++-
.../cli/commands/sql/ItSqlReplCommandTest.java | 24 ++++++++++++++++++++--
.../src/integrationTest/resources/multiline.sql | 8 ++++++++
.../internal/cli/commands/sql/SqlCommand.java | 2 +-
.../internal/cli/commands/sql/SqlReplCommand.java | 2 +-
5 files changed, 55 insertions(+), 5 deletions(-)
diff --git a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/sql/ItSqlCommandTest.java b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/sql/ItSqlCommandTest.java
index e098e959be..c8dc9a5a15 100644
--- a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/sql/ItSqlCommandTest.java
+++ b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/sql/ItSqlCommandTest.java
@@ -36,7 +36,7 @@ class ItSqlCommandTest extends CliSqlCommandTestBase {
assertAll(
() -> assertExitCodeIs(1),
this::assertOutputIsEmpty,
- () -> assertErrOutputContains("File with command not found")
+ () -> assertErrOutputContains("nonexisting] not found")
);
}
@@ -123,4 +123,26 @@ class ItSqlCommandTest extends CliSqlCommandTestBase {
() -> assertErrOutputContains("Table without PRIMARY KEY is not supported")
);
}
+
+ @Test
+ @DisplayName("Should execute multiline sql script from file")
+ void multilineScript() {
+ String filePath = getClass().getResource("/multiline.sql").getPath();
+ execute("sql", "-f", filePath, "--jdbc-url", JDBC_URL);
+
+ assertAll(
+ this::assertExitCodeIsZero,
+ this::assertOutputIsNotEmpty,
+ this::assertErrOutputIsEmpty
+ );
+
+ // test_table is created in multiline.sql and populated with 3 records.
+ execute("sql", "select count(*) from test_table", "--jdbc-url", JDBC_URL);
+
+ assertAll(
+ this::assertExitCodeIsZero,
+ () -> assertOutputContains("3"),
+ this::assertErrOutputIsEmpty
+ );
+ }
}
diff --git a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/sql/ItSqlReplCommandTest.java b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/sql/ItSqlReplCommandTest.java
index 1bb486b9e5..780db3d804 100644
--- a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/sql/ItSqlReplCommandTest.java
+++ b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/sql/ItSqlReplCommandTest.java
@@ -41,7 +41,7 @@ class ItSqlReplCommandTest extends CliIntegrationTest {
assertAll(
this::assertOutputIsEmpty,
// Actual output starts with exception since this test doesn't use ReplExecutor and exception is handled by picocli.
- () -> assertErrOutputContains("File with command not found")
+ () -> assertErrOutputContains("nonexisting] not found")
);
}
@@ -64,13 +64,33 @@ class ItSqlReplCommandTest extends CliIntegrationTest {
);
}
+ @Test
+ void multilineCommand() {
+ execute("CREATE TABLE MULTILINE_TABLE(K INT PRIMARY KEY); \n INSERT INTO MULTILINE_TABLE VALUES(1);", "--jdbc-url", JDBC_URL);
+
+ assertAll(
+ // The output from CREATE TABLE is: Updated 0 rows.
+ () -> assertOutputContains("Updated 0 rows."),
+ this::assertErrOutputIsEmpty
+ );
+
+ resetOutput();
+
+ execute("SELECT COUNT(*) FROM MULTILINE_TABLE;", "--jdbc-url", JDBC_URL);
+
+ assertAll(
+ () -> assertOutputContains("1"),
+ this::assertErrOutputIsEmpty
+ );
+ }
+
@Test
void secondInvocationFile() {
execute("-f", "nonexisting", "--jdbc-url", JDBC_URL);
assertAll(
this::assertOutputIsEmpty,
- () -> assertErrOutputContains("File with command not found")
+ () -> assertErrOutputContains("nonexisting] not found")
);
resetOutput();
diff --git a/modules/cli/src/integrationTest/resources/multiline.sql b/modules/cli/src/integrationTest/resources/multiline.sql
new file mode 100644
index 0000000000..fb98735e95
--- /dev/null
+++ b/modules/cli/src/integrationTest/resources/multiline.sql
@@ -0,0 +1,8 @@
+create table test_table (
+ id int primary key,
+ name varchar(255)
+);
+
+insert into test_table (id, name) values (1, 'test');
+insert into test_table (id, name) values (2, 'test2');
+insert into test_table (id, name) values (3, 'test3');
diff --git a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/sql/SqlCommand.java b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/sql/SqlCommand.java
index 493e5a2bb8..f267eb2231 100644
--- a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/sql/SqlCommand.java
+++ b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/sql/SqlCommand.java
@@ -74,7 +74,7 @@ public class SqlCommand extends BaseCommand implements Callable<Integer> {
try {
return String.join("\n", Files.readAllLines(file.toPath(), StandardCharsets.UTF_8));
} catch (IOException e) {
- throw new IgniteCliException("File with command not found");
+ throw new IgniteCliException("File [" + file.getAbsolutePath() + "] not found");
}
}
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 1c805fc74a..1d08869b94 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
@@ -93,7 +93,7 @@ public class SqlReplCommand extends BaseCommand implements Runnable {
try {
return String.join("\n", Files.readAllLines(file.toPath(), StandardCharsets.UTF_8));
} catch (IOException e) {
- throw new IgniteCliException("File with command not found");
+ throw new IgniteCliException("File [" + file.getAbsolutePath() + "] not found");
}
}