diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/format/DateFieldFormatter.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/format/DateFieldFormatter.java index f05d340bad..30994b089d 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/format/DateFieldFormatter.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/format/DateFieldFormatter.java @@ -160,6 +160,7 @@ private Date parseDateString(List formats, String columnOriginalDate) { try { switch (columnFormat) { case "date_optional_time": + case "strict_date_optional_time": parsedDate = DateUtils.parseDate( columnOriginalDate, FORMAT_DOT_KIBANA_SAMPLE_DATA_LOGS_EXCEPTION, diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/format/DateFormat.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/format/DateFormat.java index c3baa0d912..11606de281 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/format/DateFormat.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/format/DateFormat.java @@ -29,6 +29,7 @@ public class DateFormat { static { // Special cases that are parsed separately formatMap.put("date_optional_time", ""); + formatMap.put("strict_date_optional_time", ""); formatMap.put("epoch_millis", ""); formatMap.put("epoch_second", ""); diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/sql/executor/format/DateFieldFormatterTest.java b/src/test/java/com/amazon/opendistroforelasticsearch/sql/executor/format/DateFieldFormatterTest.java index b08dc21959..42a58e966f 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/sql/executor/format/DateFieldFormatterTest.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/sql/executor/format/DateFieldFormatterTest.java @@ -658,6 +658,25 @@ public void testNullDateData() verifyFormatting(columnName, dateFormat, originalDateValue, expectedDateValue); } + @Test + public void testStrictDateOptionalTimeOrEpochMillsShouldPass() + { + String columnName = "date_field"; + String dateFormat = "strict_date_optional_time||epoch_millis"; + + String originalDateValue = "2015-01-01"; + String expectedDateValue = "2015-01-01 00:00:00.000"; + verifyFormatting(columnName, dateFormat, originalDateValue, expectedDateValue); + + originalDateValue = "2015-01-01T12:10:30Z"; + expectedDateValue = "2015-01-01 12:10:30.000"; + verifyFormatting(columnName, dateFormat, originalDateValue, expectedDateValue); + + originalDateValue = "1420070400001"; + expectedDateValue = "2015-01-01 00:00:00.001"; + verifyFormatting(columnName, dateFormat, originalDateValue, expectedDateValue); + } + private void verifyFormatting(String columnName, String dateFormatProperty, String originalDateValue, String expectedDateValue) { List columns = buildColumnList(columnName);