Skip to content

Commit

Permalink
Removed changes introduced to support JDK8
Browse files Browse the repository at this point in the history
Signed-off-by: vamsi-amazon <[email protected]>
  • Loading branch information
vmmusings committed Mar 24, 2022
1 parent 6771968 commit adbcb70
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 71 deletions.
6 changes: 1 addition & 5 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ jacocoTestCoverageVerification {
rule {
element = 'CLASS'
excludes = [
'org.opensearch.sql.utils.MLCommonsConstants',
'org.opensearch.sql.expression.datetime.DateTimeFormatterUtil',
'org.opensearch.sql.expression.DSL',
'org.opensearch.sql.expression.datetime.CalendarLookup'

'org.opensearch.sql.utils.MLCommonsConstants'
]
limit {
counter = 'LINE'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ private FunctionResolver substr() {
*/
private FunctionResolver ltrim() {
return define(BuiltinFunctionName.LTRIM.getName(),
impl(nullMissingHandling((v) -> new ExprStringValue(v.stringValue().replaceAll(
"^\\s+", ""))),
impl(nullMissingHandling((v) -> new ExprStringValue(v.stringValue().stripLeading())),
STRING, STRING));
}

Expand All @@ -98,8 +97,7 @@ private FunctionResolver ltrim() {
*/
private FunctionResolver rtrim() {
return define(BuiltinFunctionName.RTRIM.getName(),
impl(nullMissingHandling((v) -> new ExprStringValue(v.stringValue().replaceAll(
"\\s+$", ""))),
impl(nullMissingHandling((v) -> new ExprStringValue(v.stringValue().stripTrailing())),
STRING, STRING));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.google.common.collect.ImmutableMap;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.opensearch.sql.data.model.ExprValue;
Expand All @@ -19,42 +18,6 @@

public class AggregationTest extends ExpressionTestBase {

static Map<String, Object> testTupleValue1 = new HashMap<String, Object>() {{
put("integer_value", 1);
put("long_value", 1L);
put("string_value", "f");
put("double_value", 1d);
put("float_value", 1f);
put("date_value", "2020-01-01");
put("datetime_value", "2020-01-01 00:00:00");
put("time_value", "00:00:00");
put("timestamp_value", "2020-01-01 00:00:00");
}};

static Map<String, Object> testTupleValue2 = new HashMap<String, Object>() {{
put("integer_value", 3);
put("long_value", 3L);
put("string_value", "m");
put("double_value", 3d);
put("float_value", 3f);
put("date_value", "1970-01-01");
put("datetime_value", "1970-01-01 19:00:00");
put("time_value", "19:00:00");
put("timestamp_value", "1970-01-01 19:00:00");
}};

static Map<String, Object> testTupleValue3 = new HashMap<String, Object>() {{
put("integer_value", 4);
put("long_value", 4L);
put("string_value", "n");
put("double_value", 4d);
put("float_value", 4f);
put("date_value", "2040-01-01");
put("datetime_value", "2040-01-01 07:00:00");
put("time_value", "07:00:00");
put("timestamp_value", "2040-01-01 07:00:00");
}};

protected static List<ExprValue> tuples =
Arrays.asList(
ExprValueUtils.tupleValue(
Expand All @@ -72,9 +35,66 @@ public class AggregationTest extends ExpressionTestBase {
.put("time_value", "12:00:00")
.put("timestamp_value", "2020-01-01 12:00:00")
.build()),
ExprValueUtils.tupleValue(testTupleValue1),
ExprValueUtils.tupleValue(testTupleValue2),
ExprValueUtils.tupleValue(testTupleValue3));
ExprValueUtils.tupleValue(
Map.of(
"integer_value",
1,
"long_value",
1L,
"string_value",
"f",
"double_value",
1d,
"float_value",
1f,
"date_value",
"2020-01-01",
"datetime_value",
"2020-01-01 00:00:00",
"time_value",
"00:00:00",
"timestamp_value",
"2020-01-01 00:00:00")),
ExprValueUtils.tupleValue(
Map.of(
"integer_value",
3,
"long_value",
3L,
"string_value",
"m",
"double_value",
3d,
"float_value",
3f,
"date_value",
"1970-01-01",
"datetime_value",
"1970-01-01 19:00:00",
"time_value",
"19:00:00",
"timestamp_value",
"1970-01-01 19:00:00")),
ExprValueUtils.tupleValue(
Map.of(
"integer_value",
4,
"long_value",
4L,
"string_value",
"n",
"double_value",
4d,
"float_value",
4f,
"date_value",
"2040-01-01",
"datetime_value",
"2040-01-01 07:00:00",
"time_value",
"07:00:00",
"timestamp_value",
"2040-01-01 07:00:00")));

protected static List<ExprValue> tuples_with_duplicates =
Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import lombok.AllArgsConstructor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnJre;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
Expand Down Expand Up @@ -74,7 +72,6 @@ public void setup() {
"Saturday","31st","1998","98","Sat","Jan","031","01","31","01","15","6","12345",
"q","%")
),

new DateFormatTester("1999-12-01",
ImmutableList.of("%D"),
ImmutableList.of("1st")
Expand Down Expand Up @@ -961,7 +958,6 @@ public void year() {
assertEquals(integerValue(2020), eval(expression));
}

@DisabledOnJre(JRE.JAVA_8)
@Test
public void date_format() {
dateFormatTesters.forEach(this::testDateFormat);
Expand All @@ -970,6 +966,7 @@ public void date_format() {
+ "%m %p %r %S %s %T %% %P";
String timestampFormatted = "Sat Jan 01 31st 31 31 12345 13 01 01 14 031 13 1 "
+ "January 01 PM 01:14:15 PM 15 15 13:14:15 % P";

FunctionExpression expr = dsl.date_format(DSL.literal(timestamp), DSL.literal(timestampFormat));
assertEquals(STRING, expr.type());
assertEquals(timestampFormatted, eval(expr).stringValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,13 @@ public void trim() {
void ltrimString(String str) {
FunctionExpression expression = dsl.ltrim(DSL.literal(str));
assertEquals(STRING, expression.type());
assertEquals(str.replaceAll("^\\s+", ""), eval(expression).stringValue());
assertEquals(str.stripLeading(), eval(expression).stringValue());
}

void rtrimString(String str) {
FunctionExpression expression = dsl.rtrim(DSL.literal(str));
assertEquals(STRING, expression.type());
assertEquals(str.replaceAll("\\s+$", ""), eval(expression).stringValue());
assertEquals(str.stripTrailing(), eval(expression).stringValue());
}

void trimString(String str) {
Expand Down
12 changes: 6 additions & 6 deletions docs/user/dql/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,13 @@ Return type: DOUBLE

Example::

os> SELECT DEGREES(0)
os> SELECT DEGREES(1.57)
fetched rows / total rows = 1/1
+--------------+
| DEGREES(0) |
|--------------|
| 0.0 |
+--------------+
+-------------------+
| DEGREES(1.57) |
|-------------------|
| 89.95437383553924 |
+-------------------+


DIVIDE
Expand Down
12 changes: 6 additions & 6 deletions docs/user/ppl/functions/math.rst
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,13 @@ Return type: DOUBLE

Example::

os> source=people | eval `DEGREES(0)` = DEGREES(0) | fields `DEGREES(0)`
os> source=people | eval `DEGREES(1.57)` = DEGREES(1.57) | fields `DEGREES(1.57)`
fetched rows / total rows = 1/1
+--------------+
| DEGREES(0) |
|--------------|
| 0.0 |
+--------------+
+-------------------+
| DEGREES(1.57) |
|-------------------|
| 89.95437383553924 |
+-------------------+

E
-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.io.IOException;
import org.json.JSONObject;
import org.junit.Ignore;
import org.junit.jupiter.api.Test;
import org.opensearch.sql.common.utils.StringUtils;

Expand Down Expand Up @@ -435,7 +434,6 @@ void verifyDateFormat(String date, String type, String format, String formatted)
verifySome(result.getJSONArray("datarows"), rows(formatted));
}

@Ignore
@Test
public void testDateFormat() throws IOException {
String timestamp = "1998-01-31 13:14:15.012345";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.io.IOException;
import java.util.Locale;
import org.json.JSONObject;
import org.junit.Ignore;
import org.junit.jupiter.api.Test;
import org.opensearch.client.Request;
import org.opensearch.client.RequestOptions;
Expand Down Expand Up @@ -438,7 +437,6 @@ void verifyDateFormat(String date, String type, String format, String formatted)
verifyDataRows(result, rows(formatted));
}

@Ignore
@Test
public void testDateFormat() throws IOException {
String timestamp = "1998-01-31 13:14:15.012345";
Expand Down

0 comments on commit adbcb70

Please sign in to comment.