diff --git a/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/jdbc/CsvSpecTestCase.java b/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/jdbc/CsvSpecTestCase.java index 702ec9a1a5c..9e9fccd867a 100644 --- a/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/jdbc/CsvSpecTestCase.java +++ b/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/jdbc/CsvSpecTestCase.java @@ -68,7 +68,7 @@ public abstract class CsvSpecTestCase extends SpecBaseIntegrationTestCase { csvProperties.setProperty("charset", "UTF-8"); csvProperties.setProperty("separator", "|"); csvProperties.setProperty("trimValues", "true"); - Tuple resultsAndTypes = extractColumnTypes(expectedResults); + Tuple resultsAndTypes = extractColumnTypesAndStripCli(expectedResults); csvProperties.setProperty("columnTypes", resultsAndTypes.v2()); Reader reader = new StringReader(resultsAndTypes.v1()); TableReader tableReader = new TableReader() { @@ -103,26 +103,37 @@ public abstract class CsvSpecTestCase extends SpecBaseIntegrationTestCase { return connectionProperties; } - private Tuple extractColumnTypes(String expectedResults) throws IOException { - try (StringReader reader = new StringReader(expectedResults)){ - try (BufferedReader bufferedReader = new BufferedReader(reader)){ - String header = bufferedReader.readLine(); - if (!header.contains(":")) { - // No type information in headers, no need to parse columns - trigger auto-detection - return new Tuple<>(expectedResults,""); - } - try (StringWriter writer = new StringWriter()) { - try (BufferedWriter bufferedWriter = new BufferedWriter(writer)){ - Tuple headerAndColumns = extractColumnTypesFromHeader(header); - bufferedWriter.write(headerAndColumns.v1()); - bufferedWriter.newLine(); - bufferedWriter.flush(); - // Copy the rest of test - Streams.copy(bufferedReader, bufferedWriter); - return new Tuple<>(writer.toString(), headerAndColumns.v2()); - } - } + private Tuple extractColumnTypesAndStripCli(String expectedResults) throws IOException { + try (StringReader reader = new StringReader(expectedResults); + BufferedReader bufferedReader = new BufferedReader(reader); + StringWriter writer = new StringWriter(); + BufferedWriter bufferedWriter = new BufferedWriter(writer)) { + + String header = bufferedReader.readLine(); + Tuple headerAndTypes; + + if (header.contains(":")) { + headerAndTypes = extractColumnTypesFromHeader(header); + } else { + // No type information in headers, no need to parse columns - trigger auto-detection + headerAndTypes = new Tuple<>(header, ""); } + bufferedWriter.write(headerAndTypes.v1()); + bufferedWriter.newLine(); + + /* Read the next line. It might be a separator designed to look like the cli. + * If it is, then throw it out. If it isn't then keep it. + */ + String maybeSeparator = bufferedReader.readLine(); + if (maybeSeparator != null && false == maybeSeparator.startsWith("----")) { + bufferedWriter.write(maybeSeparator); + bufferedWriter.newLine(); + } + + bufferedWriter.flush(); + // Copy the rest of test + Streams.copy(bufferedReader, bufferedWriter); + return new Tuple<>(writer.toString(), headerAndTypes.v2()); } } diff --git a/qa/sql/src/main/resources/datetime.csv-spec b/qa/sql/src/main/resources/datetime.csv-spec index 8177b5f9a4f..ce5e21e74d0 100644 --- a/qa/sql/src/main/resources/datetime.csv-spec +++ b/qa/sql/src/main/resources/datetime.csv-spec @@ -167,8 +167,8 @@ d:i | c:l | s:i constantYear // tag::year SELECT YEAR(CAST('2018-01-19T10:23:27Z' AS TIMESTAMP)) as year; - - year + year +--------------- 2018 // end::year ;