Skip to content

Commit

Permalink
spotlessApply
Browse files Browse the repository at this point in the history
Signed-off-by: currantw <[email protected]>
  • Loading branch information
currantw committed Dec 5, 2024
1 parent 5aca49d commit 85c47d1
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -948,8 +950,7 @@ private DefaultFunctionResolver timestampdiff() {
TIMESTAMP,
TIMESTAMP),
implWithProperties(
nullMissingHandlingWithProperties(
DateTimeFunctions::exprTimestampDiffForTimeType),
nullMissingHandlingWithProperties(DateTimeFunctions::exprTimestampDiffForTimeType),
TIMESTAMP,
STRING,
TIME,
Expand Down Expand Up @@ -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");
};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@ private DefaultFunctionResolver concat() {
@Override
public ExprValue valueOf(Environment<Expression, ExprValue> valueEnv) {
List<ExprValue> 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();
}
Expand Down Expand Up @@ -310,7 +308,8 @@ private DefaultFunctionResolver locate() {
BuiltinFunctionName.LOCATE.getName(),
impl(
nullMissingHandling(
(SerializableBiFunction<ExprValue, ExprValue, ExprValue>) TextFunctions::exprLocate),
(SerializableBiFunction<ExprValue, ExprValue, ExprValue>)
TextFunctions::exprLocate),
INTEGER,
STRING,
STRING),
Expand All @@ -337,7 +336,8 @@ private DefaultFunctionResolver position() {
BuiltinFunctionName.POSITION.getName(),
impl(
nullMissingHandling(
(SerializableBiFunction<ExprValue, ExprValue, ExprValue>) TextFunctions::exprLocate),
(SerializableBiFunction<ExprValue, ExprValue, ExprValue>)
TextFunctions::exprLocate),
INTEGER,
STRING,
STRING));
Expand Down Expand Up @@ -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) {
Expand Down
30 changes: 15 additions & 15 deletions core/src/test/java/org/opensearch/sql/utils/ComparisonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
};
}
}
72 changes: 36 additions & 36 deletions integ-test/src/test/java/org/opensearch/sql/legacy/CursorIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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));
}
Expand All @@ -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 <a href="https://github.com/opendistro-for-elasticsearch/sql/pull/367">PR #367</a
* <pre>
* 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
* </pre>
*/
With pagination, the field should be date formatted to MySQL format as in
@see <a href="https://github.com/opendistro-for-elasticsearch/sql/pull/367">PR #367</a
* <pre>
* 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
* </pre>
*/
List<String> actualDateList = new ArrayList<>();
String selectQuery =
StringUtils.format("SELECT login_time FROM %s LIMIT 500", TEST_INDEX_DATE_TIME);
Expand Down Expand Up @@ -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();
}
Expand All @@ -387,7 +387,7 @@ public void invalidCursorIdNotDecodable() throws IOException {

Response response = null;
try {
executeCursorQuery(randomCursor);
executeCursorQuery(randomCursor);
} catch (ResponseException ex) {
response = ex.getResponse();
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

/**
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -262,15 +262,15 @@ private static Map<String, String> fieldAliasMap(JSONObject json) {
}

private static List<Schema.Column> 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());
}
}

0 comments on commit 85c47d1

Please sign in to comment.