Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 2489 #3442

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import static org.opensearch.sql.data.type.ExprCoreType.STRUCT;
import static org.opensearch.sql.data.type.ExprCoreType.TIME;
import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP;
import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER;
import static org.opensearch.sql.utils.DateTimeFormatters.STRICT_HOUR_MINUTE_SECOND_FORMATTER;
import static org.opensearch.sql.utils.DateTimeFormatters.STRICT_YEAR_MONTH_DAY_FORMATTER;

Expand All @@ -44,6 +43,7 @@
import org.opensearch.common.time.DateFormatter;
import org.opensearch.common.time.DateFormatters;
import org.opensearch.common.time.FormatNames;
import org.opensearch.index.mapper.DateFieldMapper;
import org.opensearch.sql.data.model.ExprBooleanValue;
import org.opensearch.sql.data.model.ExprByteValue;
import org.opensearch.sql.data.model.ExprCollectionValue;
Expand Down Expand Up @@ -262,9 +262,10 @@ private static ExprValue parseDateTimeString(String value, OpenSearchDateType da
DateFormatters.from(STRICT_YEAR_MONTH_DAY_FORMATTER.parse(value)).toLocalDate());
default:
return new ExprTimestampValue(
DateFormatters.from(DATE_TIME_FORMATTER.parse(value)).toInstant());
DateFormatters.from(DateFieldMapper.getDefaultDateTimeFormatter().parse(value))
.toInstant());
}
} catch (DateTimeParseException ignored) {
} catch (DateTimeParseException | IllegalArgumentException ignored) {
// ignored
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class OpenSearchExprValueFactoryTest {
.put("dateV", OpenSearchDateType.of(DATE))
.put("timeV", OpenSearchDateType.of(TIME))
.put("timestampV", OpenSearchDateType.of(TIMESTAMP))
.put("timeonlyV", OpenSearchDateType.of("HH:mm:ss"))
.put("datetimeDefaultV", OpenSearchDateType.of())
.put("dateStringV", OpenSearchDateType.of("date"))
.put("timeStringV", OpenSearchDateType.of("time"))
Expand Down Expand Up @@ -312,10 +313,6 @@ public void constructDatetime() {
assertEquals(
new ExprTimestampValue("2015-01-01 12:10:30"),
tupleValue("{\"timestampV\":\"2015-01-01T12:10:30\"}").get("timestampV")),
() ->
assertEquals(
new ExprTimestampValue("2015-01-01 12:10:30"),
tupleValue("{\"timestampV\":\"2015-01-01 12:10:30\"}").get("timestampV")),
() ->
assertEquals(
new ExprTimestampValue(Instant.ofEpochMilli(1420070400001L)),
Expand Down Expand Up @@ -348,10 +345,6 @@ public void constructDatetime() {
assertEquals(
new ExprTimestampValue("1984-05-10 20:30:40"),
tupleValue("{ \"dateTimeCustomV\" : 19840510203040 }").get("dateTimeCustomV")),
() ->
assertEquals(
new ExprTimestampValue("2015-01-01 12:10:30"),
constructFromObject("timestampV", "2015-01-01 12:10:30")),
() ->
assertEquals(
new ExprTimestampValue(Instant.ofEpochMilli(1420070400001L)),
Expand All @@ -361,7 +354,7 @@ public void constructDatetime() {
() ->
assertEquals(
new ExprTimeValue("19:36:22"),
tupleValue("{\"timestampV\":\"19:36:22\"}").get("timestampV")),
tupleValue("{\"timeonlyV\":\"19:36:22\"}").get("timeonlyV")),

// case: timestamp-formatted field, but it only gets a date: should match a date
() ->
Expand All @@ -384,10 +377,6 @@ public void constructDatetime_fromCustomFormat() {
"Construct TIMESTAMP from \"2015-01-01 12-10-30\" failed, unsupported format.",
exception.getMessage());

assertEquals(
new ExprTimestampValue("2015-01-01 12:10:30"),
constructFromObject("customAndEpochMillisV", "2015-01-01 12:10:30"));

assertEquals(
new ExprTimestampValue("2015-01-01 12:10:30"),
constructFromObject("customAndEpochMillisV", "2015-01-01-12-10-30"));
Expand Down Expand Up @@ -700,7 +689,7 @@ public void constructArrayOfCustomEpochMillisReturnsAll() {
List.of(
new ExprTimestampValue("2015-01-01 12:10:30"),
new ExprTimestampValue("1999-11-09 01:09:44"))),
tupleValue("{\"customAndEpochMillisV\":[\"2015-01-01 12:10:30\",\"1999-11-09 01:09:44\"]}")
tupleValue("{\"customAndEpochMillisV\":[\"2015-01-01-12-10-30\",\"1999-11-09-01-09-44\"]}")
.get("customAndEpochMillisV"));
}

Expand Down
Loading