Skip to content

Commit f52cc8a

Browse files
simplified expr string type timestamp cast, fixed checkstyle failure
Signed-off-by: Matthew Wells <[email protected]>
1 parent 32e4ee7 commit f52cc8a

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

core/src/main/java/org/opensearch/sql/data/model/ExprStringValue.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,9 @@ public Instant timestampValue() {
4040
try {
4141
return new ExprTimestampValue(value).timestampValue();
4242
} catch (SemanticCheckException e) {
43-
try {
44-
return new ExprTimestampValue(
45-
LocalDateTime.of(new ExprDateValue(value).dateValue(), LocalTime.of(0, 0, 0)))
46-
.timestampValue();
47-
} catch (SemanticCheckException exception) {
48-
throw new SemanticCheckException(
49-
String.format(
50-
"timestamp:%s in unsupported format, please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'",
51-
value));
52-
}
43+
return new ExprTimestampValue(
44+
LocalDateTime.of(new ExprDateValue(value).dateValue(), LocalTime.of(0, 0, 0)))
45+
.timestampValue();
5346
}
5447
}
5548

opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilderTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,8 +1628,9 @@ void cast_to_date_in_filter() {
16281628
ref("date_value", DATE), DSL.castDate(literal("2021-11-08")))));
16291629
assertJsonEquals(json, buildQuery(DSL.equal(
16301630
ref("date_value", DATE), DSL.castDate(literal(new ExprDateValue("2021-11-08"))))));
1631-
assertJsonEquals(json, buildQuery(DSL.equal(ref(
1632-
"date_value", DATE), DSL.castDate(literal(new ExprTimestampValue("2021-11-08 17:00:00"))))));
1631+
assertJsonEquals(json, buildQuery(DSL.equal(
1632+
ref("date_value", DATE), DSL.castDate(
1633+
literal(new ExprTimestampValue("2021-11-08 17:00:00"))))));
16331634
}
16341635

16351636
@Test

0 commit comments

Comments
 (0)