diff --git a/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/cli/RemoteCli.java b/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/cli/RemoteCli.java index 4b1c00e57dd..b148a26fee6 100644 --- a/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/cli/RemoteCli.java +++ b/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/cli/RemoteCli.java @@ -8,6 +8,7 @@ package org.elasticsearch.xpack.qa.sql.cli; import org.apache.logging.log4j.Logger; import org.elasticsearch.SpecialPermission; import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.Loggers; import java.io.BufferedReader; @@ -23,6 +24,7 @@ import java.nio.charset.StandardCharsets; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.function.Predicate; @@ -161,7 +163,8 @@ public class RemoteCli implements Closeable { * terminal in unix mode to make the tests consistent. */ out.print(command + ";\n"); out.flush(); - String firstResponse = "[?1h=[33msql> [0m" + command + ";"; + final String firstResponse = "[?1h=[33msql> [0m" + + Strings.collectionToDelimitedString(Strings.splitSmart(command, "\n", false), "[?1h=[33m | [0m") + ";"; String firstLine = readLine(); assertThat(firstLine, startsWith(firstResponse)); return firstLine.substring(firstResponse.length()); diff --git a/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/cli/SelectTestCase.java b/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/cli/SelectTestCase.java index 3add41db6d5..fffa8e0f72a 100644 --- a/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/cli/SelectTestCase.java +++ b/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/cli/SelectTestCase.java @@ -19,6 +19,13 @@ public abstract class SelectTestCase extends CliIntegrationTestCase { assertThat(readLine(), containsString("test_value")); assertEquals("", readLine()); } + public void testMultiLineSelect() throws IOException { + index("test", body -> body.field("test_field", "test_value")); + assertThat(command("SELECT *\nFROM\ntest"), containsString("test_field")); + assertThat(readLine(), containsString("----------")); + assertThat(readLine(), containsString("test_value")); + assertEquals("", readLine()); + } public void testSelectWithWhere() throws IOException { index("test", body -> body.field("test_field", "test_value1").field("i", 1)); diff --git a/sql/cli/src/main/java/org/elasticsearch/xpack/sql/cli/CliRepl.java b/sql/cli/src/main/java/org/elasticsearch/xpack/sql/cli/CliRepl.java index 9fe4dece230..f591ced77ec 100644 --- a/sql/cli/src/main/java/org/elasticsearch/xpack/sql/cli/CliRepl.java +++ b/sql/cli/src/main/java/org/elasticsearch/xpack/sql/cli/CliRepl.java @@ -40,8 +40,8 @@ public class CliRepl { line = line.trim(); if (!line.endsWith(";")) { - multiLine.append(" "); multiLine.append(line); + multiLine.append(" "); prompt = MULTI_LINE_PROMPT; continue; }