From 85c47d197ed45b27855cec18ddb9e32a992c2ebc Mon Sep 17 00:00:00 2001 From: currantw Date: Thu, 5 Dec 2024 12:15:47 -0800 Subject: [PATCH] spotlessApply Signed-off-by: currantw --- .../datetime/DateTimeFunctions.java | 38 +++++----- .../sql/expression/text/TextFunctions.java | 12 ++-- .../opensearch/sql/utils/ComparisonUtil.java | 30 ++++---- .../org/opensearch/sql/legacy/CursorIT.java | 72 +++++++++---------- .../sql/legacy/cursor/DefaultCursor.java | 28 ++++---- 5 files changed, 90 insertions(+), 90 deletions(-) diff --git a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunctions.java b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunctions.java index 083387eb1c..f23a4c9411 100644 --- a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunctions.java +++ b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunctions.java @@ -615,7 +615,10 @@ private FunctionResolver from_unixtime() { BuiltinFunctionName.FROM_UNIXTIME.getName(), impl(nullMissingHandling(DateTimeFunctions::exprFromUnixTime), TIMESTAMP, DOUBLE), impl( - nullMissingHandling(DateTimeFunctions::exprFromUnixTimeFormat), STRING, DOUBLE, STRING)); + nullMissingHandling(DateTimeFunctions::exprFromUnixTimeFormat), + STRING, + DOUBLE, + STRING)); } private DefaultFunctionResolver get_format() { @@ -833,8 +836,7 @@ private DefaultFunctionResolver str_to_date() { return define( BuiltinFunctionName.STR_TO_DATE.getName(), implWithProperties( - nullMissingHandlingWithProperties( - DateTimeFunctions::exprStrToDate), + nullMissingHandlingWithProperties(DateTimeFunctions::exprStrToDate), TIMESTAMP, STRING, STRING)); @@ -948,8 +950,7 @@ private DefaultFunctionResolver timestampdiff() { TIMESTAMP, TIMESTAMP), implWithProperties( - nullMissingHandlingWithProperties( - DateTimeFunctions::exprTimestampDiffForTimeType), + nullMissingHandlingWithProperties(DateTimeFunctions::exprTimestampDiffForTimeType), TIMESTAMP, STRING, TIME, @@ -2023,24 +2024,23 @@ private DateTimeFormatter getFormatter(int dateAsInt) { } // Check below from YYYYMMDD - MMDD which format should be used - return switch (length) { - // Check if dateAsInt is at least 8 digits long - case FULL_DATE_LENGTH -> DATE_FORMATTER_LONG_YEAR; - - // Check if dateAsInt is at least 6 digits long - case SHORT_DATE_LENGTH -> DATE_FORMATTER_SHORT_YEAR; + return switch (length) { + // Check if dateAsInt is at least 8 digits long + case FULL_DATE_LENGTH -> DATE_FORMATTER_LONG_YEAR; - // Check if dateAsInt is at least 5 digits long - case SINGLE_DIGIT_YEAR_DATE_LENGTH -> DATE_FORMATTER_SINGLE_DIGIT_YEAR; + // Check if dateAsInt is at least 6 digits long + case SHORT_DATE_LENGTH -> DATE_FORMATTER_SHORT_YEAR; - // Check if dateAsInt is at least 4 digits long - case NO_YEAR_DATE_LENGTH -> DATE_FORMATTER_NO_YEAR; + // Check if dateAsInt is at least 5 digits long + case SINGLE_DIGIT_YEAR_DATE_LENGTH -> DATE_FORMATTER_SINGLE_DIGIT_YEAR; - // Check if dateAsInt is at least 3 digits long - case SINGLE_DIGIT_MONTH_DATE_LENGTH -> DATE_FORMATTER_SINGLE_DIGIT_MONTH; - default -> throw new DateTimeException("No Matching Format"); - }; + // Check if dateAsInt is at least 4 digits long + case NO_YEAR_DATE_LENGTH -> DATE_FORMATTER_NO_YEAR; + // Check if dateAsInt is at least 3 digits long + case SINGLE_DIGIT_MONTH_DATE_LENGTH -> DATE_FORMATTER_SINGLE_DIGIT_MONTH; + default -> throw new DateTimeException("No Matching Format"); + }; } /** diff --git a/core/src/main/java/org/opensearch/sql/expression/text/TextFunctions.java b/core/src/main/java/org/opensearch/sql/expression/text/TextFunctions.java index ede3220b0c..92e6b53143 100644 --- a/core/src/main/java/org/opensearch/sql/expression/text/TextFunctions.java +++ b/core/src/main/java/org/opensearch/sql/expression/text/TextFunctions.java @@ -182,9 +182,7 @@ private DefaultFunctionResolver concat() { @Override public ExprValue valueOf(Environment valueEnv) { List exprValues = - args.stream() - .map(arg -> arg.valueOf(valueEnv)) - .toList(); + args.stream().map(arg -> arg.valueOf(valueEnv)).toList(); if (exprValues.stream().anyMatch(ExprValue::isMissing)) { return ExprValueUtils.missingValue(); } @@ -310,7 +308,8 @@ private DefaultFunctionResolver locate() { BuiltinFunctionName.LOCATE.getName(), impl( nullMissingHandling( - (SerializableBiFunction) TextFunctions::exprLocate), + (SerializableBiFunction) + TextFunctions::exprLocate), INTEGER, STRING, STRING), @@ -337,7 +336,8 @@ private DefaultFunctionResolver position() { BuiltinFunctionName.POSITION.getName(), impl( nullMissingHandling( - (SerializableBiFunction) TextFunctions::exprLocate), + (SerializableBiFunction) + TextFunctions::exprLocate), INTEGER, STRING, STRING)); @@ -417,7 +417,7 @@ private static ExprValue exprLeft(ExprValue expr, ExprValue length) { private static ExprValue exprAscii(ExprValue expr) { return new ExprIntegerValue( - expr.stringValue().isEmpty() ? 0 : (int) expr.stringValue().charAt(0)); + expr.stringValue().isEmpty() ? 0 : (int) expr.stringValue().charAt(0)); } private static ExprValue exprLocate(ExprValue subStr, ExprValue str) { diff --git a/core/src/test/java/org/opensearch/sql/utils/ComparisonUtil.java b/core/src/test/java/org/opensearch/sql/utils/ComparisonUtil.java index 470e09b84a..c908242a65 100644 --- a/core/src/test/java/org/opensearch/sql/utils/ComparisonUtil.java +++ b/core/src/test/java/org/opensearch/sql/utils/ComparisonUtil.java @@ -46,20 +46,20 @@ public static int compare(ExprValue v1, ExprValue v2) { "invalid to call compare operation on values of different types"); } - return switch ((ExprCoreType) v1.type()) { - case BYTE -> v1.byteValue().compareTo(v2.byteValue()); - case SHORT -> v1.shortValue().compareTo(v2.shortValue()); - case INTEGER -> getIntegerValue(v1).compareTo(getIntegerValue(v2)); - case LONG -> getLongValue(v1).compareTo(getLongValue(v2)); - case FLOAT -> getFloatValue(v1).compareTo(getFloatValue(v2)); - case DOUBLE -> getDoubleValue(v1).compareTo(getDoubleValue(v2)); - case STRING -> getStringValue(v1).compareTo(getStringValue(v2)); - case BOOLEAN -> v1.booleanValue().compareTo(v2.booleanValue()); - case TIME -> v1.timeValue().compareTo(v2.timeValue()); - case DATE -> v1.dateValue().compareTo(v2.dateValue()); - case TIMESTAMP -> v1.timestampValue().compareTo(v2.timestampValue()); - default -> throw new ExpressionEvaluationException( - String.format("%s instances are not comparable", v1.getClass().getSimpleName())); - }; + return switch ((ExprCoreType) v1.type()) { + case BYTE -> v1.byteValue().compareTo(v2.byteValue()); + case SHORT -> v1.shortValue().compareTo(v2.shortValue()); + case INTEGER -> getIntegerValue(v1).compareTo(getIntegerValue(v2)); + case LONG -> getLongValue(v1).compareTo(getLongValue(v2)); + case FLOAT -> getFloatValue(v1).compareTo(getFloatValue(v2)); + case DOUBLE -> getDoubleValue(v1).compareTo(getDoubleValue(v2)); + case STRING -> getStringValue(v1).compareTo(getStringValue(v2)); + case BOOLEAN -> v1.booleanValue().compareTo(v2.booleanValue()); + case TIME -> v1.timeValue().compareTo(v2.timeValue()); + case DATE -> v1.dateValue().compareTo(v2.dateValue()); + case TIMESTAMP -> v1.timestampValue().compareTo(v2.timestampValue()); + default -> throw new ExpressionEvaluationException( + String.format("%s instances are not comparable", v1.getClass().getSimpleName())); + }; } } diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/CursorIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/CursorIT.java index 282f5611cc..8120ae29c8 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/CursorIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/CursorIT.java @@ -51,7 +51,7 @@ public void invalidNegativeFetchSize() throws IOException { StringUtils.format("SELECT firstname, state FROM %s", TestsConstants.TEST_INDEX_ACCOUNT); Response response = null; try { - executeFetchQuery(query, -2, JDBC); + executeFetchQuery(query, -2, JDBC); } catch (ResponseException ex) { response = ex.getResponse(); } @@ -70,7 +70,7 @@ public void invalidNonNumericFetchSize() throws IOException { StringUtils.format("SELECT firstname, state FROM %s", TestsConstants.TEST_INDEX_ACCOUNT); Response response = null; try { - executeFetchAsStringQuery(query, "hello world", JDBC); + executeFetchAsStringQuery(query, "hello world", JDBC); } catch (ResponseException ex) { response = ex.getResponse(); } @@ -88,7 +88,7 @@ public void testExceptionOnCursorExplain() throws IOException { Request sqlRequest = getSqlRequest(cursorRequest, true); Response response = null; try { - executeRequest(sqlRequest); + executeRequest(sqlRequest); } catch (ResponseException ex) { response = ex.getResponse(); } @@ -222,25 +222,25 @@ public void noCursorWhenResultsLessThanFetchSize() throws IOException { public void testCursorWithPreparedStatement() throws IOException { JSONObject response = executeJDBCRequest( - "{" - + "\"fetch_size\": 200," - + "\"query\": \" SELECT age, state FROM %s WHERE age > ? OR state IN (?, ?)\"," - + "\"parameters\": [" - + " {" - + " \"type\": \"integer\"," - + " \"value\": 25" - + " }," - + " {" - + " \"type\": \"string\"," - + " \"value\": \"WA\"" - + " }," - + " {" - + " \"type\": \"string\"," - + " \"value\": \"UT\"" - + " }" - + "]" - + "}" - + TestsConstants.TEST_INDEX_ACCOUNT); + "{" + + "\"fetch_size\": 200," + + "\"query\": \" SELECT age, state FROM %s WHERE age > ? OR state IN (?, ?)\"," + + "\"parameters\": [" + + " {" + + " \"type\": \"integer\"," + + " \"value\": 25" + + " }," + + " {" + + " \"type\": \"string\"," + + " \"value\": \"WA\"" + + " }," + + " {" + + " \"type\": \"string\"," + + " \"value\": \"UT\"" + + " }" + + "]" + + "}" + + TestsConstants.TEST_INDEX_ACCOUNT); assertTrue(response.has(CURSOR)); verifyIsV1Cursor(response.getString(CURSOR)); } @@ -249,17 +249,17 @@ public void testCursorWithPreparedStatement() throws IOException { public void testRegressionOnDateFormatChange() throws IOException { loadIndex(Index.DATETIME); /* - With pagination, the field should be date formatted to MySQL format as in - - @see PR #367 - * TEST_INDEX_DATE_TIME has three docs with login_time as date field with following values - * 1.2015-01-01 - * 2.2015-01-01T12:10:30Z - * 3.1585882955 - * 4.2020-04-08T11:10:30+05:00 - * - */ + With pagination, the field should be date formatted to MySQL format as in + + @see PR #367 + * TEST_INDEX_DATE_TIME has three docs with login_time as date field with following values + * 1.2015-01-01 + * 2.2015-01-01T12:10:30Z + * 3.1585882955 + * 4.2020-04-08T11:10:30+05:00 + * + */ List actualDateList = new ArrayList<>(); String selectQuery = StringUtils.format("SELECT login_time FROM %s LIMIT 500", TEST_INDEX_DATE_TIME); @@ -367,7 +367,7 @@ public void testCursorCloseAPI() throws IOException { // using the cursor after its cleared, will throw exception Response response = null; try { - executeCursorQuery(cursor); + executeCursorQuery(cursor); } catch (ResponseException ex) { response = ex.getResponse(); } @@ -387,7 +387,7 @@ public void invalidCursorIdNotDecodable() throws IOException { Response response = null; try { - executeCursorQuery(randomCursor); + executeCursorQuery(randomCursor); } catch (ResponseException ex) { response = ex.getResponse(); } @@ -508,7 +508,7 @@ public String executeFetchAsStringQuery(String query, String fetchSize, String r sqlRequest.setJsonEntity(requestBody); Response response = client().performRequest(sqlRequest); - return getResponseBody(response, true); + return getResponseBody(response, true); } private void verifyIsV1Cursor(String cursor) { diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/cursor/DefaultCursor.java b/legacy/src/main/java/org/opensearch/sql/legacy/cursor/DefaultCursor.java index 39006f66c1..35dd341202 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/cursor/DefaultCursor.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/cursor/DefaultCursor.java @@ -62,7 +62,7 @@ public class DefaultCursor implements Cursor { private static final String SCHEMA_COLUMNS = "c"; private static final String FIELD_ALIAS_MAP = "a"; private static final String PIT_ID = "p"; - private static final String SORT_FIELDS = "h"; + private static final String SORT_FIELDS = "h"; private static final ObjectMapper objectMapper = new ObjectMapper(); /** @@ -174,9 +174,9 @@ private boolean isCursorIdNullOrEmpty() { } public static DefaultCursor from(String cursorId) { - /** - * It is assumed that cursorId here is the second part of the original cursor passed by the - * client after removing first part which identifies cursor type + /* + It is assumed that cursorId here is the second part of the original cursor passed by the + client after removing first part which identifies cursor type */ JSONObject json = decodeCursor(cursorId); DefaultCursor cursor = new DefaultCursor(); @@ -262,15 +262,15 @@ private static Map fieldAliasMap(JSONObject json) { } private static List getColumnsFromSchema(JSONArray schema) { - return IntStream.range(0, schema.length()) - .mapToObj( - i -> { - JSONObject jsonColumn = schema.getJSONObject(i); - return new Schema.Column( - jsonColumn.getString("name"), - jsonColumn.optString("alias", null), - Schema.Type.valueOf(jsonColumn.getString("type").toUpperCase())); - }) - .collect(Collectors.toList()); + return IntStream.range(0, schema.length()) + .mapToObj( + i -> { + JSONObject jsonColumn = schema.getJSONObject(i); + return new Schema.Column( + jsonColumn.getString("name"), + jsonColumn.optString("alias", null), + Schema.Type.valueOf(jsonColumn.getString("type").toUpperCase())); + }) + .collect(Collectors.toList()); } }