diff --git a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java index 87ed7a2922..17aa76557f 100644 --- a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java +++ b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java @@ -246,7 +246,6 @@ private DefaultFunctionResolver date() { return define(BuiltinFunctionName.DATE.getName(), impl(nullMissingHandling(DateTimeFunction::exprDate), DATE, STRING), impl(nullMissingHandling(DateTimeFunction::exprDate), DATE, DATE), - impl(nullMissingHandling(DateTimeFunction::exprDate), DATE, TIME), impl(nullMissingHandling(DateTimeFunction::exprDate), DATE, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprDate), DATE, TIMESTAMP)); } @@ -652,9 +651,6 @@ private ExprValue exprConvertTZ(ExprValue startingDateTime, ExprValue fromTz, Ex * @return ExprValue. */ private ExprValue exprDate(ExprValue exprValue) { - if (exprValue.type() == TIME) { - return new ExprDateValue(LocalDate.now()); - } if (exprValue instanceof ExprStringValue) { try { return new ExprDateValue(exprValue.stringValue()); diff --git a/core/src/main/java/org/opensearch/sql/utils/DateTimeFormatters.java b/core/src/main/java/org/opensearch/sql/utils/DateTimeFormatters.java index 53aa479115..2556aed8d8 100644 --- a/core/src/main/java/org/opensearch/sql/utils/DateTimeFormatters.java +++ b/core/src/main/java/org/opensearch/sql/utils/DateTimeFormatters.java @@ -124,7 +124,7 @@ public class DateTimeFormatters { public static final DateTimeFormatter DATE_TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL = new DateTimeFormatterBuilder() - .appendPattern("[uuuu-MM-dd HH:mm:ss][HH:mm:ss][uuuu-MM-dd]") + .appendPattern("[uuuu-MM-dd HH:mm:ss][uuuu-MM-dd HH:mm][HH:mm:ss][HH:mm][uuuu-MM-dd]") .appendFraction( ChronoField.NANO_OF_SECOND, MIN_FRACTION_SECONDS, diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java index 7cfb7a372a..9e8f31aa71 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java @@ -247,9 +247,10 @@ public void date() { assertEquals(new ExprDateValue("2020-08-17 12:12:00"), eval(expr)); assertEquals("date(DATE '2020-08-17')", expr.toString()); - expr = dsl.date(dsl.time(DSL.literal("12:12:00"))); + expr = dsl.date(DSL.literal(new ExprDateValue("2020-08-17 12:12"))); assertEquals(DATE, expr.type()); - assertEquals(new ExprDateValue(LocalDate.now()), expr.valueOf(null)); + assertEquals(new ExprDateValue("2020-08-17 12:12"), eval(expr)); + assertEquals("date(DATE '2020-08-17')", expr.toString()); expr = dsl.date(DSL.literal("2020-02-30")); assertEquals(nullValue(), expr.valueOf(null)); @@ -809,11 +810,21 @@ public void time() { assertEquals(new ExprTimeValue("01:01:01"), eval(expr)); assertEquals("time(TIME '01:01:01')", expr.toString()); + expr = dsl.time(DSL.literal(new ExprTimeValue("01:01"))); + assertEquals(TIME, expr.type()); + assertEquals(new ExprTimeValue("01:01"), eval(expr)); + assertEquals("time(TIME '01:01')", expr.toString()); + expr = dsl.time(DSL.literal(new ExprTimeValue("2019-04-19 01:01:01"))); assertEquals(TIME, expr.type()); assertEquals(new ExprTimeValue("2019-04-19 01:01:01"), eval(expr)); assertEquals("time(TIME '01:01:01')", expr.toString()); + expr = dsl.time(DSL.literal(new ExprTimeValue("2019-04-19 01:01"))); + assertEquals(TIME, expr.type()); + assertEquals(new ExprTimeValue("2019-04-19 01:01"), eval(expr)); + assertEquals("time(TIME '01:01')", expr.toString()); + expr = dsl.time(DSL.literal(new ExprTimeValue("01:01:01.0123"))); assertEquals(TIME, expr.type()); assertEquals(new ExprTimeValue("01:01:01.0123"), eval(expr));