From 0e7aed38259b5af45f48f94fb4af694f86817a54 Mon Sep 17 00:00:00 2001 From: Mitchell Gale Date: Fri, 11 Aug 2023 12:11:33 -0700 Subject: [PATCH 1/4] Spotless apply on protocol Signed-off-by: Mitchell Gale --- build.gradle | 8 +- .../sql/protocol/response/QueryResult.java | 35 ++-- .../format/CommandResponseFormatter.java | 4 +- .../response/format/CsvResponseFormatter.java | 2 - .../response/format/ErrorFormatter.java | 36 ++-- .../format/FlatResponseFormatter.java | 45 ++--- .../sql/protocol/response/format/Format.java | 4 +- .../format/JdbcResponseFormatter.java | 23 +-- .../format/JsonResponseFormatter.java | 21 +- .../response/format/RawResponseFormatter.java | 8 +- .../response/format/ResponseFormatter.java | 6 +- .../format/SimpleJsonResponseFormatter.java | 9 +- .../VisualizationResponseFormatter.java | 26 +-- .../protocol/response/QueryResultTest.java | 103 +++++----- .../format/CommandResponseFormatterTest.java | 40 ++-- .../format/CsvResponseFormatterTest.java | 155 ++++++++------ .../protocol/response/format/FormatTest.java | 6 +- .../format/JdbcResponseFormatterTest.java | 106 +++++----- .../format/RawResponseFormatterTest.java | 191 ++++++++++-------- .../SimpleJsonResponseFormatterTest.java | 40 ++-- .../VisualizationResponseFormatterTest.java | 77 +++---- 21 files changed, 479 insertions(+), 466 deletions(-) diff --git a/build.gradle b/build.gradle index 166ced81ba..5c090d4d37 100644 --- a/build.gradle +++ b/build.gradle @@ -86,7 +86,8 @@ spotless { target fileTree('.') { include 'common/**/*.java', 'datasources/**/*.java', - 'core/**/*.java' + 'core/**/*.java', + 'protocol/**/*.java' exclude '**/build/**', '**/build-*/**' } importOrder() @@ -115,9 +116,8 @@ allprojects { sourceCompatibility = targetCompatibility = "11" } configurations.all { - resolutionStrategy.force "com.squareup.okio:okio:3.5.0" - resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib:1.9.0" - resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.0" + resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib:1.6.0" + resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib-common:1.6.0" } } diff --git a/protocol/src/main/java/org/opensearch/sql/protocol/response/QueryResult.java b/protocol/src/main/java/org/opensearch/sql/protocol/response/QueryResult.java index 3ce1dd8875..03be0875cf 100644 --- a/protocol/src/main/java/org/opensearch/sql/protocol/response/QueryResult.java +++ b/protocol/src/main/java/org/opensearch/sql/protocol/response/QueryResult.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.protocol.response; import java.util.Collection; @@ -20,22 +19,18 @@ import org.opensearch.sql.executor.pagination.Cursor; /** - * Query response that encapsulates query results and isolate {@link ExprValue} - * related from formatter implementation. + * Query response that encapsulates query results and isolate {@link ExprValue} related from + * formatter implementation. */ @RequiredArgsConstructor public class QueryResult implements Iterable { - @Getter - private final ExecutionEngine.Schema schema; + @Getter private final ExecutionEngine.Schema schema; - /** - * Results which are collection of expression. - */ + /** Results which are collection of expression. */ private final Collection exprValues; - @Getter - private final Cursor cursor; + @Getter private final Cursor cursor; public QueryResult(ExecutionEngine.Schema schema, Collection exprValues) { this(schema, exprValues, Cursor.None); @@ -43,6 +38,7 @@ public QueryResult(ExecutionEngine.Schema schema, Collection exprValu /** * size of results. + * * @return size of results */ public int size() { @@ -52,14 +48,18 @@ public int size() { /** * Parse column name from results. * - * @return mapping from column names to its expression type. - * note that column name could be original name or its alias if any. + * @return mapping from column names to its expression type. note that column name could be + * original name or its alias if any. */ public Map columnNameTypes() { Map colNameTypes = new LinkedHashMap<>(); - schema.getColumns().forEach(column -> colNameTypes.put( - getColumnName(column), - column.getExprType().typeName().toLowerCase(Locale.ROOT))); + schema + .getColumns() + .forEach( + column -> + colNameTypes.put( + getColumnName(column), + column.getExprType().typeName().toLowerCase(Locale.ROOT))); return colNameTypes; } @@ -78,9 +78,6 @@ private String getColumnName(Column column) { } private Object[] convertExprValuesToValues(Collection exprValues) { - return exprValues - .stream() - .map(ExprValue::value) - .toArray(Object[]::new); + return exprValues.stream().map(ExprValue::value).toArray(Object[]::new); } } diff --git a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/CommandResponseFormatter.java b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/CommandResponseFormatter.java index dfd0f91931..b781e1dbba 100644 --- a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/CommandResponseFormatter.java +++ b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/CommandResponseFormatter.java @@ -10,8 +10,8 @@ import org.opensearch.sql.protocol.response.QueryResult; /** - * A simple response formatter which contains no data. - * Supposed to use with {@link CommandPlan} only. + * A simple response formatter which contains no data. Supposed to use with {@link CommandPlan} + * only. */ public class CommandResponseFormatter extends JsonResponseFormatter { diff --git a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/CsvResponseFormatter.java b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/CsvResponseFormatter.java index 5c5b4be048..a61b54b258 100644 --- a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/CsvResponseFormatter.java +++ b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/CsvResponseFormatter.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.protocol.response.format; public class CsvResponseFormatter extends FlatResponseFormatter { @@ -14,5 +13,4 @@ public CsvResponseFormatter() { public CsvResponseFormatter(boolean sanitize) { super(",", sanitize); } - } diff --git a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/ErrorFormatter.java b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/ErrorFormatter.java index 40848e959b..5c85e5d65b 100644 --- a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/ErrorFormatter.java +++ b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/ErrorFormatter.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.protocol.response.format; import com.google.gson.Gson; @@ -17,35 +16,28 @@ @UtilityClass public class ErrorFormatter { - private static final Gson PRETTY_PRINT_GSON = AccessController.doPrivileged( - (PrivilegedAction) () -> new GsonBuilder() - .setPrettyPrinting() - .disableHtmlEscaping() - .create()); - private static final Gson GSON = AccessController.doPrivileged( - (PrivilegedAction) () -> new GsonBuilder().disableHtmlEscaping().create()); - - /** - * Util method to format {@link Throwable} response to JSON string in compact printing. - */ + private static final Gson PRETTY_PRINT_GSON = + AccessController.doPrivileged( + (PrivilegedAction) + () -> new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create()); + private static final Gson GSON = + AccessController.doPrivileged( + (PrivilegedAction) () -> new GsonBuilder().disableHtmlEscaping().create()); + + /** Util method to format {@link Throwable} response to JSON string in compact printing. */ public static String compactFormat(Throwable t) { - JsonError error = new ErrorFormatter.JsonError(t.getClass().getSimpleName(), - t.getMessage()); + JsonError error = new ErrorFormatter.JsonError(t.getClass().getSimpleName(), t.getMessage()); return compactJsonify(error); } - /** - * Util method to format {@link Throwable} response to JSON string in pretty printing. - */ - public static String prettyFormat(Throwable t) { - JsonError error = new ErrorFormatter.JsonError(t.getClass().getSimpleName(), - t.getMessage()); + /** Util method to format {@link Throwable} response to JSON string in pretty printing. */ + public static String prettyFormat(Throwable t) { + JsonError error = new ErrorFormatter.JsonError(t.getClass().getSimpleName(), t.getMessage()); return prettyJsonify(error); } public static String compactJsonify(Object jsonObject) { - return AccessController.doPrivileged( - (PrivilegedAction) () -> GSON.toJson(jsonObject)); + return AccessController.doPrivileged((PrivilegedAction) () -> GSON.toJson(jsonObject)); } public static String prettyJsonify(Object jsonObject) { diff --git a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/FlatResponseFormatter.java b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/FlatResponseFormatter.java index 0575647dad..8c67d524b8 100644 --- a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/FlatResponseFormatter.java +++ b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/FlatResponseFormatter.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.protocol.response.format; import com.google.common.collect.ImmutableList; @@ -48,9 +47,8 @@ public String format(Throwable t) { } /** - * Sanitize methods are migrated from legacy CSV result. - * Sanitize both headers and data lines by: - * 1) Second double quote entire cell if any comma is found. + * Sanitize methods are migrated from legacy CSV result. Sanitize both headers and data lines by: + * 1) Second double quote entire cell if any comma is found. */ @Getter @RequiredArgsConstructor @@ -84,29 +82,30 @@ private List getHeaders(QueryResult response, boolean sanitize) { private List> getData(QueryResult response, boolean sanitize) { ImmutableList.Builder> dataLines = new ImmutableList.Builder<>(); - response.iterator().forEachRemaining(row -> { - ImmutableList.Builder line = new ImmutableList.Builder<>(); - // replace null values with empty string - Arrays.asList(row).forEach(val -> line.add(val == null ? "" : val.toString())); - dataLines.add(line.build()); - }); + response + .iterator() + .forEachRemaining( + row -> { + ImmutableList.Builder line = new ImmutableList.Builder<>(); + // replace null values with empty string + Arrays.asList(row).forEach(val -> line.add(val == null ? "" : val.toString())); + dataLines.add(line.build()); + }); List> result = dataLines.build(); return sanitizeData(result); } - /** - * Sanitize headers because OpenSearch allows special character present in field names. - */ + /** Sanitize headers because OpenSearch allows special character present in field names. */ private List sanitizeHeaders(List headers) { if (sanitize) { return headers.stream() - .map(this::sanitizeCell) - .map(cell -> quoteIfRequired(INLINE_SEPARATOR, cell)) - .collect(Collectors.toList()); + .map(this::sanitizeCell) + .map(cell -> quoteIfRequired(INLINE_SEPARATOR, cell)) + .collect(Collectors.toList()); } else { return headers.stream() - .map(cell -> quoteIfRequired(INLINE_SEPARATOR, cell)) - .collect(Collectors.toList()); + .map(cell -> quoteIfRequired(INLINE_SEPARATOR, cell)) + .collect(Collectors.toList()); } } @@ -114,14 +113,16 @@ private List> sanitizeData(List> lines) { List> result = new ArrayList<>(); if (sanitize) { for (List line : lines) { - result.add(line.stream() + result.add( + line.stream() .map(this::sanitizeCell) .map(cell -> quoteIfRequired(INLINE_SEPARATOR, cell)) .collect(Collectors.toList())); } } else { for (List line : lines) { - result.add(line.stream() + result.add( + line.stream() .map(cell -> quoteIfRequired(INLINE_SEPARATOR, cell)) .collect(Collectors.toList())); } @@ -138,13 +139,11 @@ private String sanitizeCell(String cell) { private String quoteIfRequired(String separator, String cell) { final String quote = "\""; - return cell.contains(separator) - ? quote + cell.replaceAll("\"", "\"\"") + quote : cell; + return cell.contains(separator) ? quote + cell.replaceAll("\"", "\"\"") + quote : cell; } private boolean isStartWithSensitiveChar(String cell) { return SENSITIVE_CHAR.stream().anyMatch(cell::startsWith); } } - } diff --git a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/Format.java b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/Format.java index 4291c09df0..8f22a5380e 100644 --- a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/Format.java +++ b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/Format.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.protocol.response.format; import com.google.common.base.Strings; @@ -20,8 +19,7 @@ public enum Format { RAW("raw"), VIZ("viz"); - @Getter - private final String formatName; + @Getter private final String formatName; private static final Map ALL_FORMATS; diff --git a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/JdbcResponseFormatter.java b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/JdbcResponseFormatter.java index 1ad3ffde34..8be22af532 100644 --- a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/JdbcResponseFormatter.java +++ b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/JdbcResponseFormatter.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.protocol.response.format; import java.util.List; @@ -40,9 +39,7 @@ protected Object buildJsonObject(QueryResult response) { json.datarows(fetchDataRows(response)); // Populate other fields - json.total(response.size()) - .size(response.size()) - .status(200); + json.total(response.size()).size(response.size()).status(200); if (!response.getCursor().equals(Cursor.None)) { json.cursor(response.getCursor().toString()); } @@ -54,10 +51,7 @@ protected Object buildJsonObject(QueryResult response) { public String format(Throwable t) { int status = getStatus(t); ErrorMessage message = ErrorMessageFactory.createErrorMessage(t, status); - Error error = new Error( - message.getType(), - message.getReason(), - message.getDetails()); + Error error = new Error(message.getType(), message.getReason(), message.getDetails()); return jsonify(new JdbcErrorResponse(error, status)); } @@ -66,8 +60,8 @@ private Column fetchColumn(Schema.Column col) { } /** - * Convert type that exists in both legacy and new engine but has different name. - * Return old type name to avoid breaking impact on client-side. + * Convert type that exists in both legacy and new engine but has different name. Return old type + * name to avoid breaking impact on client-side. */ private String convertToLegacyType(ExprType type) { return type.legacyTypeName().toLowerCase(); @@ -83,18 +77,16 @@ private Object[][] fetchDataRows(QueryResult response) { } private int getStatus(Throwable t) { - return (t instanceof SyntaxCheckException - || t instanceof QueryEngineException) ? 400 : 503; + return (t instanceof SyntaxCheckException || t instanceof QueryEngineException) ? 400 : 503; } - /** - * org.json requires these inner data classes be public (and static) - */ + /** org.json requires these inner data classes be public (and static) */ @Builder @Getter public static class JdbcResponse { @Singular("column") private final List schema; + private final Object[][] datarows; private final long total; private final long size; @@ -125,5 +117,4 @@ public static class Error { private final String reason; private final String details; } - } diff --git a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/JsonResponseFormatter.java b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/JsonResponseFormatter.java index 810a7d0c2d..115ee77b2b 100644 --- a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/JsonResponseFormatter.java +++ b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/JsonResponseFormatter.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.protocol.response.format; import static org.opensearch.sql.protocol.response.format.ErrorFormatter.compactFormat; @@ -24,16 +23,13 @@ @RequiredArgsConstructor public abstract class JsonResponseFormatter implements ResponseFormatter { - /** - * JSON format styles: pretty format or compact format without indent and space. - */ + /** JSON format styles: pretty format or compact format without indent and space. */ public enum Style { - PRETTY, COMPACT + PRETTY, + COMPACT } - /** - * JSON format style. - */ + /** JSON format style. */ private final Style style; public static final String CONTENT_TYPE = "application/json; charset=UTF-8"; @@ -45,8 +41,8 @@ public String format(R response) { @Override public String format(Throwable t) { - return AccessController.doPrivileged((PrivilegedAction) () -> - (style == PRETTY) ? prettyFormat(t) : compactFormat(t)); + return AccessController.doPrivileged( + (PrivilegedAction) () -> (style == PRETTY) ? prettyFormat(t) : compactFormat(t)); } public String contentType() { @@ -62,7 +58,8 @@ public String contentType() { protected abstract Object buildJsonObject(R response); protected String jsonify(Object jsonObject) { - return AccessController.doPrivileged((PrivilegedAction) () -> - (style == PRETTY) ? prettyJsonify(jsonObject) : compactJsonify(jsonObject)); + return AccessController.doPrivileged( + (PrivilegedAction) + () -> (style == PRETTY) ? prettyJsonify(jsonObject) : compactJsonify(jsonObject)); } } diff --git a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/RawResponseFormatter.java b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/RawResponseFormatter.java index 8fe88b2f95..75883073f5 100644 --- a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/RawResponseFormatter.java +++ b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/RawResponseFormatter.java @@ -3,16 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.protocol.response.format; -/** - * Response formatter to format response to csv or raw format. - */ -//@RequiredArgsConstructor +/** Response formatter to format response to csv or raw format. */ +// @RequiredArgsConstructor public class RawResponseFormatter extends FlatResponseFormatter { public RawResponseFormatter() { super("|", false); } - } diff --git a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/ResponseFormatter.java b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/ResponseFormatter.java index 6d9cc093c5..6738cfbc9c 100644 --- a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/ResponseFormatter.java +++ b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/ResponseFormatter.java @@ -3,12 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.protocol.response.format; -/** - * Response formatter to format response to different formats. - */ +/** Response formatter to format response to different formats. */ public interface ResponseFormatter { /** @@ -33,5 +30,4 @@ public interface ResponseFormatter { * @return string */ String contentType(); - } diff --git a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/SimpleJsonResponseFormatter.java b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/SimpleJsonResponseFormatter.java index ad705ccafa..c00174dc9f 100644 --- a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/SimpleJsonResponseFormatter.java +++ b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/SimpleJsonResponseFormatter.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.protocol.response.format; import java.util.List; @@ -43,8 +42,7 @@ public SimpleJsonResponseFormatter(Style style) { public Object buildJsonObject(QueryResult response) { JsonResponse.JsonResponseBuilder json = JsonResponse.builder(); - json.total(response.size()) - .size(response.size()); + json.total(response.size()).size(response.size()); response.columnNameTypes().forEach((name, type) -> json.column(new Column(name, type))); @@ -61,9 +59,7 @@ private Object[][] fetchDataRows(QueryResult response) { return rows; } - /** - * org.json requires these inner data classes be public (and static) - */ + /** org.json requires these inner data classes be public (and static) */ @Builder @Getter public static class JsonResponse { @@ -82,5 +78,4 @@ public static class Column { private final String name; private final String type; } - } diff --git a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/VisualizationResponseFormatter.java b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/VisualizationResponseFormatter.java index 7e971c9099..d5d220dd8d 100644 --- a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/VisualizationResponseFormatter.java +++ b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/VisualizationResponseFormatter.java @@ -72,21 +72,20 @@ protected Object buildJsonObject(QueryResult response) { public String format(Throwable t) { int status = getStatus(t); ErrorMessage message = ErrorMessageFactory.createErrorMessage(t, status); - VisualizationResponseFormatter.Error error = new Error( - message.getType(), - message.getReason(), - message.getDetails()); + VisualizationResponseFormatter.Error error = + new Error(message.getType(), message.getReason(), message.getDetails()); return jsonify(new VisualizationErrorResponse(error, status)); } private int getStatus(Throwable t) { - return (t instanceof SyntaxCheckException - || t instanceof QueryEngineException) ? 400 : 503; + return (t instanceof SyntaxCheckException || t instanceof QueryEngineException) ? 400 : 503; } private Map> fetchData(QueryResult response) { Map> columnMap = new LinkedHashMap<>(); - response.getSchema().getColumns() + response + .getSchema() + .getColumns() .forEach(column -> columnMap.put(column.getName(), new LinkedList<>())); for (Object[] dataRow : response) { @@ -107,16 +106,17 @@ private Metadata constructMetadata(QueryResult response) { private List fetchFields(QueryResult response) { List columns = response.getSchema().getColumns(); ImmutableList.Builder fields = ImmutableList.builder(); - columns.forEach(column -> { - Field field = new Field(column.getName(), convertToLegacyType(column.getExprType())); - fields.add(field); - }); + columns.forEach( + column -> { + Field field = new Field(column.getName(), convertToLegacyType(column.getExprType())); + fields.add(field); + }); return fields.build(); } /** - * Convert type that exists in both legacy and new engine but has different name. - * Return old type name to avoid breaking impact on client-side. + * Convert type that exists in both legacy and new engine but has different name. Return old type + * name to avoid breaking impact on client-side. */ private String convertToLegacyType(ExprType type) { return type.legacyTypeName().toLowerCase(); diff --git a/protocol/src/test/java/org/opensearch/sql/protocol/response/QueryResultTest.java b/protocol/src/test/java/org/opensearch/sql/protocol/response/QueryResultTest.java index 4c58e189b8..e03169e9f8 100644 --- a/protocol/src/test/java/org/opensearch/sql/protocol/response/QueryResultTest.java +++ b/protocol/src/test/java/org/opensearch/sql/protocol/response/QueryResultTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.protocol.response; import static org.junit.jupiter.api.Assertions.assertArrayEquals; @@ -23,86 +22,77 @@ class QueryResultTest { - private ExecutionEngine.Schema schema = new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("name", null, STRING), - new ExecutionEngine.Schema.Column("age", null, INTEGER))); - + private ExecutionEngine.Schema schema = + new ExecutionEngine.Schema( + ImmutableList.of( + new ExecutionEngine.Schema.Column("name", null, STRING), + new ExecutionEngine.Schema.Column("age", null, INTEGER))); @Test void size() { - QueryResult response = new QueryResult( - schema, - Arrays.asList( - tupleValue(ImmutableMap.of("name", "John", "age", 20)), - tupleValue(ImmutableMap.of("name", "Allen", "age", 30)), - tupleValue(ImmutableMap.of("name", "Smith", "age", 40)) - ), Cursor.None); + QueryResult response = + new QueryResult( + schema, + Arrays.asList( + tupleValue(ImmutableMap.of("name", "John", "age", 20)), + tupleValue(ImmutableMap.of("name", "Allen", "age", 30)), + tupleValue(ImmutableMap.of("name", "Smith", "age", 40))), + Cursor.None); assertEquals(3, response.size()); } @Test void columnNameTypes() { - QueryResult response = new QueryResult( - schema, - Collections.singletonList( - tupleValue(ImmutableMap.of("name", "John", "age", 20)) - ), Cursor.None); + QueryResult response = + new QueryResult( + schema, + Collections.singletonList(tupleValue(ImmutableMap.of("name", "John", "age", 20))), + Cursor.None); - assertEquals( - ImmutableMap.of("name", "string", "age", "integer"), - response.columnNameTypes() - ); + assertEquals(ImmutableMap.of("name", "string", "age", "integer"), response.columnNameTypes()); } @Test void columnNameTypesWithAlias() { - ExecutionEngine.Schema schema = new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("name", "n", STRING))); - QueryResult response = new QueryResult( - schema, - Collections.singletonList(tupleValue(ImmutableMap.of("n", "John"))), - Cursor.None); - - assertEquals( - ImmutableMap.of("n", "string"), - response.columnNameTypes() - ); + ExecutionEngine.Schema schema = + new ExecutionEngine.Schema( + ImmutableList.of(new ExecutionEngine.Schema.Column("name", "n", STRING))); + QueryResult response = + new QueryResult( + schema, + Collections.singletonList(tupleValue(ImmutableMap.of("n", "John"))), + Cursor.None); + + assertEquals(ImmutableMap.of("n", "string"), response.columnNameTypes()); } @Test void columnNameTypesFromEmptyExprValues() { - QueryResult response = new QueryResult( - schema, - Collections.emptyList(), Cursor.None); - assertEquals( - ImmutableMap.of("name", "string", "age", "integer"), - response.columnNameTypes() - ); + QueryResult response = new QueryResult(schema, Collections.emptyList(), Cursor.None); + assertEquals(ImmutableMap.of("name", "string", "age", "integer"), response.columnNameTypes()); } @Test void columnNameTypesFromExprValuesWithMissing() { - QueryResult response = new QueryResult( - schema, - Arrays.asList( - tupleValue(ImmutableMap.of("name", "John")), - tupleValue(ImmutableMap.of("name", "John", "age", 20)) - )); - - assertEquals( - ImmutableMap.of("name", "string", "age", "integer"), - response.columnNameTypes() - ); + QueryResult response = + new QueryResult( + schema, + Arrays.asList( + tupleValue(ImmutableMap.of("name", "John")), + tupleValue(ImmutableMap.of("name", "John", "age", 20)))); + + assertEquals(ImmutableMap.of("name", "string", "age", "integer"), response.columnNameTypes()); } @Test void iterate() { - QueryResult response = new QueryResult( - schema, - Arrays.asList( - tupleValue(ImmutableMap.of("name", "John", "age", 20)), - tupleValue(ImmutableMap.of("name", "Allen", "age", 30)) - ), Cursor.None); + QueryResult response = + new QueryResult( + schema, + Arrays.asList( + tupleValue(ImmutableMap.of("name", "John", "age", 20)), + tupleValue(ImmutableMap.of("name", "Allen", "age", 30))), + Cursor.None); int i = 0; for (Object[] objects : response) { @@ -116,5 +106,4 @@ void iterate() { i++; } } - } diff --git a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CommandResponseFormatterTest.java b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CommandResponseFormatterTest.java index 85efbab369..4b20f6b1dc 100644 --- a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CommandResponseFormatterTest.java +++ b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CommandResponseFormatterTest.java @@ -29,32 +29,34 @@ public class CommandResponseFormatterTest { @Test public void produces_always_same_output_for_any_query_response() { var formatter = new CommandResponseFormatter(); - assertEquals(formatter.format(mock(QueryResult.class)), - formatter.format(mock(QueryResult.class))); + assertEquals( + formatter.format(mock(QueryResult.class)), formatter.format(mock(QueryResult.class))); - QueryResult response = new QueryResult( - new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("name", "name", STRING), - new ExecutionEngine.Schema.Column("address", "address", OpenSearchTextType.of()), - new ExecutionEngine.Schema.Column("age", "age", INTEGER))), - ImmutableList.of( - tupleValue(ImmutableMap.builder() - .put("name", "John") - .put("address", "Seattle") - .put("age", 20) - .build())), - new Cursor("test_cursor")); + QueryResult response = + new QueryResult( + new ExecutionEngine.Schema( + ImmutableList.of( + new ExecutionEngine.Schema.Column("name", "name", STRING), + new ExecutionEngine.Schema.Column( + "address", "address", OpenSearchTextType.of()), + new ExecutionEngine.Schema.Column("age", "age", INTEGER))), + ImmutableList.of( + tupleValue( + ImmutableMap.builder() + .put("name", "John") + .put("address", "Seattle") + .put("age", 20) + .build())), + new Cursor("test_cursor")); - assertEquals("{\n" - + " \"succeeded\": true\n" - + "}", - formatter.format(response)); + assertEquals("{\n" + " \"succeeded\": true\n" + "}", formatter.format(response)); } @Test public void formats_error_as_default_formatter() { var exception = new Exception("pewpew", new RuntimeException("meow meow")); - assertEquals(new JdbcResponseFormatter(PRETTY).format(exception), + assertEquals( + new JdbcResponseFormatter(PRETTY).format(exception), new CommandResponseFormatter().format(exception)); } diff --git a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CsvResponseFormatterTest.java b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CsvResponseFormatterTest.java index 82b4f372b3..13670dc7d6 100644 --- a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CsvResponseFormatterTest.java +++ b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CsvResponseFormatterTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.protocol.response.format; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -24,20 +23,23 @@ import org.opensearch.sql.executor.ExecutionEngine; import org.opensearch.sql.protocol.response.QueryResult; -/** - * Unit test for {@link CsvResponseFormatter}. - */ +/** Unit test for {@link CsvResponseFormatter}. */ public class CsvResponseFormatterTest { private static final CsvResponseFormatter formatter = new CsvResponseFormatter(); @Test void formatResponse() { - ExecutionEngine.Schema schema = new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("name", "name", STRING), - new ExecutionEngine.Schema.Column("age", "age", INTEGER))); - QueryResult response = new QueryResult(schema, Arrays.asList( - tupleValue(ImmutableMap.of("name", "John", "age", 20)), - tupleValue(ImmutableMap.of("name", "Smith", "age", 30)))); + ExecutionEngine.Schema schema = + new ExecutionEngine.Schema( + ImmutableList.of( + new ExecutionEngine.Schema.Column("name", "name", STRING), + new ExecutionEngine.Schema.Column("age", "age", INTEGER))); + QueryResult response = + new QueryResult( + schema, + Arrays.asList( + tupleValue(ImmutableMap.of("name", "John", "age", 20)), + tupleValue(ImmutableMap.of("name", "Smith", "age", 30)))); CsvResponseFormatter formatter = new CsvResponseFormatter(); String expected = "name,age%nJohn,20%nSmith,30"; assertEquals(format(expected), formatter.format(response)); @@ -45,49 +47,69 @@ void formatResponse() { @Test void sanitizeHeaders() { - ExecutionEngine.Schema schema = new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("=firstname", null, STRING), - new ExecutionEngine.Schema.Column("+lastname", null, STRING), - new ExecutionEngine.Schema.Column("-city", null, STRING), - new ExecutionEngine.Schema.Column("@age", null, INTEGER))); - QueryResult response = new QueryResult(schema, Arrays.asList( - tupleValue(ImmutableMap.of( - "=firstname", "John", "+lastname", "Smith", "-city", "Seattle", "@age", 20)))); - String expected = "'=firstname,'+lastname,'-city,'@age%n" - + "John,Smith,Seattle,20"; + ExecutionEngine.Schema schema = + new ExecutionEngine.Schema( + ImmutableList.of( + new ExecutionEngine.Schema.Column("=firstname", null, STRING), + new ExecutionEngine.Schema.Column("+lastname", null, STRING), + new ExecutionEngine.Schema.Column("-city", null, STRING), + new ExecutionEngine.Schema.Column("@age", null, INTEGER))); + QueryResult response = + new QueryResult( + schema, + Arrays.asList( + tupleValue( + ImmutableMap.of( + "=firstname", + "John", + "+lastname", + "Smith", + "-city", + "Seattle", + "@age", + 20)))); + String expected = "'=firstname,'+lastname,'-city,'@age%n" + "John,Smith,Seattle,20"; assertEquals(format(expected), formatter.format(response)); } @Test void sanitizeData() { - ExecutionEngine.Schema schema = new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("city", "city", STRING))); - QueryResult response = new QueryResult(schema, Arrays.asList( - tupleValue(ImmutableMap.of("city", "Seattle")), - tupleValue(ImmutableMap.of("city", "=Seattle")), - tupleValue(ImmutableMap.of("city", "+Seattle")), - tupleValue(ImmutableMap.of("city", "-Seattle")), - tupleValue(ImmutableMap.of("city", "@Seattle")), - tupleValue(ImmutableMap.of("city", "Seattle=")))); - String expected = "city%n" - + "Seattle%n" - + "'=Seattle%n" - + "'+Seattle%n" - + "'-Seattle%n" - + "'@Seattle%n" - + "Seattle="; + ExecutionEngine.Schema schema = + new ExecutionEngine.Schema( + ImmutableList.of(new ExecutionEngine.Schema.Column("city", "city", STRING))); + QueryResult response = + new QueryResult( + schema, + Arrays.asList( + tupleValue(ImmutableMap.of("city", "Seattle")), + tupleValue(ImmutableMap.of("city", "=Seattle")), + tupleValue(ImmutableMap.of("city", "+Seattle")), + tupleValue(ImmutableMap.of("city", "-Seattle")), + tupleValue(ImmutableMap.of("city", "@Seattle")), + tupleValue(ImmutableMap.of("city", "Seattle=")))); + String expected = + "city%n" + + "Seattle%n" + + "'=Seattle%n" + + "'+Seattle%n" + + "'-Seattle%n" + + "'@Seattle%n" + + "Seattle="; assertEquals(format(expected), formatter.format(response)); } @Test void quoteIfRequired() { - ExecutionEngine.Schema schema = new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("na,me", "na,me", STRING), - new ExecutionEngine.Schema.Column(",,age", ",,age", INTEGER))); - QueryResult response = new QueryResult(schema, Arrays.asList( - tupleValue(ImmutableMap.of("na,me", "John,Smith", ",,age", "30,,,")))); - String expected = "\"na,me\",\",,age\"%n" - + "\"John,Smith\",\"30,,,\""; + ExecutionEngine.Schema schema = + new ExecutionEngine.Schema( + ImmutableList.of( + new ExecutionEngine.Schema.Column("na,me", "na,me", STRING), + new ExecutionEngine.Schema.Column(",,age", ",,age", INTEGER))); + QueryResult response = + new QueryResult( + schema, + Arrays.asList(tupleValue(ImmutableMap.of("na,me", "John,Smith", ",,age", "30,,,")))); + String expected = "\"na,me\",\",,age\"%n" + "\"John,Smith\",\"30,,,\""; assertEquals(format(expected), formatter.format(response)); } @@ -102,32 +124,36 @@ void formatError() { @Test void escapeSanitize() { CsvResponseFormatter escapeFormatter = new CsvResponseFormatter(false); - ExecutionEngine.Schema schema = new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("city", "city", STRING))); - QueryResult response = new QueryResult(schema, Arrays.asList( - tupleValue(ImmutableMap.of("city", "=Seattle")), - tupleValue(ImmutableMap.of("city", ",,Seattle")))); - String expected = "city%n" - + "=Seattle%n" - + "\",,Seattle\""; + ExecutionEngine.Schema schema = + new ExecutionEngine.Schema( + ImmutableList.of(new ExecutionEngine.Schema.Column("city", "city", STRING))); + QueryResult response = + new QueryResult( + schema, + Arrays.asList( + tupleValue(ImmutableMap.of("city", "=Seattle")), + tupleValue(ImmutableMap.of("city", ",,Seattle")))); + String expected = "city%n" + "=Seattle%n" + "\",,Seattle\""; assertEquals(format(expected), escapeFormatter.format(response)); } @Test void replaceNullValues() { - ExecutionEngine.Schema schema = new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("name", "name", STRING), - new ExecutionEngine.Schema.Column("city", "city", STRING))); - QueryResult response = new QueryResult(schema, Arrays.asList( - tupleValue(ImmutableMap.of("name", "John","city", "Seattle")), - ExprTupleValue.fromExprValueMap( - ImmutableMap.of("firstname", LITERAL_NULL, "city", stringValue("Seattle"))), - ExprTupleValue.fromExprValueMap( - ImmutableMap.of("firstname", stringValue("John"), "city", LITERAL_MISSING)))); - String expected = "name,city%n" - + "John,Seattle%n" - + ",Seattle%n" - + "John,"; + ExecutionEngine.Schema schema = + new ExecutionEngine.Schema( + ImmutableList.of( + new ExecutionEngine.Schema.Column("name", "name", STRING), + new ExecutionEngine.Schema.Column("city", "city", STRING))); + QueryResult response = + new QueryResult( + schema, + Arrays.asList( + tupleValue(ImmutableMap.of("name", "John", "city", "Seattle")), + ExprTupleValue.fromExprValueMap( + ImmutableMap.of("firstname", LITERAL_NULL, "city", stringValue("Seattle"))), + ExprTupleValue.fromExprValueMap( + ImmutableMap.of("firstname", stringValue("John"), "city", LITERAL_MISSING)))); + String expected = "name,city%n" + "John,Seattle%n" + ",Seattle%n" + "John,"; assertEquals(format(expected), formatter.format(response)); } @@ -135,5 +161,4 @@ void replaceNullValues() { void testContentType() { assertEquals(formatter.contentType(), CONTENT_TYPE); } - } diff --git a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/FormatTest.java b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/FormatTest.java index e0e4355a24..7293048916 100644 --- a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/FormatTest.java +++ b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/FormatTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.protocol.response.format; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -13,9 +12,7 @@ import java.util.Optional; import org.junit.jupiter.api.Test; -/** - * Unit test for {@link Format}. - */ +/** Unit test for {@link Format}. */ public class FormatTest { @Test @@ -58,5 +55,4 @@ void unsupportedFormat() { Optional format = Format.of("notsupport"); assertFalse(format.isPresent()); } - } diff --git a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/JdbcResponseFormatterTest.java b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/JdbcResponseFormatterTest.java index 9c79b1bf89..16dd1590ee 100644 --- a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/JdbcResponseFormatterTest.java +++ b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/JdbcResponseFormatterTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.protocol.response.format; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -43,26 +42,35 @@ class JdbcResponseFormatterTest { @Test void format_response() { - QueryResult response = new QueryResult( - new Schema(ImmutableList.of( - new Column("name", "name", STRING), - new Column("address1", "address1", OpenSearchTextType.of()), - new Column("address2", "address2", OpenSearchTextType.of(Map.of("words", - OpenSearchDataType.of(OpenSearchDataType.MappingType.Keyword)))), - new Column("location", "location", STRUCT), - new Column("employer", "employer", ARRAY), - new Column("age", "age", INTEGER))), - ImmutableList.of( - tupleValue(ImmutableMap.builder() - .put("name", "John") - .put("address1", "Seattle") - .put("address2", "WA") - .put("location", ImmutableMap.of("x", "1", "y", "2")) - .put("employments", ImmutableList.of( - ImmutableMap.of("name", "Amazon"), - ImmutableMap.of("name", "AWS"))) - .put("age", 20) - .build()))); + QueryResult response = + new QueryResult( + new Schema( + ImmutableList.of( + new Column("name", "name", STRING), + new Column("address1", "address1", OpenSearchTextType.of()), + new Column( + "address2", + "address2", + OpenSearchTextType.of( + Map.of( + "words", + OpenSearchDataType.of(OpenSearchDataType.MappingType.Keyword)))), + new Column("location", "location", STRUCT), + new Column("employer", "employer", ARRAY), + new Column("age", "age", INTEGER))), + ImmutableList.of( + tupleValue( + ImmutableMap.builder() + .put("name", "John") + .put("address1", "Seattle") + .put("address2", "WA") + .put("location", ImmutableMap.of("x", "1", "y", "2")) + .put( + "employments", + ImmutableList.of( + ImmutableMap.of("name", "Amazon"), ImmutableMap.of("name", "AWS"))) + .put("age", 20) + .build()))); assertJsonEquals( "{" @@ -76,7 +84,8 @@ void format_response() { + "]," + "\"datarows\":[" + "[\"John\",\"Seattle\",\"WA\",{\"x\":\"1\",\"y\":\"2\"}," - + "[{\"name\":\"Amazon\"}," + "{\"name\":\"AWS\"}]," + + "[{\"name\":\"Amazon\"}," + + "{\"name\":\"AWS\"}]," + "20]]," + "\"total\":1," + "\"size\":1," @@ -86,18 +95,21 @@ void format_response() { @Test void format_response_with_cursor() { - QueryResult response = new QueryResult( - new Schema(ImmutableList.of( - new Column("name", "name", STRING), - new Column("address", "address", OpenSearchTextType.of()), - new Column("age", "age", INTEGER))), - ImmutableList.of( - tupleValue(ImmutableMap.builder() - .put("name", "John") - .put("address", "Seattle") - .put("age", 20) - .build())), - new Cursor("test_cursor")); + QueryResult response = + new QueryResult( + new Schema( + ImmutableList.of( + new Column("name", "name", STRING), + new Column("address", "address", OpenSearchTextType.of()), + new Column("age", "age", INTEGER))), + ImmutableList.of( + tupleValue( + ImmutableMap.builder() + .put("name", "John") + .put("address", "Seattle") + .put("age", 20) + .build())), + new Cursor("test_cursor")); assertJsonEquals( "{" @@ -119,9 +131,9 @@ void format_response_with_cursor() { void format_response_with_missing_and_null_value() { QueryResult response = new QueryResult( - new Schema(ImmutableList.of( - new Column("name", null, STRING), - new Column("age", null, INTEGER))), + new Schema( + ImmutableList.of( + new Column("name", null, STRING), new Column("age", null, INTEGER))), Arrays.asList( ExprTupleValue.fromExprValueMap( ImmutableMap.of("name", stringValue("John"), "age", LITERAL_MISSING)), @@ -147,8 +159,7 @@ void format_client_error_response_due_to_syntax_exception() { + "\"details\":\"Invalid query syntax\"" + "}," + "\"status\":400}", - formatter.format(new SyntaxCheckException("Invalid query syntax")) - ); + formatter.format(new SyntaxCheckException("Invalid query syntax"))); } @Test @@ -161,8 +172,7 @@ void format_client_error_response_due_to_semantic_exception() { + "\"details\":\"Invalid query semantics\"" + "}," + "\"status\":400}", - formatter.format(new SemanticCheckException("Invalid query semantics")) - ); + formatter.format(new SemanticCheckException("Invalid query semantics"))); } @Test @@ -175,8 +185,7 @@ void format_server_error_response() { + "\"details\":\"Execution error\"" + "}," + "\"status\":503}", - formatter.format(new IllegalStateException("Execution error")) - ); + formatter.format(new IllegalStateException("Execution error"))); } @Test @@ -193,15 +202,12 @@ void format_server_error_response_due_to_opensearch() { + "from OpenSearch engine.\"" + "}," + "\"status\":503}", - formatter.format(new OpenSearchException("all shards failed", - new IllegalStateException("Execution error"))) - ); + formatter.format( + new OpenSearchException( + "all shards failed", new IllegalStateException("Execution error")))); } private static void assertJsonEquals(String expected, String actual) { - assertEquals( - JsonParser.parseString(expected), - JsonParser.parseString(actual)); + assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual)); } - } diff --git a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/RawResponseFormatterTest.java b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/RawResponseFormatterTest.java index b33a4f216a..af0ab1947b 100644 --- a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/RawResponseFormatterTest.java +++ b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/RawResponseFormatterTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.protocol.response.format; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -24,69 +23,92 @@ import org.opensearch.sql.executor.ExecutionEngine; import org.opensearch.sql.protocol.response.QueryResult; -/** - * Unit test for {@link FlatResponseFormatter}. - */ +/** Unit test for {@link FlatResponseFormatter}. */ public class RawResponseFormatterTest { private FlatResponseFormatter rawFormatter = new RawResponseFormatter(); @Test void formatResponse() { - ExecutionEngine.Schema schema = new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("name", "name", STRING), - new ExecutionEngine.Schema.Column("age", "age", INTEGER))); - QueryResult response = new QueryResult(schema, Arrays.asList( - tupleValue(ImmutableMap.of("name", "John", "age", 20)), - tupleValue(ImmutableMap.of("name", "Smith", "age", 30)))); + ExecutionEngine.Schema schema = + new ExecutionEngine.Schema( + ImmutableList.of( + new ExecutionEngine.Schema.Column("name", "name", STRING), + new ExecutionEngine.Schema.Column("age", "age", INTEGER))); + QueryResult response = + new QueryResult( + schema, + Arrays.asList( + tupleValue(ImmutableMap.of("name", "John", "age", 20)), + tupleValue(ImmutableMap.of("name", "Smith", "age", 30)))); String expected = "name|age%nJohn|20%nSmith|30"; assertEquals(format(expected), rawFormatter.format(response)); } @Test void sanitizeHeaders() { - ExecutionEngine.Schema schema = new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("=firstname", null, STRING), - new ExecutionEngine.Schema.Column("+lastname", null, STRING), - new ExecutionEngine.Schema.Column("-city", null, STRING), - new ExecutionEngine.Schema.Column("@age", null, INTEGER))); - QueryResult response = new QueryResult(schema, Arrays.asList( - tupleValue(ImmutableMap.of( - "=firstname", "John", "+lastname", "Smith", "-city", "Seattle", "@age", 20)))); - String expected = "=firstname|+lastname|-city|@age%n" - + "John|Smith|Seattle|20"; + ExecutionEngine.Schema schema = + new ExecutionEngine.Schema( + ImmutableList.of( + new ExecutionEngine.Schema.Column("=firstname", null, STRING), + new ExecutionEngine.Schema.Column("+lastname", null, STRING), + new ExecutionEngine.Schema.Column("-city", null, STRING), + new ExecutionEngine.Schema.Column("@age", null, INTEGER))); + QueryResult response = + new QueryResult( + schema, + Arrays.asList( + tupleValue( + ImmutableMap.of( + "=firstname", + "John", + "+lastname", + "Smith", + "-city", + "Seattle", + "@age", + 20)))); + String expected = "=firstname|+lastname|-city|@age%n" + "John|Smith|Seattle|20"; assertEquals(format(expected), rawFormatter.format(response)); } @Test void sanitizeData() { - ExecutionEngine.Schema schema = new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("city", "city", STRING))); - QueryResult response = new QueryResult(schema, Arrays.asList( - tupleValue(ImmutableMap.of("city", "Seattle")), - tupleValue(ImmutableMap.of("city", "=Seattle")), - tupleValue(ImmutableMap.of("city", "+Seattle")), - tupleValue(ImmutableMap.of("city", "-Seattle")), - tupleValue(ImmutableMap.of("city", "@Seattle")), - tupleValue(ImmutableMap.of("city", "Seattle=")))); - String expected = "city%n" - + "Seattle%n" - + "=Seattle%n" - + "+Seattle%n" - + "-Seattle%n" - + "@Seattle%n" - + "Seattle="; + ExecutionEngine.Schema schema = + new ExecutionEngine.Schema( + ImmutableList.of(new ExecutionEngine.Schema.Column("city", "city", STRING))); + QueryResult response = + new QueryResult( + schema, + Arrays.asList( + tupleValue(ImmutableMap.of("city", "Seattle")), + tupleValue(ImmutableMap.of("city", "=Seattle")), + tupleValue(ImmutableMap.of("city", "+Seattle")), + tupleValue(ImmutableMap.of("city", "-Seattle")), + tupleValue(ImmutableMap.of("city", "@Seattle")), + tupleValue(ImmutableMap.of("city", "Seattle=")))); + String expected = + "city%n" + + "Seattle%n" + + "=Seattle%n" + + "+Seattle%n" + + "-Seattle%n" + + "@Seattle%n" + + "Seattle="; assertEquals(format(expected), rawFormatter.format(response)); } @Test void quoteIfRequired() { - ExecutionEngine.Schema schema = new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("na|me", "na|me", STRING), - new ExecutionEngine.Schema.Column("||age", "||age", INTEGER))); - QueryResult response = new QueryResult(schema, Arrays.asList( - tupleValue(ImmutableMap.of("na|me", "John|Smith", "||age", "30|||")))); - String expected = "\"na|me\"|\"||age\"%n" - + "\"John|Smith\"|\"30|||\""; + ExecutionEngine.Schema schema = + new ExecutionEngine.Schema( + ImmutableList.of( + new ExecutionEngine.Schema.Column("na|me", "na|me", STRING), + new ExecutionEngine.Schema.Column("||age", "||age", INTEGER))); + QueryResult response = + new QueryResult( + schema, + Arrays.asList(tupleValue(ImmutableMap.of("na|me", "John|Smith", "||age", "30|||")))); + String expected = "\"na|me\"|\"||age\"%n" + "\"John|Smith\"|\"30|||\""; assertEquals(format(expected), rawFormatter.format(response)); } @@ -101,59 +123,67 @@ void formatError() { @Test void escapeSanitize() { FlatResponseFormatter escapeFormatter = new RawResponseFormatter(); - ExecutionEngine.Schema schema = new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("city", "city", STRING))); - QueryResult response = new QueryResult(schema, Arrays.asList( - tupleValue(ImmutableMap.of("city", "=Seattle")), - tupleValue(ImmutableMap.of("city", "||Seattle")))); - String expected = "city%n" - + "=Seattle%n" - + "\"||Seattle\""; + ExecutionEngine.Schema schema = + new ExecutionEngine.Schema( + ImmutableList.of(new ExecutionEngine.Schema.Column("city", "city", STRING))); + QueryResult response = + new QueryResult( + schema, + Arrays.asList( + tupleValue(ImmutableMap.of("city", "=Seattle")), + tupleValue(ImmutableMap.of("city", "||Seattle")))); + String expected = "city%n" + "=Seattle%n" + "\"||Seattle\""; assertEquals(format(expected), escapeFormatter.format(response)); } @Test void senstiveCharater() { - ExecutionEngine.Schema schema = new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("city", "city", STRING))); - QueryResult response = new QueryResult(schema, Arrays.asList( - tupleValue(ImmutableMap.of("city", "@Seattle")), - tupleValue(ImmutableMap.of("city", "++Seattle")))); - String expected = "city%n" - + "@Seattle%n" - + "++Seattle"; + ExecutionEngine.Schema schema = + new ExecutionEngine.Schema( + ImmutableList.of(new ExecutionEngine.Schema.Column("city", "city", STRING))); + QueryResult response = + new QueryResult( + schema, + Arrays.asList( + tupleValue(ImmutableMap.of("city", "@Seattle")), + tupleValue(ImmutableMap.of("city", "++Seattle")))); + String expected = "city%n" + "@Seattle%n" + "++Seattle"; assertEquals(format(expected), rawFormatter.format(response)); } @Test void senstiveCharaterWithSanitize() { FlatResponseFormatter testFormater = new RawResponseFormatter(); - ExecutionEngine.Schema schema = new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("city", "city", STRING))); - QueryResult response = new QueryResult(schema, Arrays.asList( - tupleValue(ImmutableMap.of("city", "@Seattle")), - tupleValue(ImmutableMap.of("city", "++Seattle|||")))); - String expected = "city%n" - + "@Seattle%n" - + "\"++Seattle|||\""; + ExecutionEngine.Schema schema = + new ExecutionEngine.Schema( + ImmutableList.of(new ExecutionEngine.Schema.Column("city", "city", STRING))); + QueryResult response = + new QueryResult( + schema, + Arrays.asList( + tupleValue(ImmutableMap.of("city", "@Seattle")), + tupleValue(ImmutableMap.of("city", "++Seattle|||")))); + String expected = "city%n" + "@Seattle%n" + "\"++Seattle|||\""; assertEquals(format(expected), testFormater.format(response)); } @Test void replaceNullValues() { - ExecutionEngine.Schema schema = new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("name", "name", STRING), - new ExecutionEngine.Schema.Column("city", "city", STRING))); - QueryResult response = new QueryResult(schema, Arrays.asList( - tupleValue(ImmutableMap.of("name", "John","city", "Seattle")), - ExprTupleValue.fromExprValueMap( - ImmutableMap.of("firstname", LITERAL_NULL, "city", stringValue("Seattle"))), - ExprTupleValue.fromExprValueMap( - ImmutableMap.of("firstname", stringValue("John"), "city", LITERAL_MISSING)))); - String expected = "name|city%n" - + "John|Seattle%n" - + "|Seattle%n" - + "John|"; + ExecutionEngine.Schema schema = + new ExecutionEngine.Schema( + ImmutableList.of( + new ExecutionEngine.Schema.Column("name", "name", STRING), + new ExecutionEngine.Schema.Column("city", "city", STRING))); + QueryResult response = + new QueryResult( + schema, + Arrays.asList( + tupleValue(ImmutableMap.of("name", "John", "city", "Seattle")), + ExprTupleValue.fromExprValueMap( + ImmutableMap.of("firstname", LITERAL_NULL, "city", stringValue("Seattle"))), + ExprTupleValue.fromExprValueMap( + ImmutableMap.of("firstname", stringValue("John"), "city", LITERAL_MISSING)))); + String expected = "name|city%n" + "John|Seattle%n" + "|Seattle%n" + "John|"; assertEquals(format(expected), rawFormatter.format(response)); } @@ -161,5 +191,4 @@ void replaceNullValues() { void testContentType() { assertEquals(rawFormatter.contentType(), CONTENT_TYPE); } - } diff --git a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/SimpleJsonResponseFormatterTest.java b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/SimpleJsonResponseFormatterTest.java index 8b4438cf91..e5eb0f1ac7 100644 --- a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/SimpleJsonResponseFormatterTest.java +++ b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/SimpleJsonResponseFormatterTest.java @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - package org.opensearch.sql.protocol.response.format; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -25,9 +24,11 @@ class SimpleJsonResponseFormatterTest { - private final ExecutionEngine.Schema schema = new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("firstname", null, STRING), - new ExecutionEngine.Schema.Column("age", null, INTEGER))); + private final ExecutionEngine.Schema schema = + new ExecutionEngine.Schema( + ImmutableList.of( + new ExecutionEngine.Schema.Column("firstname", null, STRING), + new ExecutionEngine.Schema.Column("age", null, INTEGER))); @Test void formatResponse() { @@ -84,12 +85,12 @@ void formatResponsePretty() { @Test void formatResponseSchemaWithAlias() { - ExecutionEngine.Schema schema = new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("firstname", "name", STRING))); + ExecutionEngine.Schema schema = + new ExecutionEngine.Schema( + ImmutableList.of(new ExecutionEngine.Schema.Column("firstname", "name", STRING))); QueryResult response = new QueryResult( - schema, - ImmutableList.of(tupleValue(ImmutableMap.of("name", "John", "age", 20)))); + schema, ImmutableList.of(tupleValue(ImmutableMap.of("name", "John", "age", 20)))); SimpleJsonResponseFormatter formatter = new SimpleJsonResponseFormatter(COMPACT); assertEquals( "{\"schema\":[{\"name\":\"name\",\"type\":\"string\"}]," @@ -120,10 +121,13 @@ void formatResponseWithTupleValue() { new QueryResult( schema, Arrays.asList( - tupleValue(ImmutableMap - .of("name", "Smith", - "address", ImmutableMap.of("state", "WA", "street", - ImmutableMap.of("city", "seattle")))))); + tupleValue( + ImmutableMap.of( + "name", + "Smith", + "address", + ImmutableMap.of( + "state", "WA", "street", ImmutableMap.of("city", "seattle")))))); SimpleJsonResponseFormatter formatter = new SimpleJsonResponseFormatter(COMPACT); assertEquals( @@ -140,11 +144,13 @@ void formatResponseWithArrayValue() { new QueryResult( schema, Arrays.asList( - tupleValue(ImmutableMap - .of("name", "Smith", - "address", Arrays.asList( - ImmutableMap.of("state", "WA"), ImmutableMap.of("state", "NYC") - ))))); + tupleValue( + ImmutableMap.of( + "name", + "Smith", + "address", + Arrays.asList( + ImmutableMap.of("state", "WA"), ImmutableMap.of("state", "NYC")))))); SimpleJsonResponseFormatter formatter = new SimpleJsonResponseFormatter(COMPACT); assertEquals( "{\"schema\":[{\"name\":\"firstname\",\"type\":\"string\"}," diff --git a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/VisualizationResponseFormatterTest.java b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/VisualizationResponseFormatterTest.java index f501a53d64..a6fdd1e03e 100644 --- a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/VisualizationResponseFormatterTest.java +++ b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/VisualizationResponseFormatterTest.java @@ -24,18 +24,21 @@ import org.opensearch.sql.protocol.response.QueryResult; public class VisualizationResponseFormatterTest { - private final VisualizationResponseFormatter formatter = new VisualizationResponseFormatter( - JsonResponseFormatter.Style.COMPACT); + private final VisualizationResponseFormatter formatter = + new VisualizationResponseFormatter(JsonResponseFormatter.Style.COMPACT); @Test void formatResponse() { - QueryResult response = new QueryResult( - new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("name", "name", STRING), - new ExecutionEngine.Schema.Column("age", "age", INTEGER))), - ImmutableList.of(tupleValue(ImmutableMap.of("name", "John", "age", 20)), - tupleValue(ImmutableMap.of("name", "Amy", "age", 31)), - tupleValue(ImmutableMap.of("name", "Bob", "age", 28)))); + QueryResult response = + new QueryResult( + new ExecutionEngine.Schema( + ImmutableList.of( + new ExecutionEngine.Schema.Column("name", "name", STRING), + new ExecutionEngine.Schema.Column("age", "age", INTEGER))), + ImmutableList.of( + tupleValue(ImmutableMap.of("name", "John", "age", 20)), + tupleValue(ImmutableMap.of("name", "Amy", "age", 31)), + tupleValue(ImmutableMap.of("name", "Bob", "age", 28)))); assertJsonEquals( "{\"data\":{" @@ -55,10 +58,12 @@ void formatResponse() { void formatResponseWithNull() { QueryResult response = new QueryResult( - new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("name", null, STRING), - new ExecutionEngine.Schema.Column("age", null, INTEGER))), - ImmutableList.of(tupleValue(ImmutableMap.of("name", "John", "age", LITERAL_MISSING)), + new ExecutionEngine.Schema( + ImmutableList.of( + new ExecutionEngine.Schema.Column("name", null, STRING), + new ExecutionEngine.Schema.Column("age", null, INTEGER))), + ImmutableList.of( + tupleValue(ImmutableMap.of("name", "John", "age", LITERAL_MISSING)), tupleValue(ImmutableMap.of("name", "Allen", "age", LITERAL_NULL)), tupleValue(ImmutableMap.of("name", "Smith", "age", 30)))); @@ -73,8 +78,7 @@ void formatResponseWithNull() { + "\"size\":3," + "\"status\":200" + "}", - formatter.format(response) - ); + formatter.format(response)); } @Test @@ -87,8 +91,7 @@ void clientErrorSyntaxException() { + "\"details\":\"Invalid query syntax\"" + "}," + "\"status\":400}", - formatter.format(new SyntaxCheckException("Invalid query syntax")) - ); + formatter.format(new SyntaxCheckException("Invalid query syntax"))); } @Test @@ -101,8 +104,7 @@ void clientErrorSemanticException() { + "\"details\":\"Invalid query semantics\"" + "}," + "\"status\":400}", - formatter.format(new SemanticCheckException("Invalid query semantics")) - ); + formatter.format(new SemanticCheckException("Invalid query semantics"))); } @Test @@ -115,8 +117,7 @@ void serverError() { + "\"details\":\"Execution error\"" + "}," + "\"status\":503}", - formatter.format(new IllegalStateException("Execution error")) - ); + formatter.format(new IllegalStateException("Execution error"))); } @Test @@ -133,22 +134,25 @@ void opensearchServerError() { + "from OpenSearch engine.\"" + "}," + "\"status\":503}", - formatter.format(new OpenSearchException("all shards failed", - new IllegalStateException("Execution error"))) - ); + formatter.format( + new OpenSearchException( + "all shards failed", new IllegalStateException("Execution error")))); } @Test void prettyStyle() { - VisualizationResponseFormatter prettyFormatter = new VisualizationResponseFormatter( - JsonResponseFormatter.Style.PRETTY); - QueryResult response = new QueryResult( - new ExecutionEngine.Schema(ImmutableList.of( - new ExecutionEngine.Schema.Column("name", "name", STRING), - new ExecutionEngine.Schema.Column("age", "age", INTEGER))), - ImmutableList.of(tupleValue(ImmutableMap.of("name", "John", "age", 20)), - tupleValue(ImmutableMap.of("name", "Amy", "age", 31)), - tupleValue(ImmutableMap.of("name", "Bob", "age", 28)))); + VisualizationResponseFormatter prettyFormatter = + new VisualizationResponseFormatter(JsonResponseFormatter.Style.PRETTY); + QueryResult response = + new QueryResult( + new ExecutionEngine.Schema( + ImmutableList.of( + new ExecutionEngine.Schema.Column("name", "name", STRING), + new ExecutionEngine.Schema.Column("age", "age", INTEGER))), + ImmutableList.of( + tupleValue(ImmutableMap.of("name", "John", "age", 20)), + tupleValue(ImmutableMap.of("name", "Amy", "age", 31)), + tupleValue(ImmutableMap.of("name", "Bob", "age", 28)))); assertJsonEquals( "{\n" @@ -179,14 +183,11 @@ void prettyStyle() { + " \"size\": 3,\n" + " \"status\": 200\n" + "}", - prettyFormatter.format(response) - ); + prettyFormatter.format(response)); } private static void assertJsonEquals(String expected, String actual) { - assertEquals( - JsonParser.parseString(expected), - JsonParser.parseString(actual)); + assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual)); } @Test From 9c254c288737162a38209b4e8f63c040537d6a6c Mon Sep 17 00:00:00 2001 From: Mitchell Gale Date: Wed, 16 Aug 2023 09:35:33 -0700 Subject: [PATCH 2/4] added ignorefailures Signed-off-by: Mitchell Gale --- protocol/build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/protocol/build.gradle b/protocol/build.gradle index 92a1aa0917..dcec1c675b 100644 --- a/protocol/build.gradle +++ b/protocol/build.gradle @@ -43,6 +43,9 @@ dependencies { testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '3.12.4' } +checkstyleTest.ignoreFailures = true +checkstyleMain.ignoreFailures = true + configurations.all { resolutionStrategy.force "com.fasterxml.jackson.core:jackson-databind:${versions.jackson_databind}" } From c901883316c9230a9ed246b22fd8898c5cd6df55 Mon Sep 17 00:00:00 2001 From: Mitchell Gale Date: Wed, 16 Aug 2023 11:33:00 -0700 Subject: [PATCH 3/4] Update protocol/src/main/java/org/opensearch/sql/protocol/response/format/RawResponseFormatter.java Co-authored-by: Yury-Fridlyand Signed-off-by: Mitchell Gale --- .../sql/protocol/response/format/RawResponseFormatter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/RawResponseFormatter.java b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/RawResponseFormatter.java index 75883073f5..3b64be7062 100644 --- a/protocol/src/main/java/org/opensearch/sql/protocol/response/format/RawResponseFormatter.java +++ b/protocol/src/main/java/org/opensearch/sql/protocol/response/format/RawResponseFormatter.java @@ -6,7 +6,6 @@ package org.opensearch.sql.protocol.response.format; /** Response formatter to format response to csv or raw format. */ -// @RequiredArgsConstructor public class RawResponseFormatter extends FlatResponseFormatter { public RawResponseFormatter() { super("|", false); From 8acc03a58799b818ae7a60bee7fd4d9bdefba570 Mon Sep 17 00:00:00 2001 From: Mitchell Gale Date: Thu, 17 Aug 2023 10:41:05 -0700 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Guian Gumpac Signed-off-by: Mitchell Gale --- .../format/CommandResponseFormatterTest.java | 2 +- .../response/format/CsvResponseFormatterTest.java | 8 ++++---- .../response/format/RawResponseFormatterTest.java | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CommandResponseFormatterTest.java b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CommandResponseFormatterTest.java index 4b20f6b1dc..8e86e47754 100644 --- a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CommandResponseFormatterTest.java +++ b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CommandResponseFormatterTest.java @@ -49,7 +49,7 @@ public void produces_always_same_output_for_any_query_response() { .build())), new Cursor("test_cursor")); - assertEquals("{\n" + " \"succeeded\": true\n" + "}", formatter.format(response)); + assertEquals("{\n \"succeeded\": true\n}", formatter.format(response)); } @Test diff --git a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CsvResponseFormatterTest.java b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CsvResponseFormatterTest.java index 13670dc7d6..d27ac72373 100644 --- a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CsvResponseFormatterTest.java +++ b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CsvResponseFormatterTest.java @@ -68,7 +68,7 @@ void sanitizeHeaders() { "Seattle", "@age", 20)))); - String expected = "'=firstname,'+lastname,'-city,'@age%n" + "John,Smith,Seattle,20"; + String expected = "'=firstname,'+lastname,'-city,'@age%nJohn,Smith,Seattle,20"; assertEquals(format(expected), formatter.format(response)); } @@ -109,7 +109,7 @@ void quoteIfRequired() { new QueryResult( schema, Arrays.asList(tupleValue(ImmutableMap.of("na,me", "John,Smith", ",,age", "30,,,")))); - String expected = "\"na,me\",\",,age\"%n" + "\"John,Smith\",\"30,,,\""; + String expected = "\"na,me\",\",,age\"%n\"John,Smith\",\"30,,,\""; assertEquals(format(expected), formatter.format(response)); } @@ -133,7 +133,7 @@ void escapeSanitize() { Arrays.asList( tupleValue(ImmutableMap.of("city", "=Seattle")), tupleValue(ImmutableMap.of("city", ",,Seattle")))); - String expected = "city%n" + "=Seattle%n" + "\",,Seattle\""; + String expected = "city%n=Seattle%n\",,Seattle\""; assertEquals(format(expected), escapeFormatter.format(response)); } @@ -153,7 +153,7 @@ void replaceNullValues() { ImmutableMap.of("firstname", LITERAL_NULL, "city", stringValue("Seattle"))), ExprTupleValue.fromExprValueMap( ImmutableMap.of("firstname", stringValue("John"), "city", LITERAL_MISSING)))); - String expected = "name,city%n" + "John,Seattle%n" + ",Seattle%n" + "John,"; + String expected = "name,city%nJohn,Seattle%n,Seattle%nJohn,"; assertEquals(format(expected), formatter.format(response)); } diff --git a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/RawResponseFormatterTest.java b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/RawResponseFormatterTest.java index af0ab1947b..65111bd3b9 100644 --- a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/RawResponseFormatterTest.java +++ b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/RawResponseFormatterTest.java @@ -67,7 +67,7 @@ void sanitizeHeaders() { "Seattle", "@age", 20)))); - String expected = "=firstname|+lastname|-city|@age%n" + "John|Smith|Seattle|20"; + String expected = "=firstname|+lastname|-city|@age%nJohn|Smith|Seattle|20"; assertEquals(format(expected), rawFormatter.format(response)); } @@ -108,7 +108,7 @@ void quoteIfRequired() { new QueryResult( schema, Arrays.asList(tupleValue(ImmutableMap.of("na|me", "John|Smith", "||age", "30|||")))); - String expected = "\"na|me\"|\"||age\"%n" + "\"John|Smith\"|\"30|||\""; + String expected = "\"na|me\"|\"||age\"%n\"John|Smith\"|\"30|||\""; assertEquals(format(expected), rawFormatter.format(response)); } @@ -132,7 +132,7 @@ void escapeSanitize() { Arrays.asList( tupleValue(ImmutableMap.of("city", "=Seattle")), tupleValue(ImmutableMap.of("city", "||Seattle")))); - String expected = "city%n" + "=Seattle%n" + "\"||Seattle\""; + String expected = "city%n=Seattle%n\"||Seattle\""; assertEquals(format(expected), escapeFormatter.format(response)); } @@ -147,7 +147,7 @@ void senstiveCharater() { Arrays.asList( tupleValue(ImmutableMap.of("city", "@Seattle")), tupleValue(ImmutableMap.of("city", "++Seattle")))); - String expected = "city%n" + "@Seattle%n" + "++Seattle"; + String expected = "city%n@Seattle%n++Seattle"; assertEquals(format(expected), rawFormatter.format(response)); } @@ -163,7 +163,7 @@ void senstiveCharaterWithSanitize() { Arrays.asList( tupleValue(ImmutableMap.of("city", "@Seattle")), tupleValue(ImmutableMap.of("city", "++Seattle|||")))); - String expected = "city%n" + "@Seattle%n" + "\"++Seattle|||\""; + String expected = "city%n@Seattle%n\"++Seattle|||\""; assertEquals(format(expected), testFormater.format(response)); } @@ -183,7 +183,7 @@ void replaceNullValues() { ImmutableMap.of("firstname", LITERAL_NULL, "city", stringValue("Seattle"))), ExprTupleValue.fromExprValueMap( ImmutableMap.of("firstname", stringValue("John"), "city", LITERAL_MISSING)))); - String expected = "name|city%n" + "John|Seattle%n" + "|Seattle%n" + "John|"; + String expected = "name|city%nJohn|Seattle%n|Seattle%nJohn|"; assertEquals(format(expected), rawFormatter.format(response)); }