diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprDateValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprDateValue.java index 3f3f67a4fa..c36cd3ea6d 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprDateValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprDateValue.java @@ -6,13 +6,12 @@ package org.opensearch.sql.data.model; import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL; -import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID; import com.google.common.base.Objects; import java.time.Instant; import java.time.LocalDate; -import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; @@ -57,14 +56,9 @@ public LocalTime timeValue() { return LocalTime.of(0, 0, 0); } - @Override - public LocalDateTime datetimeValue() { - return LocalDateTime.of(date, timeValue()); - } - @Override public Instant timestampValue() { - return ZonedDateTime.of(date, timeValue(), UTC_ZONE_ID).toInstant(); + return ZonedDateTime.of(date, timeValue(), ZoneOffset.UTC).toInstant(); } @Override diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprDatetimeValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprDatetimeValue.java deleted file mode 100644 index 305958043f..0000000000 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprDatetimeValue.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.sql.data.model; - -import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_WITH_TZ; -import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID; - -import com.google.common.base.Objects; -import java.time.Instant; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeParseException; -import java.time.temporal.ChronoUnit; -import lombok.RequiredArgsConstructor; -import org.opensearch.sql.data.type.ExprCoreType; -import org.opensearch.sql.data.type.ExprType; -import org.opensearch.sql.exception.SemanticCheckException; - -@RequiredArgsConstructor -public class ExprDatetimeValue extends AbstractExprValue { - private final LocalDateTime datetime; - - /** Constructor with datetime string as input. */ - public ExprDatetimeValue(String datetime) { - try { - this.datetime = LocalDateTime.parse(datetime, DATE_TIME_FORMATTER_WITH_TZ); - } catch (DateTimeParseException e) { - throw new SemanticCheckException( - String.format( - "datetime:%s in unsupported format, please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'", - datetime)); - } - } - - @Override - public LocalDateTime datetimeValue() { - return datetime; - } - - @Override - public LocalDate dateValue() { - return datetime.toLocalDate(); - } - - @Override - public LocalTime timeValue() { - return datetime.toLocalTime(); - } - - @Override - public Instant timestampValue() { - return ZonedDateTime.of(datetime, UTC_ZONE_ID).toInstant(); - } - - @Override - public boolean isDateTime() { - return true; - } - - @Override - public int compare(ExprValue other) { - return datetime.compareTo(other.datetimeValue()); - } - - @Override - public boolean equal(ExprValue other) { - return datetime.equals(other.datetimeValue()); - } - - @Override - public String value() { - return String.format( - "%s %s", - DateTimeFormatter.ISO_DATE.format(datetime), - DateTimeFormatter.ISO_TIME.format( - (datetime.getNano() == 0) ? datetime.truncatedTo(ChronoUnit.SECONDS) : datetime)); - } - - @Override - public ExprType type() { - return ExprCoreType.DATETIME; - } - - @Override - public String toString() { - return String.format("DATETIME '%s'", value()); - } - - @Override - public int hashCode() { - return Objects.hashCode(datetime); - } -} diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprStringValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprStringValue.java index 7745af62b6..f2e63e986d 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprStringValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprStringValue.java @@ -5,6 +5,7 @@ package org.opensearch.sql.data.model; +import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; @@ -35,27 +36,20 @@ public String stringValue() { } @Override - public LocalDateTime datetimeValue() { + public Instant timestampValue() { try { - return new ExprDatetimeValue(value).datetimeValue(); + return new ExprTimestampValue(value).timestampValue(); } catch (SemanticCheckException e) { - try { - return new ExprDatetimeValue( - LocalDateTime.of(new ExprDateValue(value).dateValue(), LocalTime.of(0, 0, 0))) - .datetimeValue(); - } catch (SemanticCheckException exception) { - throw new SemanticCheckException( - String.format( - "datetime:%s in unsupported format, please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'", - value)); - } + return new ExprTimestampValue( + LocalDateTime.of(new ExprDateValue(value).dateValue(), LocalTime.of(0, 0, 0))) + .timestampValue(); } } @Override public LocalDate dateValue() { try { - return new ExprDatetimeValue(value).dateValue(); + return new ExprTimestampValue(value).dateValue(); } catch (SemanticCheckException e) { return new ExprDateValue(value).dateValue(); } @@ -64,7 +58,7 @@ public LocalDate dateValue() { @Override public LocalTime timeValue() { try { - return new ExprDatetimeValue(value).timeValue(); + return new ExprTimestampValue(value).timeValue(); } catch (SemanticCheckException e) { return new ExprTimeValue(value).timeValue(); } diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java index d808af49b1..6b5a4a7c48 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java @@ -7,12 +7,11 @@ import static java.time.format.DateTimeFormatter.ISO_LOCAL_TIME; import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL; -import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID; import java.time.Instant; import java.time.LocalDate; -import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.format.DateTimeParseException; import java.util.Objects; @@ -57,12 +56,8 @@ public LocalDate dateValue(FunctionProperties functionProperties) { return LocalDate.now(functionProperties.getQueryStartClock()); } - public LocalDateTime datetimeValue(FunctionProperties functionProperties) { - return LocalDateTime.of(dateValue(functionProperties), timeValue()); - } - public Instant timestampValue(FunctionProperties functionProperties) { - return ZonedDateTime.of(dateValue(functionProperties), timeValue(), UTC_ZONE_ID).toInstant(); + return ZonedDateTime.of(dateValue(functionProperties), timeValue(), ZoneOffset.UTC).toInstant(); } @Override diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprTimestampValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprTimestampValue.java index 455a379b03..e103dc7253 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprTimestampValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprTimestampValue.java @@ -7,12 +7,12 @@ import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_VARIABLE_NANOS; import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_WITHOUT_NANO; -import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.ZoneOffset; import java.time.format.DateTimeParseException; import java.time.temporal.ChronoUnit; import java.util.Objects; @@ -32,7 +32,7 @@ public ExprTimestampValue(String timestamp) { try { this.timestamp = LocalDateTime.parse(timestamp, DATE_TIME_FORMATTER_VARIABLE_NANOS) - .atZone(UTC_ZONE_ID) + .atZone(ZoneOffset.UTC) .toInstant(); } catch (DateTimeParseException e) { throw new SemanticCheckException( @@ -42,13 +42,18 @@ public ExprTimestampValue(String timestamp) { } } + /** localDateTime Constructor. */ + public ExprTimestampValue(LocalDateTime localDateTime) { + this.timestamp = localDateTime.atZone(ZoneOffset.UTC).toInstant(); + } + @Override public String value() { return timestamp.getNano() == 0 ? DATE_TIME_FORMATTER_WITHOUT_NANO - .withZone(UTC_ZONE_ID) + .withZone(ZoneOffset.UTC) .format(timestamp.truncatedTo(ChronoUnit.SECONDS)) - : DATE_TIME_FORMATTER_VARIABLE_NANOS.withZone(UTC_ZONE_ID).format(timestamp); + : DATE_TIME_FORMATTER_VARIABLE_NANOS.withZone(ZoneOffset.UTC).format(timestamp); } @Override @@ -63,17 +68,12 @@ public Instant timestampValue() { @Override public LocalDate dateValue() { - return timestamp.atZone(UTC_ZONE_ID).toLocalDate(); + return timestamp.atZone(ZoneOffset.UTC).toLocalDate(); } @Override public LocalTime timeValue() { - return timestamp.atZone(UTC_ZONE_ID).toLocalTime(); - } - - @Override - public LocalDateTime datetimeValue() { - return timestamp.atZone(UTC_ZONE_ID).toLocalDateTime(); + return timestamp.atZone(ZoneOffset.UTC).toLocalTime(); } @Override @@ -88,12 +88,12 @@ public String toString() { @Override public int compare(ExprValue other) { - return timestamp.compareTo(other.timestampValue().atZone(UTC_ZONE_ID).toInstant()); + return timestamp.compareTo(other.timestampValue().atZone(ZoneOffset.UTC).toInstant()); } @Override public boolean equal(ExprValue other) { - return timestamp.equals(other.timestampValue().atZone(UTC_ZONE_ID).toInstant()); + return timestamp.equals(other.timestampValue().atZone(ZoneOffset.UTC).toInstant()); } @Override diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprValue.java index 86bead77b7..034ed22a75 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprValue.java @@ -8,7 +8,6 @@ import java.io.Serializable; import java.time.Instant; import java.time.LocalDate; -import java.time.LocalDateTime; import java.time.LocalTime; import java.time.temporal.TemporalAmount; import java.util.List; @@ -133,12 +132,6 @@ default LocalDate dateValue() { "invalid to get dateValue from value of type " + type()); } - /** Get datetime value. */ - default LocalDateTime datetimeValue() { - throw new ExpressionEvaluationException( - "invalid to get datetimeValue from value of type " + type()); - } - /** Get interval value. */ default TemporalAmount intervalValue() { throw new ExpressionEvaluationException( diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprValueUtils.java b/core/src/main/java/org/opensearch/sql/data/model/ExprValueUtils.java index a259eb9fba..20813045f2 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprValueUtils.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprValueUtils.java @@ -9,6 +9,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.ZoneOffset; import java.time.temporal.TemporalAmount; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -66,10 +67,6 @@ public static ExprValue dateValue(LocalDate value) { return new ExprDateValue(value); } - public static ExprValue datetimeValue(LocalDateTime value) { - return new ExprDatetimeValue(value); - } - public static ExprValue timeValue(LocalTime value) { return new ExprTimeValue(value); } @@ -128,14 +125,14 @@ public static ExprValue fromObjectValue(Object o) { return floatValue((Float) o); } else if (o instanceof LocalDate) { return dateValue((LocalDate) o); - } else if (o instanceof LocalDateTime) { - return datetimeValue((LocalDateTime) o); } else if (o instanceof LocalTime) { return timeValue((LocalTime) o); } else if (o instanceof Instant) { return timestampValue((Instant) o); } else if (o instanceof TemporalAmount) { return intervalValue((TemporalAmount) o); + } else if (o instanceof LocalDateTime) { + return timestampValue(((LocalDateTime) o).toInstant(ZoneOffset.UTC)); } else { throw new ExpressionEvaluationException("unsupported object " + o.getClass()); } @@ -150,8 +147,6 @@ public static ExprValue fromObjectValue(Object o, ExprCoreType type) { return new ExprDateValue((String) o); case TIME: return new ExprTimeValue((String) o); - case DATETIME: - return new ExprDatetimeValue((String) o); default: return fromObjectValue(o); } diff --git a/core/src/main/java/org/opensearch/sql/data/type/ExprCoreType.java b/core/src/main/java/org/opensearch/sql/data/type/ExprCoreType.java index f1979d8666..cbc0c98255 100644 --- a/core/src/main/java/org/opensearch/sql/data/type/ExprCoreType.java +++ b/core/src/main/java/org/opensearch/sql/data/type/ExprCoreType.java @@ -42,8 +42,7 @@ public enum ExprCoreType implements ExprType { /** Date. */ DATE(STRING), TIME(STRING), - DATETIME(STRING, DATE, TIME), - TIMESTAMP(STRING, DATETIME), + TIMESTAMP(STRING, DATE, TIME), INTERVAL(UNDEFINED), /** Struct. */ diff --git a/core/src/main/java/org/opensearch/sql/expression/DSL.java b/core/src/main/java/org/opensearch/sql/expression/DSL.java index 4341668b69..12a7faafb2 100644 --- a/core/src/main/java/org/opensearch/sql/expression/DSL.java +++ b/core/src/main/java/org/opensearch/sql/expression/DSL.java @@ -819,10 +819,6 @@ public static FunctionExpression castTimestamp(Expression value) { return compile(FunctionProperties.None, BuiltinFunctionName.CAST_TO_TIMESTAMP, value); } - public static FunctionExpression castDatetime(Expression value) { - return compile(FunctionProperties.None, BuiltinFunctionName.CAST_TO_DATETIME, value); - } - public static FunctionExpression typeof(Expression value) { return compile(FunctionProperties.None, BuiltinFunctionName.TYPEOF, value); } diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunction.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunction.java index 4a1d4d309b..bfc92d73c6 100644 --- a/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunction.java +++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunction.java @@ -7,7 +7,6 @@ import static org.opensearch.sql.data.type.ExprCoreType.ARRAY; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; import static org.opensearch.sql.data.type.ExprCoreType.FLOAT; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; @@ -71,9 +70,6 @@ private static DefaultFunctionResolver avg() { .put( new FunctionSignature(functionName, Collections.singletonList(DATE)), (functionProperties, arguments) -> new AvgAggregator(arguments, DATE)) - .put( - new FunctionSignature(functionName, Collections.singletonList(DATETIME)), - (functionProperties, arguments) -> new AvgAggregator(arguments, DATETIME)) .put( new FunctionSignature(functionName, Collections.singletonList(TIME)), (functionProperties, arguments) -> new AvgAggregator(arguments, TIME)) @@ -142,9 +138,6 @@ private static DefaultFunctionResolver min() { .put( new FunctionSignature(functionName, Collections.singletonList(DATE)), (functionProperties, arguments) -> new MinAggregator(arguments, DATE)) - .put( - new FunctionSignature(functionName, Collections.singletonList(DATETIME)), - (functionProperties, arguments) -> new MinAggregator(arguments, DATETIME)) .put( new FunctionSignature(functionName, Collections.singletonList(TIME)), (functionProperties, arguments) -> new MinAggregator(arguments, TIME)) @@ -177,9 +170,6 @@ private static DefaultFunctionResolver max() { .put( new FunctionSignature(functionName, Collections.singletonList(DATE)), (functionProperties, arguments) -> new MaxAggregator(arguments, DATE)) - .put( - new FunctionSignature(functionName, Collections.singletonList(DATETIME)), - (functionProperties, arguments) -> new MaxAggregator(arguments, DATETIME)) .put( new FunctionSignature(functionName, Collections.singletonList(TIME)), (functionProperties, arguments) -> new MaxAggregator(arguments, TIME)) diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/AvgAggregator.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/AvgAggregator.java index c528968018..c32ebb6071 100644 --- a/core/src/main/java/org/opensearch/sql/expression/aggregation/AvgAggregator.java +++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/AvgAggregator.java @@ -13,7 +13,6 @@ import java.util.List; import java.util.Locale; import org.opensearch.sql.data.model.ExprDateValue; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprDoubleValue; import org.opensearch.sql.data.model.ExprIntegerValue; import org.opensearch.sql.data.model.ExprNullValue; @@ -47,8 +46,6 @@ public AvgState create() { switch (dataType) { case DATE: return new DateAvgState(); - case DATETIME: - return new DateTimeAvgState(); case TIMESTAMP: return new TimestampAvgState(); case TIME: @@ -128,28 +125,6 @@ protected AvgState iterate(ExprValue value) { } } - protected static class DateTimeAvgState extends AvgState { - @Override - public ExprValue result() { - if (0 == count.integerValue()) { - return ExprNullValue.of(); - } - - return new ExprDatetimeValue( - new ExprTimestampValue( - Instant.ofEpochMilli( - DSL.divide(DSL.literal(total), DSL.literal(count)).valueOf().longValue())) - .datetimeValue()); - } - - @Override - protected AvgState iterate(ExprValue value) { - total = - DSL.add(DSL.literal(total), DSL.literal(value.timestampValue().toEpochMilli())).valueOf(); - return super.iterate(value); - } - } - protected static class TimestampAvgState extends AvgState { @Override public ExprValue result() { diff --git a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java index 13f9a077e4..d23cbc2df3 100644 --- a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java +++ b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java @@ -12,6 +12,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; import java.time.format.ResolverStyle; @@ -21,9 +22,9 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprNullValue; import org.opensearch.sql.data.model.ExprStringValue; +import org.opensearch.sql.data.model.ExprTimestampValue; import org.opensearch.sql.data.model.ExprValue; import org.opensearch.sql.expression.function.FunctionProperties; @@ -245,12 +246,12 @@ static ExprValue getFormattedString( /** * Format the date using the date format String. * - * @param dateExpr the date ExprValue of Date/Datetime/Timestamp/String type. + * @param dateExpr the date ExprValue of Date/Timestamp/String type. * @param formatExpr the format ExprValue of String type. * @return Date formatted using format and returned as a String. */ static ExprValue getFormattedDate(ExprValue dateExpr, ExprValue formatExpr) { - final LocalDateTime date = dateExpr.datetimeValue(); + final LocalDateTime date = dateExpr.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime(); return getFormattedString(formatExpr, DATE_HANDLERS, date); } @@ -364,7 +365,7 @@ static ExprValue parseStringWithDateOrTime( output = LocalDateTime.of(year, month, day, hour, minute, second); } - return new ExprDatetimeValue(output); + return new ExprTimestampValue(output); } /** 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 d17d59d358..a42a599ad8 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 @@ -14,7 +14,6 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; import static org.opensearch.sql.data.type.ExprCoreType.FLOAT; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; @@ -41,9 +40,8 @@ import static org.opensearch.sql.utils.DateTimeFormatters.SHORT_DATE_LENGTH; import static org.opensearch.sql.utils.DateTimeFormatters.SINGLE_DIGIT_MONTH_DATE_LENGTH; import static org.opensearch.sql.utils.DateTimeFormatters.SINGLE_DIGIT_YEAR_DATE_LENGTH; -import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID; import static org.opensearch.sql.utils.DateTimeUtils.extractDate; -import static org.opensearch.sql.utils.DateTimeUtils.extractDateTime; +import static org.opensearch.sql.utils.DateTimeUtils.extractTimestamp; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableTable; @@ -74,13 +72,13 @@ import lombok.experimental.UtilityClass; import org.apache.commons.lang3.tuple.Pair; import org.opensearch.sql.data.model.ExprDateValue; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprDoubleValue; import org.opensearch.sql.data.model.ExprIntegerValue; import org.opensearch.sql.data.model.ExprLongValue; import org.opensearch.sql.data.model.ExprNullValue; import org.opensearch.sql.data.model.ExprStringValue; import org.opensearch.sql.data.model.ExprTimeValue; +import org.opensearch.sql.data.model.ExprTimestampValue; import org.opensearch.sql.data.model.ExprValue; import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.exception.ExpressionEvaluationException; @@ -110,7 +108,7 @@ public class DateTimeFunction { // The number of days from year zero to year 1970. private static final Long DAYS_0000_TO_1970 = (146097 * 5L) - (30L * 365L + 7L); - // MySQL doesn't process any datetime/timestamp values which are greater than + // MySQL doesn't process any timestamp values which are greater than // 32536771199.999999, or equivalent '3001-01-18 23:59:59.999999' UTC private static final Double MYSQL_MAX_TIMESTAMP = 32536771200d; @@ -150,11 +148,6 @@ public class DateTimeFunction { .put("date", "iso", "%Y-%m-%d") .put("date", "eur", "%d.%m.%Y") .put("date", "internal", "%Y%m%d") - .put("datetime", "usa", "%Y-%m-%d %H.%i.%s") - .put("datetime", "jis", "%Y-%m-%d %H:%i:%s") - .put("datetime", "iso", "%Y-%m-%d %H:%i:%s") - .put("datetime", "eur", "%Y-%m-%d %H.%i.%s") - .put("datetime", "internal", "%Y%m%d%H%i%s") .put("time", "usa", "%h:%i:%s %p") .put("time", "jis", "%H:%i:%s") .put("time", "iso", "%H:%i:%s") @@ -255,8 +248,8 @@ private FunctionResolver now(FunctionName functionName) { functionName, implWithProperties( functionProperties -> - new ExprDatetimeValue(formatNow(functionProperties.getQueryStartClock())), - DATETIME)); + new ExprTimestampValue(formatNow(functionProperties.getQueryStartClock())), + TIMESTAMP)); } private FunctionResolver now() { @@ -280,12 +273,12 @@ private FunctionResolver sysdate() { return define( BuiltinFunctionName.SYSDATE.getName(), implWithProperties( - functionProperties -> new ExprDatetimeValue(formatNow(Clock.systemDefaultZone())), - DATETIME), + functionProperties -> new ExprTimestampValue(formatNow(Clock.systemDefaultZone())), + TIMESTAMP), FunctionDSL.implWithProperties( (functionProperties, v) -> - new ExprDatetimeValue(formatNow(Clock.systemDefaultZone(), v.integerValue())), - DATETIME, + new ExprTimestampValue(formatNow(Clock.systemDefaultZone(), v.integerValue())), + TIMESTAMP, INTEGER)); } @@ -329,37 +322,34 @@ private FunctionResolver current_date() { * Specify a start date and add/subtract a temporal amount to/from the date.
* The return type depends on the date type and the interval unit. Detailed supported signatures: *
- * (DATE/DATETIME/TIMESTAMP/TIME, INTERVAL) -> DATETIME
+ * (DATE/TIMESTAMP/TIME, INTERVAL) -> TIMESTAMP
* MySQL has these signatures too
* (DATE, INTERVAL) -> DATE // when interval has no time part
* (TIME, INTERVAL) -> TIME // when interval has no date part
- * (STRING, INTERVAL) -> STRING // when argument has date or datetime string,
- * // result has date or datetime depending on interval type
+ * (STRING, INTERVAL) -> STRING // when argument has date or timestamp string,
+ * // result has date or timestamp depending on interval type
*/ private Stream> get_date_add_date_sub_signatures( SerializableTriFunction function) { return Stream.of( - implWithProperties(nullMissingHandlingWithProperties(function), DATETIME, DATE, INTERVAL), - implWithProperties( - nullMissingHandlingWithProperties(function), DATETIME, DATETIME, INTERVAL), + implWithProperties(nullMissingHandlingWithProperties(function), TIMESTAMP, DATE, INTERVAL), implWithProperties( - nullMissingHandlingWithProperties(function), DATETIME, TIMESTAMP, INTERVAL), - implWithProperties(nullMissingHandlingWithProperties(function), DATETIME, TIME, INTERVAL)); + nullMissingHandlingWithProperties(function), TIMESTAMP, TIMESTAMP, INTERVAL), + implWithProperties(nullMissingHandlingWithProperties(function), TIMESTAMP, TIME, INTERVAL)); } /** * A common signature for `adddate` and `subdate`.
* Adds/subtracts an integer number of days to/from the first argument.
* (DATE, LONG) -> DATE
- * (TIME/DATETIME/TIMESTAMP, LONG) -> DATETIME + * (TIME/TIMESTAMP, LONG) -> TIMESTAMP */ private Stream> get_adddate_subdate_signatures( SerializableTriFunction function) { return Stream.of( implWithProperties(nullMissingHandlingWithProperties(function), DATE, DATE, LONG), - implWithProperties(nullMissingHandlingWithProperties(function), DATETIME, DATETIME, LONG), - implWithProperties(nullMissingHandlingWithProperties(function), DATETIME, TIMESTAMP, LONG), - implWithProperties(nullMissingHandlingWithProperties(function), DATETIME, TIME, LONG)); + implWithProperties(nullMissingHandlingWithProperties(function), TIMESTAMP, TIMESTAMP, LONG), + implWithProperties(nullMissingHandlingWithProperties(function), TIMESTAMP, TIME, LONG)); } private DefaultFunctionResolver adddate() { @@ -374,8 +364,8 @@ private DefaultFunctionResolver adddate() { /** * Adds expr2 to expr1 and returns the result.
- * (TIME, TIME/DATE/DATETIME/TIMESTAMP) -> TIME
- * (DATE/DATETIME/TIMESTAMP, TIME/DATE/DATETIME/TIMESTAMP) -> DATETIME
+ * (TIME, TIME/DATE/TIMESTAMP) -> TIME
+ * (DATE/TIMESTAMP, TIME/DATE/TIMESTAMP) -> TIMESTAMP
* TODO: MySQL has these signatures too
* (STRING, STRING/TIME) -> STRING // second arg - string with time only
* (x, STRING) -> NULL // second arg - string with timestamp
@@ -388,8 +378,6 @@ private DefaultFunctionResolver addtime() { nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), TIME, TIME, TIME), implWithProperties( nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), TIME, TIME, DATE), - implWithProperties( - nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), TIME, TIME, DATETIME), implWithProperties( nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), TIME, @@ -397,56 +385,32 @@ private DefaultFunctionResolver addtime() { TIMESTAMP), implWithProperties( nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, - DATETIME, + TIMESTAMP, + DATE, TIME), implWithProperties( nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, - DATETIME, - DATE), - implWithProperties( - nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, - DATETIME, - DATETIME), - implWithProperties( - nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, - DATETIME, - TIMESTAMP), - implWithProperties( - nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), DATETIME, DATE, TIME), - implWithProperties( - nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), DATETIME, DATE, DATE), - implWithProperties( - nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, + TIMESTAMP, DATE, - DATETIME), + DATE), implWithProperties( nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, + TIMESTAMP, DATE, TIMESTAMP), implWithProperties( nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, + TIMESTAMP, TIMESTAMP, TIME), implWithProperties( nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, + TIMESTAMP, TIMESTAMP, DATE), implWithProperties( nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, TIMESTAMP, - DATETIME), - implWithProperties( - nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), - DATETIME, TIMESTAMP, TIMESTAMP)); } @@ -454,21 +418,21 @@ private DefaultFunctionResolver addtime() { /** * Converts date/time from a specified timezone to another specified timezone.
* The supported signatures:
- * (DATETIME, STRING, STRING) -> DATETIME
- * (STRING, STRING, STRING) -> DATETIME + * (TIMESTAMP, STRING, STRING) -> TIMESTAMP
+ * (STRING, STRING, STRING) -> TIMESTAMP */ private DefaultFunctionResolver convert_tz() { return define( BuiltinFunctionName.CONVERT_TZ.getName(), impl( nullMissingHandling(DateTimeFunction::exprConvertTZ), - DATETIME, - DATETIME, + TIMESTAMP, + TIMESTAMP, STRING, STRING), impl( nullMissingHandling(DateTimeFunction::exprConvertTZ), - DATETIME, + TIMESTAMP, STRING, STRING, STRING)); @@ -476,41 +440,25 @@ private DefaultFunctionResolver convert_tz() { /** * Extracts the date part of a date and time value. Also to construct a date type. The supported - * signatures: STRING/DATE/DATETIME/TIMESTAMP -> DATE + * signatures: STRING/DATE/TIMESTAMP -> DATE */ 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, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprDate), DATE, TIMESTAMP)); } - /* - * Calculates the difference of date part of given values. - * (DATE/DATETIME/TIMESTAMP/TIME, DATE/DATETIME/TIMESTAMP/TIME) -> LONG + /** + * Calculates the difference of date part of given values.
+ * (DATE/TIMESTAMP/TIME, DATE/TIMESTAMP/TIME) -> LONG */ private DefaultFunctionResolver datediff() { return define( BuiltinFunctionName.DATEDIFF.getName(), implWithProperties( nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), LONG, DATE, DATE), - implWithProperties( - nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, - DATETIME, - DATE), - implWithProperties( - nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, - DATE, - DATETIME), - implWithProperties( - nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, - DATETIME, - DATETIME), implWithProperties( nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), LONG, DATE, TIME), implWithProperties( @@ -541,40 +489,20 @@ private DefaultFunctionResolver datediff() { nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), LONG, TIME, - TIMESTAMP), - implWithProperties( - nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, - TIMESTAMP, - DATETIME), - implWithProperties( - nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, - DATETIME, - TIMESTAMP), - implWithProperties( - nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, - TIME, - DATETIME), - implWithProperties( - nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), - LONG, - DATETIME, - TIME)); + TIMESTAMP)); } /** * Specify a datetime with time zone field and a time zone to convert to.
- * Returns a local date time.
- * (STRING, STRING) -> DATETIME
- * (STRING) -> DATETIME + * Returns a local datetime.
+ * (STRING, STRING) -> TIMESTAMP
+ * (STRING) -> TIMESTAMP */ private FunctionResolver datetime() { return define( BuiltinFunctionName.DATETIME.getName(), - impl(nullMissingHandling(DateTimeFunction::exprDateTime), DATETIME, STRING, STRING), - impl(nullMissingHandling(DateTimeFunction::exprDateTimeNoTimezone), DATETIME, STRING)); + impl(nullMissingHandling(DateTimeFunction::exprDateTime), TIMESTAMP, STRING, STRING), + impl(nullMissingHandling(DateTimeFunction::exprDateTimeNoTimezone), TIMESTAMP, STRING)); } private DefaultFunctionResolver date_add() { @@ -593,30 +521,28 @@ private DefaultFunctionResolver date_sub() { .toArray(SerializableFunction[]::new)); } - /** DAY(STRING/DATE/DATETIME/TIMESTAMP). return the day of the month (1-31). */ + /** DAY(STRING/DATE/TIMESTAMP). return the day of the month (1-31). */ private DefaultFunctionResolver day() { return define( BuiltinFunctionName.DAY.getName(), impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, DATE), - impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, TIMESTAMP), impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, STRING)); } /** - * DAYNAME(STRING/DATE/DATETIME/TIMESTAMP). return the name of the weekday for date, including + * DAYNAME(STRING/DATE/TIMESTAMP). return the name of the weekday for date, including
* Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. */ private DefaultFunctionResolver dayName() { return define( BuiltinFunctionName.DAYNAME.getName(), impl(nullMissingHandling(DateTimeFunction::exprDayName), STRING, DATE), - impl(nullMissingHandling(DateTimeFunction::exprDayName), STRING, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprDayName), STRING, TIMESTAMP), impl(nullMissingHandling(DateTimeFunction::exprDayName), STRING, STRING)); } - /** DAYOFMONTH(STRING/DATE/DATETIME/TIMESTAMP). return the day of the month (1-31). */ + /** DAYOFMONTH(STRING/DATE/TIMESTAMP). return the day of the month (1-31). */ private DefaultFunctionResolver dayOfMonth(BuiltinFunctionName name) { return define( name.getName(), @@ -627,14 +553,13 @@ private DefaultFunctionResolver dayOfMonth(BuiltinFunctionName name) { INTEGER, TIME), impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, DATE), - impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, STRING), impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, TIMESTAMP)); } /** - * DAYOFWEEK(STRING/DATE/DATETIME/TIME/TIMESTAMP). return the weekday index for date (1 = Sunday, - * 2 = Monday, ..., 7 = Saturday). + * DAYOFWEEK(STRING/DATE/TIME/TIMESTAMP). return the weekday index for date (1 = Sunday, 2 = + * Monday, ..., 7 = Saturday). */ private DefaultFunctionResolver dayOfWeek(FunctionName name) { return define( @@ -646,12 +571,11 @@ private DefaultFunctionResolver dayOfWeek(FunctionName name) { INTEGER, TIME), impl(nullMissingHandling(DateTimeFunction::exprDayOfWeek), INTEGER, DATE), - impl(nullMissingHandling(DateTimeFunction::exprDayOfWeek), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprDayOfWeek), INTEGER, TIMESTAMP), impl(nullMissingHandling(DateTimeFunction::exprDayOfWeek), INTEGER, STRING)); } - /** DAYOFYEAR(STRING/DATE/DATETIME/TIMESTAMP). return the day of the year for date (1-366). */ + /** DAYOFYEAR(STRING/DATE/TIMESTAMP). return the day of the year for date (1-366). */ private DefaultFunctionResolver dayOfYear(BuiltinFunctionName dayOfYear) { return define( dayOfYear.getName(), @@ -662,7 +586,6 @@ private DefaultFunctionResolver dayOfYear(BuiltinFunctionName dayOfYear) { INTEGER, TIME), impl(nullMissingHandling(DateTimeFunction::exprDayOfYear), INTEGER, DATE), - impl(nullMissingHandling(DateTimeFunction::exprDayOfYear), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprDayOfYear), INTEGER, TIMESTAMP), impl(nullMissingHandling(DateTimeFunction::exprDayOfYear), INTEGER, STRING)); } @@ -676,7 +599,6 @@ private DefaultFunctionResolver extract() { STRING, TIME), impl(nullMissingHandling(DateTimeFunction::exprExtract), LONG, STRING, DATE), - impl(nullMissingHandling(DateTimeFunction::exprExtract), LONG, STRING, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprExtract), LONG, STRING, TIMESTAMP), impl(nullMissingHandling(DateTimeFunction::exprExtract), LONG, STRING, STRING)); } @@ -691,7 +613,7 @@ private DefaultFunctionResolver from_days() { private FunctionResolver from_unixtime() { return define( BuiltinFunctionName.FROM_UNIXTIME.getName(), - impl(nullMissingHandling(DateTimeFunction::exprFromUnixTime), DATETIME, DOUBLE), + impl(nullMissingHandling(DateTimeFunction::exprFromUnixTime), TIMESTAMP, DOUBLE), impl( nullMissingHandling(DateTimeFunction::exprFromUnixTimeFormat), STRING, DOUBLE, STRING)); } @@ -702,14 +624,13 @@ private DefaultFunctionResolver get_format() { impl(nullMissingHandling(DateTimeFunction::exprGetFormat), STRING, STRING, STRING)); } - /** HOUR(STRING/TIME/DATETIME/DATE/TIMESTAMP). return the hour value for time. */ + /** HOUR(STRING/TIME/DATE/TIMESTAMP). return the hour value for time. */ private DefaultFunctionResolver hour(BuiltinFunctionName name) { return define( name.getName(), impl(nullMissingHandling(DateTimeFunction::exprHour), INTEGER, STRING), impl(nullMissingHandling(DateTimeFunction::exprHour), INTEGER, TIME), impl(nullMissingHandling(DateTimeFunction::exprHour), INTEGER, DATE), - impl(nullMissingHandling(DateTimeFunction::exprHour), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprHour), INTEGER, TIMESTAMP)); } @@ -724,7 +645,6 @@ private DefaultFunctionResolver last_day() { DATE, TIME), impl(nullMissingHandling(DateTimeFunction::exprLastDay), DATE, DATE), - impl(nullMissingHandling(DateTimeFunction::exprLastDay), DATE, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprLastDay), DATE, TIMESTAMP)); } @@ -740,39 +660,36 @@ private FunctionResolver maketime() { impl(nullMissingHandling(DateTimeFunction::exprMakeTime), TIME, DOUBLE, DOUBLE, DOUBLE)); } - /** MICROSECOND(STRING/TIME/DATETIME/TIMESTAMP). return the microsecond value for time. */ + /** MICROSECOND(STRING/TIME/TIMESTAMP). return the microsecond value for time. */ private DefaultFunctionResolver microsecond() { return define( BuiltinFunctionName.MICROSECOND.getName(), impl(nullMissingHandling(DateTimeFunction::exprMicrosecond), INTEGER, STRING), impl(nullMissingHandling(DateTimeFunction::exprMicrosecond), INTEGER, TIME), - impl(nullMissingHandling(DateTimeFunction::exprMicrosecond), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprMicrosecond), INTEGER, TIMESTAMP)); } - /** MINUTE(STRING/TIME/DATETIME/TIMESTAMP). return the minute value for time. */ + /** MINUTE(STRING/TIME/TIMESTAMP). return the minute value for time. */ private DefaultFunctionResolver minute(BuiltinFunctionName name) { return define( name.getName(), impl(nullMissingHandling(DateTimeFunction::exprMinute), INTEGER, STRING), impl(nullMissingHandling(DateTimeFunction::exprMinute), INTEGER, TIME), - impl(nullMissingHandling(DateTimeFunction::exprMinute), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprMinute), INTEGER, DATE), impl(nullMissingHandling(DateTimeFunction::exprMinute), INTEGER, TIMESTAMP)); } - /** MINUTE(STRING/TIME/DATETIME/TIMESTAMP). return the minute value for time. */ + /** MINUTE(STRING/TIME/TIMESTAMP). return the minute value for time. */ private DefaultFunctionResolver minute_of_day() { return define( BuiltinFunctionName.MINUTE_OF_DAY.getName(), impl(nullMissingHandling(DateTimeFunction::exprMinuteOfDay), INTEGER, STRING), impl(nullMissingHandling(DateTimeFunction::exprMinuteOfDay), INTEGER, TIME), impl(nullMissingHandling(DateTimeFunction::exprMinuteOfDay), INTEGER, DATE), - impl(nullMissingHandling(DateTimeFunction::exprMinuteOfDay), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprMinuteOfDay), INTEGER, TIMESTAMP)); } - /** MONTH(STRING/DATE/DATETIME/TIMESTAMP). return the month for date (1-12). */ + /** MONTH(STRING/DATE/TIMESTAMP). return the month for date (1-12). */ private DefaultFunctionResolver month(BuiltinFunctionName month) { return define( month.getName(), @@ -783,17 +700,15 @@ private DefaultFunctionResolver month(BuiltinFunctionName month) { INTEGER, TIME), impl(nullMissingHandling(DateTimeFunction::exprMonth), INTEGER, DATE), - impl(nullMissingHandling(DateTimeFunction::exprMonth), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprMonth), INTEGER, TIMESTAMP), impl(nullMissingHandling(DateTimeFunction::exprMonth), INTEGER, STRING)); } - /** MONTHNAME(STRING/DATE/DATETIME/TIMESTAMP). return the full name of the month for date. */ + /** MONTHNAME(STRING/DATE/TIMESTAMP). return the full name of the month for date. */ private DefaultFunctionResolver monthName() { return define( BuiltinFunctionName.MONTHNAME.getName(), impl(nullMissingHandling(DateTimeFunction::exprMonthName), STRING, DATE), - impl(nullMissingHandling(DateTimeFunction::exprMonthName), STRING, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprMonthName), STRING, TIMESTAMP), impl(nullMissingHandling(DateTimeFunction::exprMonthName), STRING, STRING)); } @@ -819,12 +734,11 @@ private DefaultFunctionResolver period_diff() { impl(nullMissingHandling(DateTimeFunction::exprPeriodDiff), INTEGER, INTEGER, INTEGER)); } - /** QUARTER(STRING/DATE/DATETIME/TIMESTAMP). return the month for date (1-4). */ + /** QUARTER(STRING/DATE/TIMESTAMP). return the month for date (1-4). */ private DefaultFunctionResolver quarter() { return define( BuiltinFunctionName.QUARTER.getName(), impl(nullMissingHandling(DateTimeFunction::exprQuarter), INTEGER, DATE), - impl(nullMissingHandling(DateTimeFunction::exprQuarter), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprQuarter), INTEGER, TIMESTAMP), impl(nullMissingHandling(DateTimeFunction::exprQuarter), INTEGER, STRING)); } @@ -838,14 +752,13 @@ private DefaultFunctionResolver sec_to_time() { impl((nullMissingHandling(DateTimeFunction::exprSecToTimeWithNanos)), TIME, FLOAT)); } - /** SECOND(STRING/TIME/DATETIME/TIMESTAMP). return the second value for time. */ + /** SECOND(STRING/TIME/TIMESTAMP). return the second value for time. */ private DefaultFunctionResolver second(BuiltinFunctionName name) { return define( name.getName(), impl(nullMissingHandling(DateTimeFunction::exprSecond), INTEGER, STRING), impl(nullMissingHandling(DateTimeFunction::exprSecond), INTEGER, TIME), impl(nullMissingHandling(DateTimeFunction::exprSecond), INTEGER, DATE), - impl(nullMissingHandling(DateTimeFunction::exprSecond), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprSecond), INTEGER, TIMESTAMP)); } @@ -861,8 +774,8 @@ private DefaultFunctionResolver subdate() { /** * Subtracts expr2 from expr1 and returns the result.
- * (TIME, TIME/DATE/DATETIME/TIMESTAMP) -> TIME
- * (DATE/DATETIME/TIMESTAMP, TIME/DATE/DATETIME/TIMESTAMP) -> DATETIME
+ * (TIME, TIME/DATE/TIMESTAMP) -> TIME
+ * (DATE/TIMESTAMP, TIME/DATE/TIMESTAMP) -> TIMESTAMP
* TODO: MySQL has these signatures too
* (STRING, STRING/TIME) -> STRING // second arg - string with time only
* (x, STRING) -> NULL // second arg - string with timestamp
@@ -875,8 +788,6 @@ private DefaultFunctionResolver subtime() { nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), TIME, TIME, TIME), implWithProperties( nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), TIME, TIME, DATE), - implWithProperties( - nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), TIME, TIME, DATETIME), implWithProperties( nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), TIME, @@ -884,62 +795,38 @@ private DefaultFunctionResolver subtime() { TIMESTAMP), implWithProperties( nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, - DATETIME, + TIMESTAMP, + TIMESTAMP, TIME), implWithProperties( nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, - DATETIME, + TIMESTAMP, + TIMESTAMP, DATE), implWithProperties( nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, - DATETIME, - DATETIME), - implWithProperties( - nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, - DATETIME, - TIMESTAMP), - implWithProperties( - nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), DATETIME, DATE, TIME), - implWithProperties( - nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), DATETIME, DATE, DATE), - implWithProperties( - nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, - DATE, - DATETIME), - implWithProperties( - nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, - DATE, - TIMESTAMP), - implWithProperties( - nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, TIMESTAMP, + DATE, TIME), implWithProperties( nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, TIMESTAMP, + DATE, DATE), implWithProperties( nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, TIMESTAMP, - DATETIME), + DATE, + TIMESTAMP), implWithProperties( nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), - DATETIME, + TIMESTAMP, TIMESTAMP, TIMESTAMP)); } /** - * Extracts a date, time, or datetime from the given string. It accomplishes this using another + * Extracts a date, time, or timestamp from the given string. It accomplishes this using another * string which specifies the input format. */ private DefaultFunctionResolver str_to_date() { @@ -949,21 +836,20 @@ private DefaultFunctionResolver str_to_date() { nullMissingHandlingWithProperties( (functionProperties, arg, format) -> DateTimeFunction.exprStrToDate(functionProperties, arg, format)), - DATETIME, + TIMESTAMP, STRING, STRING)); } /** * Extracts the time part of a date and time value. Also to construct a time type. The supported - * signatures: STRING/DATE/DATETIME/TIME/TIMESTAMP -> TIME + * signatures: STRING/DATE/TIME/TIMESTAMP -> TIME */ private DefaultFunctionResolver time() { return define( BuiltinFunctionName.TIME.getName(), impl(nullMissingHandling(DateTimeFunction::exprTime), TIME, STRING), impl(nullMissingHandling(DateTimeFunction::exprTime), TIME, DATE), - impl(nullMissingHandling(DateTimeFunction::exprTime), TIME, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprTime), TIME, TIME), impl(nullMissingHandling(DateTimeFunction::exprTime), TIME, TIMESTAMP)); } @@ -973,7 +859,6 @@ private DefaultFunctionResolver time() { * (TIME, TIME) -> TIME
* MySQL has these signatures too
* (DATE, DATE) -> TIME // result is > 24 hours
- * (DATETIME, DATETIME) -> TIME // result is > 24 hours
* (TIMESTAMP, TIMESTAMP) -> TIME // result is > 24 hours
* (x, x) -> NULL // when args have different types
* (STRING, STRING) -> TIME // argument strings contain same types only
@@ -985,23 +870,20 @@ private DefaultFunctionResolver timediff() { impl(nullMissingHandling(DateTimeFunction::exprTimeDiff), TIME, TIME, TIME)); } - /** - * TIME_TO_SEC(STRING/TIME/DATETIME/TIMESTAMP). return the time argument, converted to seconds. - */ + /** TIME_TO_SEC(STRING/TIME/TIMESTAMP). return the time argument, converted to seconds. */ private DefaultFunctionResolver time_to_sec() { return define( BuiltinFunctionName.TIME_TO_SEC.getName(), impl(nullMissingHandling(DateTimeFunction::exprTimeToSec), LONG, STRING), impl(nullMissingHandling(DateTimeFunction::exprTimeToSec), LONG, TIME), - impl(nullMissingHandling(DateTimeFunction::exprTimeToSec), LONG, TIMESTAMP), - impl(nullMissingHandling(DateTimeFunction::exprTimeToSec), LONG, DATETIME)); + impl(nullMissingHandling(DateTimeFunction::exprTimeToSec), LONG, TIMESTAMP)); } /** * Extracts the timestamp of a date and time value.
* Input strings may contain a timestamp only in format 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'
- * STRING/DATE/TIME/DATETIME/TIMESTAMP -> TIMESTAMP
- * STRING/DATE/TIME/DATETIME/TIMESTAMP, STRING/DATE/TIME/DATETIME/TIMESTAMP -> TIMESTAMP
+ * STRING/DATE/TIME/TIMESTAMP -> TIMESTAMP
+ * STRING/DATE/TIME/TIMESTAMP, STRING/DATE/TIME/TIMESTAMP -> TIMESTAMP
* All types are converted to TIMESTAMP actually before the function call - it is responsibility *
* of the automatic cast mechanism defined in `ExprCoreType` and performed by `TypeCastOperator`. @@ -1020,27 +902,20 @@ private DefaultFunctionResolver timestamp() { } /** - * Adds an interval of time to the provided DATE/DATETIME/TIME/TIMESTAMP/STRING argument. The - * interval of time added is determined by the given first and second arguments. The first - * argument is an interval type, and must be one of the tokens below... [MICROSECOND, SECOND, - * MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR] The second argument is the amount of the - * interval type to be added. The third argument is the DATE/DATETIME/TIME/TIMESTAMP/STRING to add - * to. + * Adds an interval of time to the provided DATE/TIME/TIMESTAMP/STRING argument. The interval of + * time added is determined by the given first and second arguments. The first argument is an + * interval type, and must be one of the tokens below... [MICROSECOND, SECOND, MINUTE, HOUR, DAY, + * WEEK, MONTH, QUARTER, YEAR] The second argument is the amount of the interval type to be added. + * The third argument is the DATE/TIME/TIMESTAMP/STRING to add to. * - * @return The DATETIME representing the summed DATE/DATETIME/TIME/TIMESTAMP and interval. + * @return The TIMESTAMP representing the summed DATE/TIME/TIMESTAMP and interval. */ private DefaultFunctionResolver timestampadd() { return define( BuiltinFunctionName.TIMESTAMPADD.getName(), impl( nullMissingHandling(DateTimeFunction::exprTimestampAdd), - DATETIME, - STRING, - INTEGER, - DATETIME), - impl( - nullMissingHandling(DateTimeFunction::exprTimestampAdd), - DATETIME, + TIMESTAMP, STRING, INTEGER, TIMESTAMP), @@ -1049,18 +924,18 @@ private DefaultFunctionResolver timestampadd() { (functionProperties, part, amount, time) -> exprTimestampAddForTimeType( functionProperties.getQueryStartClock(), part, amount, time)), - DATETIME, + TIMESTAMP, STRING, INTEGER, TIME)); } /** - * Finds the difference between provided DATE/DATETIME/TIME/TIMESTAMP/STRING arguments. The first - * argument is an interval type, and must be one of the tokens below... [MICROSECOND, SECOND, - * MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR] The second argument the - * DATE/DATETIME/TIME/TIMESTAMP/STRING representing the start time. The third argument is the - * DATE/DATETIME/TIME/TIMESTAMP/STRING representing the end time. + * Finds the difference between provided DATE/TIME/TIMESTAMP/STRING arguments. The first argument + * is an interval type, and must be one of the tokens below... [MICROSECOND, SECOND, MINUTE, HOUR, + * DAY, WEEK, MONTH, QUARTER, YEAR] The second argument the DATE/TIME/TIMESTAMP/STRING + * representing the start time. The third argument is the DATE/TIME/TIMESTAMP/STRING representing + * the end time. * * @return A LONG representing the difference between arguments, using the given interval type. */ @@ -1069,25 +944,7 @@ private DefaultFunctionResolver timestampdiff() { BuiltinFunctionName.TIMESTAMPDIFF.getName(), impl( nullMissingHandling(DateTimeFunction::exprTimestampDiff), - DATETIME, - STRING, - DATETIME, - DATETIME), - impl( - nullMissingHandling(DateTimeFunction::exprTimestampDiff), - DATETIME, - STRING, - DATETIME, - TIMESTAMP), - impl( - nullMissingHandling(DateTimeFunction::exprTimestampDiff), - DATETIME, - STRING, TIMESTAMP, - DATETIME), - impl( - nullMissingHandling(DateTimeFunction::exprTimestampDiff), - DATETIME, STRING, TIMESTAMP, TIMESTAMP), @@ -1095,20 +952,19 @@ private DefaultFunctionResolver timestampdiff() { nullMissingHandlingWithProperties( (functionProperties, part, startTime, endTime) -> exprTimestampDiffForTimeType(functionProperties, part, startTime, endTime)), - DATETIME, + TIMESTAMP, STRING, TIME, TIME)); } - /** TO_DAYS(STRING/DATE/DATETIME/TIMESTAMP). return the day number of the given date. */ + /** TO_DAYS(STRING/DATE/TIMESTAMP). return the day number of the given date. */ private DefaultFunctionResolver to_days() { return define( BuiltinFunctionName.TO_DAYS.getName(), impl(nullMissingHandling(DateTimeFunction::exprToDays), LONG, STRING), impl(nullMissingHandling(DateTimeFunction::exprToDays), LONG, TIMESTAMP), - impl(nullMissingHandling(DateTimeFunction::exprToDays), LONG, DATE), - impl(nullMissingHandling(DateTimeFunction::exprToDays), LONG, DATETIME)); + impl(nullMissingHandling(DateTimeFunction::exprToDays), LONG, DATE)); } /** @@ -1131,7 +987,6 @@ private FunctionResolver unix_timestamp() { DateTimeFunction.unixTimeStamp(functionProperties.getQueryStartClock()), LONG), impl(nullMissingHandling(DateTimeFunction::unixTimeStampOf), DOUBLE, DATE), - impl(nullMissingHandling(DateTimeFunction::unixTimeStampOf), DOUBLE, DATETIME), impl(nullMissingHandling(DateTimeFunction::unixTimeStampOf), DOUBLE, TIMESTAMP), impl(nullMissingHandling(DateTimeFunction::unixTimeStampOf), DOUBLE, DOUBLE)); } @@ -1154,7 +1009,7 @@ private DefaultFunctionResolver utc_time() { private DefaultFunctionResolver utc_timestamp() { return define( BuiltinFunctionName.UTC_TIMESTAMP.getName(), - implWithProperties(functionProperties -> exprUtcTimeStamp(functionProperties), DATETIME)); + implWithProperties(functionProperties -> exprUtcTimeStamp(functionProperties), TIMESTAMP)); } /** WEEK(DATE[,mode]). return the week number for date. */ @@ -1169,7 +1024,6 @@ private DefaultFunctionResolver week(BuiltinFunctionName week) { INTEGER, TIME), impl(nullMissingHandling(DateTimeFunction::exprWeekWithoutMode), INTEGER, DATE), - impl(nullMissingHandling(DateTimeFunction::exprWeekWithoutMode), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprWeekWithoutMode), INTEGER, TIMESTAMP), impl(nullMissingHandling(DateTimeFunction::exprWeekWithoutMode), INTEGER, STRING), implWithProperties( @@ -1181,7 +1035,6 @@ private DefaultFunctionResolver week(BuiltinFunctionName week) { TIME, INTEGER), impl(nullMissingHandling(DateTimeFunction::exprWeek), INTEGER, DATE, INTEGER), - impl(nullMissingHandling(DateTimeFunction::exprWeek), INTEGER, DATETIME, INTEGER), impl(nullMissingHandling(DateTimeFunction::exprWeek), INTEGER, TIMESTAMP, INTEGER), impl(nullMissingHandling(DateTimeFunction::exprWeek), INTEGER, STRING, INTEGER)); } @@ -1198,17 +1051,15 @@ private DefaultFunctionResolver weekday() { INTEGER, TIME), impl(nullMissingHandling(DateTimeFunction::exprWeekday), INTEGER, DATE), - impl(nullMissingHandling(DateTimeFunction::exprWeekday), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprWeekday), INTEGER, TIMESTAMP), impl(nullMissingHandling(DateTimeFunction::exprWeekday), INTEGER, STRING)); } - /** YEAR(STRING/DATE/DATETIME/TIMESTAMP). return the year for date (1000-9999). */ + /** YEAR(STRING/DATE/TIMESTAMP). return the year for date (1000-9999). */ private DefaultFunctionResolver year() { return define( BuiltinFunctionName.YEAR.getName(), impl(nullMissingHandling(DateTimeFunction::exprYear), INTEGER, DATE), - impl(nullMissingHandling(DateTimeFunction::exprYear), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprYear), INTEGER, TIMESTAMP), impl(nullMissingHandling(DateTimeFunction::exprYear), INTEGER, STRING)); } @@ -1225,7 +1076,6 @@ private DefaultFunctionResolver yearweek() { INTEGER, TIME), impl(nullMissingHandling(DateTimeFunction::exprYearweekWithoutMode), INTEGER, DATE), - impl(nullMissingHandling(DateTimeFunction::exprYearweekWithoutMode), INTEGER, DATETIME), impl(nullMissingHandling(DateTimeFunction::exprYearweekWithoutMode), INTEGER, TIMESTAMP), impl(nullMissingHandling(DateTimeFunction::exprYearweekWithoutMode), INTEGER, STRING), implWithProperties( @@ -1236,7 +1086,6 @@ private DefaultFunctionResolver yearweek() { TIME, INTEGER), impl(nullMissingHandling(DateTimeFunction::exprYearweek), INTEGER, DATE, INTEGER), - impl(nullMissingHandling(DateTimeFunction::exprYearweek), INTEGER, DATETIME, INTEGER), impl(nullMissingHandling(DateTimeFunction::exprYearweek), INTEGER, TIMESTAMP, INTEGER), impl(nullMissingHandling(DateTimeFunction::exprYearweek), INTEGER, STRING, INTEGER)); } @@ -1246,7 +1095,6 @@ private DefaultFunctionResolver yearweek() { * Detailed supported signatures:
* (STRING, STRING) -> STRING
* (DATE, STRING) -> STRING
- * (DATETIME, STRING) -> STRING
* (TIME, STRING) -> STRING
* (TIMESTAMP, STRING) -> STRING */ @@ -1255,8 +1103,6 @@ private DefaultFunctionResolver date_format() { BuiltinFunctionName.DATE_FORMAT.getName(), impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedDate), STRING, STRING, STRING), impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedDate), STRING, DATE, STRING), - impl( - nullMissingHandling(DateTimeFormatterUtil::getFormattedDate), STRING, DATETIME, STRING), implWithProperties( nullMissingHandlingWithProperties( (functionProperties, time, formatString) -> @@ -1299,9 +1145,9 @@ private ExprValue dayOfWeekToday(Clock clock) { * DATE_ADD function implementation for ExprValue. * * @param functionProperties An FunctionProperties object. - * @param datetime ExprValue of Date/Time/Datetime/Timestamp type. + * @param datetime ExprValue of Date/Time/Timestamp type. * @param interval ExprValue of Interval type, the temporal amount to add. - * @return Datetime resulted from `interval` added to `datetime`. + * @return Timestamp resulted from `interval` added to `timestamp`. */ private ExprValue exprAddDateInterval( FunctionProperties functionProperties, ExprValue datetime, ExprValue interval) { @@ -1309,21 +1155,22 @@ private ExprValue exprAddDateInterval( } /** - * Adds or subtracts `interval` to/from `datetime`. + * Adds or subtracts `interval` to/from `timestamp`. * * @param functionProperties An FunctionProperties object. - * @param datetime A Date/Time/Datetime/Timestamp value to change. + * @param datetime A Date/Time/Timestamp value to change. * @param interval An Interval to isAdd or subtract. * @param isAdd A flag: true to isAdd, false to subtract. - * @return Datetime calculated. + * @return Timestamp calculated. */ private ExprValue exprDateApplyInterval( FunctionProperties functionProperties, ExprValue datetime, TemporalAmount interval, Boolean isAdd) { - var dt = extractDateTime(datetime, functionProperties); - return new ExprDatetimeValue(isAdd ? dt.plus(interval) : dt.minus(interval)); + var dt = + extractTimestamp(datetime, functionProperties).atZone(ZoneOffset.UTC).toLocalDateTime(); + return new ExprTimestampValue(isAdd ? dt.plus(interval) : dt.minus(interval)); } /** @@ -1331,7 +1178,6 @@ private ExprValue exprDateApplyInterval( * Detailed supported signatures:
* (STRING, STRING) -> STRING
* (DATE, STRING) -> STRING
- * (DATETIME, STRING) -> STRING
* (TIME, STRING) -> STRING
* (TIMESTAMP, STRING) -> STRING */ @@ -1340,8 +1186,6 @@ private DefaultFunctionResolver time_format() { BuiltinFunctionName.TIME_FORMAT.getName(), impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedTime), STRING, STRING, STRING), impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedTime), STRING, DATE, STRING), - impl( - nullMissingHandling(DateTimeFormatterUtil::getFormattedTime), STRING, DATETIME, STRING), impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedTime), STRING, TIME, STRING), impl( nullMissingHandling(DateTimeFormatterUtil::getFormattedTime), @@ -1354,9 +1198,9 @@ private DefaultFunctionResolver time_format() { * ADDDATE function implementation for ExprValue. * * @param functionProperties An FunctionProperties object. - * @param datetime ExprValue of Time/Date/Datetime/Timestamp type. + * @param datetime ExprValue of Time/Date/Timestamp type. * @param days ExprValue of Long type, representing the number of days to add. - * @return Date/Datetime resulted from days added to `datetime`. + * @return Date/Timestamp resulted from days added to `timestamp`. */ private ExprValue exprAddDateDays( FunctionProperties functionProperties, ExprValue datetime, ExprValue days) { @@ -1364,13 +1208,13 @@ private ExprValue exprAddDateDays( } /** - * Adds or subtracts `days` to/from `datetime`. + * Adds or subtracts `days` to/from `timestamp`. * * @param functionProperties An FunctionProperties object. - * @param datetime A Date/Time/Datetime/Timestamp value to change. + * @param datetime A Date/Time/Timestamp value to change. * @param days A days amount to add or subtract. * @param isAdd A flag: true to add, false to subtract. - * @return Datetime calculated. + * @return Timestamp calculated. */ private ExprValue exprDateApplyDays( FunctionProperties functionProperties, ExprValue datetime, Long days, Boolean isAdd) { @@ -1378,16 +1222,17 @@ private ExprValue exprDateApplyDays( return new ExprDateValue( isAdd ? datetime.dateValue().plusDays(days) : datetime.dateValue().minusDays(days)); } - var dt = extractDateTime(datetime, functionProperties); - return new ExprDatetimeValue(isAdd ? dt.plusDays(days) : dt.minusDays(days)); + var dt = + extractTimestamp(datetime, functionProperties).atZone(ZoneOffset.UTC).toLocalDateTime(); + return new ExprTimestampValue(isAdd ? dt.plusDays(days) : dt.minusDays(days)); } /** * Adds or subtracts time to/from date and returns the result. * * @param functionProperties A FunctionProperties object. - * @param temporal A Date/Time/Datetime/Timestamp value to change. - * @param temporalDelta A Date/Time/Datetime/Timestamp object to add/subtract time from. + * @param temporal A Date/Time/Timestamp value to change. + * @param temporalDelta A Date/Time/Timestamp object to add/subtract time from. * @param isAdd A flag: true to add, false to subtract. * @return A value calculated. */ @@ -1399,19 +1244,19 @@ private ExprValue exprApplyTime( var interval = Duration.between(LocalTime.MIN, temporalDelta.timeValue()); var result = isAdd - ? extractDateTime(temporal, functionProperties).plus(interval) - : extractDateTime(temporal, functionProperties).minus(interval); + ? extractTimestamp(temporal, functionProperties).plus(interval) + : extractTimestamp(temporal, functionProperties).minus(interval); return temporal.type() == TIME - ? new ExprTimeValue(result.toLocalTime()) - : new ExprDatetimeValue(result); + ? new ExprTimeValue(result.atZone(ZoneOffset.UTC).toLocalTime()) + : new ExprTimestampValue(result); } /** * Adds time to date and returns the result. * * @param functionProperties A FunctionProperties object. - * @param temporal A Date/Time/Datetime/Timestamp value to change. - * @param temporalDelta A Date/Time/Datetime/Timestamp object to add time from. + * @param temporal A Date/Time/Timestamp value to change. + * @param temporalDelta A Date/Time/Timestamp object to add time from. * @return A value calculated. */ private ExprValue exprAddTime( @@ -1423,10 +1268,10 @@ private ExprValue exprAddTime( * CONVERT_TZ function implementation for ExprValue. Returns null for time zones outside of +13:00 * and -12:00. * - * @param startingDateTime ExprValue of DateTime that is being converted from + * @param startingDateTime ExprValue of Timestamp that is being converted from * @param fromTz ExprValue of time zone, representing the time to convert from. * @param toTz ExprValue of time zone, representing the time to convert to. - * @return DateTime that has been converted to the to_tz timezone. + * @return Timestamp that has been converted to the to_tz timezone. */ private ExprValue exprConvertTZ(ExprValue startingDateTime, ExprValue fromTz, ExprValue toTz) { if (startingDateTime.type() == ExprCoreType.STRING) { @@ -1442,8 +1287,10 @@ private ExprValue exprConvertTZ(ExprValue startingDateTime, ExprValue fromTz, Ex || !DateTimeUtils.isValidMySqlTimeZoneId(convertedToTz)) { return ExprNullValue.of(); } - ZonedDateTime zonedDateTime = startingDateTime.datetimeValue().atZone(convertedFromTz); - return new ExprDatetimeValue( + ZonedDateTime zonedDateTime = + (startingDateTime.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime()) + .atZone(convertedFromTz); + return new ExprTimestampValue( zonedDateTime.withZoneSameInstant(convertedToTz).toLocalDateTime()); // Catches exception for invalid timezones. @@ -1484,43 +1331,43 @@ private ExprValue exprDateDiff( } /** - * DateTime implementation for ExprValue. + * Timestamp implementation for ExprValue. * - * @param dateTime ExprValue of String type. + * @param timestamp ExprValue of String type. * @param timeZone ExprValue of String type (or null). * @return ExprValue of date type. */ - private ExprValue exprDateTime(ExprValue dateTime, ExprValue timeZone) { + private ExprValue exprDateTime(ExprValue timestamp, ExprValue timeZone) { String defaultTimeZone = TimeZone.getDefault().getID(); try { LocalDateTime ldtFormatted = - LocalDateTime.parse(dateTime.stringValue(), DATE_TIME_FORMATTER_STRICT_WITH_TZ); + LocalDateTime.parse(timestamp.stringValue(), DATE_TIME_FORMATTER_STRICT_WITH_TZ); if (timeZone.isNull()) { - return new ExprDatetimeValue(ldtFormatted); + return new ExprTimestampValue(ldtFormatted); } - // Used if datetime field is invalid format. + // Used if timestamp field is invalid format. } catch (DateTimeParseException e) { return ExprNullValue.of(); } ExprValue convertTZResult; - ExprDatetimeValue ldt; + ExprTimestampValue tz; String toTz; try { ZonedDateTime zdtWithZoneOffset = - ZonedDateTime.parse(dateTime.stringValue(), DATE_TIME_FORMATTER_STRICT_WITH_TZ); + ZonedDateTime.parse(timestamp.stringValue(), DATE_TIME_FORMATTER_STRICT_WITH_TZ); ZoneId fromTZ = zdtWithZoneOffset.getZone(); - ldt = new ExprDatetimeValue(zdtWithZoneOffset.toLocalDateTime()); + tz = new ExprTimestampValue(zdtWithZoneOffset.toLocalDateTime()); toTz = String.valueOf(fromTZ); } catch (DateTimeParseException e) { - ldt = new ExprDatetimeValue(dateTime.stringValue()); + tz = new ExprTimestampValue(timestamp.stringValue()); toTz = defaultTimeZone; } - convertTZResult = exprConvertTZ(ldt, new ExprStringValue(toTz), timeZone); + convertTZResult = exprConvertTZ(tz, new ExprStringValue(toTz), timeZone); return convertTZResult; } @@ -1549,7 +1396,7 @@ private ExprValue exprDayName(ExprValue date) { /** * Day of Month implementation for ExprValue. * - * @param date ExprValue of Date/Datetime/String/Time/Timestamp type. + * @param date ExprValue of Date/String/Time/Timestamp type. * @return ExprValue. */ private ExprValue exprDayOfMonth(ExprValue date) { @@ -1559,7 +1406,7 @@ private ExprValue exprDayOfMonth(ExprValue date) { /** * Day of Week implementation for ExprValue. * - * @param date ExprValue of Date/Datetime/String/Timstamp type. + * @param date ExprValue of Date/String/Timstamp type. * @return ExprValue. */ private ExprValue exprDayOfWeek(ExprValue date) { @@ -1577,15 +1424,15 @@ private ExprValue exprDayOfYear(ExprValue date) { } /** - * Obtains a formatted long value for a specified part and datetime for the 'extract' function. + * Obtains a formatted long value for a specified part and timestamp for the 'extract' function. * * @param part is an ExprValue which comes from a defined list of accepted values. - * @param datetime the date to be formatted as an ExprValue. + * @param timestamp the date to be formatted as an ExprValue. * @return is a LONG formatted according to the input arguments. */ - public ExprLongValue formatExtractFunction(ExprValue part, ExprValue datetime) { + public ExprLongValue formatExtractFunction(ExprValue part, ExprValue timestamp) { String partName = part.stringValue().toUpperCase(); - LocalDateTime arg = datetime.datetimeValue(); + LocalDateTime arg = timestamp.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime(); String text = arg.format(DateTimeFormatter.ofPattern(extract_formats.get(partName), Locale.ENGLISH)); @@ -1596,11 +1443,11 @@ public ExprLongValue formatExtractFunction(ExprValue part, ExprValue datetime) { * Implements extract function. Returns a LONG formatted according to the 'part' argument. * * @param part Literal that determines the format of the outputted LONG. - * @param datetime The date/datetime to be formatted. + * @param timestamp The Date/Timestamp to be formatted. * @return A LONG */ - private ExprValue exprExtract(ExprValue part, ExprValue datetime) { - return formatExtractFunction(part, datetime); + private ExprValue exprExtract(ExprValue part, ExprValue timestamp) { + return formatExtractFunction(part, timestamp); } /** @@ -1613,7 +1460,7 @@ private ExprValue exprExtract(ExprValue part, ExprValue datetime) { private ExprValue exprExtractForTime( FunctionProperties functionProperties, ExprValue part, ExprValue time) { return formatExtractFunction( - part, new ExprDatetimeValue(extractDateTime(time, functionProperties))); + part, new ExprTimestampValue(extractTimestamp(time, functionProperties))); } /** @@ -1637,12 +1484,12 @@ private ExprValue exprFromUnixTime(ExprValue time) { if (MYSQL_MAX_TIMESTAMP <= time.doubleValue()) { return ExprNullValue.of(); } - return new ExprDatetimeValue(exprFromUnixTimeImpl(time)); + return new ExprTimestampValue(exprFromUnixTimeImpl(time)); } private LocalDateTime exprFromUnixTimeImpl(ExprValue time) { return LocalDateTime.ofInstant( - Instant.ofEpochSecond((long) Math.floor(time.doubleValue())), UTC_ZONE_ID) + Instant.ofEpochSecond((long) Math.floor(time.doubleValue())), ZoneOffset.UTC) .withNano((int) ((time.doubleValue() % 1) * 1E9)); } @@ -1694,11 +1541,11 @@ private LocalDate getLastDay(LocalDate today) { /** * Returns a DATE for the last day of the month of a given argument. * - * @param datetime A DATE/DATETIME/TIMESTAMP/STRING ExprValue. + * @param timestamp A DATE/TIMESTAMP/STRING ExprValue. * @return An DATE value corresponding to the last day of the month of the given argument. */ - private ExprValue exprLastDay(ExprValue datetime) { - return new ExprDateValue(getLastDay(datetime.dateValue())); + private ExprValue exprLastDay(ExprValue timestamp) { + return new ExprDateValue(getLastDay(timestamp.dateValue())); } /** @@ -1932,9 +1779,9 @@ private ExprValue exprSecond(ExprValue time) { * SUBDATE function implementation for ExprValue. * * @param functionProperties An FunctionProperties object. - * @param date ExprValue of Time/Date/Datetime/Timestamp type. + * @param date ExprValue of Time/Date/Timestamp type. * @param days ExprValue of Long type, representing the number of days to subtract. - * @return Date/Datetime resulted from days subtracted to date. + * @return Date/Timestamp resulted from days subtracted to date. */ private ExprValue exprSubDateDays( FunctionProperties functionProperties, ExprValue date, ExprValue days) { @@ -1945,9 +1792,9 @@ private ExprValue exprSubDateDays( * DATE_SUB function implementation for ExprValue. * * @param functionProperties An FunctionProperties object. - * @param datetime ExprValue of Time/Date/Datetime/Timestamp type. + * @param datetime ExprValue of Time/Date/Timestamp type. * @param expr ExprValue of Interval type, the temporal amount to subtract. - * @return Datetime resulted from expr subtracted to `datetime`. + * @return Timestamp resulted from expr subtracted to `timestamp`. */ private ExprValue exprSubDateInterval( FunctionProperties functionProperties, ExprValue datetime, ExprValue expr) { @@ -1957,8 +1804,8 @@ private ExprValue exprSubDateInterval( /** * Subtracts expr2 from expr1 and returns the result. * - * @param temporal A Date/Time/Datetime/Timestamp value to change. - * @param temporalDelta A Date/Time/Datetime/Timestamp to subtract time from. + * @param temporal A Date/Time/Timestamp value to change. + * @param temporalDelta A Date/Time/Timestamp to subtract time from. * @return A value calculated. */ private ExprValue exprSubTime( @@ -2012,7 +1859,8 @@ private ExprValue exprTimestampAdd( ExprValue partExpr, ExprValue amountExpr, ExprValue datetimeExpr) { String part = partExpr.stringValue(); int amount = amountExpr.integerValue(); - LocalDateTime datetime = datetimeExpr.datetimeValue(); + LocalDateTime timestamp = + datetimeExpr.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime(); ChronoUnit temporalUnit; switch (part) { @@ -2047,13 +1895,13 @@ private ExprValue exprTimestampAdd( default: return ExprNullValue.of(); } - return new ExprDatetimeValue(datetime.plus(amount, temporalUnit)); + return new ExprTimestampValue(timestamp.plus(amount, temporalUnit)); } private ExprValue exprTimestampAddForTimeType( Clock clock, ExprValue partExpr, ExprValue amountExpr, ExprValue timeExpr) { LocalDateTime datetime = LocalDateTime.of(formatNow(clock).toLocalDate(), timeExpr.timeValue()); - return exprTimestampAdd(partExpr, amountExpr, new ExprDatetimeValue(datetime)); + return exprTimestampAdd(partExpr, amountExpr, new ExprTimestampValue(datetime)); } private ExprValue getTimeDifference(String part, LocalDateTime startTime, LocalDateTime endTime) { @@ -2095,15 +1943,17 @@ private ExprValue getTimeDifference(String part, LocalDateTime startTime, LocalD private ExprValue exprTimestampDiff( ExprValue partExpr, ExprValue startTimeExpr, ExprValue endTimeExpr) { return getTimeDifference( - partExpr.stringValue(), startTimeExpr.datetimeValue(), endTimeExpr.datetimeValue()); + partExpr.stringValue(), + startTimeExpr.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime(), + endTimeExpr.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime()); } private ExprValue exprTimestampDiffForTimeType( FunctionProperties fp, ExprValue partExpr, ExprValue startTimeExpr, ExprValue endTimeExpr) { return getTimeDifference( partExpr.stringValue(), - extractDateTime(startTimeExpr, fp), - extractDateTime(endTimeExpr, fp)); + extractTimestamp(startTimeExpr, fp).atZone(ZoneOffset.UTC).toLocalDateTime(), + extractTimestamp(endTimeExpr, fp).atZone(ZoneOffset.UTC).toLocalDateTime()); } /** @@ -2134,8 +1984,9 @@ private ExprValue exprUtcTime(FunctionProperties functionProperties) { */ private ExprValue exprUtcTimeStamp(FunctionProperties functionProperties) { var zdt = - ZonedDateTime.now(functionProperties.getQueryStartClock()).withZoneSameInstant(UTC_ZONE_ID); - return new ExprDatetimeValue(zdt.toLocalDateTime()); + ZonedDateTime.now(functionProperties.getQueryStartClock()) + .withZoneSameInstant(ZoneOffset.UTC); + return new ExprTimestampValue(zdt.toLocalDateTime()); } /** @@ -2151,12 +2002,13 @@ private ExprValue exprToDays(ExprValue date) { /** * To_seconds implementation for ExprValue. * - * @param date ExprValue of Date/Datetime/Timestamp/String type. + * @param date ExprValue of Date/Timestamp/String type. * @return ExprValue. */ private ExprValue exprToSeconds(ExprValue date) { return new ExprLongValue( - date.datetimeValue().toEpochSecond(ZoneOffset.UTC) + DAYS_0000_TO_1970 * SECONDS_PER_DAY); + date.timestampValue().atOffset(ZoneOffset.UTC).toEpochSecond() + + DAYS_0000_TO_1970 * SECONDS_PER_DAY); } /** @@ -2226,7 +2078,7 @@ private ExprValue exprToSecondsForIntType(ExprValue dateExpr) { /** * Week for date implementation for ExprValue. * - * @param date ExprValue of Date/Datetime/Timestamp/String type. + * @param date ExprValue of Date/Timestamp/String type. * @param mode ExprValue of Integer type. */ private ExprValue exprWeek(ExprValue date, ExprValue mode) { @@ -2237,7 +2089,7 @@ private ExprValue exprWeek(ExprValue date, ExprValue mode) { /** * Weekday implementation for ExprValue. * - * @param date ExprValue of Date/Datetime/String/Timstamp type. + * @param date ExprValue of Date/String/Timstamp type. * @return ExprValue. */ private ExprValue exprWeekday(ExprValue date) { @@ -2270,9 +2122,6 @@ private Double unixTimeStampOfImpl(ExprValue value) { switch ((ExprCoreType) value.type()) { case DATE: return value.dateValue().toEpochSecond(LocalTime.MIN, ZoneOffset.UTC) + 0d; - case DATETIME: - return value.datetimeValue().toEpochSecond(ZoneOffset.UTC) - + value.datetimeValue().getNano() / 1E9; case TIMESTAMP: return value.timestampValue().getEpochSecond() + value.timestampValue().getNano() / 1E9; default: @@ -2323,7 +2172,7 @@ private Double unixTimeStampOfImpl(ExprValue value) { * Week for date implementation for ExprValue. When mode is not specified default value mode 0 is * used for default_week_format. * - * @param date ExprValue of Date/Datetime/Timestamp/String type. + * @param date ExprValue of Date/Timestamp/String type. * @return ExprValue. */ private ExprValue exprWeekWithoutMode(ExprValue date) { @@ -2363,7 +2212,7 @@ private ExprIntegerValue extractYearweek(LocalDate date, int mode) { /** * Yearweek for date implementation for ExprValue. * - * @param date ExprValue of Date/Datetime/Time/Timestamp/String type. + * @param date ExprValue of Date/Time/Timestamp/String type. * @param mode ExprValue of Integer type. */ private ExprValue exprYearweek(ExprValue date, ExprValue mode) { @@ -2374,7 +2223,7 @@ private ExprValue exprYearweek(ExprValue date, ExprValue mode) { * Yearweek for date implementation for ExprValue. When mode is not specified default value mode 0 * is used. * - * @param date ExprValue of Date/Datetime/Time/Timestamp/String type. + * @param date ExprValue of Date/Time/Timestamp/String type. * @return ExprValue. */ private ExprValue exprYearweekWithoutMode(ExprValue date) { diff --git a/core/src/main/java/org/opensearch/sql/expression/operator/convert/TypeCastOperator.java b/core/src/main/java/org/opensearch/sql/expression/operator/convert/TypeCastOperator.java index 7c3565f69c..db4b29f3b9 100644 --- a/core/src/main/java/org/opensearch/sql/expression/operator/convert/TypeCastOperator.java +++ b/core/src/main/java/org/opensearch/sql/expression/operator/convert/TypeCastOperator.java @@ -8,7 +8,6 @@ import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN; import static org.opensearch.sql.data.type.ExprCoreType.BYTE; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; import static org.opensearch.sql.data.type.ExprCoreType.FLOAT; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; @@ -29,7 +28,6 @@ import org.opensearch.sql.data.model.ExprBooleanValue; import org.opensearch.sql.data.model.ExprByteValue; import org.opensearch.sql.data.model.ExprDateValue; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprDoubleValue; import org.opensearch.sql.data.model.ExprFloatValue; import org.opensearch.sql.data.model.ExprIntegerValue; @@ -58,7 +56,6 @@ public static void register(BuiltinFunctionRepository repository) { repository.register(castToDate()); repository.register(castToTime()); repository.register(castToTimestamp()); - repository.register(castToDatetime()); } private static DefaultFunctionResolver castToString() { @@ -66,8 +63,7 @@ private static DefaultFunctionResolver castToString() { BuiltinFunctionName.CAST_TO_STRING.getName(), Stream.concat( Arrays.asList( - BYTE, SHORT, INTEGER, LONG, FLOAT, DOUBLE, BOOLEAN, TIME, DATE, TIMESTAMP, - DATETIME) + BYTE, SHORT, INTEGER, LONG, FLOAT, DOUBLE, BOOLEAN, TIME, DATE, TIMESTAMP) .stream() .map( type -> @@ -180,7 +176,6 @@ private static DefaultFunctionResolver castToDate() { return FunctionDSL.define( BuiltinFunctionName.CAST_TO_DATE.getName(), impl(nullMissingHandling((v) -> new ExprDateValue(v.stringValue())), DATE, STRING), - impl(nullMissingHandling((v) -> new ExprDateValue(v.dateValue())), DATE, DATETIME), impl(nullMissingHandling((v) -> new ExprDateValue(v.dateValue())), DATE, TIMESTAMP), impl(nullMissingHandling((v) -> v), DATE, DATE)); } @@ -189,21 +184,16 @@ private static DefaultFunctionResolver castToTime() { return FunctionDSL.define( BuiltinFunctionName.CAST_TO_TIME.getName(), impl(nullMissingHandling((v) -> new ExprTimeValue(v.stringValue())), TIME, STRING), - impl(nullMissingHandling((v) -> new ExprTimeValue(v.timeValue())), TIME, DATETIME), impl(nullMissingHandling((v) -> new ExprTimeValue(v.timeValue())), TIME, TIMESTAMP), impl(nullMissingHandling((v) -> v), TIME, TIME)); } - // `DATE`/`TIME`/`DATETIME` -> `DATETIME`/TIMESTAMP` cast tested in BinaryPredicateOperatorTest + // `DATE`/`TIME` -> `TIMESTAMP` cast tested in BinaryPredicateOperatorTest private static DefaultFunctionResolver castToTimestamp() { return FunctionDSL.define( BuiltinFunctionName.CAST_TO_TIMESTAMP.getName(), impl( nullMissingHandling((v) -> new ExprTimestampValue(v.stringValue())), TIMESTAMP, STRING), - impl( - nullMissingHandling((v) -> new ExprTimestampValue(v.timestampValue())), - TIMESTAMP, - DATETIME), impl( nullMissingHandling((v) -> new ExprTimestampValue(v.timestampValue())), TIMESTAMP, @@ -215,21 +205,4 @@ private static DefaultFunctionResolver castToTimestamp() { TIME), impl(nullMissingHandling((v) -> v), TIMESTAMP, TIMESTAMP)); } - - private static DefaultFunctionResolver castToDatetime() { - return FunctionDSL.define( - BuiltinFunctionName.CAST_TO_DATETIME.getName(), - impl(nullMissingHandling((v) -> new ExprDatetimeValue(v.stringValue())), DATETIME, STRING), - impl( - nullMissingHandling((v) -> new ExprDatetimeValue(v.datetimeValue())), - DATETIME, - TIMESTAMP), - impl(nullMissingHandling((v) -> new ExprDatetimeValue(v.datetimeValue())), DATETIME, DATE), - implWithProperties( - nullMissingHandlingWithProperties( - (fp, v) -> new ExprDatetimeValue(((ExprTimeValue) v).datetimeValue(fp))), - DATETIME, - TIME), - impl(nullMissingHandling((v) -> v), DATETIME, DATETIME)); - } } diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/collector/Rounding.java b/core/src/main/java/org/opensearch/sql/planner/physical/collector/Rounding.java index 81a1a0230f..82c8af52cd 100644 --- a/core/src/main/java/org/opensearch/sql/planner/physical/collector/Rounding.java +++ b/core/src/main/java/org/opensearch/sql/planner/physical/collector/Rounding.java @@ -6,17 +6,15 @@ package org.opensearch.sql.planner.physical.collector; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; import static org.opensearch.sql.data.type.ExprCoreType.LONG; import static org.opensearch.sql.data.type.ExprCoreType.TIME; import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP; -import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID; import java.time.Instant; import java.time.LocalDate; -import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.ZoneOffset; import java.time.temporal.ChronoField; import java.util.Arrays; import java.util.concurrent.TimeUnit; @@ -24,7 +22,6 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import org.opensearch.sql.data.model.ExprDateValue; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprTimeValue; import org.opensearch.sql.data.model.ExprTimestampValue; import org.opensearch.sql.data.model.ExprValue; @@ -49,9 +46,6 @@ public static Rounding createRounding(SpanExpression span) { if (DOUBLE.isCompatible(type)) { return new DoubleRounding(interval); } - if (type.equals(DATETIME)) { - return new DatetimeRounding(interval, span.getUnit().getName()); - } if (type.equals(TIMESTAMP)) { return new TimestampRounding(interval, span.getUnit().getName()); } @@ -84,26 +78,6 @@ public ExprValue round(ExprValue var) { } } - static class DatetimeRounding extends Rounding { - private final ExprValue interval; - private final DateTimeUnit dateTimeUnit; - - public DatetimeRounding(ExprValue interval, String unit) { - this.interval = interval; - this.dateTimeUnit = DateTimeUnit.resolve(unit); - } - - @Override - public ExprValue round(ExprValue var) { - Instant instant = - Instant.ofEpochMilli( - dateTimeUnit.round( - var.datetimeValue().atZone(UTC_ZONE_ID).toInstant().toEpochMilli(), - interval.integerValue())); - return new ExprDatetimeValue(instant.atZone(UTC_ZONE_ID).toLocalDateTime()); - } - } - static class DateRounding extends Rounding { private final ExprValue interval; private final DateTimeUnit dateTimeUnit; @@ -118,9 +92,9 @@ public ExprValue round(ExprValue var) { Instant instant = Instant.ofEpochMilli( dateTimeUnit.round( - var.dateValue().atStartOfDay().atZone(UTC_ZONE_ID).toInstant().toEpochMilli(), + var.dateValue().atStartOfDay().atZone(ZoneOffset.UTC).toInstant().toEpochMilli(), interval.integerValue())); - return new ExprDateValue(instant.atZone(UTC_ZONE_ID).toLocalDate()); + return new ExprDateValue(instant.atZone(ZoneOffset.UTC).toLocalDate()); } } @@ -144,7 +118,7 @@ public ExprValue round(ExprValue var) { Instant.ofEpochMilli( dateTimeUnit.round( var.timeValue().getLong(ChronoField.MILLI_OF_DAY), interval.integerValue())); - return new ExprTimeValue(instant.atZone(UTC_ZONE_ID).toLocalTime()); + return new ExprTimeValue(instant.atZone(ZoneOffset.UTC).toLocalTime()); } } diff --git a/core/src/main/java/org/opensearch/sql/utils/DateTimeUtils.java b/core/src/main/java/org/opensearch/sql/utils/DateTimeUtils.java index 593b4c4471..62d5f0246d 100644 --- a/core/src/main/java/org/opensearch/sql/utils/DateTimeUtils.java +++ b/core/src/main/java/org/opensearch/sql/utils/DateTimeUtils.java @@ -9,6 +9,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; +import java.time.ZoneOffset; import java.time.ZonedDateTime; import lombok.experimental.UtilityClass; import org.opensearch.sql.data.model.ExprTimeValue; @@ -48,9 +49,9 @@ public static long roundWeek(long utcMillis, int interval) { * @return Rounded date/time value in utc millis */ public static long roundMonth(long utcMillis, int interval) { - ZonedDateTime initDateTime = ZonedDateTime.of(1970, 1, 1, 0, 0, 0, 0, UTC_ZONE_ID); + ZonedDateTime initDateTime = ZonedDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC); ZonedDateTime zonedDateTime = - Instant.ofEpochMilli(utcMillis).atZone(UTC_ZONE_ID).plusMonths(interval); + Instant.ofEpochMilli(utcMillis).atZone(ZoneOffset.UTC).plusMonths(interval); long monthDiff = (zonedDateTime.getYear() - initDateTime.getYear()) * 12L + zonedDateTime.getMonthValue() @@ -67,9 +68,9 @@ public static long roundMonth(long utcMillis, int interval) { * @return Rounded date/time value in utc millis */ public static long roundQuarter(long utcMillis, int interval) { - ZonedDateTime initDateTime = ZonedDateTime.of(1970, 1, 1, 0, 0, 0, 0, UTC_ZONE_ID); + ZonedDateTime initDateTime = ZonedDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC); ZonedDateTime zonedDateTime = - Instant.ofEpochMilli(utcMillis).atZone(UTC_ZONE_ID).plusMonths(interval * 3L); + Instant.ofEpochMilli(utcMillis).atZone(ZoneOffset.UTC).plusMonths(interval * 3L); long monthDiff = ((zonedDateTime.getYear() - initDateTime.getYear()) * 12L + zonedDateTime.getMonthValue() @@ -86,8 +87,8 @@ public static long roundQuarter(long utcMillis, int interval) { * @return Rounded date/time value in utc millis */ public static long roundYear(long utcMillis, int interval) { - ZonedDateTime initDateTime = ZonedDateTime.of(1970, 1, 1, 0, 0, 0, 0, UTC_ZONE_ID); - ZonedDateTime zonedDateTime = Instant.ofEpochMilli(utcMillis).atZone(UTC_ZONE_ID); + ZonedDateTime initDateTime = ZonedDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC); + ZonedDateTime zonedDateTime = Instant.ofEpochMilli(utcMillis).atZone(ZoneOffset.UTC); int yearDiff = zonedDateTime.getYear() - initDateTime.getYear(); int yearToAdd = (yearDiff / interval) * interval; return initDateTime.plusYears(yearToAdd).toInstant().toEpochMilli(); @@ -136,11 +137,10 @@ public Boolean isValidMySqlTimeZoneId(ZoneId zone) { * Extracts LocalDateTime from a datetime ExprValue. Uses `FunctionProperties` for * `ExprTimeValue`. */ - public static LocalDateTime extractDateTime( - ExprValue value, FunctionProperties functionProperties) { + public static Instant extractTimestamp(ExprValue value, FunctionProperties functionProperties) { return value instanceof ExprTimeValue - ? ((ExprTimeValue) value).datetimeValue(functionProperties) - : value.datetimeValue(); + ? ((ExprTimeValue) value).timestampValue(functionProperties) + : value.timestampValue(); } /** @@ -151,6 +151,4 @@ public static LocalDate extractDate(ExprValue value, FunctionProperties function ? ((ExprTimeValue) value).dateValue(functionProperties) : value.dateValue(); } - - public static final ZoneId UTC_ZONE_ID = ZoneId.of("UTC"); } diff --git a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java index 2f4d6e8ada..8d935b11d2 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java @@ -157,7 +157,7 @@ public void filter_relation_with_invalid_qualifiedName_ExpressionEvaluationExcep assertEquals( "= function expected {[BYTE,BYTE],[SHORT,SHORT],[INTEGER,INTEGER],[LONG,LONG]," + "[FLOAT,FLOAT],[DOUBLE,DOUBLE],[STRING,STRING],[BOOLEAN,BOOLEAN],[DATE,DATE]," - + "[TIME,TIME],[DATETIME,DATETIME],[TIMESTAMP,TIMESTAMP],[INTERVAL,INTERVAL]," + + "[TIME,TIME],[TIMESTAMP,TIMESTAMP],[INTERVAL,INTERVAL]," + "[STRUCT,STRUCT],[ARRAY,ARRAY]}, but get [STRING,INTEGER]", exception.getMessage()); } diff --git a/core/src/test/java/org/opensearch/sql/data/model/DateTimeValueTest.java b/core/src/test/java/org/opensearch/sql/data/model/DateTimeValueTest.java index 01fe4a5e4e..b5a3d61211 100644 --- a/core/src/test/java/org/opensearch/sql/data/model/DateTimeValueTest.java +++ b/core/src/test/java/org/opensearch/sql/data/model/DateTimeValueTest.java @@ -10,11 +10,11 @@ import static org.opensearch.sql.data.model.ExprValueUtils.integerValue; import static org.opensearch.sql.data.type.ExprCoreType.TIME; import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP; -import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.ZoneOffset; import java.time.ZonedDateTime; import org.junit.jupiter.api.Test; import org.opensearch.sql.exception.ExpressionEvaluationException; @@ -36,8 +36,6 @@ public void timeValueInterfaceTest() { // without a FunctionProperties object var exception = assertThrows(ExpressionEvaluationException.class, timeValue::dateValue); assertEquals("invalid to get dateValue from value of type TIME", exception.getMessage()); - exception = assertThrows(ExpressionEvaluationException.class, timeValue::datetimeValue); - assertEquals("invalid to get datetimeValue from value of type TIME", exception.getMessage()); exception = assertThrows(ExpressionEvaluationException.class, timeValue::timestampValue); assertEquals("invalid to get timestampValue from value of type TIME", exception.getMessage()); @@ -45,9 +43,11 @@ public void timeValueInterfaceTest() { var today = LocalDate.now(functionProperties.getQueryStartClock()); assertEquals(today, timeValue.dateValue(functionProperties)); - assertEquals(today.atTime(1, 1, 1), timeValue.datetimeValue(functionProperties)); assertEquals( - ZonedDateTime.of(LocalTime.parse("01:01:01").atDate(today), UTC_ZONE_ID).toInstant(), + today.atTime(1, 1, 1), + LocalDateTime.ofInstant(timeValue.timestampValue(functionProperties), ZoneOffset.UTC)); + assertEquals( + ZonedDateTime.of(LocalTime.parse("01:01:01").atDate(today), ZoneOffset.UTC).toInstant(), timeValue.timestampValue(functionProperties)); assertEquals("01:01:01", timeValue.value()); @@ -63,13 +63,15 @@ public void timestampValueInterfaceTest() { assertEquals(TIMESTAMP, timestampValue.type()); assertEquals( - ZonedDateTime.of(LocalDateTime.parse("2020-07-07T01:01:01"), UTC_ZONE_ID).toInstant(), + ZonedDateTime.of(LocalDateTime.parse("2020-07-07T01:01:01"), ZoneOffset.UTC).toInstant(), timestampValue.timestampValue()); assertEquals("2020-07-07 01:01:01", timestampValue.value()); assertEquals("TIMESTAMP '2020-07-07 01:01:01'", timestampValue.toString()); assertEquals(LocalDate.parse("2020-07-07"), timestampValue.dateValue()); assertEquals(LocalTime.parse("01:01:01"), timestampValue.timeValue()); - assertEquals(LocalDateTime.parse("2020-07-07T01:01:01"), timestampValue.datetimeValue()); + assertEquals( + LocalDateTime.parse("2020-07-07T01:01:01"), + LocalDateTime.ofInstant(timestampValue.timestampValue(), ZoneOffset.UTC)); assertThrows( ExpressionEvaluationException.class, () -> integerValue(1).timestampValue(), @@ -82,32 +84,17 @@ public void dateValueInterfaceTest() { assertEquals(LocalDate.parse("2012-07-07"), dateValue.dateValue()); assertEquals(LocalTime.parse("00:00:00"), dateValue.timeValue()); - assertEquals(LocalDateTime.parse("2012-07-07T00:00:00"), dateValue.datetimeValue()); assertEquals( - ZonedDateTime.of(LocalDateTime.parse("2012-07-07T00:00:00"), UTC_ZONE_ID).toInstant(), + LocalDateTime.parse("2012-07-07T00:00:00"), + LocalDateTime.ofInstant(dateValue.timestampValue(), ZoneOffset.UTC)); + assertEquals( + ZonedDateTime.of(LocalDateTime.parse("2012-07-07T00:00:00"), ZoneOffset.UTC).toInstant(), dateValue.timestampValue()); ExpressionEvaluationException exception = assertThrows(ExpressionEvaluationException.class, () -> integerValue(1).dateValue()); assertEquals("invalid to get dateValue from value of type INTEGER", exception.getMessage()); } - @Test - public void datetimeValueInterfaceTest() { - ExprValue datetimeValue = new ExprDatetimeValue("2020-08-17 19:44:00"); - - assertEquals(LocalDateTime.parse("2020-08-17T19:44:00"), datetimeValue.datetimeValue()); - assertEquals(LocalDate.parse("2020-08-17"), datetimeValue.dateValue()); - assertEquals(LocalTime.parse("19:44:00"), datetimeValue.timeValue()); - assertEquals( - ZonedDateTime.of(LocalDateTime.parse("2020-08-17T19:44:00"), UTC_ZONE_ID).toInstant(), - datetimeValue.timestampValue()); - assertEquals("DATETIME '2020-08-17 19:44:00'", datetimeValue.toString()); - assertThrows( - ExpressionEvaluationException.class, - () -> integerValue(1).datetimeValue(), - "invalid to get datetimeValue from value of type INTEGER"); - } - @Test public void dateInUnsupportedFormat() { SemanticCheckException exception = @@ -137,21 +124,12 @@ public void timestampInUnsupportedFormat() { } @Test - public void datetimeInUnsupportedFormat() { - SemanticCheckException exception = - assertThrows( - SemanticCheckException.class, () -> new ExprDatetimeValue("2020-07-07T01:01:01Z")); - assertEquals( - "datetime:2020-07-07T01:01:01Z in unsupported format, " - + "please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'", - exception.getMessage()); - } - - @Test - public void stringDateTimeValue() { + public void stringTimestampValue() { ExprValue stringValue = new ExprStringValue("2020-08-17 19:44:00"); - assertEquals(LocalDateTime.parse("2020-08-17T19:44:00"), stringValue.datetimeValue()); + assertEquals( + LocalDateTime.parse("2020-08-17T19:44:00").atZone(ZoneOffset.UTC).toInstant(), + stringValue.timestampValue()); assertEquals(LocalDate.parse("2020-08-17"), stringValue.dateValue()); assertEquals(LocalTime.parse("19:44:00"), stringValue.timeValue()); assertEquals("\"2020-08-17 19:44:00\"", stringValue.toString()); @@ -159,10 +137,9 @@ public void stringDateTimeValue() { SemanticCheckException exception = assertThrows( SemanticCheckException.class, - () -> new ExprStringValue("2020-07-07T01:01:01Z").datetimeValue()); + () -> new ExprStringValue("2020-07-07T01:01:01Z").timestampValue()); assertEquals( - "datetime:2020-07-07T01:01:01Z in unsupported format, " - + "please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'", + "date:2020-07-07T01:01:01Z in unsupported format, " + "please use 'yyyy-MM-dd'", exception.getMessage()); } @@ -170,7 +147,8 @@ public void stringDateTimeValue() { public void stringDateValue() { ExprValue stringValue = new ExprStringValue("2020-08-17"); - assertEquals(LocalDateTime.parse("2020-08-17T00:00:00"), stringValue.datetimeValue()); + assertEquals( + ZonedDateTime.parse("2020-08-17T00:00:00Z").toInstant(), stringValue.timestampValue()); assertEquals(LocalDate.parse("2020-08-17"), stringValue.dateValue()); assertEquals("\"2020-08-17\"", stringValue.toString()); @@ -228,28 +206,9 @@ public void timestampWithVariableNanoPrecision() { assertEquals(LocalDate.parse(dateValue), timestampValue.dateValue()); assertEquals(LocalTime.parse(timeWithNanos), timestampValue.timeValue()); String localDateTime = String.format("%sT%s", dateValue, timeWithNanos); - assertEquals(LocalDateTime.parse(localDateTime), timestampValue.datetimeValue()); - } - } - - @Test - public void datetimeWithVariableNanoPrecision() { - String dateValue = "2020-08-17"; - String timeWithNanosFormat = "10:11:12.%s"; - - // Check all lengths of nanosecond precision, up to max precision accepted - StringBuilder nanos = new StringBuilder(); - for (int nanoPrecision = 1; nanoPrecision <= NANOS_PRECISION_MAX; nanoPrecision++) { - nanos.append(nanoPrecision); - String timeWithNanos = String.format(timeWithNanosFormat, nanos); - - String datetimeString = String.format("%s %s", dateValue, timeWithNanos); - ExprValue datetimeValue = new ExprDatetimeValue(datetimeString); - - assertEquals(LocalDate.parse(dateValue), datetimeValue.dateValue()); - assertEquals(LocalTime.parse(timeWithNanos), datetimeValue.timeValue()); - String localDateTime = String.format("%sT%s", dateValue, timeWithNanos); - assertEquals(LocalDateTime.parse(localDateTime), datetimeValue.datetimeValue()); + assertEquals( + LocalDateTime.parse(localDateTime), + LocalDateTime.ofInstant(timestampValue.timestampValue(), ZoneOffset.UTC)); } } @@ -265,18 +224,6 @@ public void timestampOverMaxNanoPrecision() { exception.getMessage()); } - @Test - public void datetimeOverMaxNanoPrecision() { - SemanticCheckException exception = - assertThrows( - SemanticCheckException.class, - () -> new ExprDatetimeValue("2020-07-07 01:01:01.1234567890")); - assertEquals( - "datetime:2020-07-07 01:01:01.1234567890 in unsupported format, " - + "please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'", - exception.getMessage()); - } - @Test public void timeOverMaxNanoPrecision() { SemanticCheckException exception = diff --git a/core/src/test/java/org/opensearch/sql/data/model/ExprValueCompareTest.java b/core/src/test/java/org/opensearch/sql/data/model/ExprValueCompareTest.java index b965dff643..ee30a0f0c6 100644 --- a/core/src/test/java/org/opensearch/sql/data/model/ExprValueCompareTest.java +++ b/core/src/test/java/org/opensearch/sql/data/model/ExprValueCompareTest.java @@ -11,7 +11,7 @@ import static org.opensearch.sql.data.model.ExprValueUtils.LITERAL_FALSE; import static org.opensearch.sql.data.model.ExprValueUtils.LITERAL_MISSING; import static org.opensearch.sql.data.model.ExprValueUtils.LITERAL_NULL; -import static org.opensearch.sql.utils.DateTimeUtils.extractDateTime; +import static org.opensearch.sql.utils.DateTimeUtils.extractTimestamp; import java.time.LocalDate; import java.time.Period; @@ -39,22 +39,6 @@ public void dateValueCompare() { assertEquals(-1, new ExprDateValue("2012-08-07").compareTo(new ExprDateValue("2012-08-08"))); } - @Test - public void datetimeValueCompare() { - assertEquals( - 0, - new ExprDatetimeValue("2012-08-07 18:00:00") - .compareTo(new ExprDatetimeValue("2012-08-07 18:00:00"))); - assertEquals( - 1, - new ExprDatetimeValue("2012-08-07 19:00:00") - .compareTo(new ExprDatetimeValue("2012-08-07 18:00:00"))); - assertEquals( - -1, - new ExprDatetimeValue("2012-08-07 18:00:00") - .compareTo(new ExprDatetimeValue("2012-08-07 19:00:00"))); - } - @Test public void timestampValueCompare() { assertEquals( @@ -73,26 +57,14 @@ public void timestampValueCompare() { private static Stream getEqualDatetimeValuesOfDifferentTypes() { return Stream.of( - Arguments.of( - new ExprTimestampValue("1961-04-12 09:07:00"), - new ExprDatetimeValue("1961-04-12 09:07:00")), Arguments.of( new ExprTimestampValue("1984-11-22 00:00:00"), new ExprDateValue("1984-11-22")), Arguments.of( new ExprTimestampValue(LocalDate.now() + " 00:00:00"), new ExprDateValue(LocalDate.now())), - Arguments.of( - new ExprDatetimeValue(LocalDate.now() + " 17:42:15"), new ExprTimeValue("17:42:15")), - Arguments.of( - new ExprDatetimeValue("2012-08-07 19:14:38"), - new ExprTimestampValue("2012-08-07 19:14:38")), - Arguments.of(new ExprDateValue("2012-08-07"), new ExprDatetimeValue("2012-08-07 00:00:00")), - Arguments.of(new ExprDateValue("2007-01-27"), new ExprDatetimeValue("2007-01-27 00:00:00")), Arguments.of(new ExprDateValue(LocalDate.now()), new ExprTimeValue("00:00:00")), Arguments.of( new ExprTimestampValue("1984-11-22 00:00:00"), new ExprDateValue("1984-11-22")), - Arguments.of( - new ExprTimeValue("19:14:38"), new ExprDatetimeValue(LocalDate.now() + " 19:14:38")), Arguments.of( new ExprTimeValue("17:42:15"), new ExprTimestampValue(LocalDate.now() + " 17:42:15"))); } @@ -106,34 +78,17 @@ private static Stream getEqualDatetimeValuesOfDifferentTypes() { public void compareEqDifferentDateTimeValueTypes(ExprValue left, ExprValue right) { assertEquals( 0, - extractDateTime(left, functionProperties) - .compareTo(extractDateTime(right, functionProperties))); - assertEquals( - 0, - extractDateTime(right, functionProperties) - .compareTo(extractDateTime(left, functionProperties))); + extractTimestamp(left, functionProperties) + .compareTo(extractTimestamp(right, functionProperties))); } private static Stream getNotEqualDatetimeValuesOfDifferentTypes() { return Stream.of( - Arguments.of( - new ExprDatetimeValue("2012-08-07 19:14:38"), - new ExprTimestampValue("1961-04-12 09:07:00")), - Arguments.of(new ExprDatetimeValue("2012-08-07 19:14:38"), new ExprTimeValue("09:07:00")), - Arguments.of( - new ExprDatetimeValue(LocalDate.now() + " 19:14:38"), new ExprTimeValue("09:07:00")), - Arguments.of(new ExprDatetimeValue("2012-08-07 00:00:00"), new ExprDateValue("1961-04-12")), - Arguments.of(new ExprDatetimeValue("1961-04-12 19:14:38"), new ExprDateValue("1961-04-12")), - Arguments.of(new ExprDateValue("1984-11-22"), new ExprDatetimeValue("1961-04-12 19:14:38")), Arguments.of( new ExprDateValue("1984-11-22"), new ExprTimestampValue("2020-09-16 17:30:00")), Arguments.of(new ExprDateValue("1984-11-22"), new ExprTimeValue("19:14:38")), Arguments.of(new ExprTimeValue("19:14:38"), new ExprDateValue(LocalDate.now())), - Arguments.of(new ExprTimeValue("19:14:38"), new ExprDatetimeValue("2012-08-07 09:07:00")), Arguments.of(new ExprTimeValue("19:14:38"), new ExprTimestampValue("1984-02-03 04:05:07")), - Arguments.of( - new ExprTimestampValue("2012-08-07 19:14:38"), - new ExprDatetimeValue("1961-04-12 09:07:00")), Arguments.of(new ExprTimestampValue("2012-08-07 19:14:38"), new ExprTimeValue("09:07:00")), Arguments.of( new ExprTimestampValue(LocalDate.now() + " 19:14:38"), new ExprTimeValue("09:07:00")), @@ -152,12 +107,8 @@ private static Stream getNotEqualDatetimeValuesOfDifferentTypes() { public void compareNeqDifferentDateTimeValueTypes(ExprValue left, ExprValue right) { assertNotEquals( 0, - extractDateTime(left, functionProperties) - .compareTo(extractDateTime(right, functionProperties))); - assertNotEquals( - 0, - extractDateTime(right, functionProperties) - .compareTo(extractDateTime(left, functionProperties))); + extractTimestamp(left, functionProperties) + .compareTo(extractTimestamp(right, functionProperties))); } @Test diff --git a/core/src/test/java/org/opensearch/sql/data/model/ExprValueUtilsTest.java b/core/src/test/java/org/opensearch/sql/data/model/ExprValueUtilsTest.java index c879384955..0baf5052e4 100644 --- a/core/src/test/java/org/opensearch/sql/data/model/ExprValueUtilsTest.java +++ b/core/src/test/java/org/opensearch/sql/data/model/ExprValueUtilsTest.java @@ -13,13 +13,11 @@ import static org.opensearch.sql.data.type.ExprCoreType.ARRAY; import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.INTERVAL; import static org.opensearch.sql.data.type.ExprCoreType.STRING; 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.DateTimeUtils.UTC_ZONE_ID; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -29,6 +27,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.util.AbstractMap; import java.util.ArrayList; @@ -70,7 +69,6 @@ public class ExprValueUtilsTest { new ExprTupleValue(testTuple), new ExprDateValue("2012-08-07"), new ExprTimeValue("18:00:00"), - new ExprDatetimeValue("2012-08-07 18:00:00"), new ExprTimestampValue("2012-08-07 18:00:00"), new ExprIntervalValue(Duration.ofSeconds(100))); @@ -95,7 +93,6 @@ public class ExprValueUtilsTest { Arrays.asList( ExprValue::dateValue, ExprValue::timeValue, - ExprValue::datetimeValue, ExprValue::timestampValue, ExprValue::intervalValue); private static List> allValueExtractor = @@ -113,7 +110,7 @@ public class ExprValueUtilsTest { ExprCoreType.DOUBLE); private static List nonNumberTypes = Arrays.asList(STRING, BOOLEAN, ARRAY, STRUCT); private static List dateAndTimeTypes = - Arrays.asList(DATE, TIME, DATETIME, TIMESTAMP, INTERVAL); + Arrays.asList(DATE, TIME, TIMESTAMP, INTERVAL); private static List allTypes = Lists.newArrayList(Iterables.concat(numberTypes, nonNumberTypes, dateAndTimeTypes)); @@ -132,8 +129,8 @@ private static Stream getValueTestArgumentStream() { ImmutableMap.of("1", integerValue(1)), LocalDate.parse("2012-08-07"), LocalTime.parse("18:00:00"), - LocalDateTime.parse("2012-08-07T18:00:00"), - ZonedDateTime.of(LocalDateTime.parse("2012-08-07T18:00:00"), UTC_ZONE_ID).toInstant(), + ZonedDateTime.of(LocalDateTime.parse("2012-08-07T18:00:00"), ZoneOffset.UTC) + .toInstant(), Duration.ofSeconds(100)); Stream.Builder builder = Stream.builder(); for (int i = 0; i < expectedValues.size(); i++) { @@ -237,9 +234,6 @@ public void constructDateAndTimeValue() { assertEquals( new ExprDateValue("2012-07-07"), ExprValueUtils.fromObjectValue("2012-07-07", DATE)); assertEquals(new ExprTimeValue("01:01:01"), ExprValueUtils.fromObjectValue("01:01:01", TIME)); - assertEquals( - new ExprDatetimeValue("2012-07-07 01:01:01"), - ExprValueUtils.fromObjectValue("2012-07-07 01:01:01", DATETIME)); assertEquals( new ExprTimestampValue("2012-07-07 01:01:01"), ExprValueUtils.fromObjectValue("2012-07-07 01:01:01", TIMESTAMP)); @@ -260,9 +254,6 @@ public void hashCodeTest() { new ExprDateValue("2012-08-07").hashCode(), new ExprDateValue("2012-08-07").hashCode()); assertEquals( new ExprTimeValue("18:00:00").hashCode(), new ExprTimeValue("18:00:00").hashCode()); - assertEquals( - new ExprDatetimeValue("2012-08-07 18:00:00").hashCode(), - new ExprDatetimeValue("2012-08-07 18:00:00").hashCode()); assertEquals( new ExprTimestampValue("2012-08-07 18:00:00").hashCode(), new ExprTimestampValue("2012-08-07 18:00:00").hashCode()); diff --git a/core/src/test/java/org/opensearch/sql/data/type/ExprTypeTest.java b/core/src/test/java/org/opensearch/sql/data/type/ExprTypeTest.java index 1def15cc6f..ec45c3dfec 100644 --- a/core/src/test/java/org/opensearch/sql/data/type/ExprTypeTest.java +++ b/core/src/test/java/org/opensearch/sql/data/type/ExprTypeTest.java @@ -12,7 +12,6 @@ import static org.opensearch.sql.data.type.ExprCoreType.ARRAY; import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; import static org.opensearch.sql.data.type.ExprCoreType.FLOAT; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; @@ -45,7 +44,6 @@ public void isCompatible() { assertTrue(TIMESTAMP.isCompatible(STRING)); assertTrue(DATE.isCompatible(STRING)); assertTrue(TIME.isCompatible(STRING)); - assertTrue(DATETIME.isCompatible(STRING)); } @Test diff --git a/core/src/test/java/org/opensearch/sql/expression/aggregation/AvgAggregatorTest.java b/core/src/test/java/org/opensearch/sql/expression/aggregation/AvgAggregatorTest.java index f465a6477e..10551d43a5 100644 --- a/core/src/test/java/org/opensearch/sql/expression/aggregation/AvgAggregatorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/aggregation/AvgAggregatorTest.java @@ -9,7 +9,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; import static org.opensearch.sql.data.type.ExprCoreType.STRING; @@ -19,6 +18,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.ZoneOffset; import java.util.List; import org.junit.jupiter.api.Test; import org.opensearch.sql.data.model.ExprValue; @@ -89,12 +89,6 @@ public void avg_date_no_values() { assertTrue(result.isNull()); } - @Test - public void avg_datetime_no_values() { - ExprValue result = aggregation(DSL.avg(DSL.ref("dummy", DATETIME)), List.of()); - assertTrue(result.isNull()); - } - @Test public void avg_timestamp_no_values() { ExprValue result = aggregation(DSL.avg(DSL.ref("dummy", TIMESTAMP)), List.of()); @@ -113,12 +107,6 @@ public void avg_date() { assertEquals(LocalDate.of(2007, 7, 2), result.dateValue()); } - @Test - public void avg_datetime() { - var result = aggregation(DSL.avg(DSL.datetime(DSL.ref("datetime_value", STRING))), tuples); - assertEquals(LocalDateTime.of(2012, 7, 2, 3, 30), result.datetimeValue()); - } - @Test public void avg_time() { ExprValue result = aggregation(DSL.avg(DSL.time(DSL.ref("time_value", STRING))), tuples); @@ -129,7 +117,9 @@ public void avg_time() { public void avg_timestamp() { var result = aggregation(DSL.avg(DSL.timestamp(DSL.ref("timestamp_value", STRING))), tuples); assertEquals(TIMESTAMP, result.type()); - assertEquals(LocalDateTime.of(2012, 7, 2, 3, 30), result.datetimeValue()); + assertEquals( + LocalDateTime.of(2012, 7, 2, 3, 30), + result.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime()); } @Test diff --git a/core/src/test/java/org/opensearch/sql/expression/aggregation/CountAggregatorTest.java b/core/src/test/java/org/opensearch/sql/expression/aggregation/CountAggregatorTest.java index 50bd3fedfe..2159780dc0 100644 --- a/core/src/test/java/org/opensearch/sql/expression/aggregation/CountAggregatorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/aggregation/CountAggregatorTest.java @@ -10,7 +10,6 @@ import static org.opensearch.sql.data.type.ExprCoreType.ARRAY; import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; import static org.opensearch.sql.data.type.ExprCoreType.FLOAT; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; @@ -63,12 +62,6 @@ public void count_timestamp_field_expression() { assertEquals(4, result.value()); } - @Test - public void count_datetime_field_expression() { - ExprValue result = aggregation(DSL.count(DSL.ref("datetime_value", DATETIME)), tuples); - assertEquals(4, result.value()); - } - @Test public void count_arithmetic_expression() { ExprValue result = diff --git a/core/src/test/java/org/opensearch/sql/expression/aggregation/MaxAggregatorTest.java b/core/src/test/java/org/opensearch/sql/expression/aggregation/MaxAggregatorTest.java index c6cd380ad5..f952eff982 100644 --- a/core/src/test/java/org/opensearch/sql/expression/aggregation/MaxAggregatorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/aggregation/MaxAggregatorTest.java @@ -9,7 +9,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; import static org.opensearch.sql.data.type.ExprCoreType.FLOAT; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; @@ -62,12 +61,6 @@ public void test_max_date() { assertEquals("2040-01-01", result.value()); } - @Test - public void test_max_datetime() { - ExprValue result = aggregation(DSL.max(DSL.ref("datetime_value", DATETIME)), tuples); - assertEquals("2040-01-01 07:00:00", result.value()); - } - @Test public void test_max_time() { ExprValue result = aggregation(DSL.max(DSL.ref("time_value", TIME)), tuples); diff --git a/core/src/test/java/org/opensearch/sql/expression/aggregation/MinAggregatorTest.java b/core/src/test/java/org/opensearch/sql/expression/aggregation/MinAggregatorTest.java index 1aee0f3a6c..8a3f3d15a3 100644 --- a/core/src/test/java/org/opensearch/sql/expression/aggregation/MinAggregatorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/aggregation/MinAggregatorTest.java @@ -9,7 +9,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; import static org.opensearch.sql.data.type.ExprCoreType.FLOAT; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; @@ -62,12 +61,6 @@ public void test_min_date() { assertEquals("1970-01-01", result.value()); } - @Test - public void test_min_datetime() { - ExprValue result = aggregation(DSL.min(DSL.ref("datetime_value", DATETIME)), tuples); - assertEquals("1970-01-01 19:00:00", result.value()); - } - @Test public void test_min_time() { ExprValue result = aggregation(DSL.min(DSL.ref("time_value", TIME)), tuples); diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/AddTimeAndSubTimeTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/AddTimeAndSubTimeTest.java index eed83f4fa9..49947976b4 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/AddTimeAndSubTimeTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/AddTimeAndSubTimeTest.java @@ -6,13 +6,14 @@ package org.opensearch.sql.expression.datetime; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.TIME; +import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.ZoneOffset; import java.time.temporal.Temporal; import java.util.stream.Stream; import org.junit.jupiter.api.Test; @@ -23,7 +24,7 @@ public class AddTimeAndSubTimeTest extends DateTimeTestBase { @Test - // (TIME, TIME/DATE/DATETIME/TIMESTAMP) -> TIME + // (TIME, TIME/DATE/TIMESTAMP) -> TIME public void return_time_when_first_arg_is_time() { var res = addtime(LocalTime.of(21, 0), LocalTime.of(0, 5)); assertEquals(TIME, res.type()); @@ -70,31 +71,10 @@ public void time_limited_by_24_hours() { } // Function signature is: - // (DATE/DATETIME/TIMESTAMP, TIME/DATE/DATETIME/TIMESTAMP) -> DATETIME + // (DATE/TIMESTAMP, TIME/DATE/TIMESTAMP) -> TIMESTAMP private static Stream getTestData() { return Stream.of( - // DATETIME and TIME/DATE/DATETIME/TIMESTAMP - Arguments.of( - LocalDateTime.of(1961, 4, 12, 9, 7), - LocalTime.of(1, 48), - LocalDateTime.of(1961, 4, 12, 10, 55), - LocalDateTime.of(1961, 4, 12, 7, 19)), - Arguments.of( - LocalDateTime.of(1961, 4, 12, 9, 7), - LocalDate.of(2000, 1, 1), - LocalDateTime.of(1961, 4, 12, 9, 7), - LocalDateTime.of(1961, 4, 12, 9, 7)), - Arguments.of( - LocalDateTime.of(1961, 4, 12, 9, 7), - LocalDateTime.of(1235, 5, 6, 1, 48), - LocalDateTime.of(1961, 4, 12, 10, 55), - LocalDateTime.of(1961, 4, 12, 7, 19)), - Arguments.of( - LocalDateTime.of(1961, 4, 12, 9, 7), - Instant.ofEpochSecond(42), - LocalDateTime.of(1961, 4, 12, 9, 7, 42), - LocalDateTime.of(1961, 4, 12, 9, 6, 18)), - // DATE and TIME/DATE/DATETIME/TIMESTAMP + // DATE and TIME/DATE/TIMESTAMP Arguments.of( LocalDate.of(1961, 4, 12), LocalTime.of(9, 7), @@ -115,7 +95,7 @@ private static Stream getTestData() { Instant.ofEpochSecond(42), LocalDateTime.of(1961, 4, 12, 0, 0, 42), LocalDateTime.of(1961, 4, 11, 23, 59, 18)), - // TIMESTAMP and TIME/DATE/DATETIME/TIMESTAMP + // TIMESTAMP and TIME/DATE/TIMESTAMP Arguments.of( Instant.ofEpochSecond(42), LocalTime.of(9, 7), @@ -154,11 +134,13 @@ public void return_datetime_when_first_arg_is_not_time( LocalDateTime addTimeExpectedResult, LocalDateTime subTimeExpectedResult) { var res = addtime(arg1, arg2); - assertEquals(DATETIME, res.type()); - assertEquals(addTimeExpectedResult, res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals( + addTimeExpectedResult, res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime()); res = subtime(arg1, arg2); - assertEquals(DATETIME, res.type()); - assertEquals(subTimeExpectedResult, res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals( + subTimeExpectedResult, res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime()); } } diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/ConvertTZTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/ConvertTZTest.java index 17ff4f67ab..707f995138 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/ConvertTZTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/ConvertTZTest.java @@ -6,11 +6,13 @@ package org.opensearch.sql.expression.datetime; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.opensearch.sql.data.model.ExprValueUtils.nullValue; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; +import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP; import org.junit.jupiter.api.Test; -import org.opensearch.sql.data.model.ExprDatetimeValue; +import org.opensearch.sql.data.model.ExprTimestampValue; +import org.opensearch.sql.exception.SemanticCheckException; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.ExpressionTestBase; import org.opensearch.sql.expression.FunctionExpression; @@ -21,32 +23,32 @@ class ConvertTZTest extends ExpressionTestBase { public void invalidDate() { FunctionExpression expr = DSL.convert_tz( - DSL.datetime(DSL.literal("2021-04-31 10:00:00")), + DSL.timestamp(DSL.literal("2021-04-31 10:00:00")), DSL.literal("+00:00"), DSL.literal("+00:00")); - assertEquals(DATETIME, expr.type()); - assertEquals(nullValue(), expr.valueOf()); + assertEquals(TIMESTAMP, expr.type()); + assertThrows(SemanticCheckException.class, expr::valueOf); } @Test public void conversionFromNoOffset() { FunctionExpression expr = DSL.convert_tz( - DSL.datetime(DSL.literal("2008-05-15 22:00:00")), + DSL.timestamp(DSL.literal("2008-05-15 22:00:00")), DSL.literal("+00:00"), DSL.literal("+10:00")); - assertEquals(DATETIME, expr.type()); - assertEquals(new ExprDatetimeValue("2008-05-16 08:00:00"), expr.valueOf()); + assertEquals(TIMESTAMP, expr.type()); + assertEquals(new ExprTimestampValue("2008-05-16 08:00:00"), expr.valueOf()); } @Test public void conversionToInvalidInput3Over() { FunctionExpression expr = DSL.convert_tz( - DSL.datetime(DSL.literal("2008-05-15 22:00:00")), + DSL.timestamp(DSL.literal("2008-05-15 22:00:00")), DSL.literal("+00:00"), DSL.literal("+16:00")); - assertEquals(DATETIME, expr.type()); + assertEquals(TIMESTAMP, expr.type()); assertEquals(nullValue(), expr.valueOf()); } @@ -54,10 +56,10 @@ public void conversionToInvalidInput3Over() { public void conversionToInvalidInput3Under() { FunctionExpression expr = DSL.convert_tz( - DSL.datetime(DSL.literal("2008-05-15 22:00:00")), + DSL.timestamp(DSL.literal("2008-05-15 22:00:00")), DSL.literal("+00:00"), DSL.literal("-16:00")); - assertEquals(DATETIME, expr.type()); + assertEquals(TIMESTAMP, expr.type()); assertEquals(nullValue(), expr.valueOf()); } @@ -65,10 +67,10 @@ public void conversionToInvalidInput3Under() { public void conversionFromPositiveToPositive() { FunctionExpression expr = DSL.convert_tz( - DSL.datetime(DSL.literal("2008-05-15 22:00:00")), + DSL.timestamp(DSL.literal("2008-05-15 22:00:00")), DSL.literal("+15:00"), DSL.literal("+01:00")); - assertEquals(DATETIME, expr.type()); + assertEquals(TIMESTAMP, expr.type()); assertEquals(nullValue(), expr.valueOf()); } @@ -76,10 +78,10 @@ public void conversionFromPositiveToPositive() { public void invalidInput2Under() { FunctionExpression expr = DSL.convert_tz( - DSL.datetime(DSL.literal("2008-05-15 22:00:00")), + DSL.timestamp(DSL.literal("2008-05-15 22:00:00")), DSL.literal("-15:00"), DSL.literal("+01:00")); - assertEquals(DATETIME, expr.type()); + assertEquals(TIMESTAMP, expr.type()); assertEquals(nullValue(), expr.valueOf()); } @@ -87,10 +89,10 @@ public void invalidInput2Under() { public void invalidInput3Over() { FunctionExpression expr = DSL.convert_tz( - DSL.datetime(DSL.literal("2008-05-15 22:00:00")), + DSL.timestamp(DSL.literal("2008-05-15 22:00:00")), DSL.literal("-12:00"), DSL.literal("+15:00")); - assertEquals(DATETIME, expr.type()); + assertEquals(TIMESTAMP, expr.type()); assertEquals(nullValue(), expr.valueOf()); } @@ -98,32 +100,32 @@ public void invalidInput3Over() { public void conversionToPositiveEdge() { FunctionExpression expr = DSL.convert_tz( - DSL.datetime(DSL.literal("2008-05-15 22:00:00")), + DSL.timestamp(DSL.literal("2008-05-15 22:00:00")), DSL.literal("+00:00"), DSL.literal("+14:00")); - assertEquals(DATETIME, expr.type()); - assertEquals(new ExprDatetimeValue("2008-05-16 12:00:00"), expr.valueOf()); + assertEquals(TIMESTAMP, expr.type()); + assertEquals(new ExprTimestampValue("2008-05-16 12:00:00"), expr.valueOf()); } @Test public void conversionToNegativeEdge() { FunctionExpression expr = DSL.convert_tz( - DSL.datetime(DSL.literal("2008-05-15 22:00:00")), + DSL.timestamp(DSL.literal("2008-05-15 22:00:00")), DSL.literal("+00:01"), DSL.literal("-13:59")); - assertEquals(DATETIME, expr.type()); - assertEquals(new ExprDatetimeValue("2008-05-15 08:00:00"), expr.valueOf()); + assertEquals(TIMESTAMP, expr.type()); + assertEquals(new ExprTimestampValue("2008-05-15 08:00:00"), expr.valueOf()); } @Test public void invalidInput2() { FunctionExpression expr = DSL.convert_tz( - DSL.datetime(DSL.literal("2008-05-15 22:00:00")), + DSL.timestamp(DSL.literal("2008-05-15 22:00:00")), DSL.literal("+)()"), DSL.literal("+12:00")); - assertEquals(DATETIME, expr.type()); + assertEquals(TIMESTAMP, expr.type()); assertEquals(nullValue(), expr.valueOf()); } @@ -131,10 +133,10 @@ public void invalidInput2() { public void invalidInput3() { FunctionExpression expr = DSL.convert_tz( - DSL.datetime(DSL.literal("2008-05-15 22:00:00")), + DSL.timestamp(DSL.literal("2008-05-15 22:00:00")), DSL.literal("+00:00"), DSL.literal("test")); - assertEquals(DATETIME, expr.type()); + assertEquals(TIMESTAMP, expr.type()); assertEquals(nullValue(), expr.valueOf()); } @@ -142,7 +144,7 @@ public void invalidInput3() { public void invalidInput1() { FunctionExpression expr = DSL.convert_tz(DSL.literal("test"), DSL.literal("+00:00"), DSL.literal("+00:00")); - assertEquals(DATETIME, expr.type()); + assertEquals(TIMESTAMP, expr.type()); assertEquals(nullValue(), expr.valueOf()); } @@ -150,32 +152,32 @@ public void invalidInput1() { public void invalidDateFeb30() { FunctionExpression expr = DSL.convert_tz( - DSL.datetime(DSL.literal("2021-02-30 10:00:00")), + DSL.timestamp(DSL.literal("2021-02-30 10:00:00")), DSL.literal("+00:00"), DSL.literal("+00:00")); - assertEquals(DATETIME, expr.type()); - assertEquals(nullValue(), expr.valueOf()); + assertEquals(TIMESTAMP, expr.type()); + assertThrows(SemanticCheckException.class, expr::valueOf); } @Test public void invalidDateApril31() { FunctionExpression expr = DSL.convert_tz( - DSL.datetime(DSL.literal("2021-04-31 10:00:00")), + DSL.timestamp(DSL.literal("2021-04-31 10:00:00")), DSL.literal("+00:00"), DSL.literal("+00:00")); - assertEquals(DATETIME, expr.type()); - assertEquals(nullValue(), expr.valueOf()); + assertEquals(TIMESTAMP, expr.type()); + assertThrows(SemanticCheckException.class, expr::valueOf); } @Test public void invalidMonth13() { FunctionExpression expr = DSL.convert_tz( - DSL.datetime(DSL.literal("2021-13-03 10:00:00")), + DSL.timestamp(DSL.literal("2021-13-03 10:00:00")), DSL.literal("+00:00"), DSL.literal("+00:00")); - assertEquals(DATETIME, expr.type()); - assertEquals(nullValue(), expr.valueOf()); + assertEquals(TIMESTAMP, expr.type()); + assertThrows(SemanticCheckException.class, expr::valueOf); } } diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/DateAddAndAddDateTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/DateAddAndAddDateTest.java index 52db0a17e5..519e97bdc6 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/DateAddAndAddDateTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/DateAddAndAddDateTest.java @@ -8,7 +8,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; +import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP; import java.time.Duration; import java.time.Instant; @@ -29,81 +29,99 @@ private LocalDate today() { @Test public void adddate_returns_datetime_when_args_are_time_and_time_interval() { var res = adddate(LocalTime.MIN, Duration.ofHours(1).plusMinutes(2)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalTime.of(1, 2).atDate(today()), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals( + LocalTime.of(1, 2).atDate(today()), + res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime()); } @Test public void date_add_returns_datetime_when_args_are_time_and_time_interval() { var res = date_add(LocalTime.of(10, 20, 30), Duration.ofHours(1).plusMinutes(2).plusSeconds(42)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalTime.of(11, 23, 12).atDate(today()), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals( + LocalTime.of(11, 23, 12).atDate(today()), + res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime()); } @Test public void adddate_time_limited_by_24_hours() { var res = adddate(LocalTime.MAX, Duration.ofNanos(1)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalTime.MIN, res.datetimeValue().toLocalTime()); + assertEquals(TIMESTAMP, res.type()); + assertEquals(LocalTime.MIN, res.timestampValue().atZone(ZoneOffset.UTC).toLocalTime()); } @Test public void date_add_time_limited_by_24_hours() { var res = date_add(LocalTime.of(10, 20, 30), Duration.ofHours(20).plusMinutes(50).plusSeconds(7)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalTime.of(7, 10, 37), res.datetimeValue().toLocalTime()); + assertEquals(TIMESTAMP, res.type()); + assertEquals( + LocalTime.of(7, 10, 37), res.timestampValue().atZone(ZoneOffset.UTC).toLocalTime()); } @Test public void adddate_returns_datetime_when_args_are_date_and_date_interval() { var res = adddate(LocalDate.of(2020, 2, 20), Period.of(3, 11, 21)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalDate.of(2024, 2, 10).atStartOfDay(), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals( + LocalDate.of(2024, 2, 10).atStartOfDay(), + res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime()); } @Test public void date_add_returns_datetime_when_args_are_date_and_date_interval() { var res = date_add(LocalDate.of(1961, 4, 12), Period.of(50, 50, 50)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalDate.of(2015, 8, 1).atStartOfDay(), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals( + LocalDate.of(2015, 8, 1).atStartOfDay(), + res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime()); } @Test public void adddate_returns_datetime_when_args_are_date_and_time_interval() { var res = adddate(LocalDate.of(2020, 2, 20), Duration.ofHours(1).plusMinutes(2)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalDateTime.of(2020, 2, 20, 1, 2), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals( + LocalDateTime.of(2020, 2, 20, 1, 2), + res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime()); } @Test public void date_add_returns_datetime_when_args_are_date_and_time_interval() { var res = date_add(LocalDate.of(1961, 4, 12), Duration.ofHours(9).plusMinutes(7)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalDateTime.of(1961, 4, 12, 9, 7), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals( + LocalDateTime.of(1961, 4, 12, 9, 7), + res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime()); } @Test public void adddate_returns_datetime_when_args_are_time_and_date_interval() { // Date based on today var res = adddate(LocalTime.of(1, 2, 0), Period.ofDays(1)); - assertEquals(DATETIME, res.type()); - assertEquals(today().plusDays(1).atTime(LocalTime.of(1, 2, 0)), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals( + today().plusDays(1).atTime(LocalTime.of(1, 2, 0)), + res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime()); } @Test public void date_add_returns_datetime_when_args_are_time_and_date_interval() { var res = date_add(LocalTime.MIDNIGHT, Period.ofDays(0)); - assertEquals(DATETIME, res.type()); - assertEquals(today().atStartOfDay(), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals( + today().atStartOfDay(), res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime()); } @Test public void adddate_returns_datetime_when_first_arg_is_datetime() { var res = adddate(LocalDateTime.of(1961, 4, 12, 9, 7), Duration.ofMinutes(108)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalDateTime.of(1961, 4, 12, 10, 55), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals( + LocalDateTime.of(1961, 4, 12, 10, 55), + res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime()); } @Test @@ -111,30 +129,34 @@ public void date_add_returns_datetime_when_first_arg_is_timestamp() { var res = date_add( LocalDateTime.of(1961, 4, 12, 9, 7).toInstant(ZoneOffset.UTC), Duration.ofMinutes(108)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalDateTime.of(1961, 4, 12, 10, 55), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals( + LocalDateTime.of(1961, 4, 12, 10, 55), + res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime()); } @Test public void adddate_accepts_negative_interval() { var res = adddate(LocalDateTime.of(2020, 10, 20, 14, 42), Duration.ofDays(-10)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalDateTime.of(2020, 10, 10, 14, 42), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals( + LocalDateTime.of(2020, 10, 10, 14, 42), + res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime()); assertEquals(subdate(LocalDateTime.of(2020, 10, 20, 14, 42), Duration.ofDays(10)), res); } @Test public void adddate_has_second_signature_but_not_date_add() { var res = adddate(LocalDateTime.of(1961, 4, 12, 9, 7), 100500); - assertEquals(DATETIME, res.type()); + assertEquals(TIMESTAMP, res.type()); var exception = assertThrows( ExpressionEvaluationException.class, () -> date_add(LocalDateTime.of(1961, 4, 12, 9, 7), 100500)); assertEquals( - "date_add function expected {[DATE,INTERVAL],[DATETIME,INTERVAL]," - + "[TIMESTAMP,INTERVAL],[TIME,INTERVAL]}, but get [DATETIME,INTEGER]", + "date_add function expected {[DATE,INTERVAL],[TIMESTAMP,INTERVAL]," + + "[TIME,INTERVAL]}, but get [TIMESTAMP,INTEGER]", exception.getMessage()); } @@ -148,23 +170,29 @@ public void adddate_returns_date_when_args_are_date_and_days() { @Test public void adddate_returns_datetime_when_args_are_date_but_days() { var res = adddate(LocalDate.of(2000, 1, 1).atStartOfDay(), 2); - assertEquals(DATETIME, res.type()); - assertEquals(LocalDateTime.of(2000, 1, 3, 0, 0), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals( + LocalDateTime.of(2000, 1, 3, 0, 0), + res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime()); res = adddate(LocalTime.now(), 2); - assertEquals(DATETIME, res.type()); + assertEquals(TIMESTAMP, res.type()); assertEquals(today().plusDays(2), res.dateValue()); res = adddate(Instant.ofEpochSecond(42), 2); - assertEquals(DATETIME, res.type()); - assertEquals(LocalDateTime.of(1970, 1, 3, 0, 0, 42), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals( + LocalDateTime.of(1970, 1, 3, 0, 0, 42), + res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime()); } @Test public void adddate_accepts_negative_days() { var res = adddate(LocalDateTime.of(2020, 10, 20, 8, 16, 32), -40); - assertEquals(DATETIME, res.type()); - assertEquals(LocalDateTime.of(2020, 10, 20, 8, 16, 32).minusDays(40), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals( + LocalDateTime.of(2020, 10, 20, 8, 16, 32).minusDays(40), + res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime()); assertEquals(subdate(LocalDateTime.of(2020, 10, 20, 8, 16, 32), 40), res); } } diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/DateDiffTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/DateDiffTest.java index a630758456..16d585d73e 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/DateDiffTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/DateDiffTest.java @@ -33,7 +33,7 @@ public class DateDiffTest extends DateTimeTestBase { private static final LocalDateTime dateTimeSample2 = LocalDateTime.of(1993, 3, 4, 5, 6); // Function signature is: - // (DATE/DATETIME/TIMESTAMP/TIME, DATE/DATETIME/TIMESTAMP/TIME) -> LONG + // (DATE/TIMESTAMP/TIME, DATE/TIMESTAMP/TIME) -> LONG private static Stream getTestData() { // Arguments are: first argument for `DATE_DIFF` function, second argument and expected result. return Stream.of( diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/DateSubAndSubDateTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/DateSubAndSubDateTest.java index 460e12384b..123ecda0bd 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/DateSubAndSubDateTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/DateSubAndSubDateTest.java @@ -8,7 +8,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; +import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP; import java.time.Duration; import java.time.Instant; @@ -18,10 +18,15 @@ import java.time.Period; import java.time.ZoneOffset; import org.junit.jupiter.api.Test; +import org.opensearch.sql.data.model.ExprValue; import org.opensearch.sql.exception.ExpressionEvaluationException; public class DateSubAndSubDateTest extends DateTimeTestBase { + private LocalDateTime toLocalDateTime(ExprValue res) { + return res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime(); + } + private LocalDate today() { return LocalDate.now(functionProperties.getQueryStartClock()); } @@ -29,81 +34,82 @@ private LocalDate today() { @Test public void subdate_returns_datetime_when_args_are_time_and_time_interval() { var res = subdate(LocalTime.of(21, 0), Duration.ofHours(1).plusMinutes(2)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalTime.of(19, 58).atDate(today()), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals(LocalTime.of(19, 58).atDate(today()), toLocalDateTime(res)); } @Test public void date_sub_returns_datetime_when_args_are_time_and_time_interval() { var res = date_sub(LocalTime.of(10, 20, 30), Duration.ofHours(1).plusMinutes(2).plusSeconds(42)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalTime.of(9, 17, 48).atDate(today()), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals(LocalTime.of(9, 17, 48).atDate(today()), toLocalDateTime(res)); } @Test public void subdate_time_limited_by_24_hours() { var res = subdate(LocalTime.MIN, Duration.ofNanos(1)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalTime.MAX, res.datetimeValue().toLocalTime()); + assertEquals(TIMESTAMP, res.type()); + assertEquals(LocalTime.MAX, res.timestampValue().atZone(ZoneOffset.UTC).toLocalTime()); } @Test public void date_sub_time_limited_by_24_hours() { var res = date_sub(LocalTime.of(10, 20, 30), Duration.ofHours(20).plusMinutes(50).plusSeconds(7)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalTime.of(13, 30, 23), res.datetimeValue().toLocalTime()); + assertEquals(TIMESTAMP, res.type()); + assertEquals( + LocalTime.of(13, 30, 23), res.timestampValue().atZone(ZoneOffset.UTC).toLocalTime()); } @Test public void subdate_returns_datetime_when_args_are_date_and_date_interval() { var res = subdate(LocalDate.of(2020, 2, 20), Period.of(3, 11, 21)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalDate.of(2016, 2, 28).atStartOfDay(), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals(LocalDate.of(2016, 2, 28).atStartOfDay(), toLocalDateTime(res)); } @Test public void date_sub_returns_datetime_when_args_are_date_and_date_interval() { var res = date_sub(LocalDate.of(1961, 4, 12), Period.of(50, 50, 50)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalDate.of(1906, 12, 24).atStartOfDay(), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals(LocalDate.of(1906, 12, 24).atStartOfDay(), toLocalDateTime(res)); } @Test public void subdate_returns_datetime_when_args_are_date_and_time_interval() { var res = subdate(LocalDate.of(2020, 2, 20), Duration.ofHours(1).plusMinutes(2)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalDateTime.of(2020, 2, 19, 22, 58), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals(LocalDateTime.of(2020, 2, 19, 22, 58), toLocalDateTime(res)); } @Test public void date_sub_returns_datetime_when_args_are_date_and_time_interval() { var res = date_sub(LocalDate.of(1961, 4, 12), Duration.ofHours(9).plusMinutes(7)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalDateTime.of(1961, 4, 11, 14, 53), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals(LocalDateTime.of(1961, 4, 11, 14, 53), toLocalDateTime(res)); } @Test public void subdate_returns_datetime_when_args_are_time_and_date_interval() { // Date based on today var res = subdate(LocalTime.of(1, 2, 0), Period.ofDays(1)); - assertEquals(DATETIME, res.type()); - assertEquals(today().minusDays(1).atTime(LocalTime.of(1, 2, 0)), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals(today().minusDays(1).atTime(LocalTime.of(1, 2, 0)), toLocalDateTime(res)); } @Test public void date_sub_returns_datetime_when_args_are_time_and_date_interval() { var res = date_sub(LocalTime.MIDNIGHT, Period.ofDays(0)); - assertEquals(DATETIME, res.type()); - assertEquals(today().atStartOfDay(), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals(today().atStartOfDay(), toLocalDateTime(res)); } @Test public void subdate_returns_datetime_when_first_arg_is_datetime() { var res = subdate(LocalDateTime.of(1961, 4, 12, 9, 7), Duration.ofMinutes(108)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalDateTime.of(1961, 4, 12, 7, 19), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals(LocalDateTime.of(1961, 4, 12, 7, 19), toLocalDateTime(res)); } @Test @@ -111,30 +117,30 @@ public void date_sub_returns_datetime_when_first_arg_is_timestamp() { var res = date_sub( LocalDateTime.of(1961, 4, 12, 9, 7).toInstant(ZoneOffset.UTC), Duration.ofMinutes(108)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalDateTime.of(1961, 4, 12, 7, 19), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals(LocalDateTime.of(1961, 4, 12, 7, 19), toLocalDateTime(res)); } @Test public void subdate_accepts_negative_interval() { var res = subdate(LocalDateTime.of(2020, 10, 20, 14, 42), Duration.ofDays(-10)); - assertEquals(DATETIME, res.type()); - assertEquals(LocalDateTime.of(2020, 10, 30, 14, 42), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals(LocalDateTime.of(2020, 10, 30, 14, 42), toLocalDateTime(res)); assertEquals(adddate(LocalDateTime.of(2020, 10, 20, 14, 42), Duration.ofDays(10)), res); } @Test public void subdate_has_second_signature_but_not_date_sub() { var res = subdate(LocalDateTime.of(1961, 4, 12, 9, 7), 100500); - assertEquals(DATETIME, res.type()); + assertEquals(TIMESTAMP, res.type()); var exception = assertThrows( ExpressionEvaluationException.class, () -> date_sub(LocalDateTime.of(1961, 4, 12, 9, 7), 100500)); assertEquals( - "date_sub function expected {[DATE,INTERVAL],[DATETIME,INTERVAL]," - + "[TIMESTAMP,INTERVAL],[TIME,INTERVAL]}, but get [DATETIME,INTEGER]", + "date_sub function expected {[DATE,INTERVAL],[TIMESTAMP,INTERVAL],[TIME,INTERVAL]}, but get" + + " [TIMESTAMP,INTEGER]", exception.getMessage()); } @@ -148,23 +154,23 @@ public void subdate_returns_date_when_args_are_date_and_days() { @Test public void subdate_returns_datetime_when_args_are_date_but_days() { var res = subdate(LocalDate.of(2000, 1, 1).atStartOfDay(), 2); - assertEquals(DATETIME, res.type()); - assertEquals(LocalDateTime.of(1999, 12, 30, 0, 0), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals(LocalDateTime.of(1999, 12, 30, 0, 0), toLocalDateTime(res)); res = subdate(LocalTime.now(), 2); - assertEquals(DATETIME, res.type()); + assertEquals(TIMESTAMP, res.type()); assertEquals(today().minusDays(2), res.dateValue()); res = subdate(Instant.ofEpochSecond(42), 2); - assertEquals(DATETIME, res.type()); - assertEquals(LocalDateTime.of(1969, 12, 30, 0, 0, 42), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals(LocalDateTime.of(1969, 12, 30, 0, 0, 42), toLocalDateTime(res)); } @Test public void subdate_accepts_negative_days() { var res = subdate(LocalDateTime.of(2020, 10, 20, 8, 16, 32), -40); - assertEquals(DATETIME, res.type()); - assertEquals(LocalDateTime.of(2020, 10, 20, 8, 16, 32).plusDays(40), res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals(LocalDateTime.of(2020, 10, 20, 8, 16, 32).plusDays(40), toLocalDateTime(res)); assertEquals(adddate(LocalDateTime.of(2020, 10, 20, 8, 16, 32), 40), res); } } 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 c2a6129626..d4ee7c44da 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 @@ -32,7 +32,6 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.opensearch.sql.data.model.ExprDateValue; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprDoubleValue; import org.opensearch.sql.data.model.ExprIntegerValue; import org.opensearch.sql.data.model.ExprLongValue; @@ -398,10 +397,6 @@ private static Stream getTestDataForDayOfYear() { return Stream.of( Arguments.of( DSL.literal(new ExprDateValue("2020-08-07")), "day_of_year(DATE '2020-08-07')", 220), - Arguments.of( - DSL.literal(new ExprDatetimeValue("2020-08-07 12:23:34")), - "day_of_year(DATETIME '2020-08-07 12:23:34')", - 220), Arguments.of( DSL.literal(new ExprTimestampValue("2020-08-07 12:23:34")), "day_of_year(TIMESTAMP '2020-08-07 12:23:34')", @@ -519,11 +514,6 @@ private static Stream getTestDataForGetFormat() { Arguments.of("DATE", "ISO", "%Y-%m-%d"), Arguments.of("DATE", "EUR", "%d.%m.%Y"), Arguments.of("DATE", "INTERNAL", "%Y%m%d"), - Arguments.of("DATETIME", "USA", "%Y-%m-%d %H.%i.%s"), - Arguments.of("DATETIME", "JIS", "%Y-%m-%d %H:%i:%s"), - Arguments.of("DATETIME", "ISO", "%Y-%m-%d %H:%i:%s"), - Arguments.of("DATETIME", "EUR", "%Y-%m-%d %H.%i.%s"), - Arguments.of("DATETIME", "INTERNAL", "%Y%m%d%H%i%s"), Arguments.of("TIME", "USA", "%h:%i:%s %p"), Arguments.of("TIME", "JIS", "%H:%i:%s"), Arguments.of("TIME", "ISO", "%H:%i:%s"), @@ -572,11 +562,6 @@ public void hour() { assertEquals(integerValue(1), expression.valueOf()); assertEquals("hour(TIMESTAMP '2020-08-17 01:02:03')", expression.toString()); - expression = DSL.hour(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03"))); - assertEquals(INTEGER, expression.type()); - assertEquals(integerValue(1), expression.valueOf()); - assertEquals("hour(DATETIME '2020-08-17 01:02:03')", expression.toString()); - expression = DSL.hour(DSL.literal("2020-08-17 01:02:03")); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(1), expression.valueOf()); @@ -617,9 +602,7 @@ public void hourOfDay() { FunctionExpression expression2 = DSL.hour_of_day(DSL.literal("01:02:03")); FunctionExpression expression3 = DSL.hour_of_day(DSL.literal(new ExprTimestampValue("2020-08-17 01:02:03"))); - FunctionExpression expression4 = - DSL.hour_of_day(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03"))); - FunctionExpression expression5 = DSL.hour_of_day(DSL.literal("2020-08-17 01:02:03")); + FunctionExpression expression4 = DSL.hour_of_day(DSL.literal("2020-08-17 01:02:03")); assertAll( () -> hourOfDayQuery(expression1, 1), @@ -629,9 +612,7 @@ public void hourOfDay() { () -> hourOfDayQuery(expression3, 1), () -> assertEquals("hour_of_day(TIMESTAMP '2020-08-17 01:02:03')", expression3.toString()), () -> hourOfDayQuery(expression4, 1), - () -> assertEquals("hour_of_day(DATETIME '2020-08-17 01:02:03')", expression4.toString()), - () -> hourOfDayQuery(expression5, 1), - () -> assertEquals("hour_of_day(\"2020-08-17 01:02:03\")", expression5.toString())); + () -> assertEquals("hour_of_day(\"2020-08-17 01:02:03\")", expression4.toString())); } private void invalidHourOfDayQuery(String time) { @@ -731,15 +712,10 @@ public void microsecond() { assertEquals(integerValue(120000), eval(expression)); assertEquals("microsecond(\"01:02:03.12\")", expression.toString()); - expression = DSL.microsecond(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03.000010"))); - assertEquals(INTEGER, expression.type()); - assertEquals(integerValue(10), expression.valueOf()); - assertEquals("microsecond(DATETIME '2020-08-17 01:02:03.00001')", expression.toString()); - - expression = DSL.microsecond(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03.123456"))); + expression = DSL.microsecond(DSL.literal(new ExprTimestampValue("2020-08-17 01:02:03.123456"))); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(123456), expression.valueOf()); - assertEquals("microsecond(DATETIME '2020-08-17 01:02:03.123456')", expression.toString()); + assertEquals("microsecond(TIMESTAMP '2020-08-17 01:02:03.123456')", expression.toString()); expression = DSL.microsecond(DSL.literal("2020-08-17 01:02:03.123456")); assertEquals(INTEGER, expression.type()); @@ -769,11 +745,6 @@ public void minute() { assertEquals(integerValue(2), expression.valueOf()); assertEquals("minute(TIMESTAMP '2020-08-17 01:02:03')", expression.toString()); - expression = DSL.minute(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03"))); - assertEquals(INTEGER, expression.type()); - assertEquals(integerValue(2), expression.valueOf()); - assertEquals("minute(DATETIME '2020-08-17 01:02:03')", expression.toString()); - expression = DSL.minute(DSL.literal("2020-08-17 01:02:03")); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(2), expression.valueOf()); @@ -803,11 +774,6 @@ public void minuteOfDay() { assertEquals(integerValue(62), expression.valueOf()); assertEquals("minute_of_day(TIMESTAMP '2020-08-17 01:02:03')", expression.toString()); - expression = DSL.minute_of_day(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03"))); - assertEquals(INTEGER, expression.type()); - assertEquals(integerValue(62), expression.valueOf()); - assertEquals("minute_of_day(DATETIME '2020-08-17 01:02:03')", expression.toString()); - expression = DSL.minute_of_day(DSL.literal("2020-08-17 01:02:03")); assertEquals(INTEGER, expression.type()); assertEquals(integerValue(62), expression.valueOf()); @@ -833,10 +799,6 @@ private static Stream getTestDataForMinuteOfHour() { DSL.literal(new ExprTimestampValue("2020-08-17 01:02:03")), 2, "minute_of_hour(TIMESTAMP '2020-08-17 01:02:03')"), - Arguments.of( - DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03")), - 2, - "minute_of_hour(DATETIME '2020-08-17 01:02:03')"), Arguments.of( DSL.literal("2020-08-17 01:02:03"), 2, "minute_of_hour(\"2020-08-17 01:02:03\")")); } @@ -894,10 +856,6 @@ private static Stream getTestDataForMonthOfYear() { return Stream.of( Arguments.of( DSL.literal(new ExprDateValue("2020-08-07")), "month_of_year(DATE '2020-08-07')", 8), - Arguments.of( - DSL.literal(new ExprDatetimeValue("2020-08-07 12:23:34")), - "month_of_year(DATETIME '2020-08-07 12:23:34')", - 8), Arguments.of( DSL.literal(new ExprTimestampValue("2020-08-07 12:23:34")), "month_of_year(TIMESTAMP '2020-08-07 12:23:34')", @@ -1052,11 +1010,6 @@ public void second() { assertEquals(INTEGER, expression.type()); assertEquals(integerValue(3), expression.valueOf()); assertEquals("second(TIMESTAMP '2020-08-17 01:02:03')", expression.toString()); - - expression = DSL.second(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03"))); - assertEquals(INTEGER, expression.type()); - assertEquals(integerValue(3), expression.valueOf()); - assertEquals("second(DATETIME '2020-08-17 01:02:03')", expression.toString()); } private void secondOfMinuteQuery(FunctionExpression dateExpression, int second, String testExpr) { @@ -1075,11 +1028,7 @@ private static Stream getTestDataForSecondOfMinute() { Arguments.of( DSL.literal(new ExprTimestampValue("2020-08-17 01:02:03")), 3, - "second_of_minute(TIMESTAMP '2020-08-17 01:02:03')"), - Arguments.of( - DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03")), - 3, - "second_of_minute(DATETIME '2020-08-17 01:02:03')")); + "second_of_minute(TIMESTAMP '2020-08-17 01:02:03')")); } @ParameterizedTest(name = "{2}") @@ -1253,10 +1202,6 @@ private void validateStringFormat( private static Stream getTestDataForWeekFormats() { return Stream.of( Arguments.of(DSL.literal(new ExprDateValue("2019-01-05")), "DATE '2019-01-05'", 0), - Arguments.of( - DSL.literal(new ExprDatetimeValue("2019-01-05 01:02:03")), - "DATETIME '2019-01-05 01:02:03'", - 0), Arguments.of( DSL.literal(new ExprTimestampValue("2019-01-05 01:02:03")), "TIMESTAMP '2019-01-05 01:02:03'", diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTest.java index d857122534..4bec093b57 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTest.java @@ -7,7 +7,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.opensearch.sql.data.model.ExprValueUtils.nullValue; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; +import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP; import java.time.LocalDateTime; import java.time.ZoneId; @@ -15,7 +15,7 @@ import java.time.format.DateTimeFormatter; import java.util.TimeZone; import org.junit.jupiter.api.Test; -import org.opensearch.sql.data.model.ExprDatetimeValue; +import org.opensearch.sql.data.model.ExprTimestampValue; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.ExpressionTestBase; import org.opensearch.sql.expression.FunctionExpression; @@ -25,23 +25,23 @@ class DateTimeTest extends ExpressionTestBase { @Test public void noTimeZoneNoField2() { FunctionExpression expr = DSL.datetime(DSL.literal("2008-05-15 22:00:00")); - assertEquals(DATETIME, expr.type()); - assertEquals(new ExprDatetimeValue("2008-05-15 22:00:00"), expr.valueOf()); + assertEquals(TIMESTAMP, expr.type()); + assertEquals(new ExprTimestampValue("2008-05-15 22:00:00"), expr.valueOf()); } @Test public void positiveTimeZoneNoField2() { FunctionExpression expr = DSL.datetime(DSL.literal("2008-05-15 22:00:00+01:00")); - assertEquals(DATETIME, expr.type()); - assertEquals(new ExprDatetimeValue("2008-05-15 22:00:00"), expr.valueOf()); + assertEquals(TIMESTAMP, expr.type()); + assertEquals(new ExprTimestampValue("2008-05-15 22:00:00"), expr.valueOf()); } @Test public void positiveField1WrittenField2() { FunctionExpression expr = DSL.datetime(DSL.literal("2008-05-15 22:00:00+01:00"), DSL.literal("America/Los_Angeles")); - assertEquals(DATETIME, expr.type()); - assertEquals(new ExprDatetimeValue("2008-05-15 14:00:00"), expr.valueOf()); + assertEquals(TIMESTAMP, expr.type()); + assertEquals(new ExprTimestampValue("2008-05-15 14:00:00"), expr.valueOf()); } // When no timezone argument is passed inside the datetime field, it assumes local time. @@ -57,23 +57,23 @@ public void localDateTimeConversion() { .atZone(ZoneId.of(TimeZone.getDefault().getID())) .withZoneSameInstant(ZoneId.of(timeZone)); FunctionExpression expr = DSL.datetime(DSL.literal(dt), DSL.literal(timeZone)); - assertEquals(DATETIME, expr.type()); - assertEquals(new ExprDatetimeValue(timeZoneLocal.toLocalDateTime()), expr.valueOf()); + assertEquals(TIMESTAMP, expr.type()); + assertEquals(new ExprTimestampValue(timeZoneLocal.toLocalDateTime()), expr.valueOf()); } @Test public void negativeField1WrittenField2() { FunctionExpression expr = DSL.datetime(DSL.literal("2008-05-15 22:00:00-11:00"), DSL.literal("America/Los_Angeles")); - assertEquals(DATETIME, expr.type()); - assertEquals(new ExprDatetimeValue("2008-05-16 02:00:00"), expr.valueOf()); + assertEquals(TIMESTAMP, expr.type()); + assertEquals(new ExprTimestampValue("2008-05-16 02:00:00"), expr.valueOf()); } @Test public void negativeField1PositiveField2() { FunctionExpression expr = DSL.datetime(DSL.literal("2008-05-15 22:00:00-12:00"), DSL.literal("+15:00")); - assertEquals(DATETIME, expr.type()); + assertEquals(TIMESTAMP, expr.type()); assertEquals(nullValue(), expr.valueOf()); } @@ -81,7 +81,7 @@ public void negativeField1PositiveField2() { public void twentyFourHourDifference() { FunctionExpression expr = DSL.datetime(DSL.literal("2008-05-15 22:00:00-14:00"), DSL.literal("+10:00")); - assertEquals(DATETIME, expr.type()); + assertEquals(TIMESTAMP, expr.type()); assertEquals(nullValue(), expr.valueOf()); } @@ -89,14 +89,14 @@ public void twentyFourHourDifference() { public void negativeToNull() { FunctionExpression expr = DSL.datetime(DSL.literal("2008-05-15 22:00:00-11:00"), DSL.literal(nullValue())); - assertEquals(DATETIME, expr.type()); + assertEquals(TIMESTAMP, expr.type()); assertEquals(nullValue(), expr.valueOf()); } @Test public void invalidDate() { FunctionExpression expr = DSL.datetime(DSL.literal("2008-04-31 22:00:00-11:00")); - assertEquals(DATETIME, expr.type()); + assertEquals(TIMESTAMP, expr.type()); assertEquals(nullValue(), expr.valueOf()); } } diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTestBase.java b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTestBase.java index 023a3574aa..865c162f76 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTestBase.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTestBase.java @@ -11,10 +11,10 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.ZoneOffset; import java.time.temporal.Temporal; import java.util.List; import org.opensearch.sql.data.model.ExprDateValue; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprTimeValue; import org.opensearch.sql.data.model.ExprTimestampValue; import org.opensearch.sql.data.model.ExprValue; @@ -91,7 +91,8 @@ protected Long datediff(Temporal first, Temporal second) { } protected LocalDateTime fromUnixTime(Double value) { - return fromUnixTime(DSL.literal(value)).valueOf().datetimeValue(); + return LocalDateTime.ofInstant( + fromUnixTime(DSL.literal(value)).valueOf().timestampValue(), ZoneOffset.UTC); } protected FunctionExpression fromUnixTime(Expression value) { @@ -109,7 +110,8 @@ protected FunctionExpression fromUnixTime(Expression value, Expression format) { } protected LocalDateTime fromUnixTime(Long value) { - return fromUnixTime(DSL.literal(value)).valueOf().datetimeValue(); + return LocalDateTime.ofInstant( + fromUnixTime(DSL.literal(value)).valueOf().timestampValue(), ZoneOffset.UTC); } protected String fromUnixTime(Long value, String format) { @@ -223,7 +225,7 @@ protected Double unixTimeStampOf(LocalDate value) { } protected Double unixTimeStampOf(LocalDateTime value) { - return unixTimeStampOf(DSL.literal(new ExprDatetimeValue(value))).valueOf().doubleValue(); + return unixTimeStampOf(DSL.literal(new ExprTimestampValue(value))).valueOf().doubleValue(); } protected Double unixTimeStampOf(Instant value) { diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/ExtractTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/ExtractTest.java index 820158b722..02d50d0b59 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/ExtractTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/ExtractTest.java @@ -16,8 +16,8 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.opensearch.sql.data.model.ExprDateValue; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprTimeValue; +import org.opensearch.sql.data.model.ExprTimestampValue; import org.opensearch.sql.data.model.ExprValue; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.Expression; @@ -72,12 +72,12 @@ private static Stream getDateResultsForExtractFunction() { }) public void testExtractWithDatetime(String part, long expected) { FunctionExpression datetimeExpression = - DSL.extract(DSL.literal(part), DSL.literal(new ExprDatetimeValue(datetimeInput))); + DSL.extract(DSL.literal(part), DSL.literal(new ExprTimestampValue(datetimeInput))); assertEquals(LONG, datetimeExpression.type()); assertEquals(expected, eval(datetimeExpression).longValue()); assertEquals( - String.format("extract(\"%s\", DATETIME '2023-02-11 10:11:12.123')", part), + String.format("extract(\"%s\", TIMESTAMP '2023-02-11 10:11:12.123')", part), datetimeExpression.toString()); } diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/FromUnixTimeTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/FromUnixTimeTest.java index 8fcc6904b2..a6d1da003f 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/FromUnixTimeTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/FromUnixTimeTest.java @@ -46,7 +46,9 @@ public void checkOfLong(Long value) { LocalDateTime.of(1970, 1, 1, 0, 0, 0).plus(value, ChronoUnit.SECONDS), fromUnixTime(value)); assertEquals( LocalDateTime.of(1970, 1, 1, 0, 0, 0).plus(value, ChronoUnit.SECONDS), - eval(fromUnixTime(DSL.literal(new ExprLongValue(value)))).datetimeValue()); + LocalDateTime.ofInstant( + eval(fromUnixTime(DSL.literal(new ExprLongValue(value)))).timestampValue(), + ZoneOffset.UTC)); } private static Stream getDoubleSamples() { @@ -76,7 +78,9 @@ public void checkOfDouble(Double value) { valueAsString); assertEquals( LocalDateTime.ofEpochSecond(intPart, (int) Math.round(fracPart * 1E9), ZoneOffset.UTC), - eval(fromUnixTime(DSL.literal(new ExprDoubleValue(value)))).datetimeValue(), + LocalDateTime.ofInstant( + eval(fromUnixTime(DSL.literal(new ExprDoubleValue(value)))).timestampValue(), + ZoneOffset.UTC), valueAsString); } diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/NowLikeFunctionTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/NowLikeFunctionTest.java index 0e5c00084f..8b795786c0 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/NowLikeFunctionTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/NowLikeFunctionTest.java @@ -9,13 +9,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.TIME; -import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID; +import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; import java.time.temporal.Temporal; @@ -45,7 +45,7 @@ class NowLikeFunctionTest extends ExpressionTestBase { void now() { test_now_like_functions( DSL::now, - DATETIME, + TIMESTAMP, false, () -> LocalDateTime.now(functionProperties.getQueryStartClock())); } @@ -54,7 +54,7 @@ void now() { void current_timestamp() { test_now_like_functions( DSL::current_timestamp, - DATETIME, + TIMESTAMP, false, () -> LocalDateTime.now(functionProperties.getQueryStartClock())); } @@ -63,7 +63,7 @@ void current_timestamp() { void localtimestamp() { test_now_like_functions( DSL::localtimestamp, - DATETIME, + TIMESTAMP, false, () -> LocalDateTime.now(functionProperties.getQueryStartClock())); } @@ -72,14 +72,14 @@ void localtimestamp() { void localtime() { test_now_like_functions( DSL::localtime, - DATETIME, + TIMESTAMP, false, () -> LocalDateTime.now(functionProperties.getQueryStartClock())); } @Test void sysdate() { - test_now_like_functions(DSL::sysdate, DATETIME, true, LocalDateTime::now); + test_now_like_functions(DSL::sysdate, TIMESTAMP, true, LocalDateTime::now); } @Test @@ -128,14 +128,14 @@ void utc_time() { @Test void utc_timestamp() { test_now_like_functions( - DSL::utc_timestamp, DATETIME, false, () -> utcDateTimeNow(functionProperties)); + DSL::utc_timestamp, TIMESTAMP, false, () -> utcDateTimeNow(functionProperties)); } private static LocalDateTime utcDateTimeNow(FunctionProperties functionProperties) { ZonedDateTime zonedDateTime = LocalDateTime.now(functionProperties.getQueryStartClock()) .atZone(TimeZone.getDefault().toZoneId()); - return zonedDateTime.withZoneSameInstant(UTC_ZONE_ID).toLocalDateTime(); + return zonedDateTime.withZoneSameInstant(ZoneOffset.UTC).toLocalDateTime(); } /** @@ -249,8 +249,8 @@ private Temporal extractValue(FunctionExpression func) { switch ((ExprCoreType) func.type()) { case DATE: return func.valueOf().dateValue(); - case DATETIME: - return func.valueOf().datetimeValue(); + case TIMESTAMP: + return LocalDateTime.ofInstant(func.valueOf().timestampValue(), ZoneOffset.UTC); case TIME: return func.valueOf().timeValue(); // unreachable code diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/StrToDateTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/StrToDateTest.java index 42d4aab1f6..7f0861d9c3 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/StrToDateTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/StrToDateTest.java @@ -6,21 +6,23 @@ package org.opensearch.sql.expression.datetime; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; +import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP; import static org.opensearch.sql.data.type.ExprCoreType.UNDEFINED; +import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.ZoneOffset; import java.util.stream.Stream; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprNullValue; import org.opensearch.sql.data.model.ExprStringValue; import org.opensearch.sql.data.model.ExprTimeValue; +import org.opensearch.sql.data.model.ExprTimestampValue; import org.opensearch.sql.data.model.ExprValue; import org.opensearch.sql.data.type.ExprCoreType; import org.opensearch.sql.expression.DSL; @@ -34,23 +36,23 @@ private static Stream getTestDataForStrToDate() { return Stream.of( // Date arguments Arguments.of( - "01,5,2013", "%d,%m,%Y", new ExprDatetimeValue("2013-05-01 00:00:00"), DATETIME), + "01,5,2013", "%d,%m,%Y", new ExprTimestampValue("2013-05-01 00:00:00"), TIMESTAMP), Arguments.of( - "May 1, 2013", "%M %d, %Y", new ExprDatetimeValue("2013-05-01 00:00:00"), DATETIME), + "May 1, 2013", "%M %d, %Y", new ExprTimestampValue("2013-05-01 00:00:00"), TIMESTAMP), Arguments.of( "May 1, 2013 - 9,23,11", "%M %d, %Y - %h,%i,%s", - new ExprDatetimeValue("2013-05-01 09:23:11"), - DATETIME), + new ExprTimestampValue("2013-05-01 09:23:11"), + TIMESTAMP), Arguments.of( - "2000,1,1", "%Y,%m,%d", new ExprDatetimeValue("2000-01-01 00:00:00"), DATETIME), + "2000,1,1", "%Y,%m,%d", new ExprTimestampValue("2000-01-01 00:00:00"), TIMESTAMP), Arguments.of( - "2000,1,1,10", "%Y,%m,%d,%h", new ExprDatetimeValue("2000-01-01 10:00:00"), DATETIME), + "2000,1,1,10", "%Y,%m,%d,%h", new ExprTimestampValue("2000-01-01 10:00:00"), TIMESTAMP), Arguments.of( "2000,1,1,10,11", "%Y,%m,%d,%h,%i", - new ExprDatetimeValue("2000-01-01 10:11:00"), - DATETIME), + new ExprTimestampValue("2000-01-01 10:11:00"), + TIMESTAMP), // Invalid Arguments (should return null) Arguments.of("a09:30:17", "a%h:%i:%s", ExprNullValue.of(), UNDEFINED), @@ -108,20 +110,22 @@ public void test_str_to_date_with_time_type(String parsed, String format) { ExprValue result = eval(expression); - assertEquals(DATETIME, result.type()); - assertEquals(getExpectedTimeResult(9, 23, 11), result.datetimeValue()); + assertEquals(TIMESTAMP, result.type()); + assertEquals( + getExpectedTimeResult(9, 23, 11), + LocalDateTime.ofInstant(result.timestampValue(), ZoneOffset.UTC)); } @Test public void test_str_to_date_with_date_format() { - LocalDateTime arg = LocalDateTime.of(2023, 2, 27, 10, 11, 12); + Instant arg = Instant.parse("2023-02-27T10:11:12Z"); String format = "%Y,%m,%d %h,%i,%s"; FunctionExpression dateFormatExpr = DSL.date_format( functionProperties, - DSL.literal(new ExprDatetimeValue(arg)), + DSL.literal(new ExprTimestampValue(arg)), DSL.literal(new ExprStringValue(format))); String dateFormatResult = eval(dateFormatExpr).stringValue(); @@ -130,7 +134,7 @@ public void test_str_to_date_with_date_format() { functionProperties, DSL.literal(new ExprStringValue(dateFormatResult)), DSL.literal(new ExprStringValue(format))); - LocalDateTime strToDateResult = eval(strToDateExpr).datetimeValue(); + Instant strToDateResult = eval(strToDateExpr).timestampValue(); assertEquals(arg, strToDateResult); } @@ -156,7 +160,8 @@ public void test_str_to_date_with_time_format() { functionProperties, DSL.literal(new ExprStringValue(timeFormatResult)), DSL.literal(new ExprStringValue(format))); - LocalDateTime strToDateResult = eval(strToDateExpr).datetimeValue(); + LocalDateTime strToDateResult = + LocalDateTime.ofInstant(eval(strToDateExpr).timestampValue(), ZoneOffset.UTC); assertEquals(getExpectedTimeResult(HOURS, MINUTES, SECONDS), strToDateResult); } diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/TimeStampAddTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/TimeStampAddTest.java index 243eb6bb7b..13f4f20704 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/TimeStampAddTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/TimeStampAddTest.java @@ -18,7 +18,6 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.opensearch.sql.data.model.ExprDateValue; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprIntegerValue; import org.opensearch.sql.data.model.ExprNullValue; import org.opensearch.sql.data.model.ExprStringValue; @@ -43,12 +42,6 @@ private static Stream getTestDataForTimestampAdd() { Arguments.of("MINUTE", 1, new ExprDateValue("2003-01-02"), "2003-01-02 00:01:00"), Arguments.of("WEEK", 1, new ExprDateValue("2003-01-02"), "2003-01-09 00:00:00"), - // Datetime - Arguments.of( - "MINUTE", 1, new ExprDatetimeValue("2003-01-02 00:00:00"), "2003-01-02 00:01:00"), - Arguments.of( - "WEEK", 1, new ExprDatetimeValue("2003-01-02 00:00:00"), "2003-01-09 00:00:00"), - // Timestamp Arguments.of( "MINUTE", 1, new ExprTimestampValue("2003-01-02 00:00:00"), "2003-01-02 00:01:00"), @@ -125,7 +118,7 @@ private static FunctionExpression timestampaddQuery( @MethodSource("getTestDataForTimestampAdd") public void testTimestampadd(String unit, int amount, ExprValue datetimeExpr, String expected) { FunctionExpression expr = timestampaddQuery(unit, amount, datetimeExpr); - assertEquals(new ExprDatetimeValue(expected), eval(expr)); + assertEquals(new ExprTimestampValue(expected), eval(expr)); } private static Stream getTestDataForTestAddingDatePartToTime() { @@ -165,7 +158,7 @@ public void testAddingDatePartToTime( LocalDateTime expected1 = LocalDateTime.of(expectedDate, LocalTime.parse(timeArg)); - assertEquals(new ExprDatetimeValue(expected1), eval(expr)); + assertEquals(new ExprTimestampValue(expected1), eval(expr)); } @Test @@ -184,7 +177,7 @@ public void testAddingTimePartToTime() { LocalDateTime expected = LocalDateTime.of(LocalDate.now(), LocalTime.parse(timeArg).plusMinutes(addedInterval)); - assertEquals(new ExprDatetimeValue(expected), eval(expr)); + assertEquals(new ExprTimestampValue(expected), eval(expr)); } @Test @@ -196,15 +189,11 @@ public void testDifferentInputTypesHaveSameResult() { FunctionExpression stringExpr = timestampaddQuery(part, amount, new ExprStringValue("2000-01-01 00:00:00")); - FunctionExpression datetimeExpr = - timestampaddQuery(part, amount, new ExprDatetimeValue("2000-01-01 00:00:00")); - FunctionExpression timestampExpr = timestampaddQuery(part, amount, new ExprTimestampValue("2000-01-01 00:00:00")); assertAll( () -> assertEquals(eval(dateExpr), eval(stringExpr)), - () -> assertEquals(eval(dateExpr), eval(datetimeExpr)), () -> assertEquals(eval(dateExpr), eval(timestampExpr))); } diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/TimeStampDiffTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/TimeStampDiffTest.java index 061420ceee..b5ac3b078f 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/TimeStampDiffTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/TimeStampDiffTest.java @@ -21,7 +21,6 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.opensearch.sql.data.model.ExprDateValue; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprNullValue; import org.opensearch.sql.data.model.ExprStringValue; import org.opensearch.sql.data.model.ExprTimeValue; @@ -80,8 +79,6 @@ private static ExprValue generateArg( return new ExprTimestampValue(arg.toInstant(ZoneOffset.UTC)); case "DATE": return new ExprDateValue(arg.toLocalDate()); - case "DATETIME": - return new ExprDatetimeValue(arg); case "STRING": return new ExprStringValue( String.format( @@ -118,7 +115,7 @@ private static Stream getGeneralTestDataForTimestampDiff() { final String[] intervalTypes = ArrayUtils.addAll(timeIntervalTypes, dateIntervalTypes); // TIME type not included here as it is a special case handled by a different test - final String[] expressionTypes = {"DATE", "DATETIME", "TIMESTAMP", "STRING"}; + final String[] expressionTypes = {"DATE", "TIMESTAMP", "STRING"}; final LocalDateTime baseDateTime = LocalDateTime.of(2000, 1, 1, 0, 0, 0); final int intervalDifference = 5; @@ -159,30 +156,30 @@ private static Stream getCornerCaseTestDataForTimestampDiff() { // Test around Leap Year Arguments.of( "DAY", - new ExprDatetimeValue("2019-02-28 00:00:00"), - new ExprDatetimeValue("2019-03-01 00:00:00"), + new ExprTimestampValue("2019-02-28 00:00:00"), + new ExprTimestampValue("2019-03-01 00:00:00"), 1), Arguments.of( "DAY", - new ExprDatetimeValue("2020-02-28 00:00:00"), - new ExprDatetimeValue("2020-03-01 00:00:00"), + new ExprTimestampValue("2020-02-28 00:00:00"), + new ExprTimestampValue("2020-03-01 00:00:00"), 2), // Test around year change Arguments.of( "SECOND", - new ExprDatetimeValue("2019-12-31 23:59:59"), - new ExprDatetimeValue("2020-01-01 00:00:00"), + new ExprTimestampValue("2019-12-31 23:59:59"), + new ExprTimestampValue("2020-01-01 00:00:00"), 1), Arguments.of( "DAY", - new ExprDatetimeValue("2019-12-31 23:59:59"), - new ExprDatetimeValue("2020-01-01 00:00:00"), + new ExprTimestampValue("2019-12-31 23:59:59"), + new ExprTimestampValue("2020-01-01 00:00:00"), 0), Arguments.of( "DAY", - new ExprDatetimeValue("2019-12-31 00:00:00"), - new ExprDatetimeValue("2020-01-01 00:00:00"), + new ExprTimestampValue("2019-12-31 00:00:00"), + new ExprTimestampValue("2020-01-01 00:00:00"), 1)); } @@ -295,13 +292,6 @@ public void testDifferentInputTypesHaveSameResult() { new ExprStringValue("2000-01-01 00:00:00"), new ExprStringValue("2000-01-02 00:00:00")); - FunctionExpression datetimeExpr = - timestampdiffQuery( - functionProperties, - part, - new ExprDatetimeValue("2000-01-01 00:00:00"), - new ExprDatetimeValue("2000-01-02 00:00:00")); - FunctionExpression timestampExpr = timestampdiffQuery( functionProperties, @@ -311,7 +301,6 @@ public void testDifferentInputTypesHaveSameResult() { assertAll( () -> assertEquals(eval(dateExpr), eval(stringExpr)), - () -> assertEquals(eval(dateExpr), eval(datetimeExpr)), () -> assertEquals(eval(dateExpr), eval(timestampExpr))); } diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/TimestampTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/TimestampTest.java index 7d25c0041b..5aebec9e78 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/TimestampTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/TimestampTest.java @@ -8,12 +8,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP; -import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.ZoneOffset; import java.util.stream.Stream; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; @@ -39,7 +39,9 @@ public void timestamp_one_arg_string() { expr = DSL.timestamp(functionProperties, DSL.literal("1961-04-12 09:07:00.123456")); assertEquals(TIMESTAMP, expr.type()); - assertEquals(LocalDateTime.of(1961, 4, 12, 9, 7, 0, 123456000), expr.valueOf().datetimeValue()); + assertEquals( + LocalDateTime.of(1961, 4, 12, 9, 7, 0, 123456000), + expr.valueOf().timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime()); } /** @@ -71,7 +73,8 @@ public void timestamp_one_arg_string_invalid_format(String value, String testNam public void timestamp_one_arg_time() { var expr = DSL.timestamp(functionProperties, DSL.time(DSL.literal("22:33:44"))); assertEquals(TIMESTAMP, expr.type()); - var refValue = LocalDate.now().atTime(LocalTime.of(22, 33, 44)).atZone(UTC_ZONE_ID).toInstant(); + var refValue = + LocalDate.now().atTime(LocalTime.of(22, 33, 44)).atZone(ZoneOffset.UTC).toInstant(); assertEquals(new ExprTimestampValue(refValue), expr.valueOf()); } @@ -79,17 +82,10 @@ public void timestamp_one_arg_time() { public void timestamp_one_arg_date() { var expr = DSL.timestamp(functionProperties, DSL.date(DSL.literal("2077-12-15"))); assertEquals(TIMESTAMP, expr.type()); - var refValue = LocalDate.of(2077, 12, 15).atStartOfDay().atZone(UTC_ZONE_ID).toInstant(); + var refValue = LocalDate.of(2077, 12, 15).atStartOfDay().atZone(ZoneOffset.UTC).toInstant(); assertEquals(new ExprTimestampValue(refValue), expr.valueOf()); } - @Test - public void timestamp_one_arg_datetime() { - var expr = DSL.timestamp(functionProperties, DSL.datetime(DSL.literal("1961-04-12 09:07:00"))); - assertEquals(TIMESTAMP, expr.type()); - assertEquals(LocalDateTime.of(1961, 4, 12, 9, 7, 0), expr.valueOf().datetimeValue()); - } - @Test public void timestamp_one_arg_timestamp() { var refValue = new ExprTimestampValue(Instant.ofEpochSecond(10050042)); @@ -100,7 +96,7 @@ public void timestamp_one_arg_timestamp() { } private static Instant dateTime2Instant(LocalDateTime dt) { - return dt.atZone(UTC_ZONE_ID).toInstant(); + return dt.atZone(ZoneOffset.UTC).toInstant(); } private static ExprTimestampValue dateTime2ExprTs(LocalDateTime dt) { diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/ToSecondsTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/ToSecondsTest.java index 7aa824e61d..910fe42a52 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/ToSecondsTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/ToSecondsTest.java @@ -20,7 +20,6 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.opensearch.sql.data.model.ExprDateValue; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprIntervalValue; import org.opensearch.sql.data.model.ExprLongValue; import org.opensearch.sql.data.model.ExprNullValue; @@ -52,7 +51,6 @@ private static Stream getTestDataForToSeconds() { Arguments.of(new ExprStringValue("2009-11-29 00:00:00"), new ExprLongValue(63426672000L)), Arguments.of(new ExprStringValue("2009-11-29 13:43:32"), new ExprLongValue(63426721412L)), Arguments.of(new ExprDateValue("2009-11-29"), new ExprLongValue(63426672000L)), - Arguments.of(new ExprDatetimeValue("2009-11-29 13:43:32"), new ExprLongValue(63426721412L)), Arguments.of( new ExprTimestampValue("2009-11-29 13:43:32"), new ExprLongValue(63426721412L))); } diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/UnixTimeStampTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/UnixTimeStampTest.java index c979b68302..7373b126c5 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/UnixTimeStampTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/UnixTimeStampTest.java @@ -20,7 +20,6 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.opensearch.sql.data.model.ExprDateValue; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprDoubleValue; import org.opensearch.sql.data.model.ExprNullValue; import org.opensearch.sql.data.model.ExprTimestampValue; @@ -81,7 +80,7 @@ public void checkOfDateTime(LocalDateTime value) { assertEquals(value.toEpochSecond(ZoneOffset.UTC), unixTimeStampOf(value)); assertEquals( value.toEpochSecond(ZoneOffset.UTC), - eval(unixTimeStampOf(DSL.literal(new ExprDatetimeValue(value)))).longValue()); + eval(unixTimeStampOf(DSL.literal(new ExprTimestampValue(value)))).longValue()); } private static Stream getInstantSamples() { diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/UnixTwoWayConversionTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/UnixTwoWayConversionTest.java index c74b062fba..75aed94e03 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/UnixTwoWayConversionTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/UnixTwoWayConversionTest.java @@ -6,17 +6,17 @@ package org.opensearch.sql.expression.datetime; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID; import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.util.stream.Stream; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprDoubleValue; import org.opensearch.sql.data.model.ExprLongValue; +import org.opensearch.sql.data.model.ExprTimestampValue; import org.opensearch.sql.expression.DSL; public class UnixTwoWayConversionTest extends DateTimeTestBase { @@ -28,11 +28,14 @@ public void checkConvertNow() { @Test public void checkConvertNow_with_eval() { - assertEquals(getExpectedNow(), eval(fromUnixTime(unixTimeStampExpr())).datetimeValue()); + assertEquals( + getExpectedNow(), + LocalDateTime.ofInstant( + eval(fromUnixTime(unixTimeStampExpr())).timestampValue(), ZoneOffset.UTC)); } private LocalDateTime getExpectedNow() { - return LocalDateTime.now(functionProperties.getQueryStartClock().withZone(UTC_ZONE_ID)) + return LocalDateTime.now(functionProperties.getQueryStartClock().withZone(ZoneOffset.UTC)) .withNano(0); } @@ -86,7 +89,9 @@ public void convertDateTime2Epoch2DateTime(LocalDateTime value) { assertEquals(value, fromUnixTime(unixTimeStampOf(value))); assertEquals( value, - eval(fromUnixTime(unixTimeStampOf(DSL.literal(new ExprDatetimeValue(value))))) - .datetimeValue()); + LocalDateTime.ofInstant( + eval(fromUnixTime(unixTimeStampOf(DSL.literal(new ExprTimestampValue(value))))) + .timestampValue(), + ZoneOffset.UTC)); } } diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/YearweekTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/YearweekTest.java index 4f7208d141..3533886f9c 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/YearweekTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/YearweekTest.java @@ -19,8 +19,8 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.opensearch.sql.data.model.ExprDateValue; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprTimeValue; +import org.opensearch.sql.data.model.ExprTimestampValue; import org.opensearch.sql.data.model.ExprValue; import org.opensearch.sql.exception.SemanticCheckException; import org.opensearch.sql.expression.DSL; @@ -137,7 +137,7 @@ public void yearweekModeInUnsupportedFormat() { FunctionExpression expression1 = DSL.yearweek( functionProperties, - DSL.literal(new ExprDatetimeValue("2019-01-05 10:11:12")), + DSL.literal(new ExprTimestampValue("2019-01-05 10:11:12")), DSL.literal(8)); SemanticCheckException exception = assertThrows(SemanticCheckException.class, () -> eval(expression1)); @@ -146,7 +146,7 @@ public void yearweekModeInUnsupportedFormat() { FunctionExpression expression2 = DSL.yearweek( functionProperties, - DSL.literal(new ExprDatetimeValue("2019-01-05 10:11:12")), + DSL.literal(new ExprTimestampValue("2019-01-05 10:11:12")), DSL.literal(-1)); exception = assertThrows(SemanticCheckException.class, () -> eval(expression2)); assertEquals("mode:-1 is invalid, please use mode value between 0-7", exception.getMessage()); diff --git a/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java b/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java index 3ee12f59d4..237477050d 100644 --- a/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java @@ -16,10 +16,10 @@ import static org.mockito.Mockito.when; import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN; import static org.opensearch.sql.data.type.ExprCoreType.BYTE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; import static org.opensearch.sql.data.type.ExprCoreType.STRING; import static org.opensearch.sql.data.type.ExprCoreType.STRUCT; +import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP; import static org.opensearch.sql.data.type.ExprCoreType.UNDEFINED; import static org.opensearch.sql.expression.function.BuiltinFunctionName.CAST_TO_BOOLEAN; @@ -126,7 +126,7 @@ void resolve_should_not_cast_arguments_in_cast_function() { FunctionImplementation function = repo.resolve( Collections.emptyList(), - registerFunctionResolver(CAST_TO_BOOLEAN.getName(), DATETIME, BOOLEAN)) + registerFunctionResolver(CAST_TO_BOOLEAN.getName(), TIMESTAMP, BOOLEAN)) .apply(functionProperties, ImmutableList.of(mockExpression)); assertEquals("cast_to_boolean(string)", function.toString()); } diff --git a/core/src/test/java/org/opensearch/sql/expression/function/WideningTypeRuleTest.java b/core/src/test/java/org/opensearch/sql/expression/function/WideningTypeRuleTest.java index 3b6e5f7586..9de1e65108 100644 --- a/core/src/test/java/org/opensearch/sql/expression/function/WideningTypeRuleTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/function/WideningTypeRuleTest.java @@ -10,7 +10,6 @@ import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN; import static org.opensearch.sql.data.type.ExprCoreType.BYTE; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; import static org.opensearch.sql.data.type.ExprCoreType.FLOAT; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; @@ -58,12 +57,8 @@ class WideningTypeRuleTest { .put(STRING, TIMESTAMP, 1) .put(STRING, DATE, 1) .put(STRING, TIME, 1) - .put(STRING, DATETIME, 1) - .put(DATE, DATETIME, 1) - .put(TIME, DATETIME, 1) - .put(DATE, TIMESTAMP, 2) - .put(TIME, TIMESTAMP, 2) - .put(DATETIME, TIMESTAMP, 1) + .put(DATE, TIMESTAMP, 1) + .put(TIME, TIMESTAMP, 1) .put(UNDEFINED, BYTE, 1) .put(UNDEFINED, SHORT, 2) .put(UNDEFINED, INTEGER, 3) diff --git a/core/src/test/java/org/opensearch/sql/expression/operator/convert/TypeCastOperatorTest.java b/core/src/test/java/org/opensearch/sql/expression/operator/convert/TypeCastOperatorTest.java index 7803a4dbca..44a3ccabbd 100644 --- a/core/src/test/java/org/opensearch/sql/expression/operator/convert/TypeCastOperatorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/operator/convert/TypeCastOperatorTest.java @@ -10,7 +10,6 @@ import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN; import static org.opensearch.sql.data.type.ExprCoreType.BYTE; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; import static org.opensearch.sql.data.type.ExprCoreType.FLOAT; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; @@ -27,7 +26,6 @@ import org.opensearch.sql.data.model.ExprBooleanValue; import org.opensearch.sql.data.model.ExprByteValue; import org.opensearch.sql.data.model.ExprDateValue; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprDoubleValue; import org.opensearch.sql.data.model.ExprFloatValue; import org.opensearch.sql.data.model.ExprIntegerValue; @@ -72,12 +70,8 @@ private static Stream timestamp() { return Stream.of(new ExprTimestampValue("2020-12-24 01:01:01")); } - private static Stream datetime() { - return Stream.of(new ExprDatetimeValue("2020-12-24 01:01:01")); - } - @ParameterizedTest(name = "castString({0})") - @MethodSource({"numberData", "stringData", "boolData", "date", "time", "timestamp", "datetime"}) + @MethodSource({"numberData", "stringData", "boolData", "date", "time", "timestamp"}) void castToString(ExprValue value) { FunctionExpression expression = DSL.castString(DSL.literal(value)); assertEquals(STRING, expression.type()); @@ -299,7 +293,7 @@ void castToDate() { assertEquals(DATE, expression.type()); assertEquals(new ExprDateValue("2012-08-07"), expression.valueOf()); - expression = DSL.castDate(DSL.literal(new ExprDatetimeValue("2012-08-07 01:01:01"))); + expression = DSL.castDate(DSL.literal(new ExprTimestampValue("2012-08-07 01:01:01"))); assertEquals(DATE, expression.type()); assertEquals(new ExprDateValue("2012-08-07"), expression.valueOf()); @@ -318,7 +312,7 @@ void castToTime() { assertEquals(TIME, expression.type()); assertEquals(new ExprTimeValue("01:01:01"), expression.valueOf()); - expression = DSL.castTime(DSL.literal(new ExprDatetimeValue("2012-08-07 01:01:01"))); + expression = DSL.castTime(DSL.literal(new ExprTimestampValue("2012-08-07 01:01:01"))); assertEquals(TIME, expression.type()); assertEquals(new ExprTimeValue("01:01:01"), expression.valueOf()); @@ -337,7 +331,7 @@ void castToTimestamp() { assertEquals(TIMESTAMP, expression.type()); assertEquals(new ExprTimestampValue("2012-08-07 01:01:01"), expression.valueOf()); - expression = DSL.castTimestamp(DSL.literal(new ExprDatetimeValue("2012-08-07 01:01:01"))); + expression = DSL.castTimestamp(DSL.literal(new ExprTimestampValue("2012-08-07 01:01:01"))); assertEquals(TIMESTAMP, expression.type()); assertEquals(new ExprTimestampValue("2012-08-07 01:01:01"), expression.valueOf()); @@ -345,19 +339,4 @@ void castToTimestamp() { assertEquals(TIMESTAMP, expression.type()); assertEquals(new ExprTimestampValue("2012-08-07 01:01:01"), expression.valueOf()); } - - @Test - void castToDatetime() { - FunctionExpression expression = DSL.castDatetime(DSL.literal("2012-08-07 01:01:01")); - assertEquals(DATETIME, expression.type()); - assertEquals(new ExprDatetimeValue("2012-08-07 01:01:01"), expression.valueOf()); - - expression = DSL.castDatetime(DSL.literal(new ExprTimestampValue("2012-08-07 01:01:01"))); - assertEquals(DATETIME, expression.type()); - assertEquals(new ExprDatetimeValue("2012-08-07 01:01:01"), expression.valueOf()); - - expression = DSL.castDatetime(DSL.literal(new ExprDateValue("2012-08-07"))); - assertEquals(DATETIME, expression.type()); - assertEquals(new ExprDatetimeValue("2012-08-07 00:00:00"), expression.valueOf()); - } } diff --git a/core/src/test/java/org/opensearch/sql/expression/operator/predicate/BinaryPredicateOperatorTest.java b/core/src/test/java/org/opensearch/sql/expression/operator/predicate/BinaryPredicateOperatorTest.java index e6290553ce..55dfbd35c2 100644 --- a/core/src/test/java/org/opensearch/sql/expression/operator/predicate/BinaryPredicateOperatorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/operator/predicate/BinaryPredicateOperatorTest.java @@ -18,7 +18,6 @@ import static org.opensearch.sql.data.model.ExprValueUtils.fromObjectValue; import static org.opensearch.sql.data.type.ExprCoreType.ARRAY; import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; import static org.opensearch.sql.data.type.ExprCoreType.STRUCT; import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP; @@ -472,11 +471,10 @@ private void assertStringRepr( if (v1.type() == v2.type()) { assertEquals(String.format("%s(%s, %s)", function, v1, v2), functionExpression.toString()); } else { - var widerType = v1.type() == TIMESTAMP || v2.type() == TIMESTAMP ? TIMESTAMP : DATETIME; assertEquals( String.format( "%s(%s, %s)", - function, getExpectedStringRepr(widerType, v1), getExpectedStringRepr(widerType, v2)), + function, getExpectedStringRepr(TIMESTAMP, v1), getExpectedStringRepr(TIMESTAMP, v2)), functionExpression.toString()); } } diff --git a/core/src/test/java/org/opensearch/sql/expression/system/SystemFunctionsTest.java b/core/src/test/java/org/opensearch/sql/expression/system/SystemFunctionsTest.java index ac4153f59f..4b15704c77 100644 --- a/core/src/test/java/org/opensearch/sql/expression/system/SystemFunctionsTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/system/SystemFunctionsTest.java @@ -11,7 +11,6 @@ import java.time.Duration; import java.time.Instant; import java.time.LocalDate; -import java.time.LocalDateTime; import java.time.LocalTime; import java.util.LinkedHashMap; import java.util.List; @@ -21,7 +20,6 @@ import org.opensearch.sql.data.model.ExprByteValue; import org.opensearch.sql.data.model.ExprCollectionValue; import org.opensearch.sql.data.model.ExprDateValue; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprDoubleValue; import org.opensearch.sql.data.model.ExprFloatValue; import org.opensearch.sql.data.model.ExprIntegerValue; @@ -49,7 +47,6 @@ void typeof() { assertEquals("BOOLEAN", typeofGetValue(ExprBooleanValue.of(false))); assertEquals("BYTE", typeofGetValue(new ExprByteValue(0))); assertEquals("DATE", typeofGetValue(new ExprDateValue(LocalDate.now()))); - assertEquals("DATETIME", typeofGetValue(new ExprDatetimeValue(LocalDateTime.now()))); assertEquals("DOUBLE", typeofGetValue(new ExprDoubleValue(0))); assertEquals("FLOAT", typeofGetValue(new ExprFloatValue(0))); assertEquals("INTEGER", typeofGetValue(new ExprIntegerValue(0))); diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/AggregationOperatorTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/AggregationOperatorTest.java index 0f3f4bd61f..ee784045d0 100644 --- a/core/src/test/java/org/opensearch/sql/planner/physical/AggregationOperatorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/physical/AggregationOperatorTest.java @@ -10,7 +10,6 @@ import static org.hamcrest.Matchers.containsInRelativeOrder; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; import static org.opensearch.sql.data.type.ExprCoreType.FLOAT; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; @@ -25,7 +24,6 @@ import java.util.List; import org.junit.jupiter.api.Test; import org.opensearch.sql.data.model.ExprDateValue; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprStringValue; import org.opensearch.sql.data.model.ExprTimeValue; import org.opensearch.sql.data.model.ExprTimestampValue; @@ -153,21 +151,21 @@ public void minute_span() { PhysicalPlan plan = new AggregationOperator( testScan(datetimeInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("minute", DATETIME)))), + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("minute", TIMESTAMP)))), Collections.singletonList( - DSL.named("span", DSL.span(DSL.ref("minute", DATETIME), DSL.literal(5), "m")))); + DSL.named("span", DSL.span(DSL.ref("minute", TIMESTAMP), DSL.literal(5), "m")))); List result = execute(plan); assertEquals(3, result.size()); assertThat( result, containsInRelativeOrder( ExprValueUtils.tupleValue( - ImmutableMap.of("span", new ExprDatetimeValue("2020-12-31 23:50:00"), "count", 1)), + ImmutableMap.of("span", new ExprTimestampValue("2020-12-31 23:50:00"), "count", 1)), ExprValueUtils.tupleValue( - ImmutableMap.of("span", new ExprDatetimeValue("2021-01-01 00:00:00"), "count", 3)), + ImmutableMap.of("span", new ExprTimestampValue("2021-01-01 00:00:00"), "count", 3)), ExprValueUtils.tupleValue( ImmutableMap.of( - "span", new ExprDatetimeValue("2021-01-01 00:05:00"), "count", 1)))); + "span", new ExprTimestampValue("2021-01-01 00:05:00"), "count", 1)))); plan = new AggregationOperator( @@ -296,23 +294,23 @@ public void month_span() { plan = new AggregationOperator( testScan(dateInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", DATETIME)))), + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), Collections.singletonList( - DSL.named("span", DSL.span(DSL.ref("quarter", DATETIME), DSL.literal(2), "M")))); + DSL.named("span", DSL.span(DSL.ref("quarter", TIMESTAMP), DSL.literal(2), "M")))); result = execute(plan); assertEquals(4, result.size()); assertThat( result, containsInRelativeOrder( ExprValueUtils.tupleValue( - ImmutableMap.of("span", new ExprDatetimeValue("2020-09-01 00:00:00"), "count", 1)), + ImmutableMap.of("span", new ExprTimestampValue("2020-09-01 00:00:00"), "count", 1)), ExprValueUtils.tupleValue( - ImmutableMap.of("span", new ExprDatetimeValue("2020-11-01 00:00:00"), "count", 1)), + ImmutableMap.of("span", new ExprTimestampValue("2020-11-01 00:00:00"), "count", 1)), ExprValueUtils.tupleValue( - ImmutableMap.of("span", new ExprDatetimeValue("2021-01-01 00:00:00"), "count", 1)), + ImmutableMap.of("span", new ExprTimestampValue("2021-01-01 00:00:00"), "count", 1)), ExprValueUtils.tupleValue( ImmutableMap.of( - "span", new ExprDatetimeValue("2021-05-01 00:00:00"), "count", 2)))); + "span", new ExprTimestampValue("2021-05-01 00:00:00"), "count", 2)))); plan = new AggregationOperator( @@ -340,19 +338,19 @@ public void quarter_span() { PhysicalPlan plan = new AggregationOperator( testScan(dateInputs), - Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", DATETIME)))), + Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))), Collections.singletonList( - DSL.named("span", DSL.span(DSL.ref("quarter", DATETIME), DSL.literal(2), "q")))); + DSL.named("span", DSL.span(DSL.ref("quarter", TIMESTAMP), DSL.literal(2), "q")))); List result = execute(plan); assertEquals(2, result.size()); assertThat( result, containsInRelativeOrder( ExprValueUtils.tupleValue( - ImmutableMap.of("span", new ExprDatetimeValue("2020-07-01 00:00:00"), "count", 2)), + ImmutableMap.of("span", new ExprTimestampValue("2020-07-01 00:00:00"), "count", 2)), ExprValueUtils.tupleValue( ImmutableMap.of( - "span", new ExprDatetimeValue("2021-01-01 00:00:00"), "count", 3)))); + "span", new ExprTimestampValue("2021-01-01 00:00:00"), "count", 3)))); plan = new AggregationOperator( diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanTestBase.java b/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanTestBase.java index 003e59959f..6399f945ed 100644 --- a/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanTestBase.java +++ b/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanTestBase.java @@ -14,7 +14,6 @@ import java.util.List; import java.util.Map; import org.opensearch.sql.data.model.ExprDateValue; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprTimeValue; import org.opensearch.sql.data.model.ExprTimestampValue; import org.opensearch.sql.data.model.ExprValue; @@ -109,35 +108,35 @@ public class PhysicalPlanTestBase { ImmutableMap.of( "day", new ExprDateValue("2021-01-03"), "month", new ExprDateValue("2021-02-04"), - "quarter", new ExprDatetimeValue("2021-01-01 12:25:02"), + "quarter", new ExprTimestampValue("2021-01-01 12:25:02"), "year", new ExprTimestampValue("2013-01-01 12:25:02")))) .add( ExprValueUtils.tupleValue( ImmutableMap.of( "day", new ExprDateValue("2021-01-01"), "month", new ExprDateValue("2021-03-17"), - "quarter", new ExprDatetimeValue("2021-05-17 12:25:01"), + "quarter", new ExprTimestampValue("2021-05-17 12:25:01"), "year", new ExprTimestampValue("2021-01-01 12:25:02")))) .add( ExprValueUtils.tupleValue( ImmutableMap.of( "day", new ExprDateValue("2021-01-04"), "month", new ExprDateValue("2021-02-08"), - "quarter", new ExprDatetimeValue("2021-06-08 12:25:02"), + "quarter", new ExprTimestampValue("2021-06-08 12:25:02"), "year", new ExprTimestampValue("2016-01-01 12:25:02")))) .add( ExprValueUtils.tupleValue( ImmutableMap.of( "day", new ExprDateValue("2021-01-02"), "month", new ExprDateValue("2020-12-12"), - "quarter", new ExprDatetimeValue("2020-12-12 12:25:03"), + "quarter", new ExprTimestampValue("2020-12-12 12:25:03"), "year", new ExprTimestampValue("1999-01-01 12:25:02")))) .add( ExprValueUtils.tupleValue( ImmutableMap.of( "day", new ExprDateValue("2021-01-01"), "month", new ExprDateValue("2021-02-28"), - "quarter", new ExprDatetimeValue("2020-09-28 12:25:01"), + "quarter", new ExprTimestampValue("2020-09-28 12:25:01"), "year", new ExprTimestampValue("2018-01-01 12:25:02")))) .build(); @@ -147,31 +146,31 @@ public class PhysicalPlanTestBase { ExprValueUtils.tupleValue( ImmutableMap.of( "hour", new ExprTimeValue("17:17:00"), - "minute", new ExprDatetimeValue("2020-12-31 23:54:12"), + "minute", new ExprTimestampValue("2020-12-31 23:54:12"), "second", new ExprTimestampValue("2021-01-01 00:00:05")))) .add( ExprValueUtils.tupleValue( ImmutableMap.of( "hour", new ExprTimeValue("18:17:00"), - "minute", new ExprDatetimeValue("2021-01-01 00:05:12"), + "minute", new ExprTimestampValue("2021-01-01 00:05:12"), "second", new ExprTimestampValue("2021-01-01 00:00:12")))) .add( ExprValueUtils.tupleValue( ImmutableMap.of( "hour", new ExprTimeValue("17:15:00"), - "minute", new ExprDatetimeValue("2021-01-01 00:03:12"), + "minute", new ExprTimestampValue("2021-01-01 00:03:12"), "second", new ExprTimestampValue("2021-01-01 00:00:17")))) .add( ExprValueUtils.tupleValue( ImmutableMap.of( "hour", new ExprTimeValue("19:01:00"), - "minute", new ExprDatetimeValue("2021-01-01 00:02:12"), + "minute", new ExprTimestampValue("2021-01-01 00:02:12"), "second", new ExprTimestampValue("2021-01-01 00:00:03")))) .add( ExprValueUtils.tupleValue( ImmutableMap.of( "hour", new ExprTimeValue("18:50:00"), - "minute", new ExprDatetimeValue("2021-01-01 00:00:12"), + "minute", new ExprTimestampValue("2021-01-01 00:00:12"), "second", new ExprTimestampValue("2021-01-01 00:00:13")))) .build(); diff --git a/core/src/test/java/org/opensearch/sql/utils/ComparisonUtil.java b/core/src/test/java/org/opensearch/sql/utils/ComparisonUtil.java index b25f4d1053..0d9fe80339 100644 --- a/core/src/test/java/org/opensearch/sql/utils/ComparisonUtil.java +++ b/core/src/test/java/org/opensearch/sql/utils/ComparisonUtil.java @@ -10,7 +10,7 @@ import static org.opensearch.sql.data.model.ExprValueUtils.getIntegerValue; import static org.opensearch.sql.data.model.ExprValueUtils.getLongValue; import static org.opensearch.sql.data.model.ExprValueUtils.getStringValue; -import static org.opensearch.sql.utils.DateTimeUtils.extractDateTime; +import static org.opensearch.sql.utils.DateTimeUtils.extractTimestamp; import org.opensearch.sql.data.model.ExprValue; import org.opensearch.sql.data.type.ExprCoreType; @@ -29,8 +29,8 @@ public static int compare(FunctionProperties functionProperties, ExprValue v1, E } else if (v1.isNull() || v2.isNull()) { throw new ExpressionEvaluationException("invalid to call compare operation on null value"); } else if (v1.type() != v2.type() && v1.isDateTime() && v2.isDateTime()) { - return extractDateTime(v1, functionProperties) - .compareTo(extractDateTime(v2, functionProperties)); + return extractTimestamp(v1, functionProperties) + .compareTo(extractTimestamp(v2, functionProperties)); } return compare(v1, v2); } @@ -67,8 +67,6 @@ public static int compare(ExprValue v1, ExprValue v2) { return v1.timeValue().compareTo(v2.timeValue()); case DATE: return v1.dateValue().compareTo(v2.dateValue()); - case DATETIME: - return v1.datetimeValue().compareTo(v2.datetimeValue()); case TIMESTAMP: return v1.timestampValue().compareTo(v2.timestampValue()); default: diff --git a/docs/dev/img/type-hierarchy-tree-final.png b/docs/dev/img/type-hierarchy-tree-final.png new file mode 100644 index 0000000000..883e581efb Binary files /dev/null and b/docs/dev/img/type-hierarchy-tree-final.png differ diff --git a/docs/user/dql/expressions.rst b/docs/user/dql/expressions.rst index af264b2f16..123bba046a 100644 --- a/docs/user/dql/expressions.rst +++ b/docs/user/dql/expressions.rst @@ -168,7 +168,7 @@ Here is an example for different type of comparison operators:: | True | True | False | True | False | False | +---------+----------+---------+----------+----------+---------+ -It is possible to compare datetimes. When comparing different datetime types, for example `DATE` and `TIME`, both converted to `DATETIME`. +It is possible to compare datetimes. When comparing different datetime types, for example `DATE` and `TIME`, both converted to `TIMESTAMP`. The following rule is applied on coversion: a `TIME` applied to today's date; `DATE` is interpreted at midnight. See example below:: os> SELECT current_time() > current_date() AS `now.time > today`, typeof(current_time()) AS `now.time.type`, typeof(current_date()) AS `now.date.type`; @@ -184,7 +184,7 @@ The following rule is applied on coversion: a `TIME` applied to today's date; `D +------------------+-----------------+------------+ | now.time = now | now.time.type | now.type | |------------------+-----------------+------------| - | True | TIME | DATETIME | + | True | TIME | TIMESTAMP | +------------------+-----------------+------------+ os> SELECT subtime(now(), current_time()) = current_date() AS `midnight = now.date`, typeof(subtime(now(), current_time())) AS `midnight.type`, typeof(current_date()) AS `now.date.type`; @@ -192,7 +192,7 @@ The following rule is applied on coversion: a `TIME` applied to today's date; `D +-----------------------+-----------------+-----------------+ | midnight = now.date | midnight.type | now.date.type | |-----------------------+-----------------+-----------------| - | True | DATETIME | DATE | + | True | TIMESTAMP | DATE | +-----------------------+-----------------+-----------------+ diff --git a/docs/user/dql/functions.rst b/docs/user/dql/functions.rst index 19260e8bea..5af21df2bf 100644 --- a/docs/user/dql/functions.rst +++ b/docs/user/dql/functions.rst @@ -1145,15 +1145,15 @@ Description Usage: adddate(date, INTERVAL expr unit)/ adddate(date, expr) adds the time interval of second argument to date; adddate(date, days) adds the second argument as integer number of days to date. If first argument is TIME, today's date is used; if first argument is DATE, time at midnight is used. -Argument type: DATE/DATETIME/TIMESTAMP/TIME, INTERVAL/LONG +Argument type: DATE/TIMESTAMP/TIME, INTERVAL/LONG Return type map: -(DATE/DATETIME/TIMESTAMP/TIME, INTERVAL) -> DATETIME +(DATE/TIMESTAMP/TIME, INTERVAL) -> TIMESTAMP (DATE, LONG) -> DATE -(DATETIME/TIMESTAMP/TIME, LONG) -> DATETIME +(TIMESTAMP/TIME, LONG) -> TIMESTAMP Synonyms: `DATE_ADD`_ when invoked with the INTERVAL form of the second argument. @@ -1178,13 +1178,13 @@ Description Usage: addtime(expr1, expr2) adds expr2 to expr1 and returns the result. If argument is TIME, today's date is used; if argument is DATE, time at midnight is used. -Argument type: DATE/DATETIME/TIMESTAMP/TIME, DATE/DATETIME/TIMESTAMP/TIME +Argument type: DATE/TIMESTAMP/TIME, DATE/TIMESTAMP/TIME Return type map: -(DATE/DATETIME/TIMESTAMP, DATE/DATETIME/TIMESTAMP/TIME) -> DATETIME +(DATE/TIMESTAMP, DATE/TIMESTAMP/TIME) -> TIMESTAMP -(TIME, DATE/DATETIME/TIMESTAMP/TIME) -> TIME +(TIME, DATE/TIMESTAMP/TIME) -> TIME Antonyms: `SUBTIME`_ @@ -1222,7 +1222,7 @@ Example:: | 10:26:12 | +---------------------------+ - os> SELECT ADDTIME(TIMESTAMP('2007-02-28 10:20:30'), DATETIME('2002-03-04 20:40:50')) AS `'2007-02-28 10:20:30' + '20:40:50'` + os> SELECT ADDTIME(TIMESTAMP('2007-02-28 10:20:30'), TIMESTAMP('2002-03-04 20:40:50')) AS `'2007-02-28 10:20:30' + '20:40:50'` fetched rows / total rows = 1/1 +--------------------------------------+ | '2007-02-28 10:20:30' + '20:40:50' | @@ -1237,11 +1237,11 @@ CONVERT_TZ Description >>>>>>>>>>> -Usage: convert_tz(datetime, from_timezone, to_timezone) constructs a datetime object converted from the from_timezone to the to_timezone. +Usage: convert_tz(timestamp, from_timezone, to_timezone) constructs a timestamp object converted from the from_timezone to the to_timezone. -Argument type: DATETIME, STRING, STRING +Argument type: TIMESTAMP, STRING, STRING -Return type: DATETIME +Return type: TIMESTAMP Example:: @@ -1262,7 +1262,7 @@ Example:: | 2010-10-09 23:10:10 | +---------------------------------------------------------+ -When the datedate, or either of the two time zone fields are invalid format, then the result is null. In this example any datetime that is not will result in null. +When the datedate, or either of the two time zone fields are invalid format, then the result is null. In this example any timestamp that is not will result in null. Example:: os> SELECT CONVERT_TZ("test", "+01:00", "-10:00") @@ -1273,7 +1273,7 @@ Example:: | null | +------------------------------------------+ -When the datetime, or either of the two time zone fields are invalid format, then the result is null. In this example any timezone that is not <+HH:mm> or <-HH:mm> will result in null. +When the timestamp, or either of the two time zone fields are invalid format, then the result is null. In this example any timezone that is not <+HH:mm> or <-HH:mm> will result in null. Example:: os> SELECT CONVERT_TZ("2010-10-10 10:10:10", "test", "-10:00") @@ -1440,9 +1440,9 @@ DATE Description >>>>>>>>>>> -Usage: date(expr) constructs a date type with the input string expr as a date. If the argument is of date/datetime/timestamp, it extracts the date value part from the expression. +Usage: date(expr) constructs a date type with the input string expr as a date. If the argument is of date/timestamp, it extracts the date value part from the expression. -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: DATE @@ -1463,15 +1463,15 @@ DATETIME Description >>>>>>>>>>> -Usage: datetime(datetime)/ datetime(date, to_timezone) Converts the datetime to a new timezone +Usage: datetime(timestamp)/ datetime(timestamp, to_timezone) Converts the timestamp to a new timezone -Argument type: DATETIME/STRING +Argument type: TIMESTAMP/STRING Return type map: -(DATETIME, STRING) -> DATETIME +(TIMESTAMP, STRING) -> TIMESTAMP -(DATETIME) -> DATETIME +(TIMESTAMP) -> TIMESTAMP Example:: @@ -1560,9 +1560,9 @@ Description Usage: date_add(date, INTERVAL expr unit) adds the interval expr to date. If first argument is TIME, today's date is used; if first argument is DATE, time at midnight is used. -Argument type: DATE/DATETIME/TIMESTAMP/TIME, INTERVAL +Argument type: DATE/TIMESTAMP/TIME, INTERVAL -Return type: DATETIME +Return type: TIMESTAMP Synonyms: `ADDDATE`_ @@ -1663,7 +1663,7 @@ If an argument of type TIME is provided, the local date is used. * - x - x, for any smallcase/uppercase alphabet except [aydmshiHIMYDSEL] -Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP, STRING +Argument type: STRING/DATE/TIME/TIMESTAMP, STRING Return type: STRING @@ -1686,9 +1686,9 @@ Description Usage: date_sub(date, INTERVAL expr unit) subtracts the interval expr from date. If first argument is TIME, today's date is used; if first argument is DATE, time at midnight is used. -Argument type: DATE/DATETIME/TIMESTAMP/TIME, INTERVAL +Argument type: DATE/TIMESTAMP/TIME, INTERVAL -Return type: DATETIME +Return type: TIMESTAMP Synonyms: `SUBDATE`_ @@ -1710,7 +1710,7 @@ DATEDIFF Usage: Calculates the difference of date parts of the given values. If the first argument is time, today's date is used. -Argument type: DATE/DATETIME/TIMESTAMP/TIME, DATE/DATETIME/TIMESTAMP/TIME +Argument type: DATE/TIMESTAMP/TIME, DATE/TIMESTAMP/TIME Return type: LONG @@ -1733,7 +1733,7 @@ Description Usage: day(date) extracts the day of the month for date, in the range 1 to 31. -Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP +Argument type: STRING/DATE/TIME/TIMESTAMP Return type: INTEGER @@ -1758,7 +1758,7 @@ Description Usage: dayname(date) returns the name of the weekday for date, including Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: STRING @@ -1781,7 +1781,7 @@ Description Usage: dayofmonth(date) extracts the day of the month for date, in the range 1 to 31. -Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP +Argument type: STRING/DATE/TIME/TIMESTAMP Return type: INTEGER @@ -1806,7 +1806,7 @@ Description Usage: day_of_month(date) extracts the day of the month for date, in the range 1 to 31. -Argument type: STRING/DATE/TIME/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIME/TIMESTAMP Return type: INTEGER @@ -1833,7 +1833,7 @@ Usage: dayofweek(date) returns the weekday index for date (1 = Sunday, 2 = Monda The `day_of_week` function is also provided as an alias. -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: INTEGER @@ -1858,7 +1858,7 @@ Usage: dayofyear(date) returns the day of the year for date, in the range 1 to If an argument of type `TIME` is given, the function will use the current date. The function `day_of_year`_ is also provided as an alias. -Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP +Argument type: STRING/DATE/TIME/TIMESTAMP Return type: INTEGER @@ -1872,14 +1872,6 @@ Example:: | 239 | +---------------------------------+ - os> SELECT DAYOFYEAR(DATETIME('2020-08-26 00:00:00')) - fetched rows / total rows = 1/1 - +----------------------------------------------+ - | DAYOFYEAR(DATETIME('2020-08-26 00:00:00')) | - |----------------------------------------------| - | 239 | - +----------------------------------------------+ - os> SELECT DAYOFYEAR(TIMESTAMP('2020-08-26 00:00:00')) fetched rows / total rows = 1/1 +-----------------------------------------------+ @@ -1898,7 +1890,7 @@ Description If an argument of type `TIME` is given, the function will use the current date. This function is an alias to the `dayofyear`_ function -Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP +Argument type: STRING/DATE/TIME/TIMESTAMP Return type: INTEGER @@ -1912,14 +1904,6 @@ Example:: | 239 | +-----------------------------------+ - os> SELECT DAY_OF_YEAR(DATETIME('2020-08-26 00:00:00')) - fetched rows / total rows = 1/1 - +------------------------------------------------+ - | DAY_OF_YEAR(DATETIME('2020-08-26 00:00:00')) | - |------------------------------------------------| - | 239 | - +------------------------------------------------+ - os> SELECT DAY_OF_YEAR(TIMESTAMP('2020-08-26 00:00:00')) fetched rows / total rows = 1/1 +-------------------------------------------------+ @@ -2030,7 +2014,7 @@ FROM_UNIXTIME Description >>>>>>>>>>> -Usage: Returns a representation of the argument given as a datetime or character string value. Perform reverse conversion for `UNIX_TIMESTAMP`_ function. +Usage: Returns a representation of the argument given as a timestamp or character string value. Perform reverse conversion for `UNIX_TIMESTAMP`_ function. If second argument is provided, it is used to format the result in the same way as the format string used for the `DATE_FORMAT`_ function. If timestamp is outside of range 1970-01-01 00:00:00 - 3001-01-18 23:59:59.999999 (0 to 32536771199.999999 epoch time), function returns NULL. @@ -2038,7 +2022,7 @@ Argument type: DOUBLE, STRING Return type map: -DOUBLE -> DATETIME +DOUBLE -> TIMESTAMP DOUBLE, STRING -> STRING @@ -2070,7 +2054,7 @@ Description Usage: Returns a string value containing string format specifiers based on the input arguments. Argument type: TYPE, STRING -TYPE must be one of the following tokens: [DATE, TIME, DATETIME, TIMESTAMP]. +TYPE must be one of the following tokens: [DATE, TIME, TIMESTAMP]. STRING must be one of the following tokens: ["USA", "JIS", "ISO", "EUR", "INTERNAL"] (" can be replaced by '). Examples:: @@ -2093,7 +2077,7 @@ Description Usage: hour(time) extracts the hour value for time. Different from the time of day value, the time value has a large range and can be greater than 23, so the return value of hour(time) can be also greater than 23. The function `hour_of_day` is also provided as an alias. -Argument type: STRING/TIME/DATETIME/TIMESTAMP +Argument type: STRING/TIME/TIMESTAMP Return type: INTEGER @@ -2113,7 +2097,7 @@ LAST_DAY Usage: Returns the last day of the month as a DATE for a valid argument. -Argument type: DATE/DATETIME/STRING/TIMESTAMP/TIME +Argument type: DATE/STRING/TIMESTAMP/TIME Return type: DATE @@ -2238,9 +2222,9 @@ MICROSECOND Description >>>>>>>>>>> -Usage: microsecond(expr) returns the microseconds from the time or datetime expression expr as a number in the range from 0 to 999999. +Usage: microsecond(expr) returns the microseconds from the time or timestamp expression expr as a number in the range from 0 to 999999. -Argument type: STRING/TIME/DATETIME/TIMESTAMP +Argument type: STRING/TIME/TIMESTAMP Return type: INTEGER @@ -2264,7 +2248,7 @@ Description Usage: minute(time) returns the minute for time, in the range 0 to 59. The `minute_of_hour` function is provided as an alias. -Argument type: STRING/TIME/DATETIME/TIMESTAMP +Argument type: STRING/TIME/TIMESTAMP Return type: INTEGER @@ -2287,7 +2271,7 @@ Description Usage: minute_of_day(time) returns the minute value for time within a 24 hour day, in the range 0 to 1439. -Argument type: STRING/TIME/DATETIME/TIMESTAMP +Argument type: STRING/TIME/TIMESTAMP Return type: INTEGER @@ -2312,7 +2296,7 @@ Usage: month(date) returns the month for date, in the range 1 to 12 for January If an argument of type `TIME` is given, the function will use the current date. The function `month_of_year` is also provided as an alias. -Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP +Argument type: STRING/DATE/TIME/TIMESTAMP Return type: INTEGER @@ -2344,7 +2328,7 @@ Description Usage: monthname(date) returns the full name of the month for date. -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: STRING @@ -2368,9 +2352,9 @@ Description Returns the current date and time as a value in 'YYYY-MM-DD hh:mm:ss' format. The value is expressed in the cluster time zone. `NOW()` returns a constant time that indicates the time at which the statement began to execute. This differs from the behavior for `SYSDATE() <#sysdate>`_, which returns the exact time at which it executes. -Return type: DATETIME +Return type: TIMESTAMP -Specification: NOW() -> DATETIME +Specification: NOW() -> TIMESTAMP Example:: @@ -2437,7 +2421,7 @@ Description Usage: quarter(date) returns the quarter of the year for date, in the range 1 to 4. -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: INTEGER @@ -2503,7 +2487,7 @@ Description Usage: second(time) returns the second for time, in the range 0 to 59. The function `second_of_minute` is provided as an alias -Argument type: STRING/TIME/DATETIME/TIMESTAMP +Argument type: STRING/TIME/TIMESTAMP Return type: INTEGER @@ -2532,14 +2516,14 @@ STR_TO_DATE Description >>>>>>>>>>> -Usage: str_to_date(string, string) is used to extract a DATETIME from the first argument string using the formats specified in the second argument string. -The input argument must have enough information to be parsed as a DATE, DATETIME, or TIME. +Usage: str_to_date(string, string) is used to extract a TIMESTAMP from the first argument string using the formats specified in the second argument string. +The input argument must have enough information to be parsed as a DATE, TIMESTAMP, or TIME. Acceptable string format specifiers are the same as those used in the `DATE_FORMAT`_ function. -It returns NULL when a statement cannot be parsed due to an invalid pair of arguments, and when 0 is provided for any DATE field. Otherwise, it will return a DATETIME with the parsed values (as well as default values for any field that was not parsed). +It returns NULL when a statement cannot be parsed due to an invalid pair of arguments, and when 0 is provided for any DATE field. Otherwise, it will return a TIMESTAMP with the parsed values (as well as default values for any field that was not parsed). Argument type: STRING, STRING -Return type: DATETIME +Return type: TIMESTAMP Example:: @@ -2561,15 +2545,15 @@ Description Usage: subdate(date, INTERVAL expr unit) / subdate(date, days) subtracts the time interval expr from date; subdate(date, days) subtracts the second argument as integer number of days from date. If first argument is TIME, today's date is used; if first argument is DATE, time at midnight is used. -Argument type: DATE/DATETIME/TIMESTAMP/TIME, INTERVAL/LONG +Argument type: DATE/TIMESTAMP/TIME, INTERVAL/LONG Return type map: -(DATE/DATETIME/TIMESTAMP/TIME, INTERVAL) -> DATETIME +(DATE/TIMESTAMP/TIME, INTERVAL) -> TIMESTAMP (DATE, LONG) -> DATE -(DATETIME/TIMESTAMP/TIME, LONG) -> DATETIME +(TIMESTAMP/TIME, LONG) -> TIMESTAMP Synonyms: `DATE_SUB`_ when invoked with the INTERVAL form of the second argument. @@ -2594,13 +2578,13 @@ Description Usage: subtime(expr1, expr2) subtracts expr2 from expr1 and returns the result. If argument is TIME, today's date is used; if argument is DATE, time at midnight is used. -Argument type: DATE/DATETIME/TIMESTAMP/TIME, DATE/DATETIME/TIMESTAMP/TIME +Argument type: DATE/TIMESTAMP/TIME, DATE/TIMESTAMP/TIME Return type map: -(DATE/DATETIME/TIMESTAMP, DATE/DATETIME/TIMESTAMP/TIME) -> DATETIME +(DATE/TIMESTAMP, DATE/TIMESTAMP/TIME) -> TIMESTAMP -(TIME, DATE/DATETIME/TIMESTAMP/TIME) -> TIME +(TIME, DATE/TIMESTAMP/TIME) -> TIME Antonyms: `ADDTIME`_ @@ -2638,7 +2622,7 @@ Example:: | 10:14:48 | +---------------------------+ - os> SELECT SUBTIME(TIMESTAMP('2007-03-01 10:20:30'), DATETIME('2002-03-04 20:40:50')) AS `'2007-03-01 10:20:30' - '20:40:50'` + os> SELECT SUBTIME(TIMESTAMP('2007-03-01 10:20:30'), TIMESTAMP('2002-03-04 20:40:50')) AS `'2007-03-01 10:20:30' - '20:40:50'` fetched rows / total rows = 1/1 +--------------------------------------+ | '2007-03-01 10:20:30' - '20:40:50' | @@ -2659,9 +2643,9 @@ If the argument is given, it specifies a fractional seconds precision from 0 to Optional argument type: INTEGER -Return type: DATETIME +Return type: TIMESTAMP -Specification: SYSDATE([INTEGER]) -> DATETIME +Specification: SYSDATE([INTEGER]) -> TIMESTAMP Example:: @@ -2680,9 +2664,9 @@ TIME Description >>>>>>>>>>> -Usage: time(expr) constructs a time type with the input string expr as a time. If the argument is of date/datetime/time/timestamp, it extracts the time value part from the expression. +Usage: time(expr) constructs a time type with the input string expr as a time. If the argument is of date/time/timestamp, it extracts the time value part from the expression. -Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP +Argument type: STRING/DATE/TIME/TIMESTAMP Return type: TIME @@ -2706,7 +2690,7 @@ Usage: time_format(time, format) formats the time argument using the specifiers This supports a subset of the time format specifiers available for the `date_format`_ function. Using date format specifiers supported by `date_format`_ will return 0 or null. Acceptable format specifiers are listed in the table below. -If an argument of type DATE is passed in, it is treated as a DATETIME at midnight (i.e., 00:00:00). +If an argument of type DATE is passed in, it is treated as a TIMESTAMP at midnight (i.e., 00:00:00). .. list-table:: The following table describes the available specifier arguments. :widths: 20 80 @@ -2736,7 +2720,7 @@ If an argument of type DATE is passed in, it is treated as a DATETIME at midnigh - Time, 24-hour (hh:mm:ss) -Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP, STRING +Argument type: STRING/DATE/TIME/TIMESTAMP, STRING Return type: STRING @@ -2759,7 +2743,7 @@ Description Usage: time_to_sec(time) returns the time argument, converted to seconds. -Argument type: STRING/TIME/DATETIME/TIMESTAMP +Argument type: STRING/TIME/TIMESTAMP Return type: LONG @@ -2804,15 +2788,15 @@ Description >>>>>>>>>>> Usage: timestamp(expr) constructs a timestamp type with the input string `expr` as an timestamp. If the argument is not a string, it casts `expr` to timestamp type with default timezone UTC. If argument is a time, it applies today's date before cast. -With two arguments `timestamp(expr1, expr2)` adds the time expression `expr2` to the date or datetime expression `expr1` and returns the result as a timestamp value. +With two arguments `timestamp(expr1, expr2)` adds the time expression `expr2` to the date or timestamp expression `expr1` and returns the result as a timestamp value. -Argument type: STRING/DATE/TIME/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIME/TIMESTAMP Return type map: -(STRING/DATE/TIME/DATETIME/TIMESTAMP) -> TIMESTAMP +(STRING/DATE/TIME/TIMESTAMP) -> TIMESTAMP -(STRING/DATE/TIME/DATETIME/TIMESTAMP, STRING/DATE/TIME/DATETIME/TIMESTAMP) -> TIMESTAMP +(STRING/DATE/TIME/TIMESTAMP, STRING/DATE/TIME/TIMESTAMP) -> TIMESTAMP Example:: @@ -2831,11 +2815,11 @@ TIMESTAMPADD Description >>>>>>>>>>> -Usage: Returns a DATETIME value based on a passed in DATE/DATETIME/TIME/TIMESTAMP/STRING argument and an INTERVAL and INTEGER argument which determine the amount of time to be added. -If the third argument is a STRING, it must be formatted as a valid DATETIME. If only a TIME is provided, a DATETIME is still returned with the DATE portion filled in using the current date. -If the third argument is a DATE, it will be automatically converted to a DATETIME. +Usage: Returns a TIMESTAMP value based on a passed in DATE/TIME/TIMESTAMP/STRING argument and an INTERVAL and INTEGER argument which determine the amount of time to be added. +If the third argument is a STRING, it must be formatted as a valid TIMESTAMP. If only a TIME is provided, a TIMESTAMP is still returned with the DATE portion filled in using the current date. +If the third argument is a DATE, it will be automatically converted to a TIMESTAMP. -Argument type: INTERVAL, INTEGER, DATE/DATETIME/TIME/TIMESTAMP/STRING +Argument type: INTERVAL, INTEGER, DATE/TIME/TIMESTAMP/STRING INTERVAL must be one of the following tokens: [MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR] Examples:: @@ -2856,11 +2840,11 @@ Description >>>>>>>>>>> Usage: TIMESTAMPDIFF(interval, start, end) returns the difference between the start and end date/times in interval units. -If a TIME is provided as an argument, it will be converted to a DATETIME with the DATE portion filled in using the current date. -Arguments will be automatically converted to a DATETIME/TIME/TIMESTAMP when appropriate. -Any argument that is a STRING must be formatted as a valid DATETIME. +If a TIME is provided as an argument, it will be converted to a TIMESTAMP with the DATE portion filled in using the current date. +Arguments will be automatically converted to a TIME/TIMESTAMP when appropriate. +Any argument that is a STRING must be formatted as a valid TIMESTAMP. -Argument type: INTERVAL, DATE/DATETIME/TIME/TIMESTAMP/STRING, DATE/DATETIME/TIME/TIMESTAMP/STRING +Argument type: INTERVAL, DATE/TIME/TIMESTAMP/STRING, DATE/TIME/TIMESTAMP/STRING INTERVAL must be one of the following tokens: [MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR] Examples:: @@ -2882,7 +2866,7 @@ Description Usage: to_days(date) returns the day number (the number of days since year 0) of the given date. Returns NULL if date is invalid. -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: LONG @@ -2906,7 +2890,7 @@ Description Usage: to_seconds(date) returns the number of seconds since the year 0 of the given value. Returns NULL if value is invalid. An argument of a LONG type can be used. It must be formatted as YMMDD, YYMMDD, YYYMMDD or YYYYMMDD. Note that a LONG type argument cannot have leading 0s as it will be parsed using an octal numbering system. -Argument type: STRING/LONG/DATE/DATETIME/TIME/TIMESTAMP +Argument type: STRING/LONG/DATE/TIME/TIMESTAMP Return type: LONG @@ -2928,11 +2912,11 @@ Description >>>>>>>>>>> Usage: Converts given argument to Unix time (seconds since January 1st, 1970 at 00:00:00 UTC). If no argument given, it returns current Unix time. -The date argument may be a DATE, DATETIME, or TIMESTAMP string, or a number in YYMMDD, YYMMDDhhmmss, YYYYMMDD, or YYYYMMDDhhmmss format. If the argument includes a time part, it may optionally include a fractional seconds part. +The date argument may be a DATE, TIMESTAMP, or TIMESTAMP string, or a number in YYMMDD, YYMMDDhhmmss, YYYYMMDD, or YYYYMMDDhhmmss format. If the argument includes a time part, it may optionally include a fractional seconds part. If argument is in invalid format or outside of range 1970-01-01 00:00:00 - 3001-01-18 23:59:59.999999 (0 to 32536771199.999999 epoch time), function returns NULL. You can use `FROM_UNIXTIME`_ to do reverse conversion. -Argument type: /DOUBLE/DATE/DATETIME/TIMESTAMP +Argument type: /DOUBLE/DATE/TIMESTAMP Return type: DOUBLE @@ -3009,9 +2993,9 @@ Description Returns the current UTC timestamp as a value in 'YYYY-MM-DD hh:mm:ss'. -Return type: DATETIME +Return type: TIMESTAMP -Specification: UTC_TIMESTAMP() -> DATETIME +Specification: UTC_TIMESTAMP() -> TIMESTAMP Example:: @@ -3075,7 +3059,7 @@ The functions `weekofyear` and `week_of_year` is also provided as an alias. - 1-53 - with a Monday in this year -Argument type: DATE/DATETIME/TIME/TIMESTAMP/STRING +Argument type: DATE/TIME/TIMESTAMP/STRING Return type: INTEGER @@ -3100,7 +3084,7 @@ Usage: weekday(date) returns the weekday index for date (0 = Monday, 1 = Tuesday It is similar to the `dayofweek`_ function, but returns different indexes for each day. -Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP +Argument type: STRING/DATE/TIME/TIMESTAMP Return type: INTEGER @@ -3124,7 +3108,7 @@ Description The week_of_year function is a synonym for the `week`_ function. If an argument of type `TIME` is given, the function will use the current date. -Argument type: DATE/DATETIME/TIME/TIMESTAMP/STRING +Argument type: DATE/TIME/TIMESTAMP/STRING Return type: INTEGER @@ -3148,7 +3132,7 @@ Description The weekofyear function is a synonym for the `week`_ function. If an argument of type `TIME` is given, the function will use the current date. -Argument type: DATE/DATETIME/TIME/TIMESTAMP/STRING +Argument type: DATE/TIME/TIMESTAMP/STRING Return type: INTEGER @@ -3171,7 +3155,7 @@ Description Usage: year(date) returns the year for date, in the range 1000 to 9999, or 0 for the “zero” date. -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: INTEGER @@ -3194,7 +3178,7 @@ Description Usage: yearweek(date) returns the year and week for date as an integer. It accepts and optional mode arguments aligned with those available for the `WEEK`_ function. -Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP +Argument type: STRING/DATE/TIME/TIMESTAMP Return type: INTEGER @@ -4514,6 +4498,6 @@ Example:: +----------------+---------------+-----------------+------------------+ | typeof(date) | typeof(int) | typeof(now()) | typeof(column) | |----------------+---------------+-----------------+------------------| - | DATE | INTEGER | DATETIME | OBJECT | + | DATE | INTEGER | TIMESTAMP | OBJECT | +----------------+---------------+-----------------+------------------+ diff --git a/docs/user/general/datatypes.rst b/docs/user/general/datatypes.rst index a265ffd4c9..c423bd7b10 100644 --- a/docs/user/general/datatypes.rst +++ b/docs/user/general/datatypes.rst @@ -40,8 +40,6 @@ The OpenSearch SQL Engine support the following data types. +---------------------+ | timestamp | +---------------------+ -| datetime | -+---------------------+ | date | +---------------------+ | date_nanos | @@ -128,53 +126,51 @@ Type Conversion Matrix The following matrix illustrates the conversions allowed by our query engine for all the built-in data types as well as types provided by OpenSearch storage engine. -+--------------+------------------------------------------------+---------+------------------------------+-----------------------------------------------+--------------------------+---------------------+ -| Data Types | Numeric Type Family | BOOLEAN | String Type Family | Datetime Type Family | OpenSearch Type Family | Complex Type Family | -| +------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ -| | BYTE | SHORT | INTEGER | LONG | FLOAT | DOUBLE | BOOLEAN | TEXT_KEYWORD | TEXT | STRING | TIMESTAMP | DATE | TIME | DATETIME | INTERVAL | GEO_POINT | IP | BINARY | STRUCT | ARRAY | -+==============+======+=======+=========+======+=======+========+=========+==============+======+========+===========+======+======+==========+==========+===========+=====+========+===========+=========+ -| UNDEFINED | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | -+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ -| BYTE | N/A | IE | IE | IE | IE | IE | X | X | X | E | X | X | X | X | X | X | X | X | X | X | -+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ -| SHORT | E | N/A | IE | IE | IE | IE | X | X | X | E | X | X | X | X | X | X | X | X | X | X | -+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ -| INTEGER | E | E | N/A | IE | IE | IE | X | X | X | E | X | X | X | X | X | X | X | X | X | X | -+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ -| LONG | E | E | E | N/A | IE | IE | X | X | X | E | X | X | X | X | X | X | X | X | X | X | -+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ -| FLOAT | E | E | E | E | N/A | IE | X | X | X | E | X | X | X | X | X | X | X | X | X | X | -+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ -| DOUBLE | E | E | E | E | E | N/A | X | X | X | E | X | X | X | X | X | X | X | X | X | X | -+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ -| BOOLEAN | E | E | E | E | E | E | N/A | X | X | E | X | X | X | X | X | X | X | X | X | X | -+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ -| TEXT_KEYWORD | | | | | | | | N/A | | IE | | | | X | X | X | X | X | X | X | -+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ -| TEXT | | | | | | | | | N/A | IE | | | | X | X | X | X | X | X | X | -+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ -| STRING | E | E | E | E | E | E | IE | X | X | N/A | IE | IE | IE | IE | X | X | X | X | X | X | -+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ -| TIMESTAMP | X | X | X | X | X | X | X | X | X | E | N/A | IE | IE | IE | X | X | X | X | X | X | -+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ -| DATE | X | X | X | X | X | X | X | X | X | E | E | N/A | IE | E | X | X | X | X | X | X | -+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ -| TIME | X | X | X | X | X | X | X | X | X | E | E | E | N/A | E | X | X | X | X | X | X | -+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ -| DATETIME | X | X | X | X | X | X | X | X | X | E | E | E | E | N/A | X | X | X | X | X | X | -+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ -| INTERVAL | X | X | X | X | X | X | X | X | X | E | X | X | X | X | N/A | X | X | X | X | X | -+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ -| GEO_POINT | X | X | X | X | X | X | X | X | X | | X | X | X | X | X | N/A | X | X | X | X | -+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ -| IP | X | X | X | X | X | X | X | X | X | | X | X | X | X | X | X | N/A | X | X | X | -+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ -| BINARY | X | X | X | X | X | X | X | X | X | | X | X | X | X | X | X | X | N/A | X | X | -+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ -| STRUCT | X | X | X | X | X | X | X | X | X | | X | X | X | X | X | X | X | X | N/A | X | -+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ -| ARRAY | X | X | X | X | X | X | X | X | X | | X | X | X | X | X | X | X | X | X | N/A | -+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+ ++--------------+------------------------------------------------+---------+------------------------------+------------------------------------+--------------------------+---------------------+ +| Data Types | Numeric Type Family | BOOLEAN | String Type Family | Datetime Type Family | OpenSearch Type Family | Complex Type Family | +| +------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+ +| | BYTE | SHORT | INTEGER | LONG | FLOAT | DOUBLE | BOOLEAN | TEXT_KEYWORD | TEXT | STRING | TIMESTAMP | DATE | TIME | INTERVAL | GEO_POINT | IP | BINARY | STRUCT | ARRAY | ++==============+======+=======+=========+======+=======+========+=========+==============+======+========+===========+======+======+==========+===========+=====+========+===========+=========+ +| UNDEFINED | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | ++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+ +| BYTE | N/A | IE | IE | IE | IE | IE | X | X | X | E | X | X | X | X | X | X | X | X | X | ++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+ +| SHORT | E | N/A | IE | IE | IE | IE | X | X | X | E | X | X | X | X | X | X | X | X | X | ++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+ +| INTEGER | E | E | N/A | IE | IE | IE | X | X | X | E | X | X | X | X | X | X | X | X | X | ++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+ +| LONG | E | E | E | N/A | IE | IE | X | X | X | E | X | X | X | X | X | X | X | X | X | ++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+ +| FLOAT | E | E | E | E | N/A | IE | X | X | X | E | X | X | X | X | X | X | X | X | X | ++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+ +| DOUBLE | E | E | E | E | E | N/A | X | X | X | E | X | X | X | X | X | X | X | X | X | ++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+--------------+-----------+---------+ +| BOOLEAN | E | E | E | E | E | E | N/A | X | X | E | X | X | X | X | X | X | X | X | X | ++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+ +| TEXT_KEYWORD | | | | | | | | N/A | | IE | | | | X | X | X | X | X | X | ++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+ +| TEXT | | | | | | | | | N/A | IE | | | | X | X | X | X | X | X | ++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+ +| STRING | E | E | E | E | E | E | IE | X | X | N/A | IE | IE | IE | X | X | X | X | X | X | ++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+ +| TIMESTAMP | X | X | X | X | X | X | X | X | X | E | N/A | IE | IE | X | X | X | X | X | X | ++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+ +| DATE | X | X | X | X | X | X | X | X | X | E | E | N/A | IE | X | X | X | X | X | X | ++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+ +| TIME | X | X | X | X | X | X | X | X | X | E | E | E | N/A | X | X | X | X | X | X | ++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+ +| INTERVAL | X | X | X | X | X | X | X | X | X | E | X | X | X | N/A | X | X | X | X | X | ++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+ +| GEO_POINT | X | X | X | X | X | X | X | X | X | | X | X | X | X | N/A | X | X | X | X | ++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+ +| IP | X | X | X | X | X | X | X | X | X | | X | X | X | X | X | N/A | X | X | X | ++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+ +| BINARY | X | X | X | X | X | X | X | X | X | | X | X | X | X | X | X | N/A | X | X | ++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+ +| STRUCT | X | X | X | X | X | X | X | X | X | | X | X | X | X | X | X | X | N/A | X | ++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+ +| ARRAY | X | X | X | X | X | X | X | X | X | | X | X | X | X | X | X | X | X | N/A | ++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+ Note that: @@ -236,7 +232,7 @@ Numeric values ranged from -2147483648 to +2147483647 are recognized as integer Date and Time Data Types ======================== -The datetime types supported by the SQL plugin are ``DATE``, ``TIME``, ``DATETIME``, ``TIMESTAMP``, and ``INTERVAL``, with date and time being used to represent temporal values. By default, the OpenSearch DSL uses ``date`` type as the only date and time related type as it contains all information about an absolute time point. To integrate with SQL language each of the types other than timestamp hold part of the temporal or timezone information. This information can be used to explicitly clarify the date and time types reflected in the datetime functions (see `Functions `_ for details), where some functions might have restrictions in the input argument type. +The datetime types supported by the SQL plugin are ``DATE``, ``TIME``, ``TIMESTAMP``, and ``INTERVAL``, with date and time being used to represent temporal values. By default, the OpenSearch DSL uses ``date`` type as the only date and time related type as it contains all information about an absolute time point. To integrate with SQL language each of the types other than timestamp hold part of the temporal or timezone information. This information can be used to explicitly clarify the date and time types reflected in the datetime functions (see `Functions `_ for details), where some functions might have restrictions in the input argument type. Date ---- @@ -262,19 +258,6 @@ Time represents the time on the clock or watch with no regard for which timezone +------+-----------------------+----------------------------------------------+ -Datetime --------- - -Datetime type is the combination of date and time. The conversion rule of date or time to datetime is described in `Conversion between date and time types`_. Datetime type does not contain timezone information. For an absolute time point that contains both date time and timezone information, see `Timestamp`_. - -+----------+----------------------------------+--------------------------------------------------------------------+ -| Type | Syntax | Range | -+==========+==================================+====================================================================+ -| Datetime | 'yyyy-MM-dd hh:mm:ss[.fraction]' | '0001-01-01 00:00:00.000000000' to '9999-12-31 23:59:59.999999999' | -+----------+----------------------------------+--------------------------------------------------------------------+ - - - Timestamp --------- @@ -304,16 +287,14 @@ The expr is any expression that can be iterated to a quantity value eventually, Conversion between date and time types -------------------------------------- -Basically the date and time types except interval can be converted to each other, but might suffer some alteration of the value or some information loss, for example extracting the time value from a datetime value, or convert a date value to a datetime value and so forth. Here lists the summary of the conversion rules that SQL plugin supports for each of the types: +Basically the date and time types except interval can be converted to each other, but might suffer some alteration of the value or some information loss, for example extracting the time value from a timestamp value, or convert a date value to a timestamp value and so forth. Here lists the summary of the conversion rules that SQL plugin supports for each of the types: Conversion from DATE >>>>>>>>>>>>>>>>>>>> - Since the date value does not have any time information, conversion to `Time`_ type is not useful, and will always return a zero time value '00:00:00'. -- Conversion from date to datetime has a data fill-up due to the lack of time information, and it attaches the time '00:00:00' to the original date by default and forms a datetime instance. For example, the result to covert date '2020-08-17' to datetime type is datetime '2020-08-17 00:00:00'. - -- Conversion to timestamp is to alternate both the time value and the timezone information, and it attaches the zero time value '00:00:00' and the session timezone (UTC by default) to the date. For example, the result to covert date '2020-08-17' to datetime type with session timezone UTC is datetime '2020-08-17 00:00:00' UTC. +- Conversion to timestamp is to alternate both the time value and the timezone information, and it attaches the zero time value '00:00:00' and the session timezone (UTC by default) to the date. For example, the result to covert date '2020-08-17' to timestamp type with session timezone UTC is timestamp '2020-08-17 00:00:00' UTC. Conversion from TIME @@ -322,20 +303,10 @@ Conversion from TIME - When time value is converted to any other datetime types, the date part of the new value is filled up with today's date, like with the `CURDATE` function. For example, a time value X converted to a timestamp would produce today's date at time X. -Conversion from DATETIME ->>>>>>>>>>>>>>>>>>>>>>>> - -- Conversion from datetime to date is to extract the date part from the datetime value. For example, the result to convert datetime '2020-08-17 14:09:00' to date is date '2020-08-08'. - -- Conversion to time is to extract the time part from the datetime value. For example, the result to convert datetime '2020-08-17 14:09:00' to time is time '14:09:00'. - -- Since the datetime type does not contain timezone information, the conversion to timestamp needs to fill up the timezone part with the session timezone. For example, the result to convert datetime '2020-08-17 14:09:00' with system timezone of UTC, to timestamp is timestamp '2020-08-17 14:09:00' UTC. - - Conversion from TIMESTAMP >>>>>>>>>>>>>>>>>>>>>>>>> -- Conversion from timestamp is much more straightforward. To convert it to date is to extract the date value, and conversion to time is to extract the time value. Conversion to datetime, it will extracts the datetime value and leave the timezone information over. For example, the result to convert datetime '2020-08-17 14:09:00' UTC to date is date '2020-08-17', to time is '14:09:00' and to datetime is datetime '2020-08-17 14:09:00'. +- Conversion from timestamp is much more straightforward. To convert it to date is to extract the date value, and conversion to time is to extract the time value. For example, the result to convert timestamp '2020-08-17 14:09:00' UTC to date is date '2020-08-17', to time is '14:09:00'. Conversion from string to date and time types --------------------------------------------- diff --git a/docs/user/ppl/functions/datetime.rst b/docs/user/ppl/functions/datetime.rst index f7c4091753..9e75e41136 100644 --- a/docs/user/ppl/functions/datetime.rst +++ b/docs/user/ppl/functions/datetime.rst @@ -17,15 +17,15 @@ Description Usage: adddate(date, INTERVAL expr unit) / adddate(date, days) adds the interval of second argument to date; adddate(date, days) adds the second argument as integer number of days to date. If first argument is TIME, today's date is used; if first argument is DATE, time at midnight is used. -Argument type: DATE/DATETIME/TIMESTAMP/TIME, INTERVAL/LONG +Argument type: DATE/TIMESTAMP/TIME, INTERVAL/LONG Return type map: -(DATE/DATETIME/TIMESTAMP/TIME, INTERVAL) -> DATETIME +(DATE/TIMESTAMP/TIME, INTERVAL) -> TIMESTAMP (DATE, LONG) -> DATE -(DATETIME/TIMESTAMP/TIME, LONG) -> DATETIME +(TIMESTAMP/TIME, LONG) -> TIMESTAMP Synonyms: `DATE_ADD`_ when invoked with the INTERVAL form of the second argument. @@ -51,13 +51,13 @@ Description Usage: addtime(expr1, expr2) adds expr2 to expr1 and returns the result. If argument is TIME, today's date is used; if argument is DATE, time at midnight is used. -Argument type: DATE/DATETIME/TIMESTAMP/TIME, DATE/DATETIME/TIMESTAMP/TIME +Argument type: DATE/TIMESTAMP/TIME, DATE/TIMESTAMP/TIME Return type map: -(DATE/DATETIME/TIMESTAMP, DATE/DATETIME/TIMESTAMP/TIME) -> DATETIME +(DATE/TIMESTAMP, DATE/TIMESTAMP/TIME) -> TIMESTAMP -(TIME, DATE/DATETIME/TIMESTAMP/TIME) -> TIME +(TIME, DATE/TIMESTAMP/TIME) -> TIME Antonyms: `SUBTIME`_ @@ -95,7 +95,7 @@ Example:: | 10:26:12 | +---------------------------+ - os> source=people | eval `'2007-02-28 10:20:30' + '20:40:50'` = ADDTIME(TIMESTAMP('2007-02-28 10:20:30'), DATETIME('2002-03-04 20:40:50')) | fields `'2007-02-28 10:20:30' + '20:40:50'` + os> source=people | eval `'2007-02-28 10:20:30' + '20:40:50'` = ADDTIME(TIMESTAMP('2007-02-28 10:20:30'), TIMESTAMP('2002-03-04 20:40:50')) | fields `'2007-02-28 10:20:30' + '20:40:50'` fetched rows / total rows = 1/1 +--------------------------------------+ | '2007-02-28 10:20:30' + '20:40:50' | @@ -110,13 +110,13 @@ CONVERT_TZ Description >>>>>>>>>>> -Usage: convert_tz(datetime, from_timezone, to_timezone) constructs a local datetime converted from the from_timezone to the to_timezone. CONVERT_TZ returns null when any of the three function arguments are invalid, i.e. datetime is not in the format yyyy-MM-dd HH:mm:ss or the timeszone is not in (+/-)HH:mm. It also is invalid for invalid dates, such as February 30th and invalid timezones, which are ones outside of -13:59 and +14:00. +Usage: convert_tz(timestamp, from_timezone, to_timezone) constructs a local timestamp converted from the from_timezone to the to_timezone. CONVERT_TZ returns null when any of the three function arguments are invalid, i.e. timestamp is not in the format yyyy-MM-dd HH:mm:ss or the timeszone is not in (+/-)HH:mm. It also is invalid for invalid dates, such as February 30th and invalid timezones, which are ones outside of -13:59 and +14:00. -Argument type: DATETIME, STRING, STRING +Argument type: TIMESTAMP, STRING, STRING -Return type: DATETIME +Return type: TIMESTAMP -Conversion from +00:00 timezone to +10:00 timezone. Returns the datetime argument converted from +00:00 to +10:00 +Conversion from +00:00 timezone to +10:00 timezone. Returns the timestamp argument converted from +00:00 to +10:00 Example:: os> source=people | eval `convert_tz('2008-05-15 12:00:00','+00:00','+10:00')` = convert_tz('2008-05-15 12:00:00','+00:00','+10:00') | fields `convert_tz('2008-05-15 12:00:00','+00:00','+10:00')` @@ -349,9 +349,9 @@ DATE Description >>>>>>>>>>> -Usage: date(expr) constructs a date type with the input string expr as a date. If the argument is of date/datetime/timestamp, it extracts the date value part from the expression. +Usage: date(expr) constructs a date type with the input string expr as a date. If the argument is of date/timestamp, it extracts the date value part from the expression. -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: DATE @@ -398,9 +398,9 @@ Description Usage: date_add(date, INTERVAL expr unit) adds the interval expr to date. If first argument is TIME, today's date is used; if first argument is DATE, time at midnight is used. -Argument type: DATE/DATETIME/TIMESTAMP/TIME, INTERVAL +Argument type: DATE/TIMESTAMP/TIME, INTERVAL -Return type: DATETIME +Return type: TIMESTAMP Synonyms: `ADDDATE`_ @@ -501,7 +501,7 @@ If an argument of type TIME is provided, the local date is used. * - x - x, for any smallcase/uppercase alphabet except [aydmshiHIMYDSEL] -Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP, STRING +Argument type: STRING/DATE/TIME/TIMESTAMP, STRING Return type: STRING @@ -522,18 +522,18 @@ DATETIME Description >>>>>>>>>>> -Usage: DATETIME(datetime)/ DATETIME(date, to_timezone) Converts the datetime to a new timezone +Usage: DATETIME(timestamp)/ DATETIME(date, to_timezone) Converts the datetime to a new timezone -Argument type: DATETIME/STRING +Argument type: timestamp/STRING Return type map: -(DATETIME, STRING) -> DATETIME +(TIMESTAMP, STRING) -> TIMESTAMP -(DATETIME) -> DATETIME +(TIMESTAMP) -> TIMESTAMP -Converting datetime with timezone to the second argument timezone. +Converting timestamp with timezone to the second argument timezone. Example:: os> source=people | eval `DATETIME('2004-02-28 23:00:00-10:00', '+10:00')` = DATETIME('2004-02-28 23:00:00-10:00', '+10:00') | fields `DATETIME('2004-02-28 23:00:00-10:00', '+10:00')` @@ -545,7 +545,7 @@ Example:: +---------------------------------------------------+ - The valid timezone range for convert_tz is (-13:59, +14:00) inclusive. Timezones outside of the range will result in null. +The valid timezone range for convert_tz is (-13:59, +14:00) inclusive. Timezones outside of the range will result in null. Example:: os> source=people | eval `DATETIME('2008-01-01 02:00:00', '-14:00')` = DATETIME('2008-01-01 02:00:00', '-14:00') | fields `DATETIME('2008-01-01 02:00:00', '-14:00')` @@ -556,17 +556,6 @@ Example:: | null | +---------------------------------------------+ -The valid timezone range for convert_tz is (-13:59, +14:00) inclusive. Timezones outside of the range will result in null. -Example:: - - os> source=people | eval `DATETIME('2008-02-30 02:00:00', '-00:00')` = DATETIME('2008-02-30 02:00:00', '-00:00') | fields `DATETIME('2008-02-30 02:00:00', '-00:00')` - fetched rows / total rows = 1/1 - +---------------------------------------------+ - | DATETIME('2008-02-30 02:00:00', '-00:00') | - |---------------------------------------------| - | null | - +---------------------------------------------+ - DATE_SUB -------- @@ -576,9 +565,9 @@ Description Usage: date_sub(date, INTERVAL expr unit) subtracts the interval expr from date. If first argument is TIME, today's date is used; if first argument is DATE, time at midnight is used. -Argument type: DATE/DATETIME/TIMESTAMP/TIME, INTERVAL +Argument type: DATE/TIMESTAMP/TIME, INTERVAL -Return type: DATETIME +Return type: TIMESTAMP Synonyms: `SUBDATE`_ @@ -600,7 +589,7 @@ DATEDIFF Usage: Calculates the difference of date parts of given values. If the first argument is time, today's date is used. -Argument type: DATE/DATETIME/TIMESTAMP/TIME, DATE/DATETIME/TIMESTAMP/TIME +Argument type: DATE/TIMESTAMP/TIME, DATE/TIMESTAMP/TIME Return type: LONG @@ -623,7 +612,7 @@ Description Usage: day(date) extracts the day of the month for date, in the range 1 to 31. -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: INTEGER @@ -648,7 +637,7 @@ Description Usage: dayname(date) returns the name of the weekday for date, including Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: STRING @@ -671,7 +660,7 @@ Description Usage: dayofmonth(date) extracts the day of the month for date, in the range 1 to 31. -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: INTEGER @@ -696,7 +685,7 @@ Description Usage: day_of_month(date) extracts the day of the month for date, in the range 1 to 31. -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: INTEGER @@ -721,7 +710,7 @@ Description Usage: dayofweek(date) returns the weekday index for date (1 = Sunday, 2 = Monday, ..., 7 = Saturday). -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: INTEGER @@ -746,7 +735,7 @@ Description Usage: day_of_week(date) returns the weekday index for date (1 = Sunday, 2 = Monday, ..., 7 = Saturday). -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: INTEGER @@ -771,7 +760,7 @@ Description Usage: dayofyear(date) returns the day of the year for date, in the range 1 to 366. -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: INTEGER @@ -796,7 +785,7 @@ Description Usage: day_of_year(date) returns the day of the year for date, in the range 1 to 366. -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: INTEGER @@ -913,14 +902,14 @@ FROM_UNIXTIME Description >>>>>>>>>>> -Usage: Returns a representation of the argument given as a datetime or character string value. Perform reverse conversion for `UNIX_TIMESTAMP`_ function. +Usage: Returns a representation of the argument given as a timestamp or character string value. Perform reverse conversion for `UNIX_TIMESTAMP`_ function. If second argument is provided, it is used to format the result in the same way as the format string used for the `DATE_FORMAT`_ function. If timestamp is outside of range 1970-01-01 00:00:00 - 3001-01-18 23:59:59.999999 (0 to 32536771199.999999 epoch time), function returns NULL. Argument type: DOUBLE, STRING Return type map: -DOUBLE -> DATETIME +DOUBLE -> TIMESTAMP DOUBLE, STRING -> STRING @@ -951,7 +940,7 @@ Description Usage: Returns a string value containing string format specifiers based on the input arguments. -Argument type: TYPE, STRING, where TYPE must be one of the following tokens: [DATE, TIME, DATETIME, TIMESTAMP], and +Argument type: TYPE, STRING, where TYPE must be one of the following tokens: [DATE, TIME, TIMESTAMP], and STRING must be one of the following tokens: ["USA", "JIS", "ISO", "EUR", "INTERNAL"] (" can be replaced by '). Examples:: @@ -973,7 +962,7 @@ Description Usage: hour(time) extracts the hour value for time. Different from the time of day value, the time value has a large range and can be greater than 23, so the return value of hour(time) can be also greater than 23. -Argument type: STRING/TIME/DATETIME/TIMESTAMP +Argument type: STRING/TIME/TIMESTAMP Return type: INTEGER @@ -998,7 +987,7 @@ Description Usage: hour_of_day(time) extracts the hour value for time. Different from the time of day value, the time value has a large range and can be greater than 23, so the return value of hour_of_day(time) can be also greater than 23. -Argument type: STRING/TIME/DATETIME/TIMESTAMP +Argument type: STRING/TIME/TIMESTAMP Return type: INTEGER @@ -1020,7 +1009,7 @@ LAST_DAY Usage: Returns the last day of the month as a DATE for a valid argument. -Argument type: DATE/DATETIME/STRING/TIMESTAMP/TIME +Argument type: DATE/STRING/TIMESTAMP/TIME Return type: DATE @@ -1145,9 +1134,9 @@ MICROSECOND Description >>>>>>>>>>> -Usage: microsecond(expr) returns the microseconds from the time or datetime expression expr as a number in the range from 0 to 999999. +Usage: microsecond(expr) returns the microseconds from the time or timestamp expression expr as a number in the range from 0 to 999999. -Argument type: STRING/TIME/DATETIME/TIMESTAMP +Argument type: STRING/TIME/TIMESTAMP Return type: INTEGER @@ -1170,7 +1159,7 @@ Description Usage: minute(time) returns the minute for time, in the range 0 to 59. -Argument type: STRING/TIME/DATETIME/TIMESTAMP +Argument type: STRING/TIME/TIMESTAMP Return type: INTEGER @@ -1195,7 +1184,7 @@ Description Usage: minute(time) returns the amount of minutes in the day, in the range of 0 to 1439. -Argument type: STRING/TIME/DATETIME/TIMESTAMP +Argument type: STRING/TIME/TIMESTAMP Return type: INTEGER @@ -1218,7 +1207,7 @@ Description Usage: minute(time) returns the minute for time, in the range 0 to 59. -Argument type: STRING/TIME/DATETIME/TIMESTAMP +Argument type: STRING/TIME/TIMESTAMP Return type: INTEGER @@ -1243,7 +1232,7 @@ Description Usage: month(date) returns the month for date, in the range 1 to 12 for January to December. -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: INTEGER @@ -1268,7 +1257,7 @@ Description Usage: month_of_year(date) returns the month for date, in the range 1 to 12 for January to December. -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: INTEGER @@ -1293,7 +1282,7 @@ Description Usage: monthname(date) returns the full name of the month for date. -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: STRING @@ -1317,9 +1306,9 @@ Description Returns the current date and time as a value in 'YYYY-MM-DD hh:mm:ss' format. The value is expressed in the cluster time zone. `NOW()` returns a constant time that indicates the time at which the statement began to execute. This differs from the behavior for `SYSDATE() <#sysdate>`_, which returns the exact time at which it executes. -Return type: DATETIME +Return type: TIMESTAMP -Specification: NOW() -> DATETIME +Specification: NOW() -> TIMESTAMP Example:: @@ -1386,7 +1375,7 @@ Description Usage: quarter(date) returns the quarter of the year for date, in the range 1 to 4. -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: INTEGER @@ -1435,7 +1424,7 @@ Description Usage: second(time) returns the second for time, in the range 0 to 59. -Argument type: STRING/TIME/DATETIME/TIMESTAMP +Argument type: STRING/TIME/TIMESTAMP Return type: INTEGER @@ -1460,7 +1449,7 @@ Description Usage: second_of_minute(time) returns the second for time, in the range 0 to 59. -Argument type: STRING/TIME/DATETIME/TIMESTAMP +Argument type: STRING/TIME/TIMESTAMP Return type: INTEGER @@ -1483,14 +1472,14 @@ STR_TO_DATE Description >>>>>>>>>>> -Usage: str_to_date(string, string) is used to extract a DATETIME from the first argument string using the formats specified in the second argument string. -The input argument must have enough information to be parsed as a DATE, DATETIME, or TIME. +Usage: str_to_date(string, string) is used to extract a TIMESTAMP from the first argument string using the formats specified in the second argument string. +The input argument must have enough information to be parsed as a DATE, TIMESTAMP, or TIME. Acceptable string format specifiers are the same as those used in the `DATE_FORMAT`_ function. -It returns NULL when a statement cannot be parsed due to an invalid pair of arguments, and when 0 is provided for any DATE field. Otherwise, it will return a DATETIME with the parsed values (as well as default values for any field that was not parsed). +It returns NULL when a statement cannot be parsed due to an invalid pair of arguments, and when 0 is provided for any DATE field. Otherwise, it will return a TIMESTAMP with the parsed values (as well as default values for any field that was not parsed). Argument type: STRING, STRING -Return type: DATETIME +Return type: TIMESTAMP Example:: @@ -1512,15 +1501,15 @@ Description Usage: subdate(date, INTERVAL expr unit) / subdate(date, days) subtracts the interval expr from date; subdate(date, days) subtracts the second argument as integer number of days from date. If first argument is TIME, today's date is used; if first argument is DATE, time at midnight is used. -Argument type: DATE/DATETIME/TIMESTAMP/TIME, INTERVAL/LONG +Argument type: DATE/TIMESTAMP/TIME, INTERVAL/LONG Return type map: -(DATE/DATETIME/TIMESTAMP/TIME, INTERVAL) -> DATETIME +(DATE/TIMESTAMP/TIME, INTERVAL) -> TIMESTAMP (DATE, LONG) -> DATE -(DATETIME/TIMESTAMP/TIME, LONG) -> DATETIME +(TIMESTAMP/TIME, LONG) -> TIMESTAMP Synonyms: `DATE_SUB`_ when invoked with the INTERVAL form of the second argument. @@ -1545,13 +1534,13 @@ Description Usage: subtime(expr1, expr2) subtracts expr2 from expr1 and returns the result. If argument is TIME, today's date is used; if argument is DATE, time at midnight is used. -Argument type: DATE/DATETIME/TIMESTAMP/TIME, DATE/DATETIME/TIMESTAMP/TIME +Argument type: DATE/TIMESTAMP/TIME, DATE/TIMESTAMP/TIME Return type map: -(DATE/DATETIME/TIMESTAMP, DATE/DATETIME/TIMESTAMP/TIME) -> DATETIME +(DATE/TIMESTAMP, DATE/TIMESTAMP/TIME) -> TIMESTAMP -(TIME, DATE/DATETIME/TIMESTAMP/TIME) -> TIME +(TIME, DATE/TIMESTAMP/TIME) -> TIME Antonyms: `ADDTIME`_ @@ -1589,7 +1578,7 @@ Example:: | 10:14:48 | +---------------------------+ - os> source=people | eval `'2007-03-01 10:20:30' - '20:40:50'` = SUBTIME(TIMESTAMP('2007-03-01 10:20:30'), DATETIME('2002-03-04 20:40:50')) | fields `'2007-03-01 10:20:30' - '20:40:50'` + os> source=people | eval `'2007-03-01 10:20:30' - '20:40:50'` = SUBTIME(TIMESTAMP('2007-03-01 10:20:30'), TIMESTAMP('2002-03-04 20:40:50')) | fields `'2007-03-01 10:20:30' - '20:40:50'` fetched rows / total rows = 1/1 +--------------------------------------+ | '2007-03-01 10:20:30' - '20:40:50' | @@ -1610,9 +1599,9 @@ If the argument is given, it specifies a fractional seconds precision from 0 to Optional argument type: INTEGER -Return type: DATETIME +Return type: TIMESTAMP -Specification: SYSDATE([INTEGER]) -> DATETIME +Specification: SYSDATE([INTEGER]) -> TIMESTAMP Example:: @@ -1631,9 +1620,9 @@ TIME Description >>>>>>>>>>> -Usage: time(expr) constructs a time type with the input string expr as a time. If the argument is of date/datetime/time/timestamp, it extracts the time value part from the expression. +Usage: time(expr) constructs a time type with the input string expr as a time. If the argument is of date/time/timestamp, it extracts the time value part from the expression. -Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP +Argument type: STRING/DATE/TIME/TIMESTAMP Return type: TIME @@ -1682,7 +1671,7 @@ Usage: time_format(time, format) formats the time argument using the specifiers This supports a subset of the time format specifiers available for the `date_format`_ function. Using date format specifiers supported by `date_format`_ will return 0 or null. Acceptable format specifiers are listed in the table below. -If an argument of type DATE is passed in, it is treated as a DATETIME at midnight (i.e., 00:00:00). +If an argument of type DATE is passed in, it is treated as a TIMESTAMP at midnight (i.e., 00:00:00). .. list-table:: The following table describes the available specifier arguments. :widths: 20 80 @@ -1712,7 +1701,7 @@ If an argument of type DATE is passed in, it is treated as a DATETIME at midnigh - Time, 24-hour (hh:mm:ss) -Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP, STRING +Argument type: STRING/DATE/TIME/TIMESTAMP, STRING Return type: STRING @@ -1735,7 +1724,7 @@ Description Usage: time_to_sec(time) returns the time argument, converted to seconds. -Argument type: STRING/TIME/DATETIME/TIMESTAMP +Argument type: STRING/TIME/TIMESTAMP Return type: LONG @@ -1780,15 +1769,15 @@ Description >>>>>>>>>>> Usage: timestamp(expr) constructs a timestamp type with the input string `expr` as an timestamp. If the argument is not a string, it casts `expr` to timestamp type with default timezone UTC. If argument is a time, it applies today's date before cast. -With two arguments `timestamp(expr1, expr2)` adds the time expression `expr2` to the date or datetime expression `expr1` and returns the result as a timestamp value. +With two arguments `timestamp(expr1, expr2)` adds the time expression `expr2` to the date or timestamp expression `expr1` and returns the result as a timestamp value. -Argument type: STRING/DATE/TIME/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIME/TIMESTAMP Return type map: -(STRING/DATE/TIME/DATETIME/TIMESTAMP) -> TIMESTAMP +(STRING/DATE/TIME/TIMESTAMP) -> TIMESTAMP -(STRING/DATE/TIME/DATETIME/TIMESTAMP, STRING/DATE/TIME/DATETIME/TIMESTAMP) -> TIMESTAMP +(STRING/DATE/TIME/TIMESTAMP, STRING/DATE/TIME/TIMESTAMP) -> TIMESTAMP Example:: @@ -1807,11 +1796,11 @@ TIMESTAMPADD Description >>>>>>>>>>> -Usage: Returns a DATETIME value based on a passed in DATE/DATETIME/TIME/TIMESTAMP/STRING argument and an INTERVAL and INTEGER argument which determine the amount of time to be added. -If the third argument is a STRING, it must be formatted as a valid DATETIME. If only a TIME is provided, a DATETIME is still returned with the DATE portion filled in using the current date. -If the third argument is a DATE, it will be automatically converted to a DATETIME. +Usage: Returns a TIMESTAMP value based on a passed in DATE/TIME/TIMESTAMP/STRING argument and an INTERVAL and INTEGER argument which determine the amount of time to be added. +If the third argument is a STRING, it must be formatted as a valid TIMESTAMP. If only a TIME is provided, a TIMESTAMP is still returned with the DATE portion filled in using the current date. +If the third argument is a DATE, it will be automatically converted to a TIMESTAMP. -Argument type: INTERVAL, INTEGER, DATE/DATETIME/TIME/TIMESTAMP/STRING +Argument type: INTERVAL, INTEGER, DATE/TIME/TIMESTAMP/STRING INTERVAL must be one of the following tokens: [MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR] @@ -1833,11 +1822,11 @@ Description >>>>>>>>>>> Usage: TIMESTAMPDIFF(interval, start, end) returns the difference between the start and end date/times in interval units. -If a TIME is provided as an argument, it will be converted to a DATETIME with the DATE portion filled in using the current date. -Arguments will be automatically converted to a DATETIME/TIME/TIMESTAMP when appropriate. -Any argument that is a STRING must be formatted as a valid DATETIME. +If a TIME is provided as an argument, it will be converted to a TIMESTAMP with the DATE portion filled in using the current date. +Arguments will be automatically converted to a TIME/TIMESTAMP when appropriate. +Any argument that is a STRING must be formatted as a valid TIMESTAMP. -Argument type: INTERVAL, DATE/DATETIME/TIME/TIMESTAMP/STRING, DATE/DATETIME/TIME/TIMESTAMP/STRING +Argument type: INTERVAL, DATE/TIME/TIMESTAMP/STRING, DATE/TIME/TIMESTAMP/STRING INTERVAL must be one of the following tokens: [MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR] @@ -1860,7 +1849,7 @@ Description Usage: to_days(date) returns the day number (the number of days since year 0) of the given date. Returns NULL if date is invalid. -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: LONG @@ -1884,7 +1873,7 @@ Description Usage: to_seconds(date) returns the number of seconds since the year 0 of the given value. Returns NULL if value is invalid. An argument of a LONG type can be used. It must be formatted as YMMDD, YYMMDD, YYYMMDD or YYYYMMDD. Note that a LONG type argument cannot have leading 0s as it will be parsed using an octal numbering system. -Argument type: STRING/LONG/DATE/DATETIME/TIME/TIMESTAMP +Argument type: STRING/LONG/DATE/TIME/TIMESTAMP Return type: LONG @@ -1906,11 +1895,11 @@ Description >>>>>>>>>>> Usage: Converts given argument to Unix time (seconds since Epoch - very beginning of year 1970). If no argument given, it returns the current Unix time. -The date argument may be a DATE, DATETIME, or TIMESTAMP string, or a number in YYMMDD, YYMMDDhhmmss, YYYYMMDD, or YYYYMMDDhhmmss format. If the argument includes a time part, it may optionally include a fractional seconds part. +The date argument may be a DATE, or TIMESTAMP string, or a number in YYMMDD, YYMMDDhhmmss, YYYYMMDD, or YYYYMMDDhhmmss format. If the argument includes a time part, it may optionally include a fractional seconds part. If argument is in invalid format or outside of range 1970-01-01 00:00:00 - 3001-01-18 23:59:59.999999 (0 to 32536771199.999999 epoch time), function returns NULL. You can use `FROM_UNIXTIME`_ to do reverse conversion. -Argument type: /DOUBLE/DATE/DATETIME/TIMESTAMP +Argument type: /DOUBLE/DATE/TIMESTAMP Return type: DOUBLE @@ -1979,9 +1968,9 @@ Description Returns the current UTC timestamp as a value in 'YYYY-MM-DD hh:mm:ss'. -Return type: DATETIME +Return type: TIMESTAMP -Specification: UTC_TIMESTAMP() -> DATETIME +Specification: UTC_TIMESTAMP() -> TIMESTAMP Example:: @@ -2043,7 +2032,7 @@ Usage: week(date[, mode]) returns the week number for date. If the mode argument - 1-53 - with a Monday in this year -Argument type: DATE/DATETIME/TIMESTAMP/STRING +Argument type: DATE/TIMESTAMP/STRING Return type: INTEGER @@ -2070,7 +2059,7 @@ Usage: weekday(date) returns the weekday index for date (0 = Monday, 1 = Tuesday It is similar to the `dayofweek`_ function, but returns different indexes for each day. -Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP +Argument type: STRING/DATE/TIME/TIMESTAMP Return type: INTEGER @@ -2134,7 +2123,7 @@ Usage: week_of_year(date[, mode]) returns the week number for date. If the mode - 1-53 - with a Monday in this year -Argument type: DATE/DATETIME/TIMESTAMP/STRING +Argument type: DATE/TIMESTAMP/STRING Return type: INTEGER @@ -2159,7 +2148,7 @@ Description Usage: year(date) returns the year for date, in the range 1000 to 9999, or 0 for the “zero” date. -Argument type: STRING/DATE/DATETIME/TIMESTAMP +Argument type: STRING/DATE/TIMESTAMP Return type: INTEGER @@ -2182,7 +2171,7 @@ Description Usage: yearweek(date) returns the year and week for date as an integer. It accepts and optional mode arguments aligned with those available for the `WEEK`_ function. -Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP +Argument type: STRING/DATE/TIME/TIMESTAMP Return type: INTEGER diff --git a/docs/user/ppl/functions/system.rst b/docs/user/ppl/functions/system.rst index fbe9860dce..cfe0414c49 100644 --- a/docs/user/ppl/functions/system.rst +++ b/docs/user/ppl/functions/system.rst @@ -27,5 +27,5 @@ Example:: +----------------+---------------+-----------------+------------------+ | typeof(date) | typeof(int) | typeof(now()) | typeof(column) | |----------------+---------------+-----------------+------------------| - | DATE | INTEGER | DATETIME | OBJECT | + | DATE | INTEGER | TIMESTAMP | OBJECT | +----------------+---------------+-----------------+------------------+ diff --git a/docs/user/ppl/general/datatypes.rst b/docs/user/ppl/general/datatypes.rst index cabc689526..18555dec3d 100644 --- a/docs/user/ppl/general/datatypes.rst +++ b/docs/user/ppl/general/datatypes.rst @@ -39,8 +39,6 @@ The PPL support the following data types. +---------------+ | timestamp | +---------------+ -| datetime | -+---------------+ | date | +---------------+ | time | @@ -114,7 +112,7 @@ Numeric values ranged from -2147483648 to +2147483647 are recognized as integer Date and Time Data Types ======================== -The date and time data types are the types that represent temporal values and PPL plugin supports types including DATE, TIME, DATETIME, TIMESTAMP and INTERVAL. By default, the OpenSearch DSL uses date type as the only date and time related type, which has contained all information about an absolute time point. To integrate with PPL language, each of the types other than timestamp is holding part of temporal or timezone information, and the usage to explicitly clarify the date and time types is reflected in the datetime functions (see `Functions `_ for details), where some functions might have restrictions in the input argument type. +The date and time data types are the types that represent temporal values and PPL plugin supports types including DATE, TIME, TIMESTAMP and INTERVAL. By default, the OpenSearch DSL uses date type as the only date and time related type, which has contained all information about an absolute time point. To integrate with PPL language, each of the types other than timestamp is holding part of temporal or timezone information, and the usage to explicitly clarify the date and time types is reflected in the datetime functions (see `Functions `_ for details), where some functions might have restrictions in the input argument type. Date @@ -141,19 +139,6 @@ Time represents the time on the clock or watch with no regard for which timezone +------+-----------------------+----------------------------------------+ -Datetime --------- - -Datetime type is the combination of date and time. The conversion rule of date or time to datetime is described in `Conversion between date and time types`_. Datetime type does not contain timezone information. For an absolute time point that contains both date time and timezone information, see `Timestamp`_. - -+----------+----------------------------------+--------------------------------------------------------------+ -| Type | Syntax | Range | -+==========+==================================+==============================================================+ -| Datetime | 'yyyy-MM-dd hh:mm:ss[.fraction]' | '0001-01-01 00:00:00.000000' to '9999-12-31 23:59:59.999999' | -+----------+----------------------------------+--------------------------------------------------------------+ - - - Timestamp --------- @@ -183,38 +168,26 @@ The expr is any expression that can be iterated to a quantity value eventually, Conversion between date and time types -------------------------------------- -Basically the date and time types except interval can be converted to each other, but might suffer some alteration of the value or some information loss, for example extracting the time value from a datetime value, or convert a date value to a datetime value and so forth. Here lists the summary of the conversion rules that PPL plugin supports for each of the types: +Basically the date and time types except interval can be converted to each other, but might suffer some alteration of the value or some information loss, for example extracting the time value from a timestamp value, or convert a date value to a timestamp value and so forth. Here lists the summary of the conversion rules that PPL plugin supports for each of the types: Conversion from DATE >>>>>>>>>>>>>>>>>>>> - Since the date value does not have any time information, conversion to `Time`_ type is not useful, and will always return a zero time value '00:00:00'. -- Conversion from date to datetime has a data fill-up due to the lack of time information, and it attaches the time '00:00:00' to the original date by default and forms a datetime instance. For example, the result to covert date '2020-08-17' to datetime type is datetime '2020-08-17 00:00:00'. - -- Conversion to timestamp is to alternate both the time value and the timezone information, and it attaches the zero time value '00:00:00' and the session timezone (UTC by default) to the date. For example, the result to covert date '2020-08-17' to datetime type with session timezone UTC is datetime '2020-08-17 00:00:00' UTC. +- Conversion to timestamp is to alternate both the time value and the timezone information, and it attaches the zero time value '00:00:00' and the session timezone (UTC by default) to the date. For example, the result to covert date '2020-08-17' to timestamp type with session timezone UTC is timestamp '2020-08-17 00:00:00' UTC. Conversion from TIME >>>>>>>>>>>>>>>>>>>> -- Time value cannot be converted to any other date and time types since it does not contain any date information, so it is not meaningful to give no date info to a date/datetime/timestamp instance. - - -Conversion from DATETIME ->>>>>>>>>>>>>>>>>>>>>>>> - -- Conversion from datetime to date is to extract the date part from the datetime value. For example, the result to convert datetime '2020-08-17 14:09:00' to date is date '2020-08-08'. - -- Conversion to time is to extract the time part from the datetime value. For example, the result to convert datetime '2020-08-17 14:09:00' to time is time '14:09:00'. - -- Since the datetime type does not contain timezone information, the conversion to timestamp needs to fill up the timezone part with the session timezone. For example, the result to convert datetime '2020-08-17 14:09:00' with system timezone of UTC, to timestamp is timestamp '2020-08-17 14:09:00' UTC. +- Time value cannot be converted to any other date and time types since it does not contain any date information, so it is not meaningful to give no date info to a date/timestamp instance. Conversion from TIMESTAMP >>>>>>>>>>>>>>>>>>>>>>>>> -- Conversion from timestamp is much more straightforward. To convert it to date is to extract the date value, and conversion to time is to extract the time value. Conversion to datetime, it will extracts the datetime value and leave the timezone information over. For example, the result to convert datetime '2020-08-17 14:09:00' UTC to date is date '2020-08-17', to time is '14:09:00' and to datetime is datetime '2020-08-17 14:09:00'. +- Conversion from timestamp is much more straightforward. To convert it to date is to extract the date value, and conversion to time is to extract the time value. For example, the result to convert timestamp '2020-08-17 14:09:00' UTC to date is date '2020-08-17', to time is '14:09:00'. String Data Types diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/ConvertTZFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/ConvertTZFunctionIT.java index 105669c7ca..a0749387d5 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/ConvertTZFunctionIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/ConvertTZFunctionIT.java @@ -30,7 +30,7 @@ public void inRangeZeroToPositive() throws IOException { "source=%s | eval f = convert_tz('2008-05-15 12:00:00','+00:00','+10:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-05-15 22:00:00")); } @@ -42,7 +42,7 @@ public void inRangeZeroToZero() throws IOException { "source=%s | eval f = convert_tz('2021-05-12 00:00:00','-00:00','+00:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2021-05-12 00:00:00")); } @@ -54,7 +54,7 @@ public void inRangePositiveToPositive() throws IOException { "source=%s | eval f = convert_tz('2021-05-12 00:00:00','+10:00','+11:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2021-05-12 01:00:00")); } @@ -66,7 +66,7 @@ public void inRangeNegativeToPositive() throws IOException { "source=%s | eval f = convert_tz('2021-05-12 11:34:50','-08:00','+09:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2021-05-13 04:34:50")); } @@ -78,7 +78,7 @@ public void inRangeNoTZChange() throws IOException { "source=%s | eval f = convert_tz('2021-05-12 11:34:50','+09:00','+09:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2021-05-12 11:34:50")); } @@ -90,7 +90,7 @@ public void inRangeTwentyFourHourChange() throws IOException { "source=%s | eval f = convert_tz('2021-05-12 11:34:50','-12:00','+12:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2021-05-13 11:34:50")); } @@ -102,7 +102,7 @@ public void inRangeFifteenMinuteTZ() throws IOException { "source=%s | eval f = convert_tz('2021-05-12 13:00:00','+09:30','+05:45') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2021-05-12 09:15:00")); } @@ -114,7 +114,7 @@ public void nullFromFieldUnder() throws IOException { "source=%s | eval f = convert_tz('2021-05-30 11:34:50','-17:00','+08:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } @@ -126,7 +126,7 @@ public void nullToFieldOver() throws IOException { "source=%s | eval f = convert_tz('2021-05-12 11:34:50','-12:00','+15:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } @@ -137,7 +137,7 @@ public void nullFromGarbageInput1() throws IOException { String.format( "source=%s | eval f = convert_tz('2021-05-12 11:34:50','-12:00','test') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } @@ -148,7 +148,7 @@ public void nullFromGarbageInput2() throws IOException { String.format( "source=%s | eval f = convert_tz('2021test','-12:00','+00:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } @@ -160,7 +160,7 @@ public void nullDateTimeInvalidDateValueFebruary() throws IOException { "source=%s | eval f = convert_tz('2021-02-30 10:00:00','+00:00','+00:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } @@ -172,7 +172,7 @@ public void nullDateTimeInvalidDateValueApril() throws IOException { "source=%s | eval f = convert_tz('2021-04-31 10:00:00','+00:00','+00:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } @@ -184,7 +184,7 @@ public void nullDateTimeInvalidDateValueMonth() throws IOException { "source=%s | eval f = convert_tz('2021-13-03 10:00:00','+00:00','+00:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } } diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeComparisonIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeComparisonIT.java index 6f6b5cc297..7cc083cbb6 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeComparisonIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeComparisonIT.java @@ -98,32 +98,6 @@ public static Iterable compareTwoTimes() { $("TIME('19:16:03') <= TIME('04:12:42')", "lte3", false))); } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") - public static Iterable compareTwoDateTimes() { - return Arrays.asList( - $$( - $("DATETIME('2020-09-16 10:20:30') = DATETIME('2020-09-16 10:20:30')", "eq1", true), - $("DATETIME('2020-09-16 10:20:30') = DATETIME('1961-04-12 09:07:00')", "eq2", false), - $("DATETIME('2020-09-16 10:20:30') != DATETIME('1984-12-15 22:15:07')", "neq1", true), - $("DATETIME('1984-12-15 22:15:08') != DATETIME('1984-12-15 22:15:07')", "neq2", true), - $("DATETIME('1961-04-12 09:07:00') != DATETIME('1961-04-12 09:07:00')", "neq3", false), - $("DATETIME('1984-12-15 22:15:07') > DATETIME('1961-04-12 22:15:07')", "gt1", true), - $("DATETIME('1984-12-15 22:15:07') > DATETIME('1984-12-15 22:15:06')", "gt2", true), - $("DATETIME('1984-12-15 22:15:07') > DATETIME('2020-09-16 10:20:30')", "gt3", false), - $("DATETIME('1961-04-12 09:07:00') < DATETIME('1984-12-15 09:07:00')", "lt1", true), - $("DATETIME('1984-12-15 22:15:07') < DATETIME('1984-12-15 22:15:08')", "lt2", true), - $("DATETIME('1984-12-15 22:15:07') < DATETIME('1961-04-12 09:07:00')", "lt3", false), - $("DATETIME('1984-12-15 22:15:07') >= DATETIME('1961-04-12 09:07:00')", "gte1", true), - $("DATETIME('1984-12-15 22:15:07') >= DATETIME('1984-12-15 22:15:07')", "gte2", true), - $("DATETIME('1984-12-15 22:15:07') >= DATETIME('2020-09-16 10:20:30')", "gte3", false), - $("DATETIME('1961-04-12 09:07:00') <= DATETIME('1984-12-15 22:15:07')", "lte1", true), - $("DATETIME('1961-04-12 09:07:00') <= DATETIME('1961-04-12 09:07:00')", "lte2", true), - $( - "DATETIME('2020-09-16 10:20:30') <= DATETIME('1961-04-12 09:07:00')", - "lte3", - false))); - } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareTwoTimestamps() { return Arrays.asList( @@ -161,22 +135,6 @@ public static Iterable compareEqTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $( - "TIMESTAMP('2020-09-16 10:20:30') = DATETIME('2020-09-16 10:20:30')", - "ts_dt_t", - true), - $( - "DATETIME('2020-09-16 10:20:30') = TIMESTAMP('2020-09-16 10:20:30')", - "dt_ts_t", - true), - $( - "TIMESTAMP('2020-09-16 10:20:30') = DATETIME('1961-04-12 09:07:00')", - "ts_dt_f", - false), - $( - "DATETIME('1961-04-12 09:07:00') = TIMESTAMP('1984-12-15 22:15:07')", - "dt_ts_f", - false), $("TIMESTAMP('2020-09-16 00:00:00') = DATE('2020-09-16')", "ts_d_t", true), $("DATE('2020-09-16') = TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 10:20:30') = DATE('1961-04-12')", "ts_d_f", false), @@ -187,37 +145,6 @@ public static Iterable compareEqTimestampWithOtherTypes() { $("TIME('09:07:00') = TIMESTAMP('1984-12-15 22:15:07')", "t_ts_f", false))); } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") - public static Iterable compareEqDateTimeWithOtherTypes() { - var today = LocalDate.now().toString(); - return Arrays.asList( - $$( - $( - "DATETIME('2020-09-16 10:20:30') = TIMESTAMP('2020-09-16 10:20:30')", - "dt_ts_t", - true), - $( - "TIMESTAMP('2020-09-16 10:20:30') = DATETIME('2020-09-16 10:20:30')", - "ts_dt_t", - true), - $( - "DATETIME('2020-09-16 10:20:30') = TIMESTAMP('1961-04-12 09:07:00')", - "dt_ts_f", - false), - $( - "TIMESTAMP('1961-04-12 09:07:00') = DATETIME('1984-12-15 22:15:07')", - "ts_dt_f", - false), - $("DATETIME('2020-09-16 00:00:00') = DATE('2020-09-16')", "dt_d_t", true), - $("DATE('2020-09-16') = DATETIME('2020-09-16 00:00:00')", "d_dt_t", true), - $("DATETIME('2020-09-16 10:20:30') = DATE('1961-04-12')", "dt_d_f", false), - $("DATE('1961-04-12') = DATETIME('1984-12-15 22:15:07')", "d_dt_f", false), - $("DATETIME('" + today + " 10:20:30') = TIME('10:20:30')", "dt_t_t", true), - $("TIME('10:20:30') = DATETIME('" + today + " 10:20:30')", "t_dt_t", true), - $("DATETIME('2020-09-16 10:20:30') = TIME('09:07:00')", "dt_t_f", false), - $("TIME('09:07:00') = DATETIME('1984-12-15 22:15:07')", "t_dt_f", false))); - } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareEqDateWithOtherTypes() { var today = LocalDate.now().toString(); @@ -227,10 +154,6 @@ public static Iterable compareEqDateWithOtherTypes() { $("TIMESTAMP('2020-09-16 00:00:00') = DATE('2020-09-16')", "ts_d_t", true), $("DATE('2020-09-16') = TIMESTAMP('1961-04-12 09:07:00')", "d_ts_f", false), $("TIMESTAMP('1984-12-15 09:07:00') = DATE('1984-12-15')", "ts_d_f", false), - $("DATE('2020-09-16') = DATETIME('2020-09-16 00:00:00')", "d_dt_t", true), - $("DATETIME('2020-09-16 00:00:00') = DATE('2020-09-16')", "dt_d_t", true), - $("DATE('1961-04-12') = DATETIME('1984-12-15 22:15:07')", "d_dt_f", false), - $("DATETIME('1961-04-12 10:20:30') = DATE('1961-04-12')", "dt_d_f", false), $("DATE('" + today + "') = TIME('00:00:00')", "d_t_t", true), $("TIME('00:00:00') = DATE('" + today + "')", "t_d_t", true), $("DATE('2020-09-16') = TIME('09:07:00')", "d_t_f", false), @@ -242,10 +165,6 @@ public static Iterable compareEqTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $("TIME('10:20:30') = DATETIME('" + today + " 10:20:30')", "t_dt_t", true), - $("DATETIME('" + today + " 10:20:30') = TIME('10:20:30')", "dt_t_t", true), - $("TIME('09:07:00') = DATETIME('1961-04-12 09:07:00')", "t_dt_f", false), - $("DATETIME('" + today + " 09:07:00') = TIME('10:20:30')", "dt_t_f", false), $("TIME('10:20:30') = TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), $("TIMESTAMP('" + today + " 10:20:30') = TIME('10:20:30')", "ts_t_t", true), $("TIME('22:15:07') = TIMESTAMP('1984-12-15 22:15:07')", "t_ts_f", false), @@ -261,22 +180,6 @@ public static Iterable compareNeqTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $( - "TIMESTAMP('2020-09-16 10:20:30') != DATETIME('1961-04-12 09:07:00')", - "ts_dt_t", - true), - $( - "DATETIME('1961-04-12 09:07:00') != TIMESTAMP('1984-12-15 22:15:07')", - "dt_ts_t", - true), - $( - "TIMESTAMP('2020-09-16 10:20:30') != DATETIME('2020-09-16 10:20:30')", - "ts_dt_f", - false), - $( - "DATETIME('2020-09-16 10:20:30') != TIMESTAMP('2020-09-16 10:20:30')", - "dt_ts_f", - false), $("TIMESTAMP('2020-09-16 10:20:30') != DATE('1961-04-12')", "ts_d_t", true), $("DATE('1961-04-12') != TIMESTAMP('1984-12-15 22:15:07')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 00:00:00') != DATE('2020-09-16')", "ts_d_f", false), @@ -287,37 +190,6 @@ public static Iterable compareNeqTimestampWithOtherTypes() { $("TIME('10:20:30') != TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false))); } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") - public static Iterable compareNeqDateTimeWithOtherTypes() { - var today = LocalDate.now().toString(); - return Arrays.asList( - $$( - $( - "DATETIME('2020-09-16 10:20:30') != TIMESTAMP('1961-04-12 09:07:00')", - "dt_ts_t", - true), - $( - "TIMESTAMP('1961-04-12 09:07:00') != DATETIME('1984-12-15 22:15:07')", - "ts_dt_t", - true), - $( - "DATETIME('2020-09-16 10:20:30') != TIMESTAMP('2020-09-16 10:20:30')", - "dt_ts_f", - false), - $( - "TIMESTAMP('2020-09-16 10:20:30') != DATETIME('2020-09-16 10:20:30')", - "ts_dt_f", - false), - $("DATETIME('2020-09-16 10:20:30') != DATE('1961-04-12')", "dt_d_t", true), - $("DATE('1961-04-12') != DATETIME('1984-12-15 22:15:07')", "d_dt_t", true), - $("DATETIME('2020-09-16 00:00:00') != DATE('2020-09-16')", "dt_d_f", false), - $("DATE('2020-09-16') != DATETIME('2020-09-16 00:00:00')", "d_dt_f", false), - $("DATETIME('2020-09-16 10:20:30') != TIME('09:07:00')", "dt_t_t", true), - $("TIME('09:07:00') != DATETIME('1984-12-15 22:15:07')", "t_dt_t", true), - $("DATETIME('" + today + " 10:20:30') != TIME('10:20:30')", "dt_t_f", false), - $("TIME('10:20:30') != DATETIME('" + today + " 10:20:30')", "t_dt_f", false))); - } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareNeqDateWithOtherTypes() { var today = LocalDate.now().toString(); @@ -327,10 +199,6 @@ public static Iterable compareNeqDateWithOtherTypes() { $("TIMESTAMP('1984-12-15 09:07:00') != DATE('1984-12-15')", "ts_d_t", true), $("DATE('2020-09-16') != TIMESTAMP('2020-09-16 00:00:00')", "d_ts_f", false), $("TIMESTAMP('2020-09-16 00:00:00') != DATE('2020-09-16')", "ts_d_f", false), - $("DATE('1961-04-12') != DATETIME('1984-12-15 22:15:07')", "d_dt_t", true), - $("DATETIME('1961-04-12 10:20:30') != DATE('1961-04-12')", "dt_d_t", true), - $("DATE('2020-09-16') != DATETIME('2020-09-16 00:00:00')", "d_dt_f", false), - $("DATETIME('2020-09-16 00:00:00') != DATE('2020-09-16')", "dt_d_f", false), $("DATE('2020-09-16') != TIME('09:07:00')", "d_t_t", true), $("TIME('09:07:00') != DATE('" + today + "')", "t_d_t", true), $("DATE('" + today + "') != TIME('00:00:00')", "d_t_f", false), @@ -342,10 +210,6 @@ public static Iterable compareNeqTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $("TIME('09:07:00') != DATETIME('1961-04-12 09:07:00')", "t_dt_t", true), - $("DATETIME('" + today + " 09:07:00') != TIME('10:20:30')", "dt_t_t", true), - $("TIME('10:20:30') != DATETIME('" + today + " 10:20:30')", "t_dt_f", false), - $("DATETIME('" + today + " 10:20:30') != TIME('10:20:30')", "dt_t_f", false), $("TIME('22:15:07') != TIMESTAMP('1984-12-15 22:15:07')", "t_ts_t", true), $("TIMESTAMP('1984-12-15 10:20:30') != TIME('10:20:30')", "ts_t_t", true), $("TIME('10:20:30') != TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false), @@ -361,22 +225,6 @@ public static Iterable compareLtTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $( - "TIMESTAMP('2020-09-16 10:20:30') < DATETIME('2061-04-12 09:07:00')", - "ts_dt_t", - true), - $( - "DATETIME('1961-04-12 09:07:00') < TIMESTAMP('1984-12-15 22:15:07')", - "dt_ts_t", - true), - $( - "TIMESTAMP('2020-09-16 10:20:30') < DATETIME('2020-09-16 10:20:30')", - "ts_dt_f", - false), - $( - "DATETIME('2020-09-16 10:20:30') < TIMESTAMP('1961-04-12 09:07:00')", - "dt_ts_f", - false), $("TIMESTAMP('2020-09-16 10:20:30') < DATE('2077-04-12')", "ts_d_t", true), $("DATE('1961-04-12') < TIMESTAMP('1984-12-15 22:15:07')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 10:20:30') < DATE('1961-04-12')", "ts_d_f", false), @@ -387,37 +235,6 @@ public static Iterable compareLtTimestampWithOtherTypes() { $("TIME('20:50:40') < TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false))); } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") - public static Iterable compareLtDateTimeWithOtherTypes() { - var today = LocalDate.now().toString(); - return Arrays.asList( - $$( - $( - "DATETIME('2020-09-16 10:20:30') < TIMESTAMP('2077-04-12 09:07:00')", - "dt_ts_t", - true), - $( - "TIMESTAMP('1961-04-12 09:07:00') < DATETIME('1984-12-15 22:15:07')", - "ts_dt_t", - true), - $( - "DATETIME('2020-09-16 10:20:30') < TIMESTAMP('2020-09-16 10:20:30')", - "dt_ts_f", - false), - $( - "TIMESTAMP('2020-09-16 10:20:30') < DATETIME('1984-12-15 22:15:07')", - "ts_dt_f", - false), - $("DATETIME('2020-09-16 10:20:30') < DATE('3077-04-12')", "dt_d_t", true), - $("DATE('1961-04-12') < DATETIME('1984-12-15 22:15:07')", "d_dt_t", true), - $("DATETIME('2020-09-16 00:00:00') < DATE('2020-09-16')", "dt_d_f", false), - $("DATE('2020-09-16') < DATETIME('1961-04-12 09:07:00')", "d_dt_f", false), - $("DATETIME('2020-09-16 10:20:30') < TIME('09:07:00')", "dt_t_t", true), - $("TIME('09:07:00') < DATETIME('3077-12-15 22:15:07')", "t_dt_t", true), - $("DATETIME('" + today + " 10:20:30') < TIME('10:20:30')", "dt_t_f", false), - $("TIME('20:40:50') < DATETIME('" + today + " 10:20:30')", "t_dt_f", false))); - } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareLtDateWithOtherTypes() { return Arrays.asList( @@ -426,10 +243,6 @@ public static Iterable compareLtDateWithOtherTypes() { $("TIMESTAMP('1961-04-12 09:07:00') < DATE('1984-12-15')", "ts_d_t", true), $("DATE('2020-09-16') < TIMESTAMP('2020-09-16 00:00:00')", "d_ts_f", false), $("TIMESTAMP('2077-04-12 09:07:00') < DATE('2020-09-16')", "ts_d_f", false), - $("DATE('1961-04-12') < DATETIME('1984-12-15 22:15:07')", "d_dt_t", true), - $("DATETIME('1961-04-12 10:20:30') < DATE('1984-11-15')", "dt_d_t", true), - $("DATE('2020-09-16') < DATETIME('2020-09-16 00:00:00')", "d_dt_f", false), - $("DATETIME('2020-09-16 00:00:00') < DATE('1984-03-22')", "dt_d_f", false), $("DATE('2020-09-16') < TIME('09:07:00')", "d_t_t", true), $("TIME('09:07:00') < DATE('3077-04-12')", "t_d_t", true), $("DATE('3077-04-12') < TIME('00:00:00')", "d_t_f", false), @@ -441,10 +254,6 @@ public static Iterable compareLtTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $("TIME('09:07:00') < DATETIME('3077-04-12 09:07:00')", "t_dt_t", true), - $("DATETIME('" + today + " 09:07:00') < TIME('10:20:30')", "dt_t_t", true), - $("TIME('10:20:30') < DATETIME('" + today + " 10:20:30')", "t_dt_f", false), - $("DATETIME('" + today + " 20:40:50') < TIME('10:20:30')", "dt_t_f", false), $("TIME('22:15:07') < TIMESTAMP('3077-12-15 22:15:07')", "t_ts_t", true), $("TIMESTAMP('1984-12-15 10:20:30') < TIME('10:20:30')", "ts_t_t", true), $("TIME('10:20:30') < TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false), @@ -460,22 +269,6 @@ public static Iterable compareGtTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $( - "TIMESTAMP('2020-09-16 10:20:30') > DATETIME('2020-09-16 10:20:25')", - "ts_dt_t", - true), - $( - "DATETIME('2020-09-16 10:20:30') > TIMESTAMP('1961-04-12 09:07:00')", - "dt_ts_t", - true), - $( - "TIMESTAMP('2020-09-16 10:20:30') > DATETIME('2061-04-12 09:07:00')", - "ts_dt_f", - false), - $( - "DATETIME('1961-04-12 09:07:00') > TIMESTAMP('1984-12-15 09:07:00')", - "dt_ts_f", - false), $("TIMESTAMP('2020-09-16 10:20:30') > DATE('1961-04-12')", "ts_d_t", true), $("DATE('2020-09-16') > TIMESTAMP('2020-09-15 22:15:07')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 10:20:30') > DATE('2077-04-12')", "ts_d_f", false), @@ -486,37 +279,6 @@ public static Iterable compareGtTimestampWithOtherTypes() { $("TIME('09:07:00') > TIMESTAMP('3077-12-15 22:15:07')", "t_ts_f", false))); } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") - public static Iterable compareGtDateTimeWithOtherTypes() { - var today = LocalDate.now().toString(); - return Arrays.asList( - $$( - $( - "DATETIME('2020-09-16 10:20:31') > TIMESTAMP('2020-09-16 10:20:30')", - "dt_ts_t", - true), - $( - "TIMESTAMP('2020-09-16 10:20:30') > DATETIME('1984-12-15 22:15:07')", - "ts_dt_t", - true), - $( - "DATETIME('2020-09-16 10:20:30') > TIMESTAMP('2077-04-12 09:07:00')", - "dt_ts_f", - false), - $( - "TIMESTAMP('1961-04-12 09:07:00') > DATETIME('1961-04-12 09:07:00')", - "ts_dt_f", - false), - $("DATETIME('3077-04-12 10:20:30') > DATE('2020-09-16')", "dt_d_t", true), - $("DATE('2020-09-16') > DATETIME('1961-04-12 09:07:00')", "d_dt_t", true), - $("DATETIME('2020-09-16 00:00:00') > DATE('2020-09-16')", "dt_d_f", false), - $("DATE('1961-04-12') > DATETIME('1984-12-15 22:15:07')", "d_dt_f", false), - $("DATETIME('3077-04-12 10:20:30') > TIME('09:07:00')", "dt_t_t", true), - $("TIME('20:40:50') > DATETIME('" + today + " 10:20:30')", "t_dt_t", true), - $("DATETIME('" + today + " 10:20:30') > TIME('10:20:30')", "dt_t_f", false), - $("TIME('09:07:00') > DATETIME('3077-12-15 22:15:07')", "t_dt_f", false))); - } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareGtDateWithOtherTypes() { return Arrays.asList( @@ -525,10 +287,6 @@ public static Iterable compareGtDateWithOtherTypes() { $("TIMESTAMP('2077-04-12 09:07:00') > DATE('2020-09-16')", "ts_d_t", true), $("DATE('2020-09-16') > TIMESTAMP('2020-09-16 00:00:00')", "d_ts_f", false), $("TIMESTAMP('1961-04-12 09:07:00') > DATE('1984-12-15')", "ts_d_f", false), - $("DATE('1984-12-15') > DATETIME('1961-04-12 09:07:00')", "d_dt_t", true), - $("DATETIME('2020-09-16 00:00:00') > DATE('1984-03-22')", "dt_d_t", true), - $("DATE('2020-09-16') > DATETIME('2020-09-16 00:00:00')", "d_dt_f", false), - $("DATETIME('1961-04-12 10:20:30') > DATE('1984-11-15')", "dt_d_f", false), $("DATE('3077-04-12') > TIME('00:00:00')", "d_t_t", true), $("TIME('00:00:00') > DATE('2020-09-16')", "t_d_t", true), $("DATE('2020-09-16') > TIME('09:07:00')", "d_t_f", false), @@ -540,10 +298,6 @@ public static Iterable compareGtTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $("TIME('09:07:00') > DATETIME('1961-04-12 09:07:00')", "t_dt_t", true), - $("DATETIME('" + today + " 20:40:50') > TIME('10:20:30')", "dt_t_t", true), - $("TIME('10:20:30') > DATETIME('" + today + " 10:20:30')", "t_dt_f", false), - $("DATETIME('" + today + " 09:07:00') > TIME('10:20:30')", "dt_t_f", false), $("TIME('22:15:07') > TIMESTAMP('1984-12-15 22:15:07')", "t_ts_t", true), $("TIMESTAMP('" + today + " 20:50:42') > TIME('10:20:30')", "ts_t_t", true), $("TIME('10:20:30') > TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false), @@ -559,22 +313,6 @@ public static Iterable compareLteTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $( - "TIMESTAMP('2020-09-16 10:20:30') <= DATETIME('2020-09-16 10:20:30')", - "ts_dt_t", - true), - $( - "DATETIME('1961-04-12 09:07:00') <= TIMESTAMP('1984-12-15 22:15:07')", - "dt_ts_t", - true), - $( - "TIMESTAMP('2020-09-16 10:20:30') <= DATETIME('1961-04-12 09:07:00')", - "ts_dt_f", - false), - $( - "DATETIME('2020-09-16 10:20:30') <= TIMESTAMP('1961-04-12 09:07:00')", - "dt_ts_f", - false), $("TIMESTAMP('2020-09-16 10:20:30') <= DATE('2077-04-12')", "ts_d_t", true), $("DATE('2020-09-16') <= TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 10:20:30') <= DATE('1961-04-12')", "ts_d_f", false), @@ -585,37 +323,6 @@ public static Iterable compareLteTimestampWithOtherTypes() { $("TIME('20:50:40') <= TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false))); } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") - public static Iterable compareLteDateTimeWithOtherTypes() { - var today = LocalDate.now().toString(); - return Arrays.asList( - $$( - $( - "DATETIME('2020-09-16 10:20:30') <= TIMESTAMP('2020-09-16 10:20:30')", - "dt_ts_t", - true), - $( - "TIMESTAMP('1961-04-12 09:07:00') <= DATETIME('1984-12-15 22:15:07')", - "ts_dt_t", - true), - $( - "DATETIME('3077-09-16 10:20:30') <= TIMESTAMP('2077-04-12 09:07:00')", - "dt_ts_f", - false), - $( - "TIMESTAMP('2020-09-16 10:20:30') <= DATETIME('1984-12-15 22:15:07')", - "ts_dt_f", - false), - $("DATETIME('2020-09-16 00:00:00') <= DATE('2020-09-16')", "dt_d_t", true), - $("DATE('1961-04-12') <= DATETIME('1984-12-15 22:15:07')", "d_dt_t", true), - $("DATETIME('2020-09-16 10:20:30') <= DATE('1984-04-12')", "dt_d_f", false), - $("DATE('2020-09-16') <= DATETIME('1961-04-12 09:07:00')", "d_dt_f", false), - $("DATETIME('" + today + " 10:20:30') <= TIME('10:20:30')", "dt_t_t", true), - $("TIME('09:07:00') <= DATETIME('3077-12-15 22:15:07')", "t_dt_t", true), - $("DATETIME('3077-09-16 10:20:30') <= TIME('19:07:00')", "dt_t_f", false), - $("TIME('20:40:50') <= DATETIME('" + today + " 10:20:30')", "t_dt_f", false))); - } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareLteDateWithOtherTypes() { return Arrays.asList( @@ -624,10 +331,6 @@ public static Iterable compareLteDateWithOtherTypes() { $("TIMESTAMP('1961-04-12 09:07:00') <= DATE('1984-12-15')", "ts_d_t", true), $("DATE('2020-09-16') <= TIMESTAMP('1961-04-12 09:07:00')", "d_ts_f", false), $("TIMESTAMP('2077-04-12 09:07:00') <= DATE('2020-09-16')", "ts_d_f", false), - $("DATE('2020-09-16') <= DATETIME('2020-09-16 00:00:00')", "d_dt_t", true), - $("DATETIME('1961-04-12 10:20:30') <= DATE('1984-11-15')", "dt_d_t", true), - $("DATE('2077-04-12') <= DATETIME('1984-12-15 22:15:07')", "d_dt_f", false), - $("DATETIME('2020-09-16 00:00:00') <= DATE('1984-03-22')", "dt_d_f", false), $("DATE('2020-09-16') <= TIME('09:07:00')", "d_t_t", true), $("TIME('09:07:00') <= DATE('3077-04-12')", "t_d_t", true), $("DATE('3077-04-12') <= TIME('00:00:00')", "d_t_f", false), @@ -639,10 +342,6 @@ public static Iterable compareLteTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $("TIME('10:20:30') <= DATETIME('" + today + " 10:20:30')", "t_dt_t", true), - $("DATETIME('" + today + " 09:07:00') <= TIME('10:20:30')", "dt_t_t", true), - $("TIME('09:07:00') <= DATETIME('1961-04-12 09:07:00')", "t_dt_f", false), - $("DATETIME('" + today + " 20:40:50') <= TIME('10:20:30')", "dt_t_f", false), $("TIME('10:20:30') <= TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), $("TIMESTAMP('1984-12-15 10:20:30') <= TIME('10:20:30')", "ts_t_t", true), $("TIME('22:15:07') <= TIMESTAMP('1984-12-15 22:15:07')", "t_ts_f", false), @@ -658,22 +357,6 @@ public static Iterable compareGteTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $( - "TIMESTAMP('2020-09-16 10:20:30') >= DATETIME('2020-09-16 10:20:30')", - "ts_dt_t", - true), - $( - "DATETIME('2020-09-16 10:20:30') >= TIMESTAMP('1961-04-12 09:07:00')", - "dt_ts_t", - true), - $( - "TIMESTAMP('2020-09-16 10:20:30') >= DATETIME('2061-04-12 09:07:00')", - "ts_dt_f", - false), - $( - "DATETIME('1961-04-12 09:07:00') >= TIMESTAMP('1984-12-15 09:07:00')", - "dt_ts_f", - false), $("TIMESTAMP('2020-09-16 10:20:30') >= DATE('1961-04-12')", "ts_d_t", true), $("DATE('2020-09-16') >= TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 10:20:30') >= DATE('2077-04-12')", "ts_d_f", false), @@ -684,37 +367,6 @@ public static Iterable compareGteTimestampWithOtherTypes() { $("TIME('09:07:00') >= TIMESTAMP('3077-12-15 22:15:07')", "t_ts_f", false))); } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") - public static Iterable compareGteDateTimeWithOtherTypes() { - var today = LocalDate.now().toString(); - return Arrays.asList( - $$( - $( - "DATETIME('2020-09-16 10:20:30') >= TIMESTAMP('2020-09-16 10:20:30')", - "dt_ts_t", - true), - $( - "TIMESTAMP('2020-09-16 10:20:30') >= DATETIME('1984-12-15 22:15:07')", - "ts_dt_t", - true), - $( - "DATETIME('2020-09-16 10:20:30') >= TIMESTAMP('2077-04-12 09:07:00')", - "dt_ts_f", - false), - $( - "TIMESTAMP('1961-04-12 00:00:00') >= DATETIME('1961-04-12 09:07:00')", - "ts_dt_f", - false), - $("DATETIME('2020-09-16 00:00:00') >= DATE('2020-09-16')", "dt_d_t", true), - $("DATE('2020-09-16') >= DATETIME('1961-04-12 09:07:00')", "d_dt_t", true), - $("DATETIME('1961-04-12 09:07:00') >= DATE('2020-09-16')", "dt_d_f", false), - $("DATE('1961-04-12') >= DATETIME('1984-12-15 22:15:07')", "d_dt_f", false), - $("DATETIME('" + today + " 10:20:30') >= TIME('10:20:30')", "dt_t_t", true), - $("TIME('20:40:50') >= DATETIME('" + today + " 10:20:30')", "t_dt_t", true), - $("DATETIME('1961-04-12 09:07:00') >= TIME('09:07:00')", "dt_t_f", false), - $("TIME('09:07:00') >= DATETIME('3077-12-15 22:15:07')", "t_dt_f", false))); - } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareGteDateWithOtherTypes() { return Arrays.asList( @@ -723,10 +375,6 @@ public static Iterable compareGteDateWithOtherTypes() { $("TIMESTAMP('2077-04-12 09:07:00') >= DATE('2020-09-16')", "ts_d_t", true), $("DATE('1961-04-12') >= TIMESTAMP('1961-04-12 09:07:00')", "d_ts_f", false), $("TIMESTAMP('1961-04-12 09:07:00') >= DATE('1984-12-15')", "ts_d_f", false), - $("DATE('2020-09-16') >= DATETIME('2020-09-16 00:00:00')", "d_dt_t", true), - $("DATETIME('2020-09-16 00:00:00') >= DATE('1984-03-22')", "dt_d_t", true), - $("DATE('1960-12-15') >= DATETIME('1961-04-12 09:07:00')", "d_dt_f", false), - $("DATETIME('1961-04-12 10:20:30') >= DATE('1984-11-15')", "dt_d_f", false), $("DATE('3077-04-12') >= TIME('00:00:00')", "d_t_t", true), $("TIME('00:00:00') >= DATE('2020-09-16')", "t_d_t", true), $("DATE('2020-09-16') >= TIME('09:07:00')", "d_t_f", false), @@ -738,10 +386,6 @@ public static Iterable compareGteTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $("TIME('10:20:30') >= DATETIME('" + today + " 10:20:30')", "t_dt_t", true), - $("DATETIME('" + today + " 20:40:50') >= TIME('10:20:30')", "dt_t_t", true), - $("TIME('09:07:00') >= DATETIME('3077-04-12 09:07:00')", "t_dt_f", false), - $("DATETIME('" + today + " 09:07:00') >= TIME('10:20:30')", "dt_t_f", false), $("TIME('10:20:30') >= TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), $("TIMESTAMP('" + today + " 20:50:42') >= TIME('10:20:30')", "ts_t_t", true), $("TIME('22:15:07') >= TIMESTAMP('3077-12-15 22:15:07')", "t_ts_f", false), diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeFunctionIT.java index 1df87a87b3..3ea6897087 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeFunctionIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeFunctionIT.java @@ -67,25 +67,15 @@ public void testAddDateWithDays() throws IOException { + " f = adddate(timestamp('2020-09-16 17:30:00'), 1)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-17 17:30:00")); - result = - executeQuery( - String.format( - "source=%s | eval " - + " f = adddate(DATETIME('2020-09-16 07:40:00'), 1)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); - verifySome(result.getJSONArray("datarows"), rows("2020-09-17 07:40:00")); - result = executeQuery( String.format( "source=%s | eval " + " f = adddate(TIME('07:40:00'), 0)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(LocalDate.now() + " 07:40:00")); } @@ -98,17 +88,7 @@ public void testAddDateWithInterval() throws IOException { + " f = adddate(timestamp('2020-09-16 17:30:00'), interval 1 day)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); - verifySome(result.getJSONArray("datarows"), rows("2020-09-17 17:30:00")); - - result = - executeQuery( - String.format( - "source=%s | eval " - + " f = adddate(DATETIME('2020-09-16 17:30:00'), interval 1 day)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-17 17:30:00")); result = @@ -118,7 +98,7 @@ public void testAddDateWithInterval() throws IOException { + " f = adddate(date('2020-09-16'), interval 1 day) " + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-17 00:00:00")); result = @@ -128,7 +108,7 @@ public void testAddDateWithInterval() throws IOException { + " f = adddate(date('2020-09-16'), interval 1 hour)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-16 01:00:00")); result = @@ -138,7 +118,7 @@ public void testAddDateWithInterval() throws IOException { + " f = adddate(TIME('07:40:00'), interval 1 day)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome( result.getJSONArray("datarows"), rows( @@ -155,7 +135,7 @@ public void testAddDateWithInterval() throws IOException { + " f = adddate(TIME('07:40:00'), interval 1 hour)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome( result.getJSONArray("datarows"), rows( @@ -173,7 +153,7 @@ public void testConvertTZ() throws IOException { "source=%s | eval f = convert_tz('2008-05-15 12:00:00','+00:00','+10:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-05-15 22:00:00")); result = @@ -182,7 +162,7 @@ public void testConvertTZ() throws IOException { "source=%s | eval f = convert_tz('2021-05-12 00:00:00','-00:00','+00:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2021-05-12 00:00:00")); result = @@ -191,7 +171,7 @@ public void testConvertTZ() throws IOException { "source=%s | eval f = convert_tz('2021-05-12 00:00:00','+10:00','+11:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2021-05-12 01:00:00")); result = @@ -200,7 +180,7 @@ public void testConvertTZ() throws IOException { "source=%s | eval f = convert_tz('2021-05-12 11:34:50','-08:00','+09:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2021-05-13 04:34:50")); result = @@ -209,7 +189,7 @@ public void testConvertTZ() throws IOException { "source=%s | eval f = convert_tz('2021-05-12 11:34:50','+09:00','+09:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2021-05-12 11:34:50")); result = @@ -218,7 +198,7 @@ public void testConvertTZ() throws IOException { "source=%s | eval f = convert_tz('2021-05-12 11:34:50','-12:00','+12:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2021-05-13 11:34:50")); result = @@ -227,7 +207,7 @@ public void testConvertTZ() throws IOException { "source=%s | eval f = convert_tz('2021-05-12 13:00:00','+09:30','+05:45') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2021-05-12 09:15:00")); result = @@ -236,7 +216,7 @@ public void testConvertTZ() throws IOException { "source=%s | eval f = convert_tz('2021-05-30 11:34:50','-17:00','+08:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); result = @@ -245,7 +225,7 @@ public void testConvertTZ() throws IOException { "source=%s | eval f = convert_tz('2021-05-12 11:34:50','-12:00','+15:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } @@ -258,17 +238,7 @@ public void testDateAdd() throws IOException { + " f = date_add(timestamp('2020-09-16 17:30:00'), interval 1 day)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); - verifySome(result.getJSONArray("datarows"), rows("2020-09-17 17:30:00")); - - result = - executeQuery( - String.format( - "source=%s | eval " - + " f = date_add(DATETIME('2020-09-16 17:30:00'), interval 1 day)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-17 17:30:00")); result = @@ -278,7 +248,7 @@ public void testDateAdd() throws IOException { + " f = date_add(date('2020-09-16'), interval 1 day)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-17 00:00:00")); result = @@ -288,7 +258,7 @@ public void testDateAdd() throws IOException { + " f = date_add(date('2020-09-16'), interval 1 hour)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-16 01:00:00")); result = @@ -298,7 +268,7 @@ public void testDateAdd() throws IOException { + " f = date_add(TIME('07:40:00'), interval 1 day)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome( result.getJSONArray("datarows"), rows( @@ -315,7 +285,7 @@ public void testDateAdd() throws IOException { + " f = date_add(TIME('07:40:00'), interval 1 hour)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome( result.getJSONArray("datarows"), rows( @@ -329,7 +299,7 @@ public void testDateAdd() throws IOException { String.format( "source=%s | eval " + " f = DATE_ADD(birthdate, INTERVAL 1 YEAR)" + " | fields f", TEST_INDEX_BANK)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifyDataRows( result, rows("2018-10-23 00:00:00"), @@ -349,7 +319,7 @@ public void testDateTime() throws IOException { "source=%s | eval f = DATETIME('2008-12-25 05:30:00+00:00', 'America/Los_Angeles')" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-12-24 21:30:00")); result = @@ -357,7 +327,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-12-25 05:30:00+00:00', '+01:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-12-25 06:30:00")); result = @@ -365,7 +335,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-12-25 05:30:00-05:00', '+05:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-12-25 15:30:00")); result = @@ -373,7 +343,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2004-02-28 23:00:00-10:00', '+10:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2004-02-29 19:00:00")); result = @@ -381,7 +351,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2003-02-28 23:00:00-10:00', '+10:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2003-03-01 19:00:00")); result = @@ -389,7 +359,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-12-25 05:30:00+00:00', '+14:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-12-25 19:30:00")); result = @@ -397,7 +367,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00+10:00', '-10:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2007-12-31 06:00:00")); result = @@ -405,7 +375,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00+10:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-01-01 02:00:00")); result = @@ -413,7 +383,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-01-01 02:00:00")); result = @@ -421,7 +391,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00+15:00', '-12:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); result = @@ -429,7 +399,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00+10:00', '-14:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); result = @@ -437,7 +407,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00', '-14:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } @@ -450,17 +420,7 @@ public void testDateSub() throws IOException { + " f = date_sub(timestamp('2020-09-16 17:30:00'), interval 1 day)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); - verifySome(result.getJSONArray("datarows"), rows("2020-09-15 17:30:00")); - - result = - executeQuery( - String.format( - "source=%s | eval " - + " f = date_sub(DATETIME('2020-09-16 17:30:00'), interval 1 day)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-15 17:30:00")); result = @@ -470,7 +430,7 @@ public void testDateSub() throws IOException { + " f = date_sub(date('2020-09-16'), interval 1 day)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-15 00:00:00")); result = @@ -480,7 +440,7 @@ public void testDateSub() throws IOException { + " f = date_sub(date('2020-09-16'), interval 1 hour)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-15 23:00:00")); result = @@ -490,7 +450,7 @@ public void testDateSub() throws IOException { + " f = date_sub(TIME('07:40:00'), interval 1 day)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome( result.getJSONArray("datarows"), rows( @@ -507,7 +467,7 @@ public void testDateSub() throws IOException { + " f = date_sub(TIME('07:40:00'), interval 1 hour)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome( result.getJSONArray("datarows"), rows( @@ -1051,7 +1011,7 @@ public void testSubDateDays() throws IOException { + " f = subdate(timestamp('2020-09-16 17:30:00'), 1)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-15 17:30:00")); result = @@ -1067,7 +1027,7 @@ public void testSubDateDays() throws IOException { String.format( "source=%s | eval " + " f = subdate(TIME('07:40:00'), 0)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(LocalDate.now() + " 07:40:00")); } @@ -1080,17 +1040,7 @@ public void testSubDateInterval() throws IOException { + " f = subdate(timestamp('2020-09-16 17:30:00'), interval 1 day)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); - verifySome(result.getJSONArray("datarows"), rows("2020-09-15 17:30:00")); - - result = - executeQuery( - String.format( - "source=%s | eval " - + " f = subdate(DATETIME('2020-09-16 17:30:00'), interval 1 day)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-15 17:30:00")); result = @@ -1100,7 +1050,7 @@ public void testSubDateInterval() throws IOException { + " f = subdate(date('2020-09-16'), interval 1 day) " + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-15 00:00:00")); result = @@ -1110,7 +1060,7 @@ public void testSubDateInterval() throws IOException { + " f = subdate(date('2020-09-16'), interval 1 hour)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-15 23:00:00")); result = @@ -1120,7 +1070,7 @@ public void testSubDateInterval() throws IOException { + " f = subdate(TIME('07:40:00'), interval 1 day)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome( result.getJSONArray("datarows"), rows( @@ -1137,7 +1087,7 @@ public void testSubDateInterval() throws IOException { + " f = subdate(TIME('07:40:00'), interval 1 hour)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome( result.getJSONArray("datarows"), rows( @@ -1316,17 +1266,17 @@ public void testAddTime() throws IOException { + " DATE('2004-01-01')), `'2004-01-01' + '23:59:59'` =" + " ADDTIME(DATE('2004-01-01'), TIME('23:59:59')), `'10:20:30' + '00:05:42'` =" + " ADDTIME(TIME('10:20:30'), TIME('00:05:42')), `'15:42:13' + '09:07:00'` =" - + " ADDTIME(TIMESTAMP('1999-12-31 15:42:13'), DATETIME('1961-04-12 09:07:00'))" + + " ADDTIME(TIMESTAMP('1999-12-31 15:42:13'), TIMESTAMP('1961-04-12 09:07:00'))" + " | fields `'2008-12-12' + 0`, `'23:59:59' + 0`, `'2004-01-01' + '23:59:59'`," + " `'10:20:30' + '00:05:42'`, `'15:42:13' + '09:07:00'`", TEST_INDEX_DATE)); verifySchema( result, - schema("'2008-12-12' + 0", null, "datetime"), + schema("'2008-12-12' + 0", null, "timestamp"), schema("'23:59:59' + 0", null, "time"), - schema("'2004-01-01' + '23:59:59'", null, "datetime"), + schema("'2004-01-01' + '23:59:59'", null, "timestamp"), schema("'10:20:30' + '00:05:42'", null, "time"), - schema("'15:42:13' + '09:07:00'", null, "datetime")); + schema("'15:42:13' + '09:07:00'", null, "timestamp")); verifySome( result.getJSONArray("datarows"), rows( @@ -1347,17 +1297,17 @@ public void testSubTime() throws IOException { + " DATE('2004-01-01')), `'2004-01-01' - '23:59:59'` =" + " SUBTIME(DATE('2004-01-01'), TIME('23:59:59')), `'10:20:30' - '00:05:42'` =" + " SUBTIME(TIME('10:20:30'), TIME('00:05:42')), `'15:42:13' - '09:07:00'` =" - + " SUBTIME(TIMESTAMP('1999-12-31 15:42:13'), DATETIME('1961-04-12 09:07:00'))" + + " SUBTIME(TIMESTAMP('1999-12-31 15:42:13'), TIMESTAMP('1961-04-12 09:07:00'))" + " | fields `'2008-12-12' - 0`, `'23:59:59' - 0`, `'2004-01-01' - '23:59:59'`," + " `'10:20:30' - '00:05:42'`, `'15:42:13' - '09:07:00'`", TEST_INDEX_DATE)); verifySchema( result, - schema("'2008-12-12' - 0", null, "datetime"), + schema("'2008-12-12' - 0", null, "timestamp"), schema("'23:59:59' - 0", null, "time"), - schema("'2004-01-01' - '23:59:59'", null, "datetime"), + schema("'2004-01-01' - '23:59:59'", null, "timestamp"), schema("'10:20:30' - '00:05:42'", null, "time"), - schema("'15:42:13' - '09:07:00'", null, "datetime")); + schema("'15:42:13' - '09:07:00'", null, "timestamp")); verifySome( result.getJSONArray("datarows"), rows( @@ -1378,8 +1328,8 @@ public void testFromUnixTime() throws IOException { TEST_INDEX_DATE)); verifySchema( result, - schema("f1", null, "datetime"), - schema("f2", null, "datetime"), + schema("f1", null, "timestamp"), + schema("f2", null, "timestamp"), schema("f3", null, "string")); verifySome( result.getJSONArray("datarows"), @@ -1427,6 +1377,7 @@ public void testPeriodDiff() throws IOException { verifySome(result.getJSONArray("datarows"), rows(11, -25)); } + @Test public void testDateDiff() throws IOException { var result = executeQuery( @@ -1435,7 +1386,7 @@ public void testDateDiff() throws IOException { + " 00:00:00'), TIMESTAMP('2000-01-01 23:59:59')), `'2001-02-01' -" + " '2004-01-01'` = DATEDIFF(DATE('2001-02-01'), TIMESTAMP('2004-01-01" + " 00:00:00')), `'2004-01-01' - '2002-02-01'` = DATEDIFF(TIMESTAMP('2004-01-01" - + " 00:00:00'), DATETIME('2002-02-01 14:25:30')), `today - today` =" + + " 00:00:00'), TIMESTAMP('2002-02-01 14:25:30')), `today - today` =" + " DATEDIFF(TIME('23:59:59'), TIME('00:00:00')) | fields `'2000-01-02' -" + " '2000-01-01'`, `'2001-02-01' - '2004-01-01'`, `'2004-01-01' -" + " '2002-02-01'`, `today - today`", @@ -1519,7 +1470,7 @@ public void testToSeconds() throws IOException { String.format( "source=%s | eval f1 = to_seconds(date('2008-10-07')) | " + "eval f2 = to_seconds('2020-09-16 07:40:00') | " - + "eval f3 = to_seconds(DATETIME('2020-09-16 07:40:00')) | fields f1, f2, f3", + + "eval f3 = to_seconds(TIMESTAMP('2020-09-16 07:40:00')) | fields f1, f2, f3", TEST_INDEX_DATE)); verifySchema( result, schema("f1", null, "long"), schema("f2", null, "long"), schema("f3", null, "long")); @@ -1533,7 +1484,7 @@ public void testStrToDate() throws IOException { String.format( "source=%s | eval f = str_to_date('01,5,2013', '%s') | fields f", TEST_INDEX_DATE, "%d,%m,%Y")); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2013-05-01 00:00:00")); } @@ -1544,7 +1495,7 @@ public void testTimeStampAdd() throws IOException { String.format( "source=%s | eval f = timestampadd(YEAR, 15, '2001-03-06 00:00:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2016-03-06 00:00:00")); } @@ -1556,7 +1507,7 @@ public void testTimestampDiff() throws IOException { "source=%s | eval f = timestampdiff(YEAR, '1997-01-01 00:00:00', '2001-03-06" + " 00:00:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(4)); } diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeImplementationIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeImplementationIT.java index dd86470a39..f9dc7d8027 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeImplementationIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeImplementationIT.java @@ -30,7 +30,7 @@ public void inRangeZeroToStringTZ() throws IOException { "source=%s | eval f = DATETIME('2008-12-25 05:30:00+00:00', 'America/Los_Angeles')" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-12-24 21:30:00")); } @@ -41,7 +41,7 @@ public void inRangeZeroToPositive() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-12-25 05:30:00+00:00', '+01:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-12-25 06:30:00")); } @@ -52,7 +52,7 @@ public void inRangeNegativeToPositive() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-12-25 05:30:00-05:00', '+05:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-12-25 15:30:00")); } @@ -63,7 +63,7 @@ public void inRangeTwentyHourOffset() throws IOException { String.format( "source=%s | eval f = DATETIME('2004-02-28 23:00:00-10:00', '+10:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2004-02-29 19:00:00")); } @@ -74,7 +74,7 @@ public void inRangeYearChange() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00+10:00', '-10:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2007-12-31 06:00:00")); } @@ -85,7 +85,7 @@ public void inRangeZeroToMax() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-12-25 05:30:00+00:00', '+14:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-12-25 19:30:00")); } @@ -96,7 +96,7 @@ public void inRangeNoToTZ() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00+10:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-01-01 02:00:00")); } @@ -107,7 +107,7 @@ public void inRangeNoTZ() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-01-01 02:00:00")); } @@ -118,7 +118,7 @@ public void nullField3Over() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00+15:00', '-12:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } @@ -129,7 +129,7 @@ public void nullField2Under() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00+10:00', '-14:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } @@ -140,7 +140,7 @@ public void nullTField3Over() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00', '+15:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } @@ -151,7 +151,7 @@ public void nullDateTimeInvalidDateValueFebruary() throws IOException { String.format( "source=%s | eval f = DATETIME('2021-02-30 10:00:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } @@ -162,7 +162,7 @@ public void nullDateTimeInvalidDateValueApril() throws IOException { String.format( "source=%s | eval f = DATETIME('2021-04-31 10:00:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } @@ -173,7 +173,7 @@ public void nullDateTimeInvalidDateValueMonth() throws IOException { String.format( "source=%s | eval f = DATETIME('2021-13-03 10:00:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } } diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/SystemFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/SystemFunctionIT.java index 1c23935f81..c1356ce838 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/SystemFunctionIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/SystemFunctionIT.java @@ -45,11 +45,10 @@ public void typeof_sql_types() throws IOException { "source=%s | eval " + "`timestamp` = typeof(CAST('1961-04-12 09:07:00' AS TIMESTAMP))," + "`time` = typeof(CAST('09:07:00' AS TIME))," - + "`date` = typeof(CAST('1961-04-12' AS DATE))," - + "`datetime` = typeof(DATETIME('1961-04-12 09:07:00'))" - + " | fields `timestamp`, `time`, `date`, `datetime`", + + "`date` = typeof(CAST('1961-04-12' AS DATE))" + + " | fields `timestamp`, `time`, `date`", TEST_INDEX_DATATYPE_NUMERIC)); - verifyDataRows(response, rows("TIMESTAMP", "TIME", "DATE", "DATETIME")); + verifyDataRows(response, rows("TIMESTAMP", "TIME", "DATE")); } @Test diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/AggregationIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/AggregationIT.java index 339cd56370..3f71499f97 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/AggregationIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/AggregationIT.java @@ -287,13 +287,14 @@ public void testPushDownAggregationOnNullDateTimeValuesReturnsNull() throws IOEx var response = executeQuery( String.format( - "SELECT " + "max(datetime(NULL)), min(datetime(NULL)), avg(datetime(NULL)) from %s", + "SELECT " + + "max(timestamp(NULL)), min(timestamp(NULL)), avg(timestamp(NULL)) from %s", TEST_INDEX_CALCS)); verifySchema( response, - schema("max(datetime(NULL))", null, "datetime"), - schema("min(datetime(NULL))", null, "datetime"), - schema("avg(datetime(NULL))", null, "datetime")); + schema("max(timestamp(NULL))", null, "timestamp"), + schema("min(timestamp(NULL))", null, "timestamp"), + schema("avg(timestamp(NULL))", null, "timestamp")); verifyDataRows(response, rows(null, null, null)); } @@ -480,8 +481,8 @@ public void testMinDateTimePushedDown() throws IOException { var response = executeQuery( String.format( - "SELECT min(datetime(CAST(time0 AS STRING)))" + " from %s", TEST_INDEX_CALCS)); - verifySchema(response, schema("min(datetime(CAST(time0 AS STRING)))", null, "datetime")); + "SELECT min(timestamp(CAST(time0 AS STRING)))" + " from %s", TEST_INDEX_CALCS)); + verifySchema(response, schema("min(timestamp(CAST(time0 AS STRING)))", null, "timestamp")); verifyDataRows(response, rows("1899-12-30 21:07:32")); } @@ -490,8 +491,8 @@ public void testMaxDateTimePushedDown() throws IOException { var response = executeQuery( String.format( - "SELECT max(datetime(CAST(time0 AS STRING)))" + " from %s", TEST_INDEX_CALCS)); - verifySchema(response, schema("max(datetime(CAST(time0 AS STRING)))", null, "datetime")); + "SELECT max(timestamp(CAST(time0 AS STRING)))" + " from %s", TEST_INDEX_CALCS)); + verifySchema(response, schema("max(timestamp(CAST(time0 AS STRING)))", null, "timestamp")); verifyDataRows(response, rows("1900-01-01 20:36:00")); } @@ -500,8 +501,8 @@ public void testAvgDateTimePushedDown() throws IOException { var response = executeQuery( String.format( - "SELECT avg(datetime(CAST(time0 AS STRING)))" + " from %s", TEST_INDEX_CALCS)); - verifySchema(response, schema("avg(datetime(CAST(time0 AS STRING)))", null, "datetime")); + "SELECT avg(timestamp(CAST(time0 AS STRING)))" + " from %s", TEST_INDEX_CALCS)); + verifySchema(response, schema("avg(timestamp(CAST(time0 AS STRING)))", null, "timestamp")); verifyDataRows(response, rows("1900-01-01 03:35:00.236")); } @@ -591,13 +592,15 @@ public void testMinDateTimeInMemory() throws IOException { var response = executeQuery( String.format( - "SELECT min(datetime(CAST(time0 AS STRING)))" + "SELECT min(timestamp(CAST(time0 AS STRING)))" + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); verifySchema( response, schema( - "min(datetime(CAST(time0 AS STRING))) OVER(PARTITION BY datetime1)", null, "datetime")); + "min(timestamp(CAST(time0 AS STRING))) OVER(PARTITION BY datetime1)", + null, + "timestamp")); verifySome(response.getJSONArray("datarows"), rows("1899-12-30 21:07:32")); } @@ -606,13 +609,15 @@ public void testMaxDateTimeInMemory() throws IOException { var response = executeQuery( String.format( - "SELECT max(datetime(CAST(time0 AS STRING)))" + "SELECT max(timestamp(CAST(time0 AS STRING)))" + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); verifySchema( response, schema( - "max(datetime(CAST(time0 AS STRING))) OVER(PARTITION BY datetime1)", null, "datetime")); + "max(timestamp(CAST(time0 AS STRING))) OVER(PARTITION BY datetime1)", + null, + "timestamp")); verifySome(response.getJSONArray("datarows"), rows("1900-01-01 20:36:00")); } @@ -621,13 +626,15 @@ public void testAvgDateTimeInMemory() throws IOException { var response = executeQuery( String.format( - "SELECT avg(datetime(CAST(time0 AS STRING)))" + "SELECT avg(timestamp(CAST(time0 AS STRING)))" + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); verifySchema( response, schema( - "avg(datetime(CAST(time0 AS STRING))) OVER(PARTITION BY datetime1)", null, "datetime")); + "avg(timestamp(CAST(time0 AS STRING))) OVER(PARTITION BY datetime1)", + null, + "timestamp")); verifySome(response.getJSONArray("datarows"), rows("1900-01-01 03:35:00.236")); } diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/ConvertTZFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/ConvertTZFunctionIT.java index 76600b6561..776c4de290 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/ConvertTZFunctionIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/ConvertTZFunctionIT.java @@ -26,7 +26,7 @@ public void init() throws Exception { public void inRangeZeroToPositive() throws IOException { var result = executeJdbcRequest("SELECT convert_tz('2008-05-15 12:00:00','+00:00','+10:00')"); verifySchema( - result, schema("convert_tz('2008-05-15 12:00:00','+00:00','+10:00')", null, "datetime")); + result, schema("convert_tz('2008-05-15 12:00:00','+00:00','+10:00')", null, "timestamp")); verifyDataRows(result, rows("2008-05-15 22:00:00")); } @@ -34,7 +34,7 @@ public void inRangeZeroToPositive() throws IOException { public void inRangeNegativeZeroToPositiveZero() throws IOException { var result = executeJdbcRequest("SELECT convert_tz('2021-05-12 00:00:00','-00:00','+00:00')"); verifySchema( - result, schema("convert_tz('2021-05-12 00:00:00','-00:00','+00:00')", null, "datetime")); + result, schema("convert_tz('2021-05-12 00:00:00','-00:00','+00:00')", null, "timestamp")); verifyDataRows(result, rows("2021-05-12 00:00:00")); } @@ -42,7 +42,7 @@ public void inRangeNegativeZeroToPositiveZero() throws IOException { public void inRangePositiveToPositive() throws IOException { var result = executeJdbcRequest("SELECT convert_tz('2021-05-12 00:00:00','+10:00','+11:00')"); verifySchema( - result, schema("convert_tz('2021-05-12 00:00:00','+10:00','+11:00')", null, "datetime")); + result, schema("convert_tz('2021-05-12 00:00:00','+10:00','+11:00')", null, "timestamp")); verifyDataRows(result, rows("2021-05-12 01:00:00")); } @@ -50,7 +50,7 @@ public void inRangePositiveToPositive() throws IOException { public void inRangeNegativeToPositive() throws IOException { var result = executeJdbcRequest("SELECT convert_tz('2021-05-12 11:34:50','-08:00','+09:00')"); verifySchema( - result, schema("convert_tz('2021-05-12 11:34:50','-08:00','+09:00')", null, "datetime")); + result, schema("convert_tz('2021-05-12 11:34:50','-08:00','+09:00')", null, "timestamp")); verifyDataRows(result, rows("2021-05-13 04:34:50")); } @@ -58,7 +58,7 @@ public void inRangeNegativeToPositive() throws IOException { public void inRangeSameTimeZone() throws IOException { var result = executeJdbcRequest("SELECT convert_tz('2021-05-12 11:34:50','+09:00','+09:00')"); verifySchema( - result, schema("convert_tz('2021-05-12 11:34:50','+09:00','+09:00')", null, "datetime")); + result, schema("convert_tz('2021-05-12 11:34:50','+09:00','+09:00')", null, "timestamp")); verifyDataRows(result, rows("2021-05-12 11:34:50")); } @@ -66,7 +66,7 @@ public void inRangeSameTimeZone() throws IOException { public void inRangeTwentyFourHourTimeOffset() throws IOException { var result = executeJdbcRequest("SELECT convert_tz('2021-05-12 11:34:50','-12:00','+12:00')"); verifySchema( - result, schema("convert_tz('2021-05-12 11:34:50','-12:00','+12:00')", null, "datetime")); + result, schema("convert_tz('2021-05-12 11:34:50','-12:00','+12:00')", null, "timestamp")); verifyDataRows(result, rows("2021-05-13 11:34:50")); } @@ -74,7 +74,7 @@ public void inRangeTwentyFourHourTimeOffset() throws IOException { public void inRangeFifteenMinuteTimeZones() throws IOException { var result = executeJdbcRequest("SELECT convert_tz('2021-05-12 13:00:00','+09:30','+05:45')"); verifySchema( - result, schema("convert_tz('2021-05-12 13:00:00','+09:30','+05:45')", null, "datetime")); + result, schema("convert_tz('2021-05-12 13:00:00','+09:30','+05:45')", null, "timestamp")); verifyDataRows(result, rows("2021-05-12 09:15:00")); } @@ -82,7 +82,7 @@ public void inRangeFifteenMinuteTimeZones() throws IOException { public void inRangeRandomTimes() throws IOException { var result = executeJdbcRequest("SELECT convert_tz('2021-05-12 13:00:00','+09:31','+05:11')"); verifySchema( - result, schema("convert_tz('2021-05-12 13:00:00','+09:31','+05:11')", null, "datetime")); + result, schema("convert_tz('2021-05-12 13:00:00','+09:31','+05:11')", null, "timestamp")); verifyDataRows(result, rows("2021-05-12 08:40:00")); } @@ -90,7 +90,7 @@ public void inRangeRandomTimes() throws IOException { public void nullField2Under() throws IOException { var result = executeJdbcRequest("SELECT convert_tz('2021-05-30 11:34:50','-14:00','+08:00')"); verifySchema( - result, schema("convert_tz('2021-05-30 11:34:50','-14:00','+08:00')", null, "datetime")); + result, schema("convert_tz('2021-05-30 11:34:50','-14:00','+08:00')", null, "timestamp")); verifyDataRows(result, rows(new Object[] {null})); } @@ -98,7 +98,7 @@ public void nullField2Under() throws IOException { public void nullField3Over() throws IOException { var result = executeJdbcRequest("SELECT convert_tz('2021-05-12 11:34:50','-12:00','+14:01')"); verifySchema( - result, schema("convert_tz('2021-05-12 11:34:50','-12:00','+14:01')", null, "datetime")); + result, schema("convert_tz('2021-05-12 11:34:50','-12:00','+14:01')", null, "timestamp")); verifyDataRows(result, rows(new Object[] {null})); } @@ -106,7 +106,7 @@ public void nullField3Over() throws IOException { public void inRangeMinOnPoint() throws IOException { var result = executeJdbcRequest("SELECT convert_tz('2021-05-12 15:00:00','-13:59','-13:59')"); verifySchema( - result, schema("convert_tz('2021-05-12 15:00:00','-13:59','-13:59')", null, "datetime")); + result, schema("convert_tz('2021-05-12 15:00:00','-13:59','-13:59')", null, "timestamp")); verifyDataRows(result, rows("2021-05-12 15:00:00")); } @@ -118,7 +118,7 @@ public void inRangeMinOnPoint() throws IOException { public void nullField3InvalidInput() throws IOException { var result = executeJdbcRequest("SELECT convert_tz('2021-05-12 11:34:50','+10:0','+14:01')"); verifySchema( - result, schema("convert_tz('2021-05-12 11:34:50','+10:0','+14:01')", null, "datetime")); + result, schema("convert_tz('2021-05-12 11:34:50','+10:0','+14:01')", null, "timestamp")); verifyDataRows(result, rows(new Object[] {null})); } @@ -126,16 +126,16 @@ public void nullField3InvalidInput() throws IOException { public void nullField2InvalidInput() throws IOException { var result = executeJdbcRequest("SELECT convert_tz('2021-05-12 11:34:50','+14:01','****')"); verifySchema( - result, schema("convert_tz('2021-05-12 11:34:50','+14:01','****')", null, "datetime")); + result, schema("convert_tz('2021-05-12 11:34:50','+14:01','****')", null, "timestamp")); verifyDataRows(result, rows(new Object[] {null})); } - // Invalid input in the datetime field of CONVERT_TZ results in a null field. It is any input + // Invalid input in the timestamp field of CONVERT_TZ results in a null field. It is any input // which is not of the format `yyyy-MM-dd HH:mm:ss` @Test - public void nullDateTimeInvalidInput() throws IOException { + public void nulltimestampInvalidInput() throws IOException { var result = executeJdbcRequest("SELECT convert_tz('2021----','+00:00','+00:00')"); - verifySchema(result, schema("convert_tz('2021----','+00:00','+00:00')", null, "datetime")); + verifySchema(result, schema("convert_tz('2021----','+00:00','+00:00')", null, "timestamp")); verifyDataRows(result, rows(new Object[] {null})); } @@ -143,7 +143,7 @@ public void nullDateTimeInvalidInput() throws IOException { public void nullDateTimeInvalidDateValueFebruary() throws IOException { var result = executeJdbcRequest("SELECT convert_tz('2021-02-30 10:00:00','+00:00','+00:00')"); verifySchema( - result, schema("convert_tz('2021-02-30 10:00:00','+00:00','+00:00')", null, "datetime")); + result, schema("convert_tz('2021-02-30 10:00:00','+00:00','+00:00')", null, "timestamp")); verifyDataRows(result, rows(new Object[] {null})); } @@ -151,7 +151,7 @@ public void nullDateTimeInvalidDateValueFebruary() throws IOException { public void nullDateTimeInvalidDateValueApril() throws IOException { var result = executeJdbcRequest("SELECT convert_tz('2021-04-31 10:00:00','+00:00','+00:00')"); verifySchema( - result, schema("convert_tz('2021-04-31 10:00:00','+00:00','+00:00')", null, "datetime")); + result, schema("convert_tz('2021-04-31 10:00:00','+00:00','+00:00')", null, "timestamp")); verifyDataRows(result, rows(new Object[] {null})); } @@ -159,7 +159,7 @@ public void nullDateTimeInvalidDateValueApril() throws IOException { public void nullDateTimeInvalidDateValueMonth() throws IOException { var result = executeJdbcRequest("SELECT convert_tz('2021-13-03 10:00:00','+00:00','+00:00')"); verifySchema( - result, schema("convert_tz('2021-13-03 10:00:00','+00:00','+00:00')", null, "datetime")); + result, schema("convert_tz('2021-13-03 10:00:00','+00:00','+00:00')", null, "timestamp")); verifyDataRows(result, rows(new Object[] {null})); } } diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeComparisonIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeComparisonIT.java index 432daef82f..af3d81e374 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeComparisonIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeComparisonIT.java @@ -105,32 +105,6 @@ public static Iterable compareTwoTimes() { $("TIME('19:16:03') <= TIME('04:12:42')", "lte3", false))); } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") - public static Iterable compareTwoDateTimes() { - return Arrays.asList( - $$( - $("DATETIME('2020-09-16 10:20:30') = DATETIME('2020-09-16 10:20:30')", "eq1", true), - $("DATETIME('2020-09-16 10:20:30') = DATETIME('1961-04-12 09:07:00')", "eq2", false), - $("DATETIME('2020-09-16 10:20:30') != DATETIME('1984-12-15 22:15:07')", "neq1", true), - $("DATETIME('1984-12-15 22:15:08') != DATETIME('1984-12-15 22:15:07')", "neq2", true), - $("DATETIME('1961-04-12 09:07:00') != DATETIME('1961-04-12 09:07:00')", "neq3", false), - $("DATETIME('1984-12-15 22:15:07') > DATETIME('1961-04-12 22:15:07')", "gt1", true), - $("DATETIME('1984-12-15 22:15:07') > DATETIME('1984-12-15 22:15:06')", "gt2", true), - $("DATETIME('1984-12-15 22:15:07') > DATETIME('2020-09-16 10:20:30')", "gt3", false), - $("DATETIME('1961-04-12 09:07:00') < DATETIME('1984-12-15 09:07:00')", "lt1", true), - $("DATETIME('1984-12-15 22:15:07') < DATETIME('1984-12-15 22:15:08')", "lt2", true), - $("DATETIME('1984-12-15 22:15:07') < DATETIME('1961-04-12 09:07:00')", "lt3", false), - $("DATETIME('1984-12-15 22:15:07') >= DATETIME('1961-04-12 09:07:00')", "gte1", true), - $("DATETIME('1984-12-15 22:15:07') >= DATETIME('1984-12-15 22:15:07')", "gte2", true), - $("DATETIME('1984-12-15 22:15:07') >= DATETIME('2020-09-16 10:20:30')", "gte3", false), - $("DATETIME('1961-04-12 09:07:00') <= DATETIME('1984-12-15 22:15:07')", "lte1", true), - $("DATETIME('1961-04-12 09:07:00') <= DATETIME('1961-04-12 09:07:00')", "lte2", true), - $( - "DATETIME('2020-09-16 10:20:30') <= DATETIME('1961-04-12 09:07:00')", - "lte3", - false))); - } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareTwoTimestamps() { return Arrays.asList( @@ -168,22 +142,6 @@ public static Iterable compareEqTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $( - "TIMESTAMP('2020-09-16 10:20:30') = DATETIME('2020-09-16 10:20:30')", - "ts_dt_t", - true), - $( - "DATETIME('2020-09-16 10:20:30') = TIMESTAMP('2020-09-16 10:20:30')", - "dt_ts_t", - true), - $( - "TIMESTAMP('2020-09-16 10:20:30') = DATETIME('1961-04-12 09:07:00')", - "ts_dt_f", - false), - $( - "DATETIME('1961-04-12 09:07:00') = TIMESTAMP('1984-12-15 22:15:07')", - "dt_ts_f", - false), $("TIMESTAMP('2020-09-16 00:00:00') = DATE('2020-09-16')", "ts_d_t", true), $("DATE('2020-09-16') = TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 10:20:30') = DATE('1961-04-12')", "ts_d_f", false), @@ -194,37 +152,6 @@ public static Iterable compareEqTimestampWithOtherTypes() { $("TIME('09:07:00') = TIMESTAMP('1984-12-15 22:15:07')", "t_ts_f", false))); } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") - public static Iterable compareEqDateTimeWithOtherTypes() { - var today = LocalDate.now().toString(); - return Arrays.asList( - $$( - $( - "DATETIME('2020-09-16 10:20:30') = TIMESTAMP('2020-09-16 10:20:30')", - "dt_ts_t", - true), - $( - "TIMESTAMP('2020-09-16 10:20:30') = DATETIME('2020-09-16 10:20:30')", - "ts_dt_t", - true), - $( - "DATETIME('2020-09-16 10:20:30') = TIMESTAMP('1961-04-12 09:07:00')", - "dt_ts_f", - false), - $( - "TIMESTAMP('1961-04-12 09:07:00') = DATETIME('1984-12-15 22:15:07')", - "ts_dt_f", - false), - $("DATETIME('2020-09-16 00:00:00') = DATE('2020-09-16')", "dt_d_t", true), - $("DATE('2020-09-16') = DATETIME('2020-09-16 00:00:00')", "d_dt_t", true), - $("DATETIME('2020-09-16 10:20:30') = DATE('1961-04-12')", "dt_d_f", false), - $("DATE('1961-04-12') = DATETIME('1984-12-15 22:15:07')", "d_dt_f", false), - $("DATETIME('" + today + " 10:20:30') = TIME('10:20:30')", "dt_t_t", true), - $("TIME('10:20:30') = DATETIME('" + today + " 10:20:30')", "t_dt_t", true), - $("DATETIME('2020-09-16 10:20:30') = TIME('09:07:00')", "dt_t_f", false), - $("TIME('09:07:00') = DATETIME('1984-12-15 22:15:07')", "t_dt_f", false))); - } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareEqDateWithOtherTypes() { var today = LocalDate.now().toString(); @@ -234,10 +161,6 @@ public static Iterable compareEqDateWithOtherTypes() { $("TIMESTAMP('2020-09-16 00:00:00') = DATE('2020-09-16')", "ts_d_t", true), $("DATE('2020-09-16') = TIMESTAMP('1961-04-12 09:07:00')", "d_ts_f", false), $("TIMESTAMP('1984-12-15 09:07:00') = DATE('1984-12-15')", "ts_d_f", false), - $("DATE('2020-09-16') = DATETIME('2020-09-16 00:00:00')", "d_dt_t", true), - $("DATETIME('2020-09-16 00:00:00') = DATE('2020-09-16')", "dt_d_t", true), - $("DATE('1961-04-12') = DATETIME('1984-12-15 22:15:07')", "d_dt_f", false), - $("DATETIME('1961-04-12 10:20:30') = DATE('1961-04-12')", "dt_d_f", false), $("DATE('" + today + "') = TIME('00:00:00')", "d_t_t", true), $("TIME('00:00:00') = DATE('" + today + "')", "t_d_t", true), $("DATE('2020-09-16') = TIME('09:07:00')", "d_t_f", false), @@ -249,10 +172,6 @@ public static Iterable compareEqTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $("TIME('10:20:30') = DATETIME('" + today + " 10:20:30')", "t_dt_t", true), - $("DATETIME('" + today + " 10:20:30') = TIME('10:20:30')", "dt_t_t", true), - $("TIME('09:07:00') = DATETIME('1961-04-12 09:07:00')", "t_dt_f", false), - $("DATETIME('" + today + " 09:07:00') = TIME('10:20:30')", "dt_t_f", false), $("TIME('10:20:30') = TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), $("TIMESTAMP('" + today + " 10:20:30') = TIME('10:20:30')", "ts_t_t", true), $("TIME('22:15:07') = TIMESTAMP('1984-12-15 22:15:07')", "t_ts_f", false), @@ -268,22 +187,6 @@ public static Iterable compareNeqTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $( - "TIMESTAMP('2020-09-16 10:20:30') != DATETIME('1961-04-12 09:07:00')", - "ts_dt_t", - true), - $( - "DATETIME('1961-04-12 09:07:00') != TIMESTAMP('1984-12-15 22:15:07')", - "dt_ts_t", - true), - $( - "TIMESTAMP('2020-09-16 10:20:30') != DATETIME('2020-09-16 10:20:30')", - "ts_dt_f", - false), - $( - "DATETIME('2020-09-16 10:20:30') != TIMESTAMP('2020-09-16 10:20:30')", - "dt_ts_f", - false), $("TIMESTAMP('2020-09-16 10:20:30') != DATE('1961-04-12')", "ts_d_t", true), $("DATE('1961-04-12') != TIMESTAMP('1984-12-15 22:15:07')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 00:00:00') != DATE('2020-09-16')", "ts_d_f", false), @@ -294,37 +197,6 @@ public static Iterable compareNeqTimestampWithOtherTypes() { $("TIME('10:20:30') != TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false))); } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") - public static Iterable compareNeqDateTimeWithOtherTypes() { - var today = LocalDate.now().toString(); - return Arrays.asList( - $$( - $( - "DATETIME('2020-09-16 10:20:30') != TIMESTAMP('1961-04-12 09:07:00')", - "dt_ts_t", - true), - $( - "TIMESTAMP('1961-04-12 09:07:00') != DATETIME('1984-12-15 22:15:07')", - "ts_dt_t", - true), - $( - "DATETIME('2020-09-16 10:20:30') != TIMESTAMP('2020-09-16 10:20:30')", - "dt_ts_f", - false), - $( - "TIMESTAMP('2020-09-16 10:20:30') != DATETIME('2020-09-16 10:20:30')", - "ts_dt_f", - false), - $("DATETIME('2020-09-16 10:20:30') != DATE('1961-04-12')", "dt_d_t", true), - $("DATE('1961-04-12') != DATETIME('1984-12-15 22:15:07')", "d_dt_t", true), - $("DATETIME('2020-09-16 00:00:00') != DATE('2020-09-16')", "dt_d_f", false), - $("DATE('2020-09-16') != DATETIME('2020-09-16 00:00:00')", "d_dt_f", false), - $("DATETIME('2020-09-16 10:20:30') != TIME('09:07:00')", "dt_t_t", true), - $("TIME('09:07:00') != DATETIME('1984-12-15 22:15:07')", "t_dt_t", true), - $("DATETIME('" + today + " 10:20:30') != TIME('10:20:30')", "dt_t_f", false), - $("TIME('10:20:30') != DATETIME('" + today + " 10:20:30')", "t_dt_f", false))); - } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareNeqDateWithOtherTypes() { var today = LocalDate.now().toString(); @@ -334,10 +206,6 @@ public static Iterable compareNeqDateWithOtherTypes() { $("TIMESTAMP('1984-12-15 09:07:00') != DATE('1984-12-15')", "ts_d_t", true), $("DATE('2020-09-16') != TIMESTAMP('2020-09-16 00:00:00')", "d_ts_f", false), $("TIMESTAMP('2020-09-16 00:00:00') != DATE('2020-09-16')", "ts_d_f", false), - $("DATE('1961-04-12') != DATETIME('1984-12-15 22:15:07')", "d_dt_t", true), - $("DATETIME('1961-04-12 10:20:30') != DATE('1961-04-12')", "dt_d_t", true), - $("DATE('2020-09-16') != DATETIME('2020-09-16 00:00:00')", "d_dt_f", false), - $("DATETIME('2020-09-16 00:00:00') != DATE('2020-09-16')", "dt_d_f", false), $("DATE('2020-09-16') != TIME('09:07:00')", "d_t_t", true), $("TIME('09:07:00') != DATE('" + today + "')", "t_d_t", true), $("DATE('" + today + "') != TIME('00:00:00')", "d_t_f", false), @@ -349,10 +217,6 @@ public static Iterable compareNeqTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $("TIME('09:07:00') != DATETIME('1961-04-12 09:07:00')", "t_dt_t", true), - $("DATETIME('" + today + " 09:07:00') != TIME('10:20:30')", "dt_t_t", true), - $("TIME('10:20:30') != DATETIME('" + today + " 10:20:30')", "t_dt_f", false), - $("DATETIME('" + today + " 10:20:30') != TIME('10:20:30')", "dt_t_f", false), $("TIME('22:15:07') != TIMESTAMP('1984-12-15 22:15:07')", "t_ts_t", true), $("TIMESTAMP('1984-12-15 10:20:30') != TIME('10:20:30')", "ts_t_t", true), $("TIME('10:20:30') != TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false), @@ -368,22 +232,6 @@ public static Iterable compareLtTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $( - "TIMESTAMP('2020-09-16 10:20:30') < DATETIME('2061-04-12 09:07:00')", - "ts_dt_t", - true), - $( - "DATETIME('1961-04-12 09:07:00') < TIMESTAMP('1984-12-15 22:15:07')", - "dt_ts_t", - true), - $( - "TIMESTAMP('2020-09-16 10:20:30') < DATETIME('2020-09-16 10:20:30')", - "ts_dt_f", - false), - $( - "DATETIME('2020-09-16 10:20:30') < TIMESTAMP('1961-04-12 09:07:00')", - "dt_ts_f", - false), $("TIMESTAMP('2020-09-16 10:20:30') < DATE('2077-04-12')", "ts_d_t", true), $("DATE('1961-04-12') < TIMESTAMP('1984-12-15 22:15:07')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 10:20:30') < DATE('1961-04-12')", "ts_d_f", false), @@ -394,37 +242,6 @@ public static Iterable compareLtTimestampWithOtherTypes() { $("TIME('20:50:40') < TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false))); } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") - public static Iterable compareLtDateTimeWithOtherTypes() { - var today = LocalDate.now().toString(); - return Arrays.asList( - $$( - $( - "DATETIME('2020-09-16 10:20:30') < TIMESTAMP('2077-04-12 09:07:00')", - "dt_ts_t", - true), - $( - "TIMESTAMP('1961-04-12 09:07:00') < DATETIME('1984-12-15 22:15:07')", - "ts_dt_t", - true), - $( - "DATETIME('2020-09-16 10:20:30') < TIMESTAMP('2020-09-16 10:20:30')", - "dt_ts_f", - false), - $( - "TIMESTAMP('2020-09-16 10:20:30') < DATETIME('1984-12-15 22:15:07')", - "ts_dt_f", - false), - $("DATETIME('2020-09-16 10:20:30') < DATE('3077-04-12')", "dt_d_t", true), - $("DATE('1961-04-12') < DATETIME('1984-12-15 22:15:07')", "d_dt_t", true), - $("DATETIME('2020-09-16 00:00:00') < DATE('2020-09-16')", "dt_d_f", false), - $("DATE('2020-09-16') < DATETIME('1961-04-12 09:07:00')", "d_dt_f", false), - $("DATETIME('2020-09-16 10:20:30') < TIME('09:07:00')", "dt_t_t", true), - $("TIME('09:07:00') < DATETIME('3077-12-15 22:15:07')", "t_dt_t", true), - $("DATETIME('" + today + " 10:20:30') < TIME('10:20:30')", "dt_t_f", false), - $("TIME('20:40:50') < DATETIME('" + today + " 10:20:30')", "t_dt_f", false))); - } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareLtDateWithOtherTypes() { return Arrays.asList( @@ -433,10 +250,6 @@ public static Iterable compareLtDateWithOtherTypes() { $("TIMESTAMP('1961-04-12 09:07:00') < DATE('1984-12-15')", "ts_d_t", true), $("DATE('2020-09-16') < TIMESTAMP('2020-09-16 00:00:00')", "d_ts_f", false), $("TIMESTAMP('2077-04-12 09:07:00') < DATE('2020-09-16')", "ts_d_f", false), - $("DATE('1961-04-12') < DATETIME('1984-12-15 22:15:07')", "d_dt_t", true), - $("DATETIME('1961-04-12 10:20:30') < DATE('1984-11-15')", "dt_d_t", true), - $("DATE('2020-09-16') < DATETIME('2020-09-16 00:00:00')", "d_dt_f", false), - $("DATETIME('2020-09-16 00:00:00') < DATE('1984-03-22')", "dt_d_f", false), $("DATE('2020-09-16') < TIME('09:07:00')", "d_t_t", true), $("TIME('09:07:00') < DATE('3077-04-12')", "t_d_t", true), $("DATE('3077-04-12') < TIME('00:00:00')", "d_t_f", false), @@ -448,10 +261,6 @@ public static Iterable compareLtTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $("TIME('09:07:00') < DATETIME('3077-04-12 09:07:00')", "t_dt_t", true), - $("DATETIME('" + today + " 09:07:00') < TIME('10:20:30')", "dt_t_t", true), - $("TIME('10:20:30') < DATETIME('" + today + " 10:20:30')", "t_dt_f", false), - $("DATETIME('" + today + " 20:40:50') < TIME('10:20:30')", "dt_t_f", false), $("TIME('22:15:07') < TIMESTAMP('3077-12-15 22:15:07')", "t_ts_t", true), $("TIMESTAMP('1984-12-15 10:20:30') < TIME('10:20:30')", "ts_t_t", true), $("TIME('10:20:30') < TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false), @@ -467,22 +276,6 @@ public static Iterable compareGtTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $( - "TIMESTAMP('2020-09-16 10:20:30') > DATETIME('2020-09-16 10:20:25')", - "ts_dt_t", - true), - $( - "DATETIME('2020-09-16 10:20:30') > TIMESTAMP('1961-04-12 09:07:00')", - "dt_ts_t", - true), - $( - "TIMESTAMP('2020-09-16 10:20:30') > DATETIME('2061-04-12 09:07:00')", - "ts_dt_f", - false), - $( - "DATETIME('1961-04-12 09:07:00') > TIMESTAMP('1984-12-15 09:07:00')", - "dt_ts_f", - false), $("TIMESTAMP('2020-09-16 10:20:30') > DATE('1961-04-12')", "ts_d_t", true), $("DATE('2020-09-16') > TIMESTAMP('2020-09-15 22:15:07')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 10:20:30') > DATE('2077-04-12')", "ts_d_f", false), @@ -493,37 +286,6 @@ public static Iterable compareGtTimestampWithOtherTypes() { $("TIME('09:07:00') > TIMESTAMP('3077-12-15 22:15:07')", "t_ts_f", false))); } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") - public static Iterable compareGtDateTimeWithOtherTypes() { - var today = LocalDate.now().toString(); - return Arrays.asList( - $$( - $( - "DATETIME('2020-09-16 10:20:31') > TIMESTAMP('2020-09-16 10:20:30')", - "dt_ts_t", - true), - $( - "TIMESTAMP('2020-09-16 10:20:30') > DATETIME('1984-12-15 22:15:07')", - "ts_dt_t", - true), - $( - "DATETIME('2020-09-16 10:20:30') > TIMESTAMP('2077-04-12 09:07:00')", - "dt_ts_f", - false), - $( - "TIMESTAMP('1961-04-12 09:07:00') > DATETIME('1961-04-12 09:07:00')", - "ts_dt_f", - false), - $("DATETIME('3077-04-12 10:20:30') > DATE('2020-09-16')", "dt_d_t", true), - $("DATE('2020-09-16') > DATETIME('1961-04-12 09:07:00')", "d_dt_t", true), - $("DATETIME('2020-09-16 00:00:00') > DATE('2020-09-16')", "dt_d_f", false), - $("DATE('1961-04-12') > DATETIME('1984-12-15 22:15:07')", "d_dt_f", false), - $("DATETIME('3077-04-12 10:20:30') > TIME('09:07:00')", "dt_t_t", true), - $("TIME('20:40:50') > DATETIME('" + today + " 10:20:30')", "t_dt_t", true), - $("DATETIME('" + today + " 10:20:30') > TIME('10:20:30')", "dt_t_f", false), - $("TIME('09:07:00') > DATETIME('3077-12-15 22:15:07')", "t_dt_f", false))); - } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareGtDateWithOtherTypes() { return Arrays.asList( @@ -532,10 +294,6 @@ public static Iterable compareGtDateWithOtherTypes() { $("TIMESTAMP('2077-04-12 09:07:00') > DATE('2020-09-16')", "ts_d_t", true), $("DATE('2020-09-16') > TIMESTAMP('2020-09-16 00:00:00')", "d_ts_f", false), $("TIMESTAMP('1961-04-12 09:07:00') > DATE('1984-12-15')", "ts_d_f", false), - $("DATE('1984-12-15') > DATETIME('1961-04-12 09:07:00')", "d_dt_t", true), - $("DATETIME('2020-09-16 00:00:00') > DATE('1984-03-22')", "dt_d_t", true), - $("DATE('2020-09-16') > DATETIME('2020-09-16 00:00:00')", "d_dt_f", false), - $("DATETIME('1961-04-12 10:20:30') > DATE('1984-11-15')", "dt_d_f", false), $("DATE('3077-04-12') > TIME('00:00:00')", "d_t_t", true), $("TIME('00:00:00') > DATE('2020-09-16')", "t_d_t", true), $("DATE('2020-09-16') > TIME('09:07:00')", "d_t_f", false), @@ -547,10 +305,6 @@ public static Iterable compareGtTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $("TIME('09:07:00') > DATETIME('1961-04-12 09:07:00')", "t_dt_t", true), - $("DATETIME('" + today + " 20:40:50') > TIME('10:20:30')", "dt_t_t", true), - $("TIME('10:20:30') > DATETIME('" + today + " 10:20:30')", "t_dt_f", false), - $("DATETIME('" + today + " 09:07:00') > TIME('10:20:30')", "dt_t_f", false), $("TIME('22:15:07') > TIMESTAMP('1984-12-15 22:15:07')", "t_ts_t", true), $("TIMESTAMP('" + today + " 20:50:42') > TIME('10:20:30')", "ts_t_t", true), $("TIME('10:20:30') > TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false), @@ -566,22 +320,6 @@ public static Iterable compareLteTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $( - "TIMESTAMP('2020-09-16 10:20:30') <= DATETIME('2020-09-16 10:20:30')", - "ts_dt_t", - true), - $( - "DATETIME('1961-04-12 09:07:00') <= TIMESTAMP('1984-12-15 22:15:07')", - "dt_ts_t", - true), - $( - "TIMESTAMP('2020-09-16 10:20:30') <= DATETIME('1961-04-12 09:07:00')", - "ts_dt_f", - false), - $( - "DATETIME('2020-09-16 10:20:30') <= TIMESTAMP('1961-04-12 09:07:00')", - "dt_ts_f", - false), $("TIMESTAMP('2020-09-16 10:20:30') <= DATE('2077-04-12')", "ts_d_t", true), $("DATE('2020-09-16') <= TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 10:20:30') <= DATE('1961-04-12')", "ts_d_f", false), @@ -592,37 +330,6 @@ public static Iterable compareLteTimestampWithOtherTypes() { $("TIME('20:50:40') <= TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false))); } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") - public static Iterable compareLteDateTimeWithOtherTypes() { - var today = LocalDate.now().toString(); - return Arrays.asList( - $$( - $( - "DATETIME('2020-09-16 10:20:30') <= TIMESTAMP('2020-09-16 10:20:30')", - "dt_ts_t", - true), - $( - "TIMESTAMP('1961-04-12 09:07:00') <= DATETIME('1984-12-15 22:15:07')", - "ts_dt_t", - true), - $( - "DATETIME('3077-09-16 10:20:30') <= TIMESTAMP('2077-04-12 09:07:00')", - "dt_ts_f", - false), - $( - "TIMESTAMP('2020-09-16 10:20:30') <= DATETIME('1984-12-15 22:15:07')", - "ts_dt_f", - false), - $("DATETIME('2020-09-16 00:00:00') <= DATE('2020-09-16')", "dt_d_t", true), - $("DATE('1961-04-12') <= DATETIME('1984-12-15 22:15:07')", "d_dt_t", true), - $("DATETIME('2020-09-16 10:20:30') <= DATE('1984-04-12')", "dt_d_f", false), - $("DATE('2020-09-16') <= DATETIME('1961-04-12 09:07:00')", "d_dt_f", false), - $("DATETIME('" + today + " 10:20:30') <= TIME('10:20:30')", "dt_t_t", true), - $("TIME('09:07:00') <= DATETIME('3077-12-15 22:15:07')", "t_dt_t", true), - $("DATETIME('3077-09-16 10:20:30') <= TIME('19:07:00')", "dt_t_f", false), - $("TIME('20:40:50') <= DATETIME('" + today + " 10:20:30')", "t_dt_f", false))); - } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareLteDateWithOtherTypes() { return Arrays.asList( @@ -631,10 +338,6 @@ public static Iterable compareLteDateWithOtherTypes() { $("TIMESTAMP('1961-04-12 09:07:00') <= DATE('1984-12-15')", "ts_d_t", true), $("DATE('2020-09-16') <= TIMESTAMP('1961-04-12 09:07:00')", "d_ts_f", false), $("TIMESTAMP('2077-04-12 09:07:00') <= DATE('2020-09-16')", "ts_d_f", false), - $("DATE('2020-09-16') <= DATETIME('2020-09-16 00:00:00')", "d_dt_t", true), - $("DATETIME('1961-04-12 10:20:30') <= DATE('1984-11-15')", "dt_d_t", true), - $("DATE('2077-04-12') <= DATETIME('1984-12-15 22:15:07')", "d_dt_f", false), - $("DATETIME('2020-09-16 00:00:00') <= DATE('1984-03-22')", "dt_d_f", false), $("DATE('2020-09-16') <= TIME('09:07:00')", "d_t_t", true), $("TIME('09:07:00') <= DATE('3077-04-12')", "t_d_t", true), $("DATE('3077-04-12') <= TIME('00:00:00')", "d_t_f", false), @@ -646,10 +349,6 @@ public static Iterable compareLteTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $("TIME('10:20:30') <= DATETIME('" + today + " 10:20:30')", "t_dt_t", true), - $("DATETIME('" + today + " 09:07:00') <= TIME('10:20:30')", "dt_t_t", true), - $("TIME('09:07:00') <= DATETIME('1961-04-12 09:07:00')", "t_dt_f", false), - $("DATETIME('" + today + " 20:40:50') <= TIME('10:20:30')", "dt_t_f", false), $("TIME('10:20:30') <= TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), $("TIMESTAMP('1984-12-15 10:20:30') <= TIME('10:20:30')", "ts_t_t", true), $("TIME('22:15:07') <= TIMESTAMP('1984-12-15 22:15:07')", "t_ts_f", false), @@ -665,22 +364,6 @@ public static Iterable compareGteTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $( - "TIMESTAMP('2020-09-16 10:20:30') >= DATETIME('2020-09-16 10:20:30')", - "ts_dt_t", - true), - $( - "DATETIME('2020-09-16 10:20:30') >= TIMESTAMP('1961-04-12 09:07:00')", - "dt_ts_t", - true), - $( - "TIMESTAMP('2020-09-16 10:20:30') >= DATETIME('2061-04-12 09:07:00')", - "ts_dt_f", - false), - $( - "DATETIME('1961-04-12 09:07:00') >= TIMESTAMP('1984-12-15 09:07:00')", - "dt_ts_f", - false), $("TIMESTAMP('2020-09-16 10:20:30') >= DATE('1961-04-12')", "ts_d_t", true), $("DATE('2020-09-16') >= TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 10:20:30') >= DATE('2077-04-12')", "ts_d_f", false), @@ -691,37 +374,6 @@ public static Iterable compareGteTimestampWithOtherTypes() { $("TIME('09:07:00') >= TIMESTAMP('3077-12-15 22:15:07')", "t_ts_f", false))); } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") - public static Iterable compareGteDateTimeWithOtherTypes() { - var today = LocalDate.now().toString(); - return Arrays.asList( - $$( - $( - "DATETIME('2020-09-16 10:20:30') >= TIMESTAMP('2020-09-16 10:20:30')", - "dt_ts_t", - true), - $( - "TIMESTAMP('2020-09-16 10:20:30') >= DATETIME('1984-12-15 22:15:07')", - "ts_dt_t", - true), - $( - "DATETIME('2020-09-16 10:20:30') >= TIMESTAMP('2077-04-12 09:07:00')", - "dt_ts_f", - false), - $( - "TIMESTAMP('1961-04-12 00:00:00') >= DATETIME('1961-04-12 09:07:00')", - "ts_dt_f", - false), - $("DATETIME('2020-09-16 00:00:00') >= DATE('2020-09-16')", "dt_d_t", true), - $("DATE('2020-09-16') >= DATETIME('1961-04-12 09:07:00')", "d_dt_t", true), - $("DATETIME('1961-04-12 09:07:00') >= DATE('2020-09-16')", "dt_d_f", false), - $("DATE('1961-04-12') >= DATETIME('1984-12-15 22:15:07')", "d_dt_f", false), - $("DATETIME('" + today + " 10:20:30') >= TIME('10:20:30')", "dt_t_t", true), - $("TIME('20:40:50') >= DATETIME('" + today + " 10:20:30')", "t_dt_t", true), - $("DATETIME('1961-04-12 09:07:00') >= TIME('09:07:00')", "dt_t_f", false), - $("TIME('09:07:00') >= DATETIME('3077-12-15 22:15:07')", "t_dt_f", false))); - } - @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareGteDateWithOtherTypes() { return Arrays.asList( @@ -730,10 +382,6 @@ public static Iterable compareGteDateWithOtherTypes() { $("TIMESTAMP('2077-04-12 09:07:00') >= DATE('2020-09-16')", "ts_d_t", true), $("DATE('1961-04-12') >= TIMESTAMP('1961-04-12 09:07:00')", "d_ts_f", false), $("TIMESTAMP('1961-04-12 09:07:00') >= DATE('1984-12-15')", "ts_d_f", false), - $("DATE('2020-09-16') >= DATETIME('2020-09-16 00:00:00')", "d_dt_t", true), - $("DATETIME('2020-09-16 00:00:00') >= DATE('1984-03-22')", "dt_d_t", true), - $("DATE('1960-12-15') >= DATETIME('1961-04-12 09:07:00')", "d_dt_f", false), - $("DATETIME('1961-04-12 10:20:30') >= DATE('1984-11-15')", "dt_d_f", false), $("DATE('3077-04-12') >= TIME('00:00:00')", "d_t_t", true), $("TIME('00:00:00') >= DATE('2020-09-16')", "t_d_t", true), $("DATE('2020-09-16') >= TIME('09:07:00')", "d_t_f", false), @@ -745,10 +393,6 @@ public static Iterable compareGteTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( - $("TIME('10:20:30') >= DATETIME('" + today + " 10:20:30')", "t_dt_t", true), - $("DATETIME('" + today + " 20:40:50') >= TIME('10:20:30')", "dt_t_t", true), - $("TIME('09:07:00') >= DATETIME('3077-04-12 09:07:00')", "t_dt_f", false), - $("DATETIME('" + today + " 09:07:00') >= TIME('10:20:30')", "dt_t_f", false), $("TIME('10:20:30') >= TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), $("TIMESTAMP('" + today + " 20:50:42') >= TIME('10:20:30')", "ts_t_t", true), $("TIME('22:15:07') >= TIMESTAMP('3077-12-15 22:15:07')", "t_ts_f", false), diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeFunctionIT.java index 33eb8b693f..0ec77f9f31 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeFunctionIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeFunctionIT.java @@ -94,15 +94,15 @@ public void testAddDateWithDays() throws IOException { verifyDataRows(result, rows("2020-09-17")); result = executeQuery("select adddate(timestamp('2020-09-16 17:30:00'), 1)"); - verifySchema(result, schema("adddate(timestamp('2020-09-16 17:30:00'), 1)", null, "datetime")); + verifySchema(result, schema("adddate(timestamp('2020-09-16 17:30:00'), 1)", null, "timestamp")); verifyDataRows(result, rows("2020-09-17 17:30:00")); - result = executeQuery("select adddate(DATETIME('2020-09-16 07:40:00'), 1)"); - verifySchema(result, schema("adddate(DATETIME('2020-09-16 07:40:00'), 1)", null, "datetime")); + result = executeQuery("select adddate(TIMESTAMP('2020-09-16 07:40:00'), 1)"); + verifySchema(result, schema("adddate(TIMESTAMP('2020-09-16 07:40:00'), 1)", null, "timestamp")); verifyDataRows(result, rows("2020-09-17 07:40:00")); result = executeQuery("select adddate(TIME('07:40:00'), 0)"); - verifySchema(result, schema("adddate(TIME('07:40:00'), 0)", null, "datetime")); + verifySchema(result, schema("adddate(TIME('07:40:00'), 0)", null, "timestamp")); verifyDataRows(result, rows(LocalDate.now() + " 07:40:00")); } @@ -112,25 +112,19 @@ public void testAddDateWithInterval() throws IOException { executeQuery("select adddate(timestamp('2020-09-16 17:30:00'), interval 1 day)"); verifySchema( result, - schema("adddate(timestamp('2020-09-16 17:30:00'), interval 1 day)", null, "datetime")); - verifyDataRows(result, rows("2020-09-17 17:30:00")); - - result = executeQuery("select adddate(DATETIME('2020-09-16 17:30:00'), interval 1 day)"); - verifySchema( - result, - schema("adddate(DATETIME('2020-09-16 17:30:00'), interval 1 day)", null, "datetime")); + schema("adddate(timestamp('2020-09-16 17:30:00'), interval 1 day)", null, "timestamp")); verifyDataRows(result, rows("2020-09-17 17:30:00")); result = executeQuery("select adddate(date('2020-09-16'), interval 1 day)"); - verifySchema(result, schema("adddate(date('2020-09-16'), interval 1 day)", null, "datetime")); + verifySchema(result, schema("adddate(date('2020-09-16'), interval 1 day)", null, "timestamp")); verifyDataRows(result, rows("2020-09-17 00:00:00")); result = executeQuery("select adddate(date('2020-09-16'), interval 1 hour)"); - verifySchema(result, schema("adddate(date('2020-09-16'), interval 1 hour)", null, "datetime")); + verifySchema(result, schema("adddate(date('2020-09-16'), interval 1 hour)", null, "timestamp")); verifyDataRows(result, rows("2020-09-16 01:00:00")); result = executeQuery("select adddate(TIME('07:40:00'), interval 1 day)"); - verifySchema(result, schema("adddate(TIME('07:40:00'), interval 1 day)", null, "datetime")); + verifySchema(result, schema("adddate(TIME('07:40:00'), interval 1 day)", null, "timestamp")); verifyDataRows( result, rows( @@ -141,7 +135,7 @@ public void testAddDateWithInterval() throws IOException { .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); result = executeQuery("select adddate(TIME('07:40:00'), interval 1 hour)"); - verifySchema(result, schema("adddate(TIME('07:40:00'), interval 1 hour)", null, "datetime")); + verifySchema(result, schema("adddate(TIME('07:40:00'), interval 1 hour)", null, "timestamp")); verifyDataRows( result, rows( @@ -157,25 +151,26 @@ public void testDateAdd() throws IOException { executeQuery("select date_add(timestamp('2020-09-16 17:30:00'), interval 1 day)"); verifySchema( result, - schema("date_add(timestamp('2020-09-16 17:30:00'), interval 1 day)", null, "datetime")); + schema("date_add(timestamp('2020-09-16 17:30:00'), interval 1 day)", null, "timestamp")); verifyDataRows(result, rows("2020-09-17 17:30:00")); - result = executeQuery("select date_add(DATETIME('2020-09-16 17:30:00'), interval 1 day)"); + result = executeQuery("select date_add(TIMESTAMP('2020-09-16 17:30:00'), interval 1 day)"); verifySchema( result, - schema("date_add(DATETIME('2020-09-16 17:30:00'), interval 1 day)", null, "datetime")); + schema("date_add(TIMESTAMP('2020-09-16 17:30:00'), interval 1 day)", null, "timestamp")); verifyDataRows(result, rows("2020-09-17 17:30:00")); result = executeQuery("select date_add(date('2020-09-16'), interval 1 day)"); - verifySchema(result, schema("date_add(date('2020-09-16'), interval 1 day)", null, "datetime")); + verifySchema(result, schema("date_add(date('2020-09-16'), interval 1 day)", null, "timestamp")); verifyDataRows(result, rows("2020-09-17 00:00:00")); result = executeQuery("select date_add(date('2020-09-16'), interval 1 hour)"); - verifySchema(result, schema("date_add(date('2020-09-16'), interval 1 hour)", null, "datetime")); + verifySchema( + result, schema("date_add(date('2020-09-16'), interval 1 hour)", null, "timestamp")); verifyDataRows(result, rows("2020-09-16 01:00:00")); result = executeQuery("select date_add(TIME('07:40:00'), interval 1 day)"); - verifySchema(result, schema("date_add(TIME('07:40:00'), interval 1 day)", null, "datetime")); + verifySchema(result, schema("date_add(TIME('07:40:00'), interval 1 day)", null, "timestamp")); verifyDataRows( result, rows( @@ -186,7 +181,7 @@ public void testDateAdd() throws IOException { .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); result = executeQuery("select date_add(TIME('07:40:00'), interval 1 hour)"); - verifySchema(result, schema("date_add(TIME('07:40:00'), interval 1 hour)", null, "datetime")); + verifySchema(result, schema("date_add(TIME('07:40:00'), interval 1 hour)", null, "timestamp")); verifyDataRows( result, rows( @@ -199,7 +194,7 @@ public void testDateAdd() throws IOException { executeQuery( String.format("SELECT DATE_ADD(birthdate, INTERVAL 1 YEAR) FROM %s", TEST_INDEX_BANK)); - verifySchema(result, schema("DATE_ADD(birthdate, INTERVAL 1 YEAR)", null, "datetime")); + verifySchema(result, schema("DATE_ADD(birthdate, INTERVAL 1 YEAR)", null, "timestamp")); verifyDataRows( result, rows("2018-10-23 00:00:00"), @@ -217,25 +212,26 @@ public void testDateSub() throws IOException { executeQuery("select date_sub(timestamp('2020-09-16 17:30:00'), interval 1 day)"); verifySchema( result, - schema("date_sub(timestamp('2020-09-16 17:30:00'), interval 1 day)", null, "datetime")); + schema("date_sub(timestamp('2020-09-16 17:30:00'), interval 1 day)", null, "timestamp")); verifyDataRows(result, rows("2020-09-15 17:30:00")); - result = executeQuery("select date_sub(DATETIME('2020-09-16 17:30:00'), interval 1 day)"); + result = executeQuery("select date_sub(TIMESTAMP('2020-09-16 17:30:00'), interval 1 day)"); verifySchema( result, - schema("date_sub(DATETIME('2020-09-16 17:30:00'), interval 1 day)", null, "datetime")); + schema("date_sub(TIMESTAMP('2020-09-16 17:30:00'), interval 1 day)", null, "timestamp")); verifyDataRows(result, rows("2020-09-15 17:30:00")); result = executeQuery("select date_sub(date('2020-09-16'), interval 1 day)"); - verifySchema(result, schema("date_sub(date('2020-09-16'), interval 1 day)", null, "datetime")); + verifySchema(result, schema("date_sub(date('2020-09-16'), interval 1 day)", null, "timestamp")); verifyDataRows(result, rows("2020-09-15 00:00:00")); result = executeQuery("select date_sub(date('2020-09-16'), interval 1 hour)"); - verifySchema(result, schema("date_sub(date('2020-09-16'), interval 1 hour)", null, "datetime")); + verifySchema( + result, schema("date_sub(date('2020-09-16'), interval 1 hour)", null, "timestamp")); verifyDataRows(result, rows("2020-09-15 23:00:00")); result = executeQuery("select date_sub(TIME('07:40:00'), interval 1 day)"); - verifySchema(result, schema("date_sub(TIME('07:40:00'), interval 1 day)", null, "datetime")); + verifySchema(result, schema("date_sub(TIME('07:40:00'), interval 1 day)", null, "timestamp")); verifyDataRows( result, rows( @@ -246,7 +242,7 @@ public void testDateSub() throws IOException { .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); result = executeQuery("select date_sub(TIME('07:40:00'), interval 1 hour)"); - verifySchema(result, schema("date_sub(TIME('07:40:00'), interval 1 hour)", null, "datetime")); + verifySchema(result, schema("date_sub(TIME('07:40:00'), interval 1 hour)", null, "timestamp")); verifyDataRows( result, rows( @@ -314,11 +310,11 @@ public void testDayOfMonthAliasesReturnTheSameResults() throws IOException { result1 = executeQuery( String.format( - "SELECT dayofmonth(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT dayofmonth(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result2 = executeQuery( String.format( - "SELECT day_of_month(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT day_of_month(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); result1 = @@ -371,11 +367,11 @@ public void testDayOfWeekAliasesReturnTheSameResults() throws IOException { result1 = executeQuery( String.format( - "SELECT dayofweek(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT dayofweek(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result2 = executeQuery( String.format( - "SELECT day_of_week(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT day_of_week(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); result1 = @@ -409,8 +405,8 @@ public void testDayOfYearWithUnderscores() throws IOException { verifySchema(result, schema("day_of_year(date('2020-09-16'))", null, "integer")); verifyDataRows(result, rows(260)); - result = executeQuery("select day_of_year(datetime('2020-09-16 00:00:00'))"); - verifySchema(result, schema("day_of_year(datetime('2020-09-16 00:00:00'))", null, "integer")); + result = executeQuery("select day_of_year(timestamp('2020-09-16 00:00:00'))"); + verifySchema(result, schema("day_of_year(timestamp('2020-09-16 00:00:00'))", null, "integer")); verifyDataRows(result, rows(260)); result = executeQuery("select day_of_year(timestamp('2020-09-16 00:00:00'))"); @@ -436,11 +432,11 @@ public void testDayOfYearAlternateSyntaxesReturnTheSameResults() throws IOExcept result1 = executeQuery( String.format( - "SELECT dayofyear(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT dayofyear(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result2 = executeQuery( String.format( - "SELECT day_of_year(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT day_of_year(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); result1 = @@ -489,10 +485,6 @@ public void testHourOfDayWithUnderscores() throws IOException { verifySchema(result, schema("hour_of_day(timestamp('2020-09-16 17:30:00'))", null, "integer")); verifyDataRows(result, rows(17)); - result = executeQuery("select hour_of_day(datetime('2020-09-16 17:30:00'))"); - verifySchema(result, schema("hour_of_day(datetime('2020-09-16 17:30:00'))", null, "integer")); - verifyDataRows(result, rows(17)); - result = executeQuery("select hour_of_day(time('17:30:00'))"); verifySchema(result, schema("hour_of_day(time('17:30:00'))", null, "integer")); verifyDataRows(result, rows(17)); @@ -511,7 +503,7 @@ public void testExtractWithDatetime() throws IOException { JSONObject datetimeResult = executeQuery( String.format( - "SELECT extract(DAY_SECOND FROM datetime(cast(datetime0 AS STRING))) FROM %s LIMIT" + "SELECT extract(DAY_SECOND FROM timestamp(cast(datetime0 AS STRING))) FROM %s LIMIT" + " 1", TEST_INDEX_CALCS)); verifyDataRows(datetimeResult, rows(9101735)); @@ -561,11 +553,11 @@ public void testHourFunctionAliasesReturnTheSameResults() throws IOException { result1 = executeQuery( String.format( - "SELECT hour(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT hour(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result2 = executeQuery( String.format( - "SELECT hour_of_day(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT hour_of_day(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); result1 = @@ -663,8 +655,9 @@ public void testMinuteOfDay() throws IOException { result, schema("minute_of_day(timestamp('2020-09-16 17:30:00'))", null, "integer")); verifyDataRows(result, rows(1050)); - result = executeQuery("select minute_of_day(datetime('2020-09-16 17:30:00'))"); - verifySchema(result, schema("minute_of_day(datetime('2020-09-16 17:30:00'))", null, "integer")); + result = executeQuery("select minute_of_day(timestamp('2020-09-16 17:30:00'))"); + verifySchema( + result, schema("minute_of_day(timestamp('2020-09-16 17:30:00'))", null, "integer")); verifyDataRows(result, rows(1050)); result = executeQuery("select minute_of_day(time('17:30:00'))"); @@ -710,11 +703,11 @@ public void testMinuteFunctionAliasesReturnTheSameResults() throws IOException { result1 = executeQuery( String.format( - "SELECT minute(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT minute(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result2 = executeQuery( String.format( - "SELECT minute_of_hour(datetime(CAST(time0 AS STRING))) FROM %s", + "SELECT minute_of_hour(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); @@ -750,8 +743,9 @@ public void testMonthOfYearTypes() throws IOException { verifySchema(result, schema("month_of_year(date('2020-09-16'))", null, "integer")); verifyDataRows(result, rows(9)); - result = executeQuery("select month_of_year(datetime('2020-09-16 00:00:00'))"); - verifySchema(result, schema("month_of_year(datetime('2020-09-16 00:00:00'))", null, "integer")); + result = executeQuery("select month_of_year(timestamp('2020-09-16 00:00:00'))"); + verifySchema( + result, schema("month_of_year(timestamp('2020-09-16 00:00:00'))", null, "integer")); verifyDataRows(result, rows(9)); result = executeQuery("select month_of_year(timestamp('2020-09-16 00:00:00'))"); @@ -778,11 +772,12 @@ public void testMonthAlternateSyntaxesReturnTheSameResults() throws IOException result1 = executeQuery( String.format( - "SELECT month(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT month(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result2 = executeQuery( String.format( - "SELECT month_of_year(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT month_of_year(timestamp(CAST(time0 AS STRING))) FROM %s", + TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); result1 = @@ -876,11 +871,11 @@ public void testSecondFunctionAliasesReturnTheSameResults() throws IOException { result1 = executeQuery( String.format( - "SELECT second(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT second(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result2 = executeQuery( String.format( - "SELECT second_of_minute(datetime(CAST(time0 AS STRING))) FROM %s", + "SELECT second_of_minute(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); @@ -934,15 +929,15 @@ public void testSubDateWithDays() throws IOException { verifyDataRows(result, rows("2020-09-15")); result = executeQuery("select subdate(timestamp('2020-09-16 17:30:00'), 1)"); - verifySchema(result, schema("subdate(timestamp('2020-09-16 17:30:00'), 1)", null, "datetime")); + verifySchema(result, schema("subdate(timestamp('2020-09-16 17:30:00'), 1)", null, "timestamp")); verifyDataRows(result, rows("2020-09-15 17:30:00")); - result = executeQuery("select subdate(DATETIME('2020-09-16 07:40:00'), 1)"); - verifySchema(result, schema("subdate(DATETIME('2020-09-16 07:40:00'), 1)", null, "datetime")); + result = executeQuery("select subdate(TIMESTAMP('2020-09-16 07:40:00'), 1)"); + verifySchema(result, schema("subdate(TIMESTAMP('2020-09-16 07:40:00'), 1)", null, "timestamp")); verifyDataRows(result, rows("2020-09-15 07:40:00")); result = executeQuery("select subdate(TIME('07:40:00'), 0)"); - verifySchema(result, schema("subdate(TIME('07:40:00'), 0)", null, "datetime")); + verifySchema(result, schema("subdate(TIME('07:40:00'), 0)", null, "timestamp")); verifyDataRows(result, rows(LocalDate.now() + " 07:40:00")); } @@ -952,25 +947,25 @@ public void testSubDateWithInterval() throws IOException { executeQuery("select subdate(timestamp('2020-09-16 17:30:00'), interval 1 day)"); verifySchema( result, - schema("subdate(timestamp('2020-09-16 17:30:00'), interval 1 day)", null, "datetime")); + schema("subdate(timestamp('2020-09-16 17:30:00'), interval 1 day)", null, "timestamp")); verifyDataRows(result, rows("2020-09-15 17:30:00")); - result = executeQuery("select subdate(DATETIME('2020-09-16 17:30:00'), interval 1 day)"); + result = executeQuery("select subdate(TIMESTAMP('2020-09-16 17:30:00'), interval 1 day)"); verifySchema( result, - schema("subdate(DATETIME('2020-09-16 17:30:00'), interval 1 day)", null, "datetime")); + schema("subdate(TIMESTAMP('2020-09-16 17:30:00'), interval 1 day)", null, "timestamp")); verifyDataRows(result, rows("2020-09-15 17:30:00")); result = executeQuery("select subdate(date('2020-09-16'), interval 1 day)"); - verifySchema(result, schema("subdate(date('2020-09-16'), interval 1 day)", null, "datetime")); + verifySchema(result, schema("subdate(date('2020-09-16'), interval 1 day)", null, "timestamp")); verifyDataRows(result, rows("2020-09-15 00:00:00")); result = executeQuery("select subdate(date('2020-09-16'), interval 1 hour)"); - verifySchema(result, schema("subdate(date('2020-09-16'), interval 1 hour)", null, "datetime")); + verifySchema(result, schema("subdate(date('2020-09-16'), interval 1 hour)", null, "timestamp")); verifyDataRows(result, rows("2020-09-15 23:00:00")); result = executeQuery("select subdate(TIME('07:40:00'), interval 1 day)"); - verifySchema(result, schema("subdate(TIME('07:40:00'), interval 1 day)", null, "datetime")); + verifySchema(result, schema("subdate(TIME('07:40:00'), interval 1 day)", null, "timestamp")); verifyDataRows( result, rows( @@ -981,7 +976,7 @@ public void testSubDateWithInterval() throws IOException { .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); result = executeQuery("select subdate(TIME('07:40:00'), interval 1 hour)"); - verifySchema(result, schema("subdate(TIME('07:40:00'), interval 1 hour)", null, "datetime")); + verifySchema(result, schema("subdate(TIME('07:40:00'), interval 1 hour)", null, "timestamp")); verifyDataRows( result, rows( @@ -1045,7 +1040,7 @@ public void testToSeconds() throws IOException { result = executeQuery( String.format( - "SELECT to_seconds(datetime(cast(datetime0 AS string))) FROM %s LIMIT 2", + "SELECT to_seconds(timestamp(cast(datetime0 AS string))) FROM %s LIMIT 2", TEST_INDEX_CALCS)); verifyDataRows(result, rows(63256587455L), rows(63258064234L)); @@ -1142,7 +1137,7 @@ public void testWeekAlternateSyntaxesReturnTheSameResults() throws IOException { result1.getJSONArray("datarows").similar(result3.getJSONArray("datarows")); compareWeekResults("date0", TEST_INDEX_CALCS); - compareWeekResults("datetime(CAST(time0 AS STRING))", TEST_INDEX_CALCS); + compareWeekResults("timestamp(CAST(time0 AS STRING))", TEST_INDEX_CALCS); compareWeekResults("CAST(time0 AS STRING)", TEST_INDEX_CALCS); compareWeekResults("datetime0", TEST_INDEX_CALCS); } @@ -1215,8 +1210,8 @@ public void testFromUnixTime() throws IOException { + "FROM_UNIXTIME(1662601316, '%T') f3"); verifySchema( result, - schema("FROM_UNIXTIME(200300400)", "f1", "datetime"), - schema("FROM_UNIXTIME(12224.12)", "f2", "datetime"), + schema("FROM_UNIXTIME(200300400)", "f1", "timestamp"), + schema("FROM_UNIXTIME(12224.12)", "f2", "timestamp"), schema("FROM_UNIXTIME(1662601316, '%T')", "f3", "keyword")); verifySome( result.getJSONArray("datarows"), @@ -1272,21 +1267,21 @@ public void testAddTime() throws IOException { + " ADDTIME(TIME('23:59:59'), DATE('2004-01-01')) AS `'23:59:59' + 0`," + " ADDTIME(DATE('2004-01-01'), TIME('23:59:59')) AS `'2004-01-01' + '23:59:59'`," + " ADDTIME(TIME('10:20:30'), TIME('00:05:42')) AS `'10:20:30' + '00:05:42'`," - + " ADDTIME(TIMESTAMP('1999-12-31 15:42:13'), DATETIME('1961-04-12 09:07:00')) AS" + + " ADDTIME(TIMESTAMP('1999-12-31 15:42:13'), TIMESTAMP('1961-04-12 09:07:00')) AS" + " `'15:42:13' + '09:07:00'`"); verifySchema( result, - schema("ADDTIME(DATE('2008-12-12'), DATE('2008-11-15'))", "'2008-12-12' + 0", "datetime"), + schema("ADDTIME(DATE('2008-12-12'), DATE('2008-11-15'))", "'2008-12-12' + 0", "timestamp"), schema("ADDTIME(TIME('23:59:59'), DATE('2004-01-01'))", "'23:59:59' + 0", "time"), schema( "ADDTIME(DATE('2004-01-01'), TIME('23:59:59'))", "'2004-01-01' + '23:59:59'", - "datetime"), + "timestamp"), schema("ADDTIME(TIME('10:20:30'), TIME('00:05:42'))", "'10:20:30' + '00:05:42'", "time"), schema( - "ADDTIME(TIMESTAMP('1999-12-31 15:42:13'), DATETIME('1961-04-12 09:07:00'))", + "ADDTIME(TIMESTAMP('1999-12-31 15:42:13'), TIMESTAMP('1961-04-12 09:07:00'))", "'15:42:13' + '09:07:00'", - "datetime")); + "timestamp")); verifyDataRows( result, rows( @@ -1305,21 +1300,21 @@ public void testSubTime() throws IOException { + " SUBTIME(TIME('23:59:59'), DATE('2004-01-01')) AS `'23:59:59' - 0`," + " SUBTIME(DATE('2004-01-01'), TIME('23:59:59')) AS `'2004-01-01' - '23:59:59'`," + " SUBTIME(TIME('10:20:30'), TIME('00:05:42')) AS `'10:20:30' - '00:05:42'`," - + " SUBTIME(TIMESTAMP('1999-12-31 15:42:13'), DATETIME('1961-04-12 09:07:00')) AS" + + " SUBTIME(TIMESTAMP('1999-12-31 15:42:13'), TIMESTAMP('1961-04-12 09:07:00')) AS" + " `'15:42:13' - '09:07:00'`"); verifySchema( result, - schema("SUBTIME(DATE('2008-12-12'), DATE('2008-11-15'))", "'2008-12-12' - 0", "datetime"), + schema("SUBTIME(DATE('2008-12-12'), DATE('2008-11-15'))", "'2008-12-12' - 0", "timestamp"), schema("SUBTIME(TIME('23:59:59'), DATE('2004-01-01'))", "'23:59:59' - 0", "time"), schema( "SUBTIME(DATE('2004-01-01'), TIME('23:59:59'))", "'2004-01-01' - '23:59:59'", - "datetime"), + "timestamp"), schema("SUBTIME(TIME('10:20:30'), TIME('00:05:42'))", "'10:20:30' - '00:05:42'", "time"), schema( - "SUBTIME(TIMESTAMP('1999-12-31 15:42:13'), DATETIME('1961-04-12 09:07:00'))", + "SUBTIME(TIMESTAMP('1999-12-31 15:42:13'), TIMESTAMP('1961-04-12 09:07:00'))", "'15:42:13' - '09:07:00'", - "datetime")); + "timestamp")); verifyDataRows( result, rows( @@ -1336,7 +1331,7 @@ public void testDateDiff() throws IOException { "SELECT DATEDIFF(TIMESTAMP('2000-01-02 00:00:00'), TIMESTAMP('2000-01-01 23:59:59')) AS" + " `'2000-01-02' - '2000-01-01'`, DATEDIFF(DATE('2001-02-01')," + " TIMESTAMP('2004-01-01 00:00:00')) AS `'2001-02-01' - '2004-01-01'`," - + " DATEDIFF(TIMESTAMP('2004-01-01 00:00:00'), DATETIME('2002-02-01 14:25:30')) AS" + + " DATEDIFF(TIMESTAMP('2004-01-01 00:00:00'), TIMESTAMP('2002-02-01 14:25:30')) AS" + " `'2004-01-01' - '2002-02-01'`, DATEDIFF(TIME('23:59:59'), TIME('00:00:00')) AS" + " `today - today`"); verifySchema( @@ -1350,7 +1345,7 @@ public void testDateDiff() throws IOException { "'2001-02-01' - '2004-01-01'", "long"), schema( - "DATEDIFF(TIMESTAMP('2004-01-01 00:00:00'), DATETIME('2002-02-01 14:25:30'))", + "DATEDIFF(TIMESTAMP('2004-01-01 00:00:00'), TIMESTAMP('2002-02-01 14:25:30'))", "'2004-01-01' - '2002-02-01'", "long"), schema("DATEDIFF(TIME('23:59:59'), TIME('00:00:00'))", "today - today", "long")); @@ -1446,12 +1441,12 @@ public void testDateBracket() throws IOException { verifyDataRows(result, rows("2020-09-16")); } - private void compareBrackets(String query1, String query2, String datetime) throws IOException { - JSONObject result1 = executeQuery("select " + query1 + " '" + datetime + "'"); - JSONObject result2 = executeQuery("select {" + query2 + " '" + datetime + "'}"); + private void compareBrackets(String query1, String query2, String timestamp) throws IOException { + JSONObject result1 = executeQuery("select " + query1 + " '" + timestamp + "'"); + JSONObject result2 = executeQuery("select {" + query2 + " '" + timestamp + "'}"); - verifyDataRows(result1, rows(datetime)); - verifyDataRows(result2, rows(datetime)); + verifyDataRows(result1, rows(timestamp)); + verifyDataRows(result2, rows(timestamp)); } @Test diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeImplementationIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeImplementationIT.java index 8ffa1df8f3..490272d950 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeImplementationIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeImplementationIT.java @@ -28,7 +28,7 @@ public void inRangeZeroToStringTZ() throws IOException { executeJdbcRequest("SELECT DATETIME('2008-12-25 05:30:00+00:00', 'America/Los_Angeles')"); verifySchema( result, - schema("DATETIME('2008-12-25 05:30:00+00:00', 'America/Los_Angeles')", null, "datetime")); + schema("DATETIME('2008-12-25 05:30:00+00:00', 'America/Los_Angeles')", null, "timestamp")); verifyDataRows(result, rows("2008-12-24 21:30:00")); } @@ -36,7 +36,7 @@ public void inRangeZeroToStringTZ() throws IOException { public void inRangeZeroToPositive() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2008-12-25 05:30:00+00:00', '+01:00')"); verifySchema( - result, schema("DATETIME('2008-12-25 05:30:00+00:00', '+01:00')", null, "datetime")); + result, schema("DATETIME('2008-12-25 05:30:00+00:00', '+01:00')", null, "timestamp")); verifyDataRows(result, rows("2008-12-25 06:30:00")); } @@ -44,7 +44,7 @@ public void inRangeZeroToPositive() throws IOException { public void inRangeNegativeToPositive() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2008-12-25 05:30:00-05:00', '+05:00')"); verifySchema( - result, schema("DATETIME('2008-12-25 05:30:00-05:00', '+05:00')", null, "datetime")); + result, schema("DATETIME('2008-12-25 05:30:00-05:00', '+05:00')", null, "timestamp")); verifyDataRows(result, rows("2008-12-25 15:30:00")); } @@ -52,7 +52,7 @@ public void inRangeNegativeToPositive() throws IOException { public void inRangeTwentyHourOffset() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2004-02-28 23:00:00-10:00', '+10:00')"); verifySchema( - result, schema("DATETIME('2004-02-28 23:00:00-10:00', '+10:00')", null, "datetime")); + result, schema("DATETIME('2004-02-28 23:00:00-10:00', '+10:00')", null, "timestamp")); verifyDataRows(result, rows("2004-02-29 19:00:00")); } @@ -60,21 +60,21 @@ public void inRangeTwentyHourOffset() throws IOException { public void inRangeYearChange() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2008-01-01 02:00:00+10:00', '-10:00')"); verifySchema( - result, schema("DATETIME('2008-01-01 02:00:00+10:00', '-10:00')", null, "datetime")); + result, schema("DATETIME('2008-01-01 02:00:00+10:00', '-10:00')", null, "timestamp")); verifyDataRows(result, rows("2007-12-31 06:00:00")); } @Test public void inRangeZeroNoToTZ() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2008-01-01 02:00:00+10:00')"); - verifySchema(result, schema("DATETIME('2008-01-01 02:00:00+10:00')", null, "datetime")); + verifySchema(result, schema("DATETIME('2008-01-01 02:00:00+10:00')", null, "timestamp")); verifyDataRows(result, rows("2008-01-01 02:00:00")); } @Test public void inRangeZeroNoTZ() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2008-01-01 02:00:00')"); - verifySchema(result, schema("DATETIME('2008-01-01 02:00:00')", null, "datetime")); + verifySchema(result, schema("DATETIME('2008-01-01 02:00:00')", null, "timestamp")); verifyDataRows(result, rows("2008-01-01 02:00:00")); } @@ -82,7 +82,7 @@ public void inRangeZeroNoTZ() throws IOException { public void inRangeZeroDayConvert() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2008-01-01 02:00:00+12:00', '-12:00')"); verifySchema( - result, schema("DATETIME('2008-01-01 02:00:00+12:00', '-12:00')", null, "datetime")); + result, schema("DATETIME('2008-01-01 02:00:00+12:00', '-12:00')", null, "timestamp")); verifyDataRows(result, rows("2007-12-31 02:00:00")); } @@ -90,7 +90,7 @@ public void inRangeZeroDayConvert() throws IOException { public void inRangeJustInRangeNegative() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2008-01-01 02:00:00+10:00', '-13:59')"); verifySchema( - result, schema("DATETIME('2008-01-01 02:00:00+10:00', '-13:59')", null, "datetime")); + result, schema("DATETIME('2008-01-01 02:00:00+10:00', '-13:59')", null, "timestamp")); verifyDataRows(result, rows("2007-12-31 02:01:00")); } @@ -98,7 +98,7 @@ public void inRangeJustInRangeNegative() throws IOException { public void inRangeJustInRangePositive() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2008-01-01 02:00:00+14:00', '-10:00')"); verifySchema( - result, schema("DATETIME('2008-01-01 02:00:00+14:00', '-10:00')", null, "datetime")); + result, schema("DATETIME('2008-01-01 02:00:00+14:00', '-10:00')", null, "timestamp")); verifyDataRows(result, rows("2007-12-31 02:00:00")); } @@ -106,7 +106,7 @@ public void inRangeJustInRangePositive() throws IOException { public void nullField3Under() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2008-01-01 02:00:00+10:00', '-14:01')"); verifySchema( - result, schema("DATETIME('2008-01-01 02:00:00+10:00', '-14:01')", null, "datetime")); + result, schema("DATETIME('2008-01-01 02:00:00+10:00', '-14:01')", null, "timestamp")); verifyDataRows(result, rows(new Object[] {null})); } @@ -114,28 +114,28 @@ public void nullField3Under() throws IOException { public void nullField1Over() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2008-01-01 02:00:00+14:01', '-10:00')"); verifySchema( - result, schema("DATETIME('2008-01-01 02:00:00+14:01', '-10:00')", null, "datetime")); + result, schema("DATETIME('2008-01-01 02:00:00+14:01', '-10:00')", null, "timestamp")); verifyDataRows(result, rows(new Object[] {null})); } @Test public void nullDateTimeInvalidDateValueFebruary() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2021-02-30 10:00:00')"); - verifySchema(result, schema("DATETIME('2021-02-30 10:00:00')", null, "datetime")); + verifySchema(result, schema("DATETIME('2021-02-30 10:00:00')", null, "timestamp")); verifyDataRows(result, rows(new Object[] {null})); } @Test public void nullDateTimeInvalidDateValueApril() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2021-04-31 10:00:00')"); - verifySchema(result, schema("DATETIME('2021-04-31 10:00:00')", null, "datetime")); + verifySchema(result, schema("DATETIME('2021-04-31 10:00:00')", null, "timestamp")); verifyDataRows(result, rows(new Object[] {null})); } @Test public void nullDateTimeInvalidDateValueMonth() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2021-13-03 10:00:00')"); - verifySchema(result, schema("DATETIME('2021-13-03 10:00:00')", null, "datetime")); + verifySchema(result, schema("DATETIME('2021-13-03 10:00:00')", null, "timestamp")); verifyDataRows(result, rows(new Object[] {null})); } } diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/SystemFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/SystemFunctionIT.java index d2798728a1..7129d058c0 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/SystemFunctionIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/SystemFunctionIT.java @@ -35,9 +35,8 @@ public void typeof_sql_types() { "SELECT" + " typeof(CAST('1961-04-12 09:07:00' AS TIMESTAMP))," + " typeof(CAST('09:07:00' AS TIME))," - + " typeof(CAST('1961-04-12' AS DATE))," - + " typeof(DATETIME('1961-04-12 09:07:00'))"); - verifyDataRows(response, rows("TIMESTAMP", "TIME", "DATE", "DATETIME")); + + " typeof(CAST('1961-04-12' AS DATE))"); + verifyDataRows(response, rows("TIMESTAMP", "TIME", "DATE")); } @Test diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/data/type/OpenSearchDateType.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/data/type/OpenSearchDateType.java index d0a924c494..7e6bee77c2 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/data/type/OpenSearchDateType.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/data/type/OpenSearchDateType.java @@ -375,7 +375,6 @@ public static boolean isDateTypeCompatible(ExprType exprType) { } switch ((ExprCoreType) exprType) { case TIMESTAMP: - case DATETIME: case DATE: case TIME: return true; diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactory.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactory.java index 22c2ece4a7..3341e01ab2 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactory.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactory.java @@ -8,7 +8,6 @@ import static org.opensearch.sql.data.type.ExprCoreType.ARRAY; import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; import static org.opensearch.sql.data.type.ExprCoreType.FLOAT; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; @@ -20,7 +19,6 @@ 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; -import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -29,6 +27,7 @@ import java.time.Instant; import java.time.LocalDate; import java.time.LocalTime; +import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.format.DateTimeParseException; import java.time.temporal.TemporalAccessor; @@ -132,8 +131,6 @@ public void extendTypeMapping(Map typeMapping) { .put( OpenSearchDateType.of(TIMESTAMP), OpenSearchExprValueFactory::createOpenSearchDateType) - .put( - OpenSearchDateType.of(DATETIME), OpenSearchExprValueFactory::createOpenSearchDateType) .put( OpenSearchDataType.of(OpenSearchDataType.MappingType.Ip), (c, dt) -> new OpenSearchExprIpValue(c.stringValue())) @@ -241,11 +238,12 @@ private static ExprValue parseDateTimeString(String value, OpenSearchDateType da ZonedDateTime zonedDateTime = DateFormatters.from(accessor); switch (returnFormat) { case TIME: - return new ExprTimeValue(zonedDateTime.withZoneSameLocal(UTC_ZONE_ID).toLocalTime()); + return new ExprTimeValue(zonedDateTime.withZoneSameLocal(ZoneOffset.UTC).toLocalTime()); case DATE: - return new ExprDateValue(zonedDateTime.withZoneSameLocal(UTC_ZONE_ID).toLocalDate()); + return new ExprDateValue(zonedDateTime.withZoneSameLocal(ZoneOffset.UTC).toLocalDate()); default: - return new ExprTimestampValue(zonedDateTime.withZoneSameLocal(UTC_ZONE_ID).toInstant()); + return new ExprTimestampValue( + zonedDateTime.withZoneSameLocal(ZoneOffset.UTC).toInstant()); } } catch (IllegalArgumentException ignored) { // nothing to do, try another format @@ -291,9 +289,9 @@ private static ExprValue createOpenSearchDateType(Content value, ExprType type) Instant instant = Instant.ofEpochMilli(epochMillis); switch ((ExprCoreType) returnFormat) { case TIME: - return new ExprTimeValue(LocalTime.from(instant.atZone(UTC_ZONE_ID))); + return new ExprTimeValue(LocalTime.from(instant.atZone(ZoneOffset.UTC))); case DATE: - return new ExprDateValue(LocalDate.ofInstant(instant, UTC_ZONE_ID)); + return new ExprDateValue(LocalDate.ofInstant(instant, ZoneOffset.UTC)); default: return new ExprTimestampValue(instant); } diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/aggregation/ExpressionAggregationScript.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/aggregation/ExpressionAggregationScript.java index 7e7b2e959a..06cca5dcc6 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/aggregation/ExpressionAggregationScript.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/aggregation/ExpressionAggregationScript.java @@ -49,7 +49,6 @@ public Object execute() { // Can't get timestamp from `ExprTimeValue` return MILLIS.between(LocalTime.MIN, expr.timeValue()); case DATE: - case DATETIME: case TIMESTAMP: return expr.timestampValue().toEpochMilli(); default: diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/BucketAggregationBuilder.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/BucketAggregationBuilder.java index 4485626742..ff66ec425a 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/BucketAggregationBuilder.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/BucketAggregationBuilder.java @@ -6,7 +6,6 @@ package org.opensearch.sql.opensearch.storage.script.aggregation.dsl; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.TIME; import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP; @@ -66,7 +65,7 @@ private CompositeValuesSourceBuilder buildCompositeValuesSourceBuilder( .missingOrder(missingOrder) .order(sortOrder); // Time types values are converted to LONG in ExpressionAggregationScript::execute - if (List.of(TIMESTAMP, TIME, DATE, DATETIME).contains(expr.getDelegated().type())) { + if (List.of(TIMESTAMP, TIME, DATE).contains(expr.getDelegated().type())) { sourceBuilder.userValuetypeHint(ValueType.LONG); } return helper.build(expr.getDelegated(), sourceBuilder::field, sourceBuilder::script); diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/LuceneQuery.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/LuceneQuery.java index 753c2bbbc7..11533c754e 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/LuceneQuery.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/LuceneQuery.java @@ -14,7 +14,6 @@ import org.opensearch.sql.data.model.ExprBooleanValue; import org.opensearch.sql.data.model.ExprByteValue; import org.opensearch.sql.data.model.ExprDateValue; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprDoubleValue; import org.opensearch.sql.data.model.ExprFloatValue; import org.opensearch.sql.data.model.ExprIntegerValue; @@ -225,15 +224,6 @@ private ExprValue cast(FunctionExpression castFunction) { return new ExprTimeValue(expr.valueOf().timeValue()); } }) - .put( - BuiltinFunctionName.CAST_TO_DATETIME.getName(), - expr -> { - if (expr.type().equals(ExprCoreType.STRING)) { - return new ExprDatetimeValue(expr.valueOf().stringValue()); - } else { - return new ExprDatetimeValue(expr.valueOf().datetimeValue()); - } - }) .put( BuiltinFunctionName.CAST_TO_TIMESTAMP.getName(), expr -> { diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/data/type/OpenSearchDateTypeTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/data/type/OpenSearchDateTypeTest.java index a9511f8c0b..34738224e7 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/data/type/OpenSearchDateTypeTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/data/type/OpenSearchDateTypeTest.java @@ -12,7 +12,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.TIME; import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP; import static org.opensearch.sql.opensearch.data.type.OpenSearchDateType.SUPPORTED_NAMED_DATETIME_FORMATS; @@ -43,14 +42,14 @@ class OpenSearchDateTypeTest { private static final String timeFormatString = "hourMinuteSecond"; - private static final String datetimeFormatString = "basic_date_time"; + private static final String timestampFormatString = "basic_date_time"; private static final OpenSearchDateType defaultDateType = OpenSearchDateType.of(defaultFormatString); private static final OpenSearchDateType dateDateType = OpenSearchDateType.of(dateFormatString); private static final OpenSearchDateType timeDateType = OpenSearchDateType.of(timeFormatString); private static final OpenSearchDateType datetimeDateType = - OpenSearchDateType.of(datetimeFormatString); + OpenSearchDateType.of(timestampFormatString); @Test public void isCompatible() { @@ -59,25 +58,16 @@ public void isCompatible() { () -> assertTrue(TIMESTAMP.isCompatible(defaultDateType)), () -> assertTrue(TIMESTAMP.isCompatible(dateDateType)), () -> assertTrue(TIMESTAMP.isCompatible(timeDateType)), - () -> assertTrue(TIMESTAMP.isCompatible(datetimeDateType)), - - // datetime - () -> assertFalse(DATETIME.isCompatible(defaultDateType)), - () -> assertTrue(DATETIME.isCompatible(dateDateType)), - () -> assertTrue(DATETIME.isCompatible(timeDateType)), - () -> assertFalse(DATETIME.isCompatible(datetimeDateType)), // time type () -> assertFalse(TIME.isCompatible(defaultDateType)), () -> assertFalse(TIME.isCompatible(dateDateType)), () -> assertTrue(TIME.isCompatible(timeDateType)), - () -> assertFalse(TIME.isCompatible(datetimeDateType)), // date type () -> assertFalse(DATE.isCompatible(defaultDateType)), () -> assertTrue(DATE.isCompatible(dateDateType)), - () -> assertFalse(DATE.isCompatible(timeDateType)), - () -> assertFalse(DATE.isCompatible(datetimeDateType))); + () -> assertFalse(DATE.isCompatible(timeDateType))); } // `typeName` and `legacyTypeName` return the same thing for date objects: @@ -88,8 +78,7 @@ public void check_typeName() { // always use the MappingType of "DATE" () -> assertEquals("DATE", defaultDateType.typeName()), () -> assertEquals("DATE", timeDateType.typeName()), - () -> assertEquals("DATE", dateDateType.typeName()), - () -> assertEquals("DATE", datetimeDateType.typeName())); + () -> assertEquals("DATE", dateDateType.typeName())); } @Test @@ -98,8 +87,7 @@ public void check_legacyTypeName() { // always use the legacy "DATE" type () -> assertEquals("DATE", defaultDateType.legacyTypeName()), () -> assertEquals("DATE", timeDateType.legacyTypeName()), - () -> assertEquals("DATE", dateDateType.legacyTypeName()), - () -> assertEquals("DATE", datetimeDateType.legacyTypeName())); + () -> assertEquals("DATE", dateDateType.legacyTypeName())); } @Test @@ -108,8 +96,7 @@ public void check_exprTypeName() { // exprType changes based on type (no datetime): () -> assertEquals(TIMESTAMP, defaultDateType.getExprType()), () -> assertEquals(TIME, timeDateType.getExprType()), - () -> assertEquals(DATE, dateDateType.getExprType()), - () -> assertEquals(TIMESTAMP, datetimeDateType.getExprType())); + () -> assertEquals(DATE, dateDateType.getExprType())); } private static Stream getAllSupportedFormats() { diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactoryTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactoryTest.java index bfc06b94c0..83e26f85e4 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactoryTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactoryTest.java @@ -24,7 +24,6 @@ import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN; import static org.opensearch.sql.data.type.ExprCoreType.BYTE; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; import static org.opensearch.sql.data.type.ExprCoreType.FLOAT; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; @@ -34,7 +33,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.DateTimeUtils.UTC_ZONE_ID; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -42,6 +40,7 @@ import java.time.Instant; import java.time.LocalDate; import java.time.LocalTime; +import java.time.ZoneOffset; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -50,7 +49,6 @@ import org.junit.jupiter.api.Test; import org.opensearch.sql.data.model.ExprCollectionValue; import org.opensearch.sql.data.model.ExprDateValue; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprTimeValue; import org.opensearch.sql.data.model.ExprTimestampValue; import org.opensearch.sql.data.model.ExprTupleValue; @@ -72,7 +70,6 @@ class OpenSearchExprValueFactoryTest { .put("doubleV", OpenSearchDataType.of(DOUBLE)) .put("stringV", OpenSearchDataType.of(STRING)) .put("dateV", OpenSearchDateType.of(DATE)) - .put("datetimeV", OpenSearchDateType.of(DATETIME)) .put("timeV", OpenSearchDateType.of(TIME)) .put("timestampV", OpenSearchDateType.of(TIMESTAMP)) .put("datetimeDefaultV", OpenSearchDateType.of()) @@ -248,7 +245,7 @@ public void constructDates() { () -> assertEquals( new ExprDateValue( - LocalDate.ofInstant(Instant.ofEpochMilli(450576000000L), UTC_ZONE_ID)), + LocalDate.ofInstant(Instant.ofEpochMilli(450576000000L), ZoneOffset.UTC)), constructFromObject("dateV", 450576000000L)), () -> assertEquals( @@ -270,7 +267,7 @@ public void constructTimes() { () -> assertEquals( new ExprTimeValue( - LocalTime.from(Instant.ofEpochMilli(1420070400001L).atZone(UTC_ZONE_ID))), + LocalTime.from(Instant.ofEpochMilli(1420070400001L).atZone(ZoneOffset.UTC))), constructFromObject("timeV", 1420070400001L)), () -> assertEquals( @@ -337,14 +334,6 @@ public void constructDatetime() { assertEquals( new ExprTimestampValue("2015-01-01 12:10:30"), constructFromObject("timestampV", "2015-01-01 12:10:30")), - () -> - assertEquals( - new ExprDatetimeValue("2015-01-01 12:10:30"), - constructFromObject("datetimeV", "2015-01-01 12:10:30")), - () -> - assertEquals( - new ExprDatetimeValue("2015-01-01 12:10:30"), - constructFromObject("datetimeDefaultV", "2015-01-01 12:10:30")), () -> assertEquals( new ExprTimestampValue(Instant.ofEpochMilli(1420070400001L)), @@ -366,7 +355,7 @@ public void constructDatetime() { @Test public void constructDatetime_fromCustomFormat() { assertEquals( - new ExprDatetimeValue("2015-01-01 12:10:30"), + new ExprTimestampValue("2015-01-01 12:10:30"), constructFromObject("customFormatV", "2015-01-01-12-10-30")); IllegalArgumentException exception = @@ -378,11 +367,11 @@ public void constructDatetime_fromCustomFormat() { exception.getMessage()); assertEquals( - new ExprDatetimeValue("2015-01-01 12:10:30"), + new ExprTimestampValue("2015-01-01 12:10:30"), constructFromObject("customAndEpochMillisV", "2015-01-01 12:10:30")); assertEquals( - new ExprDatetimeValue("2015-01-01 12:10:30"), + new ExprTimestampValue("2015-01-01 12:10:30"), constructFromObject("customAndEpochMillisV", "2015-01-01-12-10-30")); } @@ -626,7 +615,7 @@ public void constructBinaryArrayReturnsFirstIndex() { @Test public void constructArrayOfCustomEpochMillisReturnsFirstIndex() { assertEquals( - new ExprDatetimeValue("2015-01-01 12:10:30"), + new ExprTimestampValue("2015-01-01 12:10:30"), tupleValue("{\"customAndEpochMillisV\":[\"2015-01-01 12:10:30\",\"1999-11-09 01:09:44\"]}") .get("customAndEpochMillisV")); } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilderTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilderTest.java index 6485dce124..1bb988dacd 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilderTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilderTest.java @@ -13,7 +13,6 @@ import static org.mockito.Mockito.doAnswer; import static org.opensearch.sql.common.utils.StringUtils.format; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; import static org.opensearch.sql.data.type.ExprCoreType.STRING; @@ -150,20 +149,6 @@ void should_build_type_mapping_for_field_reference() { map("name", OpenSearchDataType.of(STRING)))); } - @Test - void should_build_type_mapping_for_datetime_type() { - assertThat( - buildTypeMapping( - Arrays.asList( - named( - "avg(datetime)", - new AvgAggregator(Arrays.asList(ref("datetime", DATETIME)), DATETIME))), - Arrays.asList(named("datetime", ref("datetime", DATETIME)))), - containsInAnyOrder( - map("avg(datetime)", OpenSearchDateType.of(DATETIME)), - map("datetime", OpenSearchDateType.of(DATETIME)))); - } - @Test void should_build_type_mapping_for_timestamp_type() { assertThat( diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/ExpressionAggregationScriptTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/ExpressionAggregationScriptTest.java index 520e301301..6d90cce704 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/ExpressionAggregationScriptTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/ExpressionAggregationScriptTest.java @@ -34,7 +34,6 @@ import org.opensearch.search.lookup.LeafSearchLookup; import org.opensearch.search.lookup.SearchLookup; import org.opensearch.sql.data.model.ExprDateValue; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprTimestampValue; import org.opensearch.sql.expression.DSL; import org.opensearch.sql.expression.Expression; @@ -113,14 +112,6 @@ void can_execute_expression_interpret_dates_for_aggregation() { .shouldMatch(new ExprDateValue(LocalDate.of(1961, 4, 12)).timestampValue().toEpochMilli()); } - @Test - void can_execute_expression_interpret_datetimes_for_aggregation() { - assertThat() - .docValues("datetime", "1984-03-17 22:16:42") - .evaluate(DSL.datetime(ref("datetime", STRING))) - .shouldMatch(new ExprDatetimeValue("1984-03-17 22:16:42").timestampValue().toEpochMilli()); - } - @Test void can_execute_expression_interpret_times_for_aggregation() { assertThat() diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/BucketAggregationBuilderTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/BucketAggregationBuilderTest.java index d11d7da2fe..4250b3297f 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/BucketAggregationBuilderTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/BucketAggregationBuilderTest.java @@ -137,7 +137,7 @@ void should_build_bucket_with_parse_expression() { @ParameterizedTest(name = "{0}") @EnumSource( value = ExprCoreType.class, - names = {"TIMESTAMP", "TIME", "DATE", "DATETIME"}) + names = {"TIMESTAMP", "TIME", "DATE"}) void terms_bucket_for_datetime_types_uses_long(ExprType dataType) { assertEquals( "{\n" diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/ExpressionFilterScriptTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/ExpressionFilterScriptTest.java index cca51c8f4a..df754887cf 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/ExpressionFilterScriptTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/ExpressionFilterScriptTest.java @@ -15,7 +15,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.FLOAT; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; import static org.opensearch.sql.data.type.ExprCoreType.STRING; @@ -116,15 +115,6 @@ void can_execute_expression_with_timestamp_field() { .shouldMatch(); } - @Test - void can_execute_expression_with_datetime_field() { - ExprTimestampValue ts = new ExprTimestampValue("2020-08-04 10:00:00"); - assertThat() - .docValues("birthday", ZonedDateTime.parse("2020-08-04T10:00:00Z")) - .filterBy(DSL.equal(ref("birthday", DATETIME), new LiteralExpression(ts))) - .shouldMatch(); - } - @Test void can_execute_expression_with_date_field() { ExprDateValue date = new ExprDateValue("2020-08-04"); diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilderTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilderTest.java index 1fc2d5ee29..90b982e017 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilderTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilderTest.java @@ -13,7 +13,6 @@ import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN; import static org.opensearch.sql.data.type.ExprCoreType.BYTE; import static org.opensearch.sql.data.type.ExprCoreType.DATE; -import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; import static org.opensearch.sql.data.type.ExprCoreType.FLOAT; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; @@ -42,7 +41,6 @@ import org.opensearch.sql.common.antlr.SyntaxCheckException; import org.opensearch.sql.common.utils.StringUtils; import org.opensearch.sql.data.model.ExprDateValue; -import org.opensearch.sql.data.model.ExprDatetimeValue; import org.opensearch.sql.data.model.ExprTimeValue; import org.opensearch.sql.data.model.ExprTimestampValue; import org.opensearch.sql.data.model.ExprTupleValue; @@ -1787,7 +1785,7 @@ void cast_to_date_in_filter() { buildQuery( DSL.equal( ref("date_value", DATE), - DSL.castDate(literal(new ExprDatetimeValue("2021-11-08 17:00:00")))))); + DSL.castDate(literal(new ExprTimestampValue("2021-11-08 17:00:00")))))); } @Test @@ -1817,32 +1815,6 @@ void cast_to_time_in_filter() { DSL.castTime(literal(new ExprTimestampValue("2021-11-08 17:00:00")))))); } - @Test - void cast_to_datetime_in_filter() { - String json = - "{\n" - + " \"term\" : {\n" - + " \"datetime_value\" : {\n" - + " \"value\" : \"2021-11-08 17:00:00\",\n" - + " \"boost\" : 1.0\n" - + " }\n" - + " }\n" - + "}"; - - assertJsonEquals( - json, - buildQuery( - DSL.equal( - ref("datetime_value", DATETIME), - DSL.castDatetime(literal("2021-11-08 17:00:00"))))); - assertJsonEquals( - json, - buildQuery( - DSL.equal( - ref("datetime_value", DATETIME), - DSL.castDatetime(literal(new ExprTimestampValue("2021-11-08 17:00:00")))))); - } - @Test void cast_to_timestamp_in_filter() { String json =