From d429c001f75a2ad8215b37d5caa09de15425b4f4 Mon Sep 17 00:00:00 2001 From: Matthew Wells Date: Wed, 16 Aug 2023 17:15:07 -0700 Subject: [PATCH] Remove Datetime data type (#336) * removed datetime type, updated tests and documentation Signed-off-by: Matthew Wells --- .../sql/data/model/ExprDateValue.java | 6 - .../sql/data/model/ExprDatetimeValue.java | 99 -- .../sql/data/model/ExprStringValue.java | 22 +- .../sql/data/model/ExprTimeValue.java | 5 - .../sql/data/model/ExprTimestampValue.java | 10 +- .../opensearch/sql/data/model/ExprValue.java | 7 - .../sql/data/model/ExprValueUtils.java | 11 +- .../sql/data/type/ExprCoreType.java | 3 +- .../org/opensearch/sql/expression/DSL.java | 4 - .../aggregation/AggregatorFunction.java | 10 - .../expression/aggregation/AvgAggregator.java | 25 - .../datetime/DateTimeFormatterUtil.java | 10 +- .../expression/datetime/DateTimeFunction.java | 492 ++---- .../operator/convert/TypeCastOperator.java | 31 +- .../planner/physical/collector/Rounding.java | 26 - .../opensearch/sql/utils/DateTimeUtils.java | 7 +- .../opensearch/sql/analysis/AnalyzerTest.java | 2 +- .../sql/data/model/DateTimeValueTest.java | 98 +- .../sql/data/model/ExprValueCompareTest.java | 59 +- .../sql/data/model/ExprValueUtilsTest.java | 12 +- .../sql/data/type/ExprTypeTest.java | 2 - .../aggregation/AvgAggregatorTest.java | 18 +- .../aggregation/CountAggregatorTest.java | 7 - .../aggregation/MaxAggregatorTest.java | 7 - .../aggregation/MinAggregatorTest.java | 7 - .../datetime/AddTimeAndSubTimeTest.java | 40 +- .../expression/datetime/ConvertTZTest.java | 78 +- .../datetime/DateAddAndAddDateTest.java | 102 +- .../sql/expression/datetime/DateDiffTest.java | 2 +- .../datetime/DateSubAndSubDateTest.java | 80 +- .../datetime/DateTimeFunctionTest.java | 65 +- .../sql/expression/datetime/DateTimeTest.java | 32 +- .../expression/datetime/DateTimeTestBase.java | 10 +- .../sql/expression/datetime/ExtractTest.java | 6 +- .../expression/datetime/FromUnixTimeTest.java | 8 +- .../datetime/NowLikeFunctionTest.java | 19 +- .../expression/datetime/StrToDateTest.java | 37 +- .../expression/datetime/TimeStampAddTest.java | 17 +- .../datetime/TimeStampDiffTest.java | 33 +- .../expression/datetime/TimestampTest.java | 11 +- .../expression/datetime/ToSecondsTest.java | 2 - .../datetime/UnixTimeStampTest.java | 3 +- .../datetime/UnixTwoWayConversionTest.java | 14 +- .../sql/expression/datetime/YearweekTest.java | 6 +- .../BuiltinFunctionRepositoryTest.java | 4 +- .../function/WideningTypeRuleTest.java | 9 +- .../convert/TypeCastOperatorTest.java | 29 +- .../BinaryPredicateOperatorTest.java | 4 +- .../system/SystemFunctionsTest.java | 3 - .../physical/AggregationOperatorTest.java | 32 +- .../physical/PhysicalPlanTestBase.java | 21 +- .../opensearch/sql/utils/ComparisonUtil.java | 8 +- docs/dev/img/type-hierarchy-tree-final.png | Bin 0 -> 30902 bytes docs/user/dql/expressions.rst | 6 +- docs/user/dql/functions.rst | 194 +-- docs/user/general/datatypes.rst | 127 +- docs/user/ppl/functions/datetime.rst | 197 ++- docs/user/ppl/functions/system.rst | 2 +- docs/user/ppl/general/datatypes.rst | 37 +- .../sql/ppl/ConvertTZFunctionIT.java | 28 +- .../sql/ppl/DateTimeComparisonIT.java | 716 ++------ .../sql/ppl/DateTimeFunctionIT.java | 1455 ++++++----------- .../sql/ppl/DateTimeImplementationIT.java | 147 +- .../opensearch/sql/ppl/SystemFunctionIT.java | 7 +- .../org/opensearch/sql/sql/AggregationIT.java | 32 +- .../sql/sql/ConvertTZFunctionIT.java | 36 +- .../sql/sql/DateTimeComparisonIT.java | 838 +++------- .../sql/sql/DateTimeFunctionIT.java | 929 +++++------ .../sql/sql/DateTimeImplementationIT.java | 114 +- .../opensearch/sql/sql/SystemFunctionIT.java | 14 +- .../data/type/OpenSearchDateType.java | 1 - .../value/OpenSearchExprValueFactory.java | 3 - .../ExpressionAggregationScript.java | 1 - .../dsl/BucketAggregationBuilder.java | 3 +- .../script/filter/lucene/LuceneQuery.java | 8 - .../data/type/OpenSearchDateTypeTest.java | 25 +- .../value/OpenSearchExprValueFactoryTest.java | 17 +- .../AggregationQueryBuilderTest.java | 14 - .../ExpressionAggregationScriptTest.java | 11 - .../dsl/BucketAggregationBuilderTest.java | 2 +- .../filter/ExpressionFilterScriptTest.java | 10 - .../script/filter/FilterQueryBuilderTest.java | 24 +- 82 files changed, 2279 insertions(+), 4374 deletions(-) delete mode 100644 core/src/main/java/org/opensearch/sql/data/model/ExprDatetimeValue.java create mode 100644 docs/dev/img/type-hierarchy-tree-final.png 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..fbaeecab3d 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 @@ -11,7 +11,6 @@ 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; @@ -57,11 +56,6 @@ 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(); 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..94c13318bb 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 @@ -11,7 +11,6 @@ import java.time.Instant; import java.time.LocalDate; -import java.time.LocalDateTime; import java.time.LocalTime; import java.time.ZonedDateTime; import java.time.format.DateTimeParseException; @@ -57,10 +56,6 @@ 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(); } 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..4ac60312d7 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 @@ -42,6 +42,11 @@ public ExprTimestampValue(String timestamp) { } } + /** localDateTime Constructor. */ + public ExprTimestampValue(LocalDateTime localDateTime) { + this.timestamp = localDateTime.atZone(UTC_ZONE_ID).toInstant(); + } + @Override public String value() { return timestamp.getNano() == 0 @@ -71,11 +76,6 @@ public LocalTime timeValue() { return timestamp.atZone(UTC_ZONE_ID).toLocalTime(); } - @Override - public LocalDateTime datetimeValue() { - return timestamp.atZone(UTC_ZONE_ID).toLocalDateTime(); - } - @Override public boolean isDateTime() { return true; 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..701b865a03 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 @@ -5,6 +5,8 @@ package org.opensearch.sql.expression.datetime; +import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID; + import com.google.common.collect.ImmutableMap; import java.text.ParsePosition; import java.time.Clock; @@ -21,9 +23,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 +247,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(UTC_ZONE_ID).toLocalDateTime(); return getFormattedString(formatExpr, DATE_HANDLERS, date); } @@ -364,7 +366,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..723e173883 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; @@ -43,7 +42,7 @@ 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 +73,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 +109,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 +149,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 +249,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 +274,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 +323,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 +365,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 +379,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 +386,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 +419,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 +441,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 +490,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 +522,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 +554,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 +572,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 +587,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 +600,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 +614,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 +625,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 +646,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 +661,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 +701,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 +735,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 +753,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 +775,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 +789,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 +796,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 +837,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 +860,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 +871,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 +903,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 +925,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 +945,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 +953,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 +988,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 +1010,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 +1025,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 +1036,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 +1052,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 +1077,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 +1087,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 +1096,6 @@ private DefaultFunctionResolver yearweek() { * Detailed supported signatures:
* (STRING, STRING) -> STRING
* (DATE, STRING) -> STRING
- * (DATETIME, STRING) -> STRING
* (TIME, STRING) -> STRING
* (TIMESTAMP, STRING) -> STRING */ @@ -1255,8 +1104,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 +1146,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 +1156,21 @@ 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(UTC_ZONE_ID).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,16 @@ 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(UTC_ZONE_ID).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 +1243,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(UTC_ZONE_ID).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 +1267,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 +1286,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(UTC_ZONE_ID).toLocalDateTime()) + .atZone(convertedFromTz); + return new ExprTimestampValue( zonedDateTime.withZoneSameInstant(convertedToTz).toLocalDateTime()); // Catches exception for invalid timezones. @@ -1484,43 +1330,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 +1395,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 +1405,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 +1423,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(UTC_ZONE_ID).toLocalDateTime(); String text = arg.format(DateTimeFormatter.ofPattern(extract_formats.get(partName), Locale.ENGLISH)); @@ -1596,11 +1442,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 +1459,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,7 +1483,7 @@ 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) { @@ -1694,11 +1540,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 +1778,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 +1791,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 +1803,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 +1858,7 @@ 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(UTC_ZONE_ID).toLocalDateTime(); ChronoUnit temporalUnit; switch (part) { @@ -2047,13 +1893,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 +1941,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(UTC_ZONE_ID).toLocalDateTime(), + endTimeExpr.timestampValue().atZone(UTC_ZONE_ID).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(UTC_ZONE_ID).toLocalDateTime(), + extractTimestamp(endTimeExpr, fp).atZone(UTC_ZONE_ID).toLocalDateTime()); } /** @@ -2135,7 +1983,7 @@ 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()); + return new ExprTimestampValue(zdt.toLocalDateTime()); } /** @@ -2151,12 +1999,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 +2075,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 +2086,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 +2119,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 +2169,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 +2209,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 +2220,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..af82a8af77 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,7 +6,6 @@ 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; @@ -15,7 +14,6 @@ import java.time.Instant; import java.time.LocalDate; -import java.time.LocalDateTime; import java.time.LocalTime; import java.time.temporal.ChronoField; import java.util.Arrays; @@ -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; 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..40c8200818 100644 --- a/core/src/main/java/org/opensearch/sql/utils/DateTimeUtils.java +++ b/core/src/main/java/org/opensearch/sql/utils/DateTimeUtils.java @@ -136,11 +136,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(); } /** 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..e5768f45f2 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 @@ -36,8 +36,8 @@ 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()); exception = assertThrows(ExpressionEvaluationException.class, timeValue::timestampValue); assertEquals("invalid to get timestampValue from value of type TIME", exception.getMessage()); @@ -45,7 +45,9 @@ public void timeValueInterfaceTest() { var today = LocalDate.now(functionProperties.getQueryStartClock()); assertEquals(today, timeValue.dateValue(functionProperties)); - assertEquals(today.atTime(1, 1, 1), timeValue.datetimeValue(functionProperties)); + assertEquals( + today.atTime(1, 1, 1), + LocalDateTime.ofInstant(timeValue.timestampValue(functionProperties), UTC_ZONE_ID)); assertEquals( ZonedDateTime.of(LocalTime.parse("01:01:01").atDate(today), UTC_ZONE_ID).toInstant(), timeValue.timestampValue(functionProperties)); @@ -69,7 +71,9 @@ public void timestampValueInterfaceTest() { 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(), UTC_ZONE_ID)); assertThrows( ExpressionEvaluationException.class, () -> integerValue(1).timestampValue(), @@ -82,7 +86,9 @@ 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( + LocalDateTime.parse("2012-07-07T00:00:00"), + LocalDateTime.ofInstant(dateValue.timestampValue(), UTC_ZONE_ID)); assertEquals( ZonedDateTime.of(LocalDateTime.parse("2012-07-07T00:00:00"), UTC_ZONE_ID).toInstant(), dateValue.timestampValue()); @@ -91,23 +97,6 @@ public void dateValueInterfaceTest() { 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 = @@ -136,41 +125,11 @@ public void timestampInUnsupportedFormat() { exception.getMessage()); } - @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() { - ExprValue stringValue = new ExprStringValue("2020-08-17 19:44:00"); - - assertEquals(LocalDateTime.parse("2020-08-17T19:44:00"), stringValue.datetimeValue()); - 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()); - - SemanticCheckException exception = - assertThrows( - SemanticCheckException.class, - () -> new ExprStringValue("2020-07-07T01:01:01Z").datetimeValue()); - assertEquals( - "datetime:2020-07-07T01:01:01Z in unsupported format, " - + "please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'", - exception.getMessage()); - } - @Test public void stringDateValue() { ExprValue stringValue = new ExprStringValue("2020-08-17"); - assertEquals(LocalDateTime.parse("2020-08-17T00:00:00"), stringValue.datetimeValue()); + assertEquals(LocalDate.parse("2020-08-17"), stringValue.dateValue()); assertEquals(LocalDate.parse("2020-08-17"), stringValue.dateValue()); assertEquals("\"2020-08-17\"", stringValue.toString()); @@ -228,28 +187,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(), UTC_ZONE_ID)); } } @@ -260,8 +200,8 @@ public void timestampOverMaxNanoPrecision() { SemanticCheckException.class, () -> new ExprTimestampValue("2020-07-07 01:01:01.1234567890")); assertEquals( - "timestamp:2020-07-07 01:01:01.1234567890 in unsupported format, please use " - + "'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'", + "timestamp:2020-07-07 01:01:01.1234567890 in unsupported format, " + + "please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'", exception.getMessage()); } @@ -270,9 +210,9 @@ public void datetimeOverMaxNanoPrecision() { SemanticCheckException exception = assertThrows( SemanticCheckException.class, - () -> new ExprDatetimeValue("2020-07-07 01:01:01.1234567890")); + () -> new ExprTimestampValue("2020-07-07 01:01:01.1234567890")); assertEquals( - "datetime:2020-07-07 01:01:01.1234567890 in unsupported format, " + "timestamp:2020-07-07 01:01:01.1234567890 in unsupported format, " + "please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'", exception.getMessage()); } 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..ad57421dbd 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,21 @@ private static Stream getEqualDatetimeValuesOfDifferentTypes() { public void compareEqDifferentDateTimeValueTypes(ExprValue left, ExprValue right) { assertEquals( 0, - extractDateTime(left, functionProperties) - .compareTo(extractDateTime(right, functionProperties))); + extractTimestamp(left, functionProperties) + .compareTo(extractTimestamp(right, functionProperties))); assertEquals( 0, - extractDateTime(right, functionProperties) - .compareTo(extractDateTime(left, functionProperties))); + extractTimestamp(right, functionProperties) + .compareTo(extractTimestamp(left, 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 +111,12 @@ private static Stream getNotEqualDatetimeValuesOfDifferentTypes() { public void compareNeqDifferentDateTimeValueTypes(ExprValue left, ExprValue right) { assertNotEquals( 0, - extractDateTime(left, functionProperties) - .compareTo(extractDateTime(right, functionProperties))); + extractTimestamp(left, functionProperties) + .compareTo(extractTimestamp(right, functionProperties))); assertNotEquals( 0, - extractDateTime(right, functionProperties) - .compareTo(extractDateTime(left, functionProperties))); + extractTimestamp(right, functionProperties) + .compareTo(extractTimestamp(left, 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..de9d3b0e03 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,7 +13,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.INTERVAL; import static org.opensearch.sql.data.type.ExprCoreType.STRING; import static org.opensearch.sql.data.type.ExprCoreType.STRUCT; @@ -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,7 +129,6 @@ 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(), Duration.ofSeconds(100)); Stream.Builder builder = Stream.builder(); @@ -237,9 +233,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 +253,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..44f7e08f2e 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,12 +9,12 @@ 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; 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; @@ -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(UTC_ZONE_ID).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..e26f61028e 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,8 +6,9 @@ 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 static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID; import java.time.Instant; import java.time.LocalDate; @@ -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,11 @@ 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(UTC_ZONE_ID).toLocalDateTime()); res = subtime(arg1, arg2); - assertEquals(DATETIME, res.type()); - assertEquals(subTimeExpectedResult, res.datetimeValue()); + assertEquals(TIMESTAMP, res.type()); + assertEquals(subTimeExpectedResult, res.timestampValue().atZone(UTC_ZONE_ID).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..0ed462abba 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,8 @@ 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 static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID; import java.time.Duration; import java.time.Instant; @@ -29,81 +30,98 @@ 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(UTC_ZONE_ID).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(UTC_ZONE_ID).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(UTC_ZONE_ID).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(UTC_ZONE_ID).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(UTC_ZONE_ID).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(UTC_ZONE_ID).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(UTC_ZONE_ID).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(UTC_ZONE_ID).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(UTC_ZONE_ID).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(UTC_ZONE_ID).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(UTC_ZONE_ID).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(UTC_ZONE_ID).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(UTC_ZONE_ID).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(UTC_ZONE_ID).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(UTC_ZONE_ID).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(UTC_ZONE_ID).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..e306896362 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,8 @@ 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 static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID; import java.time.Duration; import java.time.Instant; @@ -18,10 +19,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(UTC_ZONE_ID).toLocalDateTime(); + } + private LocalDate today() { return LocalDate.now(functionProperties.getQueryStartClock()); } @@ -29,81 +35,81 @@ 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(UTC_ZONE_ID).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(UTC_ZONE_ID).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..3f3e5f6695 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,14 @@ 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.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 java.time.temporal.ChronoUnit; import java.time.temporal.Temporal; @@ -45,7 +46,7 @@ class NowLikeFunctionTest extends ExpressionTestBase { void now() { test_now_like_functions( DSL::now, - DATETIME, + TIMESTAMP, false, () -> LocalDateTime.now(functionProperties.getQueryStartClock())); } @@ -54,7 +55,7 @@ void now() { void current_timestamp() { test_now_like_functions( DSL::current_timestamp, - DATETIME, + TIMESTAMP, false, () -> LocalDateTime.now(functionProperties.getQueryStartClock())); } @@ -63,7 +64,7 @@ void current_timestamp() { void localtimestamp() { test_now_like_functions( DSL::localtimestamp, - DATETIME, + TIMESTAMP, false, () -> LocalDateTime.now(functionProperties.getQueryStartClock())); } @@ -72,14 +73,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,7 +129,7 @@ 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) { @@ -249,8 +250,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..f1d9a62f63 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 @@ -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(UTC_ZONE_ID).toLocalDateTime()); } /** @@ -83,13 +85,6 @@ public void timestamp_one_arg_date() { 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)); 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..d1ce9bcbcc 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 @@ -9,14 +9,15 @@ 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,7 +29,10 @@ 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() { @@ -86,7 +90,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 0000000000000000000000000000000000000000..883e581efbdbe3fc0f9b0a8902fa6187cb44988a GIT binary patch literal 30902 zcmeFa2UL?;_dXg#jU$f1GJuK!D>~9F2tsH!EFh>Th(fTUAc9H>B?%f)7(`SYP?4e{ zB1jVfr6eFt2PuLvLWCd@kWgY0LLec@J@1=<=*)b-|NY;)?z;D`Z(Vtsc zd{S9-#O3-oWyg?BxAlf9Uq1dteOigyi)jnf12JTiUr#TzwkTf`bv?}Vm;DaZw;7lF zQUXtl?+G>Iu@mxzOUbJzduT+fmf%b&c<|X{}OUC?KsoH*+L!H-r9M+G}j_YuGKrzSP1)Uahp;3`+R} zUz&%g=-gKM(Lbj@*K{ceBXoCB>-Q^t_S*mOtg)n!{v4lBU?zCCii!^|=zlNWhjqxP z;eWuJ(uF44PW~nNlvQqWv9K(%QR=XX_$sWAke;LTtPgP5l$W$ix|m1~VfcuhVtYM> zfh=B$=7V6Px%R&Y1;0z0DsO_w#!KYlseY zVKNCL`NgReI;*_n`{92l#L~5cyn9)yEgfZC$3yK}&Y85%-X{e`qYGoI)3ToQGX7jE z7wDwcl+b~~Ej}e)pRohoN*%fd2llu6JztAz99l1#nP)>gDEVP88u|;v2%;`()IOyS zjmN~7?7+A!0hT30r!TArFX8tFP>5GrQhIfy&Ks7#T8T zO(9FT5>M^-9-g%3F2>>JwB8Ki_q9EBNZf_hyW5nSf3SY5V?mfpabkX`fa}QL5L1tE z^o`S166W_F>SBAp%R1HSi@WvT+yB3<-cIe_6ZvKPQ6bYdm@kl)yIpfL-=;y=HC(=7 zHmo=67XYn&C5;o4vw#^D+%rftGcv>L;ZGNRy4^RtY2=^^P_Au>;&KxyV=k((x>yPP zy?qh%QH0}8=-MJa%mx|+5t0X8L4>Q${|kQQIy+ON&J6FpPE@%1?MHJm4{NU>74=r< zvel|SJ`B_$pZCUyVlN-QYAlHaqIJn(VRmucOs5&;`ZLPa&Z^fEu0KA32*I&PF=A#@ z{Q_~6twy4xKbKU|By|(!9=>WY6y+xMm9!BHS|s>#{i=B)tH;v5z93E=wr=lQgayVI z^Ez%&d&;F;oW3ZqZOX$Jl2?6uc~ffM^=xmOa@AFOa){e3=;-SNyQzuhxH@(y><&XJ zlfYc8FXHsIIUy^65wirlyWA3^7K5{x3+$aHxZ%;7=ovdPn$v-4R7N2}wkxA9FGDMb z;t;EWVk%u4hAf|r3fqVYQ3Ge;I=g~&I2^fo5!zw~xas=8bd+URC_Yd|X-)-4bbIoD zU;BS%ll7mwVKD)Vr(EpZT{4yNmebzaS<`4_lu&YuJ?ZO>?+3TKPa~f2P~yTi9`d^9 zQe%h=Tne3=o!(sTa??2|wN29%_=3RL8%H*gS2nDL4&qW^&UM3{JGfFu-E%`1a%Z|4 z!KcMPvdF7(Ehi+$$5d2$011Qwezr{Z?CrvP`1YrYKsJELY%FmF;%1F;wT`PZ^ZuYP z!xoa9`!4Ig*aR*|>*xErX&Ch)E^EmqGG8_kdRi{(o-cw4%TcQ8%z)?wAS?}j@D$W# zQ+Oqt!nBxrXxOV(vSBgsu*#Jk&B!|A5DqMP?<1}hZ?6a9l`4A_(hM@$Rjv_>1m^p= z!zfCy{}53^X%#U&WB*(O{6#O*8`zopK$zvyXsHc3kU>lB74(r zmt)EF&LZHY+v2@%Lc*>bfwNoB3Ax{|5ufm$cP92mW}?@0gnp(Fu?&)W&6p=uB#lqS z!oesqH(U@?O^TzDZ)B|zw11%LC5z3AefetxXfK6kZ7)aO*PzZg2l;XcEn5rOGHVPp8j4*+rZVQ)o zC=7ZvL3as(c=ZHj4`0tC%_TVfs7aA)Q8z17?WDL(^aIFn970U@k-guWrTFLg`|nBX zNHN$$IKq&n?*abVPWaJsM_<{a*I6X_qbX=qOI2DZ9zSF`KfTU)TVVyMGe>vpW}qWd z_Q|*DiJ7B(n_}xQ+gKJ2Do7QApsXd7ycXqZR3m>X-ON?~6s@D|)hp>n=@jN-4&rid zuQ_cy4JVlW`*9;lKJkF?&5~2vUkjgdhnPuEmmC>lt z7aKhnaFQf!O^4utJi&r@mzZUb)3U@Fm7#weR=ZzSM8&Nk)=Vlr1KZAuHB?-wpEU+O zJc66{d$lPC5z@N&y8t5wff07q3Wx0Kky)s}fTqC%h52#&gga!R0rZmJO~`C(s&JA( z@Y;X`!^AKB?=Z;!NA_k}CCMkmfi=u%#fWRHvJ%Ybeg_sY4bvB)5eJu{5!unOAC!}< zSiGm&eE5ohlIRkF9cA@U&J-0VajbYXht~jaOQ)m&Sh7BKnOk&-czEc^pwlOFB&&G3>XjsSYBNBW$&+<9#U3p&5TkA(Ul>`pyS)%fT4(8GR24^TQC?EXd zwxpX$O$-wQH(*22&~lcJd3jCC(1X2Y8R^(Xu~?$!lNOIrJN?ci&Pro-I5iEoR#Sv8X{N&Ysn+u?Vu^A%&9 zm!p^VZnUJ6SrVcS{*cSJg4PqCJ=`mPxeUTn`8fc8)H)W|kjTR|oQtuHtEnQ%batGE zUR8)Mr#(K-!932qzAE>(mb!b8XN)k}F86`Ue8Q39Cr2%4l>$3AbTXcwNSkuS28${m zzmoF9`Rah*Z{c*yL4%ecB;LWX^pt!mD$Uam~H!Y+KMVjUq-9ZXIw;8cV9FJ`Aa)2 zrI&^A$V4+Uv3N8=2aRZ;e0Nb{|8Vgf)MZ+Jn62&{l**Z04sn+wKOmh>c8W|a0U%RE zO{|xYp;AGT06eZQdHl15iNIwgeFY1AG$p|4>0^!GUKe$NA#P^gccu3CBChKmBnN-C zTH-`m&PgId2mi!HU*^K5oPi9FrZFeU{8WyM&eMbS(@u&^C&fl0J(WfyDoDwN{Udso zhkjE{<81quT5qk462cP4nzE@a*$vq37T7SQSYW<7l(=Hm(^Xo)XSX|z>gf*X%}22i zIV^7S%qbB^Ip-Tukn*!;kB>o7F@5OU`y)`Q1W$tO67Njs7CJ*LaOhPGlfAF%SI=L`r2c$C_fYmb|PTnQVp zJ>;*$U6*dVkk&2jr7i_g1<d7|@S6ToN0v{EQ7VQ+s{r{2QyJINVLVFF#3GO0ley`3oq+u3* z3D$HnaB_#vBp%veMCKh5-uBO_l0-Inywh04332v@qAAq1T|}paMH1GQ#T%j9QoG&p z{8L^uo7mHGg-3NVec{Vj>dg$g!F(tj_H6Ziu#=7ND4PjX@iKJ9Yy~~%=vNcnF!H6~Ii;WXo^zPGIpCS#LUmdV`9S1W*RT^EoOaWrhE-XT_#j?@5d`+( zj3gS;uaeQ6LUBQd`Tib+F|h_{fh1cVPM?T>#QZQYYf&g^9k*-g^M$?dtJj>8rV+0O z;EH+gz3erJpZu)zPd0Jh6&@{mvW<*+t+n~r4h0`A zw2#|N&)KN2dp$6z)px_PJvgqdXAhWV-c1ZWfVaMJxIbz`7}DBByc_~m6cZg6SCImb zG_MOdv<~faph53YcQE%LKi~tNz(EwwK^3mOvOXL+c*+yZZs+EYdARHL)oY_JUEm#! zSO2Y0d(?2DhVRQLVBZ!x5P99Q*@ba5pQuVtO*)Y9)V+84?R;DV|LSFyapW)0z_|#p zkssdJf*q(J4ZOW?qr_>)KCZ6P&)+cf8k>w860-DF7QdQVO{%&RS5xied@XlJ7?Khs zw3YVLBsD?ijs#QRc{G$;Vx50(V_Sc8b)(+AGezPh%&MNe;I;XWBq{X(geLfX!sHYiqA6GrtZ# z)|2El5sQO3?e8>1huR9f`*OL}n~JJPox7ch{ZX4XbMKf33G|+m*BeKf)OQxS`+8$~ z(Rp3W0lm(+XTS0lx^+40`#4>msdgaB`XxySM~<6DXsejT9IUt^w-t}$JH zIj8lkFwQM2>&#K<*TH_4-xaOgAR>WQk8w1rJEg8frQiZN!ydb7xazn+f z5g?%7g#mv~3I{noj9pRHd}gyhSNG%HT@+r@d@83GGrzCZ?B&ffv9HRmRgrjh-V$cq zPO0X3GO?0l`wJ&2aA4DD9qD=Ijx1Y_YYoe5wD^q*Rj;KEY1(&VF>UY<@6!BtwI-tGukCJ!LK`hL}IFhLc3DOI#-MJ|BX_1SM0QBL_(X-mNd%(T%1^c0gEta|$@vW3U;1gKuBe9zH zb5Kbp9O%z>pr?E>U+4eozV{lk=3&3l32ILLgMGASpWyd?!TAFo;VX7vlC*f+UjSbL zeHsHn5D&xWqtq@#SfQnVhh;R*BC*k{gtBd2s?BP2wrNM%wRF{N`NNhCC&y4kpi|ZX zIB_ZZmJR0PS^lK;UX9UzLcXc1eTQXph2mle682fI_15LDB1cQiNq~54gCNOlCTq*- zwq&hUU>6bVeurU#S$(ZW0l@@!Z~kibktxtBG#5j^fL@&gUTq4)!5|?H-W76c7V0h- zel~hw|5od>0<-MRn>R;$ zwg50!KN7?9U_8_VtK$WiV zgL$o&n)q0C-xH?)t^qNzWk_|MWZ$hR2l;tn$SLUwL=Iy4W_TqlAZxQc^o@rp$JHTn zE^2gkQ+m?9kxxE5Blcd$5uxSpI{Ls8Os1y%0D5hK0 z#B(`(T(@LS;^qUr;Yib2D7CwAMrD@0(&zGGO*3G3WG5wmW%#oXb5Mb65-+9SFbq=d zoKlH{(^XYJVAZv^n=aO7Eab%yxS&4{NHuKH#;-iV04mfpzO z*QR|fuk9L0%{V>BU3ZCEc8wwIH|^5+up}+>KR~Ke$fGhsG2I__RHgWivLN<8(d9M|7akW1gg>w%!)(&Q4kCD@Euvhd$T@?t%YsGp~@!r zT(R-8tI^TX*w=bUwaPM1-=o}@xS>65mD6EewAqV1(#7=Td9GZt(BTog#^)Z@FW{Gl z#vi1Wqvu>{_ZDUYXj^L!X2k(ve{N5Zxp;j`v65O@TV!-K;9VSsyvvKweYe06YRpYM z&3FLav3@L__(-y-T3$q8x=Q-4$p1iuyXPWDZIh z1yYS6APNQQC(H^H_V9~z_ftdp5<3(+EJ1Qn-vF950;Gag+t-(`qVm2C}9=_3z~x}pUHZyu|u z$GGNUVeJ@SC4&YOr)~t=ny3d~-w+taTZKtE(FoVZrM|oyC zM^oo@FEKC6jO--cfDJxF?T~(cB|Xh);|E3*5`Oh`(|B4$0JaSpEStD4XrwRbtje0< zt&3$R{KFn^i9&Wi9_=RfVEz3{(`sS_{v|H`i?N%Y;fBfzHD`t5^q-b6qfw6x>pIVV zJ0hXgF`MH&W7!O&k{CGo*$^+2HI$5wQ*$n-YDm0~^#*be4UPsCr}`XzVfY>q3A-;vy#+UCs|s-e58$*(Sgct` z;Mtj5+xncp;Idi7m8q&-H4)s-wbNAyQVZsgb5`u3L66joqIzKUKRXZiDY`8z1+W~f z%YQ!G*PQlIt6yRW7*}eP+EdZlOO;y)wBBW^;`#1M@9y)t+bT$B#}l|RSLLUp)IEoB z#PBJe_DZ~}s9&FNxsbmWS?Hqo@+-}54(ekv4^FaL0`ENhA4GRIvn-|3pALWSSOAgM z>)hp$8jkeI>49hc?O$e{%1Ls0?LQnpsXKzVZ@246p=wFn7V>3a7F8F(`P&&XHy6?p z5g*hrDAPMKbr3NhmA1uSs5jF=;x+XR*LVMx3&%Kx&RGS+-NBqC`<<;YN$IjoQq>Qq z2sA>lfm`vwN57h`Xm11V3HF03MF0w4_2`7xw>xZXeM`{UP4Y)76e~y^9SAg3RExrm z30a52M17{lfSjOS#MUL_Li3aI!o6@k3v$;z0A+1#K7!sTGw|YoTBgnmi-+C8U+VG%~G-@?{ZcpB{)4)gh zb2h3m$oFnm0$0XyuK`w8hzXa1Hi*FyCC9Gg&XC_Wb$E zs2A5+0k}tj=r;UNWwaJBhlkC6i9pU+(P(J_yHn>arZ>U&{gwr$ea-h%1a6X#vK?Nh z!?H~M`m5*gLYINzX4G%89pC%K3n$xSL6%k@nXC_<1P<~q6^gp$<7&->6S57dK&354 z&wZ<~a#k|-tB-eZ_Xf(xQ)^*|9OU3*KaXFvc$`HtDTL)Q3pKqfu}Qq^?M{wK^lDYp&P$P~k&{CmFu zOJ-D8Y(;8X)+WpfNB*dZ=5e1f_Y0iHG?^J}T#GaVDVXEuEp|*sR_Dgnb#*lF1UL8g zrnm~l9hzthO*f==N12`aaK&Quty&FW$#2tMy=Pqv2sbCr!#J?A3M}byBGY={on(jRl#4B9G1>~vC~^q#~);;Y2>tRRJoz82qRpQF4<>-8q?woJRR48H+L5}fnw)o}i>ND@{mibTep zq5PF1%E%~mq0t3fK(GzY*v1t7{^;J#D-3}DIr2V(<+n;PsL;iCq#jJEzjB{o^@q_y zAU}|f+b*t(mmysbsz{-vNFMR5qrc`i0<&y{t?{D$$yI06u9i%PMBi+d2l^t2LwZz= z7pgM?>h%0t-m14e2RJ7>eeuR89M{j*6(8vPMOd3yaeIwJR#st@4UacB40-4>a98;Y z{6J6-?aO?WN&!uL=vYQ?*&A+Zrg_wybU4|VNIz||;7GuGL0ncoH}I$iaCbM`)grG1 zxERU6)#o1IRW-BjzsFr4dZe-P=^4>$z11$GITRbg4S$;$T;c#zk__pR&&#vyD#mY>LvlS3SfN9XfyFNQqZ~c3Zvus1?y~=%8m-L?*N8%42Cw zutNsGK(QW0&a|9hX}U@VU4p6kL@emOAb3J3^?)%4Kp+1d2Cn#2WG1mo6NR4elyCo*$i$ z-^(|Yw3V0-{VDAm0JC^v^HA7k^r;BXbtI?nM_LKY+WhFc5Bnt!I!*=RfS8xkGxdt> zz2d3yhVx2CRgW%A3|`^2<^hN>0^cR*9`x1Bj>KhudpJ2mkkgO5?gK6(z>IEd48K*~ z(NVU%!?Ni;8Wf|{kpkAeHjEn#;;#pk_0dE4d(sCLLP_DL>RbEjOBeyAp#gF!Sn=1~ z4$GS}=QbWs*JW&l_&|1%R)h_E@h4ub2d<~RrK)~f!!@up)gR8%xKzu9T z_EUi7wHJCA#dbrZVkF&D06j%1#B z!ewLgwm+U9Fy{|oL2Smyc8{utVr{+in(UH7!1$4QI*m`Zf?3E75^S#au8g`OU;zT+ zp{;xj23ul9Ci{!N?11sKc=sg0eCY4@z!b#!PJT z-bk71m6_u2CN?$?+7ihU`kF*|HRJRAZfe`t09*7YaCQZ7@~-IP<&l3M4t6@BqkwfK zyq1ZE6!!N1Z4I#g`*|MACIX5ls4m{CU8+VSO?b^8e?*jO5Vm~ohfY$TNmhGIRySH3) z&lXFH1d>LLfKx*cV9g zBPsp@T9ZKHMm{IpPw#wm)eGNykjAZ1*g6(z9yc;76mV=c>J#eXDxV|-aYB@M5Mlz& zep2W*uM_~3mAve7E|meZDK|ST4cb=u1`pJ?;@NjpcQHh*3<@JKV9_Q_`$otgW|?yN za-i|Bd=!{H55@6sn7c0nYj?0GfJ|UYq61Vfgd_W&%f%9;c`^HKxL11SJ}*`R^8*BY zOMjIb8+6o~FeC`cpb!_n<0eopIN>X{rpQ%B@%M4d`SgXef`kJx7Zm8q1a*!n2#}S_ zC&Gk4yrQh;Rggel;NvNon`=D?bNz!1ccCZV+vxQUVC_>m5C(4q<+I-qj~$dR=N}$X`-j+$4PTcH|>;)=^#)x{VM3NLk0{hN-m%`gIlON0^xhKa7aYp$KRGSYQAJUn5weO3_` z|3wtk3Y?dbvUep>-EoShJ17k+Yu^!anof-GIE?OPPXQ5!VRy9kmEET8UMAO@&E}XM z-A2*wY6p4K8bSVcDMEtDTZaEd@zkF`tZFPOwY1i=9=!S}u;14NX85OyA2!$Y z1nJ2W;c_v6LACtk8VD!(8Wo<9;{zD99&@HHgOl6x6NK&B!A2PM83a?PTidfbbNR)r zPG|kwEQ|AE7-T5}AkqPC!vM@*nrQ0?7+ceE@`qSVLPKe#W3`sXUvc`kBLSX*2>r)r zgP>K;6F!tZb%F`(fy5VCMx_^z<0AbYbu-BLG8b$HZaK#{qS+ z@`1tB`tq1Oh}@*OVxw`xX#zad;=c_Qn2m#8n54dPu04Y%JueosOXmQ3`OmKmY%qfM z&+Zl|@S*Vp5(^8Chr9Z6%_e0yaZx|AZNejc*msA#w)2o;&aVYxqL}*;j|6zQUT`d;b>aPw8pD z+sg~2{fQgI8ZEkd$L$$X+b^+-S2s?a1t10psup+!m&_;HMMm$bj&BlC82OY-yLHfQ z)*8H;`~HA@h)!QVvgvVnwVkPetwTodm@oZSz-HJ+)8D20Qy5SZKqw&=L6j||S|~s< zD$hlaU2v03`*iC_bRh zmO@^~_tOJu$MfGD^Y1e+gqy`QGA(MP1p^W?*VSqK_v*LEgofmeRZiD`Sm< z>VJLW@(+MmX2170$MJdoFoCf91>I%;I?Pl~hzoGz<^VrPtO3QBV=5Vf(@T`09PF)H zk@*P1vc`VaUNFUvb{BC$Ld=-LFE~W&v^W4^qtm6<;APGZvz5 zj_6exn~m7D9osBBI>@h{AVKhmS8*2V|N7gFP%_(Y{ojP=r;Pzl%Xdxl^LG4b3xC{) zf0)p}zY;=~`REZL;J&O1p!pf$w4u3yJ#CXhuF&`U4{ly}d(P=i)g&N6QTw7tKf~(X z`JZ>owR(#wE*MJuZ~+C3E%~}C5toIg4$0A!^n0SR+H_kz7xt(SW_CUL+z&X*`&(%c zC+z*mg&igA#e%)gQfg6-ux^ zHw2N#I3*7yZO-=CHopVUSS4M#U*<;s-hJYaJUvGPa-!~jtAIr(&@;AD2TnSVKN!pZZ5nv@pT&`PWfx*27 zLuXcyYKpyR4-r5iy?Od^Z~m=>(PgXu<3VWTC%^EwoufMndUS*Y66ewIp^shge|{h+i3kd4-L0ajhj=O}lpSXn-mGMc@=LQv$qoGTHo!ajM|I`)iqjsvXtzdtL1eyKwk}#biWS(c6kemN zUI9;Nt{Q5-AV(d^>KBp=t4KZ!e$ZA^6$bXfY(R9F;E7e(nWC~lepSxN$Xht)8q%X4 z1m%e~E@ol=U1giVwVi$yxeEM@uEa>^)l&`7+U`Nb@EtNpYg|2T@~YpIOsdw6=*#bY z>NKo(s36Dn#c9lo)01EH^0(_H-#urQY{VdhGIbA8;=4uz)-N~61ckSp(Yb3b9_g^e>r+^zMV_@r?vq-+oSc3@t-1&7KKktJrfu{v0CPjzgC;)~mIE(om#U~Q{qUKmuE z=^<4;v!u&N+%qcTRyH3dOrK}D8gPuH$Gt|{i;OiBrF))rDvI|hh3peVXJT6&x)C`~ z$phSu``0GdB-)Nk{Fevp1#b$$Ci!{BCR$a*WSyeYX59b?AFT4HAnz`KH%!?!?&ZqkIo_fQd3^+k;Iu=YB9BzTY=$%vAT>coZA^Cqg24Z1H^#?O zR=NIkAMAk(o>!u~Lrwanu2o8vO3Yu1 z1d=|6u{esZt9KYAc6+H-oRHmPVHLE?m)kllecOlkIALOpB_*IPme_N_v*_t9P&7_3 zpr}t>Jr-zPP3`B~{WWX?G9--0Y_YUFks@N|*X*1p7-$VzPEiMVfDAH#WB_=pIJ?4; zh#~+)uGk#7)`lVKsWo6v+B)XJ%eIb`@D}?CASM=z;O+r32S~p2rgtbW0H5u`M!3&_ z%r?%o0z!HLR~)cKnrT0@DXC27-*@(seYM~hG|dmF7@1*fP+Bmb$wh5 zuVV1+=K6+4%88W3M=ofjl|R9>L?zvvk{8_E{6cgmSQWA8`%rYiMSdK3fdY}B0lJW! ztJIZMq!bB=(s7D1L;|`i>LBLJ{9^u02O?Tl@D~UY-^M|2QDbTB{%Ur@t1E8OrNdAR zH1U$geJBi2wT8feLw!)Rjo^&ER(TWtQ=CLWhkdbU^}Dq(128!v?9KQU0DE;2Oh$${ zSXe^_QLd=7=KwI`l#Fh2{}J}bBg>X zjy<~>OE(0KU-z2cWKX#bl5lI^ zRm1rhI8z&daXkd#X$O#f7ll)xJYl#Qlz@zqcDS z1W8D)mI{?}ZGj}4E*Cn&$bi0%?DFNXpc{O36UJ3b<}5593uu(BKqrAZW3@=YXwsK2 z_y=+`$VC9XpbZ!0yF#a3HolE%BklV2N>|3v1m&Gf_$@moyhT~YtC@f~DBHp{jaAFg zkTS@D5s)w_kd~>BF6hdF)@x(8^laJ}i<#F3Fl)`XVG{5V$|O7XF#%NGZBT&T&&;@4 zO(QVdP;@}`J~7g%KObff%H)v;c!jMYdb$4h2h4D)_g=9cBFBh(i6AS z0-#o45a&bI4uZEJgCnaE8}L_UKd$j?>V8cVzY$P;`pZGUp2wzEiaZveK=tiba^Q*y z7k#X5KnAVPJr2nAGpBfh_)tiWQRQ|YcCDNwJ;qjy+9#0KA`23Pkt}8u4X=aB3hJjb zL>*RUxBahx-auncHwnrgPWb~_@4&v1#fFMh067=r=2k637vp)X>c&^ZeVVC?8|mFo zyhL@i>51`IE*Q80wc~wu%n^Z#4^)<+8|HwT@}Km{?v)(ZCSR6@+eszGk$j$pL#m9I z`biUAS~=z)jjagOkV5PSUE4vR+OMWwf=X;C-tk-2j2MXzU!`POVL~E6wH1uY{;9qbAkjpcGwWjPk-(ly!PI3WX;jD zHz=LBh8KyQB9}153=qzRM9}}{4vf`!fPzzS7p#||ub%BH+c@pyy~yikSm9k(?ktsX zq(veWpQGeu8Af1Z!1V@ITFxqip0ope^L6*wUN6l#h_BI*9UYUd0wPAV%Yai1dj@7P zvpX#JIFpBn+fSO9+&3$CrJfYs15G5fAgB*Mwk>}k|Jh5>*trta^d#nM7;KASAKg1S zwfq%V{KKrkc>(=H-cw>u9&;MZV)k@cK65X_whmD{>vLAFznAzVdoEyACE3Cn3EDHI zxu{)@BBspEcMXJ4lO33Cv;%1BB*~2=J1P0%qh3=ka|V@cCFu@5?n#@43NZs|N(@@I zZ6P{q-c`>wMK|cl_&HxVveFiX(>KO+^B8yvGX}?(8jj4~GNvJaq^|ta5Pcf8F1vUe zVY>VG4OaZP7@YLDE&^410hlq_lld3_qvn!d^o8p2l69t_3`pTEarFnzn=9PqOW+Ee z@7Kz#U;HK-3uhjSn?b9A3Hkxb?N2bWgFV7Xku4ewi76rL&Ysl<#JVD1>UI;yuurJ9S^C6Grt3o`NY zHa5pqM~bx5D4DFGG0e@ZAdYGycSNxFDSh?<91vO00B4mCHEqIAR$2B1(t)%r z&jU1^T_XP*tckFcWt#{2{)dL=J4_ANh3YGz>Q9(EF>!yNfEw7NHk-qgQFW?}Rc8+N z6Ahe)NP5_kw&RCO`Y`Cz!#Nk6XrNH^{35-!^r#+>;A4vz-Hg>l$yj#_U2CYQE6zg3 z;+SX`5kP2*_xAIwuG3}=aKONx8UxS3Y(vGkN)D(I!d>;0mc!|MIYW3NDG z?-ti48vbZN0*7(;>KYS&JsQUZl%NQ{@nNQ8*tFdpmL(xBW+tv2tU&KswoCqS#BaT# z8dcK=J28%jzCG^W=Vk~N-^VrZo3#QBI3(Aw42TN|NO>$TAxN!{8^PA*i_3NFD@aSl zw0i#8dxtNn0V``RS(Qtiy$GG$&&rS7D=ixBCBV!l+YB-#wD&n7!&#-PM#`di$5q`y z&__*l2X+c_i`i=)0I+2bF&7ZQ@&P>~hn3WwUE`Jhh&X<&=AiC2uC4@SVh;6^N}7JY z=`Lcficfb<6xai!=&Ex zmWMi_pP&ALOn+dhUMb2(J$$Cw5}TfiWN z-CxLcoL+w58Zr+4a4Or4obAFhSN-A~ukxYCn2KKy7ftym>)Y@u+dk)y9@WF#j-HI7*P=T##_|!blO2w3w zdoZakMGjnz<`|eO`e)@h%Ll4jTzzF@F!WW6VjGk&tAb@FFwVmp^?2@RxQ(fwm+Grp{agKOR(X{t2*M1k4a3EdVn^?-PttpV~qUYP-^`WK<>y&EH9Es_pE z-|sKbcp!&W&abF|OF2KDr7DVo4Sq4%cTN*P2nlyImZBjNPnoP8Az<)?48swE$pFM9 z=($iEH^WsDk#o(~?3UqSIZXs~Nrv_n=t4udglinv0aaLI4lY#VGLGDUG9dZe;fky| zD=xuJBSBS(a^jfP0tHtfJO)p~#dQB$FVL~W;K+B^x{Rr)3dI$mFl;q|WMwbPU%?4U zfQxNl?WuSiVvM;DVcsX*E0A;){x;%2tgWN2rs7Sqb zCeImRIvdsUD0}3!sIl;@kMR6qbd`KV_{oqXwpVvv`ABaj^CJlA==EV``e|FZJKY#T zxv^Z`-@9{4diAq5!iBQH{MZ)CTlc(zQH-g%{>(3&LDN`(bR2{0q!li~KsC6J70}qA zw__p9chLN!&Q0U?-bFKHlTO!agE}NARyB^mFwO;8X|gixIk;ALR#p_rUUW*eoy<%nF^ed-3?t^OL>r~_mq7)0XQ4I{Ah-o3D0|IB?HN`x$-SSSDrzRd zCCZ3bfQsAtJVg8KD0DS$wj~mJ3mC(ypp;9Pnjj)3n03XLpB#$Xg?*B6#lOkP5P(Ra zSoYxb$=%2{rSbzv3wuz$tRK742(C`-!6xop2vDm)^AdCM6NdppNkFEf{AbZ-^WJLjDe7y-epmg(OvmbMkzwvjn~RFEv2Xa55NuIQ8@e*+A<5;C!ad zj42*cikTVHbm4s4rQMsukyOD&#ituPLH@Q>MONIlJJxYVYy$~@2u z2=oAup-ESPcJ7zeDbC@9+=O)o2!mb0Z%@nX?!u6_tf5>9D3Mn<3W~0SWHg%1pkL3J z7XTnF1U;7+EHvpc6*pC{mHsve;!JSCfBNK}b*U;KjRrAV+bXA}b+?az#=5lh?#~bv z_NS*2UpHga_NQG(TIK!>SHZ158^S?7BBaV|HFyu3Jpxq6UGmb8pc9iZz45R&f@z?x&khVjF?2>gdlKmdG-#yjMfIRNu4X+Iz2J}^tp-gN4!_S%_nAhno z8NTPTww4IcCLF3#4}!oX(C$UFGa!1_qwd9^d?Ns=)Pl<*fSK;Flv!1yCD37o^lvaq z5Q|50$RYY^KUhnUNSip1j|uMY0&ia9XHoQd3C4@-6-_MV{WcM9u;GxO_s3s;egS;m zrMo~$ugqyIYu2L`@;=?BeB2HlG=dHn#$JdA)xhuzH7|}?KLb#`HZB@Szl&oHJSUU@ zOqDe%kO|d=kifrNcaT(vAY_x@7cN^?gzw6g?+sVVi`?(*p!%pT<^6e;R9`CpwUxaC5nA?UxJY}3w0>xcCMmig38;~l(LJ+f=t5U*6v+x z3-O~+9r6-!Ys(o2M)#F==YP9c5Dr!S40xiMA` z>npxLvl!Z|3pnqWf*8*dt04|LhJ9YboKCHtdr@QLU8vBkUa`E<_wqlC_YBuC@@?Hm zD_gG&okQIlp^X7^^`%7J`}JM*1%Vw5U!(C}FW-t^ed(2Aexho< z*^AfR!IbaPGz+z&c{AuQk>p1`Fr|j;nU6;8kDsZHE*0gfp~lK^d+BBj+VTBbzqt!-&d#2?cjSgF1+2%=4Rsf!30SU zv$+W<8f8=<(4o(UIqjb<`=_9;E2nArp5wq;;%Xp&d$5{^bB54Mp~%nHTk-h8V_Zb@h754n9XB;q+zXpA~-_jOE!lJyN9l zB)#{e+c3?CxjnYhC}Ph5_KiO^E^~Zi)-%dm>NK~tw3)=R&u>^WV}!gC^aF%6u#dOD z_c{{{M7aiYvssFMi`u97v#?@t_G|tOQD8JV^r>=D6m6S*O2K9ny!T4|BimT*Yqj5j@z9P zpUA(?d{roVO8H=uc>bW=#6dm3mH{e}uzd}-e^!lj&7WSmT>Dlh{I^1%A}cf6-K^dl zihV*0e5)^=+!orKAubvM<;QCQ2QEf%;m-&`O)UL@Lh08gyff?*p|4dv#7QKtKrED9gI{jTsyWpM)E203g5d z{0-^re2l2$%^aH7C*m5op|dO@1HNnokR3{gAaRt8I$|x>4RU4VBYb@WI(XVPfo@qpRcidrA`T|~fxHEpiu}($nY_aV z0Qlj#0&P9f2m`eVLzN%{IB_1~IEy#11F=~Xtq+`}d^hRvpnqeK@NtxzZMXAPkR|!s zBU)QX?w^HJh*t@~{G`B{2@G>Hd`TcW^NaIoK!g2ZK=|rCnjSDgaZGeP5%Ew>KHkC})80lxr|1SKAT0!*yulrCKuB12apT1|XyC5X~80cRa}U9kHI#CJkIF@bPT z2XK>R4vK7;A3dXg{#i7r@9w2wg2jV+k7yklB>_UDXKd`6fmR+P zWh00-tm%R)yWitL{1GC6NO6MhYT=|;sZflzU22gaqXB?sMsSz~s0fC%Xz-O1A%aDq zYYa2p=iZUqTLZdt@~@mI9mtmTL1A6Mw>`O8z5!HDz8%%% z;D++Xs$vwzpZUA9cWJlmD>1Uc_tikHPnMddf)1i`d;-xo6As)=x1-!4Qj84EKopfj z6W?UpNV+?YeSCk%U{cCB0|xQ)uyEN7S-{4cW5nQlIn+QwTeitilr2%KB*(;xfF17x*-LY#S*RW9J)A*PRgkAVlccDxPfU{m&_B-aUC7VyO) zQ2SFwgi5WnJNjWW)aOS50eEDf;Xd@$E9c;t2K=9O9kBBz)FVT!Fud>p2Spt~Xc$8~ zTfng&g^K)T=)t_*fw~ZO_dMhUT*d@{3B*~bQC_3RSvIGnsg~xC;sq@ z@rq@{?FlhHpfoKK`#%8)n}lv3@+21$El7XMzwRWY^{}j|4*=JS_b$6~9%99V-ea6T z5Fvs(4CpIS#-I6n`uUfKFiMAT^&bzSo5qP$;G|^%^iA}8(38w=8sHCs`{Q>-7O2Za zLdJvo{*E5Yc=K$)A9(5RBOV#`DaogM&42XCeDh-X>sWq}`^QMX{@d8@I;k-ud7p4u zNc=#$=Ui`TdLJOaVh^%&%TviK$v4<1mI){>p9RvWv?xKAMuOxVxyTB(vOP9}HAf)` zdgRRhbJE_IQodiO1kkBQh0TJ_c&s@k3ZfM`96SY;OF{T4o)8x?LqH+Ckn+pLSsDXG z@kfp*>sl=V$ogZE?Rm>yypP(cYp?xZ-V|XojO%_w3GGZ%iD#s^p$~;;flG8=8d@Zc z2#($_GTfC_n?*Y(vUzw(gnblvSX!P-s;ar#95+6fG!d~#oF88$4mMl`ruIo1Xo8o5 z%mlH^p>4P_mRn zNe}_q^F{31?XIocpFMwlzt5NN^L+R|&%^WObDz)qRsSXm&fNf~JqImkI}{<7YsHf~ zB^Fdb9x#>;>Ny79p&*D26I&pt1qjoFl1^RG4=Q37UIW_`e2$t5>#|gtt6ayNprxPS zlo$8&G&>!ZI3fnvtaf+=q!A zN*7iDBd3xXwgP{v79CSQUE?M5Q^38kHK6yfwC6YOIz+Y=#(|p48<7rL4mdn=8Ms=3 zG7u=gjV?Lds}OXccdx?_3o3mib!)^4Fc@o03UImI5sU-hqecb85k=srr$)K{!O$72 zvmuD!P)(+NXk+C@W6@AO3riSkG);7)9vP_;EGr!F%it9 zyH_J_14n6QMbH$P_LiccdgTI zHTYqJf`!b=dl?QlkWC@IB^Diompg!1CiA09BpeYEF(ItPjN{!#$7OZ$Pnh0E&M^z^ zABZub!jF^zCcfXZZ;%f(5IeSP*v<@TH1dCJ<5`0%3@plB!wHqSC5gh!qsIYjxyu76WL~IS83- zd0pRpmkVjil(Asdi}^v;5>kP3Z6j;{X8qVFFKnT-$k1EV|;H(Y^WA z2rhx)uWRONikG`2qgOO)Nwxx6>Us_x_p4EEL9F&s1^d8PE=E6>=KE(luv>JAQs%q5{EJzA+tg7gyl;q?&ubZP}iga%ur4xim$f=7GU5Dse&_fAJ!F+twnzvRT|rZ>0?xI=m}^`}c2S zcOR!Ucy?w^Ho1^q^&CzCUP0LoSuR84jn!H_H`K=4JvMuQC<;>(y%oPBv~y{cSW6e- z;Vo8o0h-)&93~c*+%{x4V8=W6J$ZpZx-SQ&dFEdu{I~fB6@}Xh8q~ literal 0 HcmV?d00001 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..ab29f7cbaf 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( @@ -159,597 +133,267 @@ public static Iterable compareTwoTimestamps() { @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("DATE('1961-04-12') = TIMESTAMP('1984-12-15 22:15:07')", "d_ts_f", false), - $("TIMESTAMP('" + today + " 10:20:30') = TIME('10:20:30')", "ts_t_t", true), - $("TIME('10:20:30') = TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), - $("TIMESTAMP('2020-09-16 10:20:30') = TIME('09:07:00')", "ts_t_f", false), - $("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))); + return Arrays.asList($$( + $("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), + $("DATE('1961-04-12') = TIMESTAMP('1984-12-15 22:15:07')", "d_ts_f", false), + $("TIMESTAMP('" + today + " 10:20:30') = TIME('10:20:30')", "ts_t_t", true), + $("TIME('10:20:30') = TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), + $("TIMESTAMP('2020-09-16 10:20:30') = TIME('09:07:00')", "ts_t_f", false), + $("TIME('09:07:00') = TIMESTAMP('1984-12-15 22:15:07')", "t_ts_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareEqDateWithOtherTypes() { var today = LocalDate.now().toString(); - return Arrays.asList( - $$( - $("DATE('2020-09-16') = TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), - $("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), - $("TIME('09:07:00') = DATE('" + today + "')", "t_d_f", false))); + return Arrays.asList($$( + $("DATE('2020-09-16') = TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), + $("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('" + 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), + $("TIME('09:07:00') = DATE('" + today + "')", "t_d_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("TIMESTAMP('1984-12-15 10:20:30') = TIME('10:20:30')", "ts_t_f", false), - $("TIME('00:00:00') = DATE('" + today + "')", "t_d_t", true), - $("DATE('" + today + "') = TIME('00:00:00')", "d_t_t", true), - $("TIME('09:07:00') = DATE('" + today + "')", "t_d_f", false), - $("DATE('2020-09-16') = TIME('09:07:00')", "d_t_f", false))); + return Arrays.asList($$( + $("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), + $("TIMESTAMP('1984-12-15 10:20:30') = TIME('10:20:30')", "ts_t_f", false), + $("TIME('00:00:00') = DATE('" + today + "')", "t_d_t", true), + $("DATE('" + today + "') = TIME('00:00:00')", "d_t_t", true), + $("TIME('09:07:00') = DATE('" + today + "')", "t_d_f", false), + $("DATE('2020-09-16') = TIME('09:07:00')", "d_t_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("DATE('2020-09-16') != TIMESTAMP('2020-09-16 00:00:00')", "d_ts_f", false), - $("TIMESTAMP('2020-09-16 10:20:30') != TIME('09:07:00')", "ts_t_t", true), - $("TIME('09:07:00') != TIMESTAMP('1984-12-15 22:15:07')", "t_ts_t", true), - $("TIMESTAMP('" + today + " 10:20:30') != TIME('10:20:30')", "ts_t_f", false), - $("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))); + return Arrays.asList($$( + $("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), + $("DATE('2020-09-16') != TIMESTAMP('2020-09-16 00:00:00')", "d_ts_f", false), + $("TIMESTAMP('2020-09-16 10:20:30') != TIME('09:07:00')", "ts_t_t", true), + $("TIME('09:07:00') != TIMESTAMP('1984-12-15 22:15:07')", "t_ts_t", true), + $("TIMESTAMP('" + today + " 10:20:30') != TIME('10:20:30')", "ts_t_f", false), + $("TIME('10:20:30') != TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareNeqDateWithOtherTypes() { var today = LocalDate.now().toString(); - return Arrays.asList( - $$( - $("DATE('2020-09-16') != TIMESTAMP('1961-04-12 09:07:00')", "d_ts_t", true), - $("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), - $("TIME('00:00:00') != DATE('" + today + "')", "t_d_f", false))); + return Arrays.asList($$( + $("DATE('2020-09-16') != TIMESTAMP('1961-04-12 09:07:00')", "d_ts_t", true), + $("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('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), + $("TIME('00:00:00') != DATE('" + today + "')", "t_d_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("TIMESTAMP('" + today + " 10:20:30') != TIME('10:20:30')", "ts_t_f", false), - $("TIME('09:07:00') != DATE('" + today + "')", "t_d_t", true), - $("DATE('2020-09-16') != TIME('09:07:00')", "d_t_t", true), - $("TIME('00:00:00') != DATE('" + today + "')", "t_d_f", false), - $("DATE('" + today + "') != TIME('00:00:00')", "d_t_f", false))); + return Arrays.asList($$( + $("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), + $("TIMESTAMP('" + today + " 10:20:30') != TIME('10:20:30')", "ts_t_f", false), + $("TIME('09:07:00') != DATE('" + today + "')", "t_d_t", true), + $("DATE('2020-09-16') != TIME('09:07:00')", "d_t_t", true), + $("TIME('00:00:00') != DATE('" + today + "')", "t_d_f", false), + $("DATE('" + today + "') != TIME('00:00:00')", "d_t_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("DATE('2020-09-16') < TIMESTAMP('2020-09-16 00:00:00')", "d_ts_f", false), - $("TIMESTAMP('2020-09-16 10:20:30') < TIME('09:07:00')", "ts_t_t", true), - $("TIME('09:07:00') < TIMESTAMP('3077-12-15 22:15:07')", "t_ts_t", true), - $("TIMESTAMP('" + today + " 10:20:30') < TIME('10:20:30')", "ts_t_f", false), - $("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))); + return Arrays.asList($$( + $("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), + $("DATE('2020-09-16') < TIMESTAMP('2020-09-16 00:00:00')", "d_ts_f", false), + $("TIMESTAMP('2020-09-16 10:20:30') < TIME('09:07:00')", "ts_t_t", true), + $("TIME('09:07:00') < TIMESTAMP('3077-12-15 22:15:07')", "t_ts_t", true), + $("TIMESTAMP('" + today + " 10:20:30') < TIME('10:20:30')", "ts_t_f", false), + $("TIME('20:50:40') < TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareLtDateWithOtherTypes() { - return Arrays.asList( - $$( - $("DATE('2020-09-16') < TIMESTAMP('3077-04-12 09:07:00')", "d_ts_t", true), - $("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), - $("TIME('00:00:00') < DATE('2020-09-16')", "t_d_f", false))); + return Arrays.asList($$( + $("DATE('2020-09-16') < TIMESTAMP('3077-04-12 09:07:00')", "d_ts_t", true), + $("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('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), + $("TIME('00:00:00') < DATE('2020-09-16')", "t_d_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("TIMESTAMP('" + today + " 20:50:42') < TIME('10:20:30')", "ts_t_f", false), - $("TIME('09:07:00') < DATE('3077-04-12')", "t_d_t", true), - $("DATE('2020-09-16') < TIME('09:07:00')", "d_t_t", true), - $("TIME('00:00:00') < DATE('1961-04-12')", "t_d_f", false), - $("DATE('3077-04-12') < TIME('10:20:30')", "d_t_f", false))); + return Arrays.asList($$( + $("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), + $("TIMESTAMP('" + today + " 20:50:42') < TIME('10:20:30')", "ts_t_f", false), + $("TIME('09:07:00') < DATE('3077-04-12')", "t_d_t", true), + $("DATE('2020-09-16') < TIME('09:07:00')", "d_t_t", true), + $("TIME('00:00:00') < DATE('1961-04-12')", "t_d_f", false), + $("DATE('3077-04-12') < TIME('10:20:30')", "d_t_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("DATE('1961-04-12') > TIMESTAMP('1961-04-12 00:00:00')", "d_ts_f", false), - $("TIMESTAMP('3077-07-08 20:20:30') > TIME('10:20:30')", "ts_t_t", true), - $("TIME('20:50:40') > TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), - $("TIMESTAMP('" + today + " 10:20:30') > TIME('10:20:30')", "ts_t_f", false), - $("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))); + return Arrays.asList($$( + $("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), + $("DATE('1961-04-12') > TIMESTAMP('1961-04-12 00:00:00')", "d_ts_f", false), + $("TIMESTAMP('3077-07-08 20:20:30') > TIME('10:20:30')", "ts_t_t", true), + $("TIME('20:50:40') > TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), + $("TIMESTAMP('" + today + " 10:20:30') > TIME('10:20:30')", "ts_t_f", false), + $("TIME('09:07:00') > TIMESTAMP('3077-12-15 22:15:07')", "t_ts_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareGtDateWithOtherTypes() { - return Arrays.asList( - $$( - $("DATE('2020-09-16') > TIMESTAMP('1961-04-12 09:07:00')", "d_ts_t", true), - $("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), - $("TIME('09:07:00') > DATE('3077-04-12')", "t_d_f", false))); + return Arrays.asList($$( + $("DATE('2020-09-16') > TIMESTAMP('1961-04-12 09:07:00')", "d_ts_t", true), + $("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('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), + $("TIME('09:07:00') > DATE('3077-04-12')", "t_d_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("TIMESTAMP('1984-12-15 10:20:30') > TIME('10:20:30')", "ts_t_f", false), - $("TIME('00:00:00') > DATE('1961-04-12')", "t_d_t", true), - $("DATE('3077-04-12') > TIME('10:20:30')", "d_t_t", true), - $("TIME('09:07:00') > DATE('3077-04-12')", "t_d_f", false), - $("DATE('2020-09-16') > TIME('09:07:00')", "d_t_f", false))); + return Arrays.asList($$( + $("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), + $("TIMESTAMP('1984-12-15 10:20:30') > TIME('10:20:30')", "ts_t_f", false), + $("TIME('00:00:00') > DATE('1961-04-12')", "t_d_t", true), + $("DATE('3077-04-12') > TIME('10:20:30')", "d_t_t", true), + $("TIME('09:07:00') > DATE('3077-04-12')", "t_d_f", false), + $("DATE('2020-09-16') > TIME('09:07:00')", "d_t_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("DATE('2077-04-12') <= TIMESTAMP('1984-12-15 22:15:07')", "d_ts_f", false), - $("TIMESTAMP('" + today + " 10:20:30') <= TIME('10:20:30')", "ts_t_t", true), - $("TIME('09:07:00') <= TIMESTAMP('3077-12-15 22:15:07')", "t_ts_t", true), - $("TIMESTAMP('3077-09-16 10:20:30') <= TIME('09:07:00')", "ts_t_f", false), - $("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))); + return Arrays.asList($$( + $("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), + $("DATE('2077-04-12') <= TIMESTAMP('1984-12-15 22:15:07')", "d_ts_f", false), + $("TIMESTAMP('" + today + " 10:20:30') <= TIME('10:20:30')", "ts_t_t", true), + $("TIME('09:07:00') <= TIMESTAMP('3077-12-15 22:15:07')", "t_ts_t", true), + $("TIMESTAMP('3077-09-16 10:20:30') <= TIME('09:07:00')", "ts_t_f", false), + $("TIME('20:50:40') <= TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareLteDateWithOtherTypes() { - return Arrays.asList( - $$( - $("DATE('2020-09-16') <= TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), - $("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), - $("TIME('00:00:00') <= DATE('2020-09-16')", "t_d_f", false))); + return Arrays.asList($$( + $("DATE('2020-09-16') <= TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), + $("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') <= 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), + $("TIME('00:00:00') <= DATE('2020-09-16')", "t_d_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("TIMESTAMP('" + today + " 20:50:42') <= TIME('10:20:30')", "ts_t_f", false), - $("TIME('09:07:00') <= DATE('3077-04-12')", "t_d_t", true), - $("DATE('2020-09-16') <= TIME('09:07:00')", "d_t_t", true), - $("TIME('00:00:00') <= DATE('1961-04-12')", "t_d_f", false), - $("DATE('3077-04-12') <= TIME('10:20:30')", "d_t_f", false))); + return Arrays.asList($$( + $("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), + $("TIMESTAMP('" + today + " 20:50:42') <= TIME('10:20:30')", "ts_t_f", false), + $("TIME('09:07:00') <= DATE('3077-04-12')", "t_d_t", true), + $("DATE('2020-09-16') <= TIME('09:07:00')", "d_t_t", true), + $("TIME('00:00:00') <= DATE('1961-04-12')", "t_d_f", false), + $("DATE('3077-04-12') <= TIME('10:20:30')", "d_t_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("DATE('1961-04-11') >= TIMESTAMP('1961-04-12 00:00:00')", "d_ts_f", false), - $("TIMESTAMP('" + today + " 10:20:30') >= TIME('10:20:30')", "ts_t_t", true), - $("TIME('20:50:40') >= TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), - $("TIMESTAMP('1977-07-08 10:20:30') >= TIME('10:20:30')", "ts_t_f", false), - $("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))); + return Arrays.asList($$( + $("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), + $("DATE('1961-04-11') >= TIMESTAMP('1961-04-12 00:00:00')", "d_ts_f", false), + $("TIMESTAMP('" + today + " 10:20:30') >= TIME('10:20:30')", "ts_t_t", true), + $("TIME('20:50:40') >= TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), + $("TIMESTAMP('1977-07-08 10:20:30') >= TIME('10:20:30')", "ts_t_f", false), + $("TIME('09:07:00') >= TIMESTAMP('3077-12-15 22:15:07')", "t_ts_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareGteDateWithOtherTypes() { - return Arrays.asList( - $$( - $("DATE('2020-09-16') >= TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), - $("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), - $("TIME('09:07:00') >= DATE('3077-04-12')", "t_d_f", false))); + return Arrays.asList($$( + $("DATE('2020-09-16') >= TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), + $("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('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), + $("TIME('09:07:00') >= DATE('3077-04-12')", "t_d_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("TIMESTAMP('1984-12-15 10:20:30') >= TIME('10:20:30')", "ts_t_f", false), - $("TIME('00:00:00') >= DATE('1961-04-12')", "t_d_t", true), - $("DATE('3077-04-12') >= TIME('10:20:30')", "d_t_t", true), - $("TIME('09:07:00') >= DATE('3077-04-12')", "t_d_f", false), - $("DATE('2020-09-16') >= TIME('09:07:00')", "d_t_f", false))); + return Arrays.asList($$( + $("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), + $("TIMESTAMP('1984-12-15 10:20:30') >= TIME('10:20:30')", "ts_t_f", false), + $("TIME('00:00:00') >= DATE('1961-04-12')", "t_d_t", true), + $("DATE('3077-04-12') >= TIME('10:20:30')", "d_t_t", true), + $("TIME('09:07:00') >= DATE('3077-04-12')", "t_d_f", false), + $("DATE('2020-09-16') >= TIME('09:07:00')", "d_t_f", false) + )); } @Test 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..202808ae6c 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 @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ + package org.opensearch.sql.ppl; import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK; @@ -52,1151 +53,796 @@ public void resetTimeZone() { @Test public void testAddDateWithDays() throws IOException { - var result = - executeQuery( - String.format( - "source=%s | eval " + " f = adddate(date('2020-09-16'), 1)" + " | fields f", - TEST_INDEX_DATE)); + var result = executeQuery(String.format("source=%s | eval " + + " f = adddate(date('2020-09-16'), 1)" + + " | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "date")); verifySome(result.getJSONArray("datarows"), rows("2020-09-17")); - result = - executeQuery( - String.format( - "source=%s | eval " - + " f = adddate(timestamp('2020-09-16 17:30:00'), 1)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + result = executeQuery(String.format("source=%s | eval " + + " f = adddate(timestamp('2020-09-16 17:30:00'), 1)" + + " | fields f", TEST_INDEX_DATE)); + 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")); + result = executeQuery(String.format("source=%s | eval " + + " f = adddate(TIME('07:40:00'), 0)" + + " | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(LocalDate.now() + " 07:40:00")); } @Test public void testAddDateWithInterval() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval " - + " 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")); + JSONObject result = executeQuery(String.format("source=%s | eval " + + " f = adddate(timestamp('2020-09-16 17:30:00'), interval 1 day)" + + " | fields f", TEST_INDEX_DATE)); + 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(date('2020-09-16'), interval 1 day) " - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + result = executeQuery(String.format("source=%s | eval " + + " f = adddate(date('2020-09-16'), interval 1 day) " + + " | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-17 00:00:00")); - result = - executeQuery( - String.format( - "source=%s | eval " - + " f = adddate(date('2020-09-16'), interval 1 hour)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + result = executeQuery(String.format("source=%s | eval " + + " f = adddate(date('2020-09-16'), interval 1 hour)" + + " | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-16 01:00:00")); - result = - executeQuery( - String.format( - "source=%s | eval " - + " f = adddate(TIME('07:40:00'), interval 1 day)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); - verifySome( - result.getJSONArray("datarows"), - rows( - LocalDate.now() - .plusDays(1) - .atTime(LocalTime.of(7, 40)) - .atZone(systemTz.toZoneId()) - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); - - result = - executeQuery( - String.format( - "source=%s | eval " - + " f = adddate(TIME('07:40:00'), interval 1 hour)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); - verifySome( - result.getJSONArray("datarows"), - rows( - LocalDate.now() - .atTime(LocalTime.of(8, 40)) - .atZone(systemTz.toZoneId()) - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); + result = executeQuery(String.format("source=%s | eval " + + " f = adddate(TIME('07:40:00'), interval 1 day)" + + " | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); + verifySome(result.getJSONArray("datarows"), + rows(LocalDate.now().plusDays(1).atTime(LocalTime.of(7, 40)).atZone(systemTz.toZoneId()) + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); + + result = executeQuery(String.format("source=%s | eval " + + " f = adddate(TIME('07:40:00'), interval 1 hour)" + + " | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); + verifySome(result.getJSONArray("datarows"), + rows(LocalDate.now().atTime(LocalTime.of(8, 40)).atZone(systemTz.toZoneId()) + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); } @Test public void testConvertTZ() throws IOException { JSONObject result = - executeQuery( - String.format( - "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")); + executeQuery(String.format( + "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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-05-15 22:00:00")); result = - executeQuery( - String.format( - "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")); + executeQuery(String.format( + "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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2021-05-12 00:00:00")); result = - executeQuery( - String.format( - "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")); + executeQuery(String.format( + "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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2021-05-12 01:00:00")); result = - executeQuery( - String.format( - "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")); + executeQuery(String.format( + "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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2021-05-13 04:34:50")); result = - executeQuery( - String.format( - "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")); + executeQuery(String.format( + "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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2021-05-12 11:34:50")); result = - executeQuery( - String.format( - "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")); + executeQuery(String.format( + "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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2021-05-13 11:34:50")); result = - executeQuery( - String.format( - "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")); + executeQuery(String.format( + "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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2021-05-12 09:15:00")); result = - executeQuery( - String.format( - "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")); - verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); + executeQuery(String.format( + "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, "timestamp")); + verifySome(result.getJSONArray("datarows"), rows(new Object[]{null})); result = - executeQuery( - String.format( - "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")); - verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); + executeQuery(String.format( + "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, "timestamp")); + verifySome(result.getJSONArray("datarows"), rows(new Object[]{null})); } @Test public void testDateAdd() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval " - + " f = date_add(timestamp('2020-09-16 17:30:00'), interval 1 day)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + JSONObject result = executeQuery(String.format("source=%s | eval " + + " f = date_add(timestamp('2020-09-16 17:30:00'), interval 1 day)" + + " | fields f", TEST_INDEX_DATE)); + 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 = date_add(DATETIME('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(date('2020-09-16'), interval 1 day)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + result = executeQuery(String.format("source=%s | eval " + + " f = date_add(date('2020-09-16'), interval 1 day)" + + " | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-17 00:00:00")); - result = - executeQuery( - String.format( - "source=%s | eval " - + " f = date_add(date('2020-09-16'), interval 1 hour)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + result = executeQuery(String.format("source=%s | eval " + + " f = date_add(date('2020-09-16'), interval 1 hour)" + + " | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-16 01:00:00")); - result = - executeQuery( - String.format( - "source=%s | eval " - + " f = date_add(TIME('07:40:00'), interval 1 day)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); - verifySome( - result.getJSONArray("datarows"), - rows( - LocalDate.now() - .plusDays(1) - .atTime(LocalTime.of(7, 40)) - .atZone(systemTz.toZoneId()) - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); - - result = - executeQuery( - String.format( - "source=%s | eval " - + " f = date_add(TIME('07:40:00'), interval 1 hour)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); - verifySome( - result.getJSONArray("datarows"), - rows( - LocalDate.now() - .atTime(LocalTime.of(8, 40)) - .atZone(systemTz.toZoneId()) - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); - - result = - executeQuery( - String.format( - "source=%s | eval " + " f = DATE_ADD(birthdate, INTERVAL 1 YEAR)" + " | fields f", - TEST_INDEX_BANK)); - verifySchema(result, schema("f", null, "datetime")); - verifyDataRows( - result, - rows("2018-10-23 00:00:00"), - rows("2018-11-20 00:00:00"), - rows("2019-06-23 00:00:00"), - rows("2019-11-13 23:33:20"), - rows("2019-06-27 00:00:00"), - rows("2019-08-19 00:00:00"), - rows("2019-08-11 00:00:00")); + result = executeQuery(String.format("source=%s | eval " + + " f = date_add(TIME('07:40:00'), interval 1 day)" + + " | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); + verifySome(result.getJSONArray("datarows"), + rows(LocalDate.now().plusDays(1).atTime(LocalTime.of(7, 40)).atZone(systemTz.toZoneId()) + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); + + result = executeQuery(String.format("source=%s | eval " + + " f = date_add(TIME('07:40:00'), interval 1 hour)" + + " | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); + verifySome(result.getJSONArray("datarows"), + rows(LocalDate.now().atTime(LocalTime.of(8, 40)).atZone(systemTz.toZoneId()) + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); + + result = executeQuery(String.format("source=%s | eval " + + " f = DATE_ADD(birthdate, INTERVAL 1 YEAR)" + + " | fields f", TEST_INDEX_BANK)); + verifySchema(result, schema("f", null, "timestamp")); + verifyDataRows(result, + rows("2018-10-23 00:00:00"), + rows("2018-11-20 00:00:00"), + rows("2019-06-23 00:00:00"), + rows("2019-11-13 23:33:20"), + rows("2019-06-27 00:00:00"), + rows("2019-08-19 00:00:00"), + rows("2019-08-11 00:00:00")); } @Test public void testDateTime() throws IOException { JSONObject result = - executeQuery( - String.format( - "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")); + executeQuery(String.format( + "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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-12-24 21:30:00")); result = - executeQuery( - 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")); + executeQuery(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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-12-25 06:30:00")); result = - executeQuery( - 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")); + executeQuery(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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-12-25 15:30:00")); result = - executeQuery( - 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")); + executeQuery(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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2004-02-29 19:00:00")); result = - executeQuery( - 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")); + executeQuery(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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2003-03-01 19:00:00")); result = - executeQuery( - 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")); + executeQuery(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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-12-25 19:30:00")); result = - executeQuery( - 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")); + executeQuery(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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2007-12-31 06:00:00")); result = - executeQuery( - 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")); + executeQuery(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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-01-01 02:00:00")); result = - executeQuery( - String.format( - "source=%s | eval f = DATETIME('2008-01-01 02:00:00') | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + executeQuery(String.format( + "source=%s | eval f = DATETIME('2008-01-01 02:00:00') | fields f", + TEST_INDEX_DATE)); + verifySchema(result, + schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-01-01 02:00:00")); result = - executeQuery( - 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")); - verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); + executeQuery(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, "timestamp")); + verifySome(result.getJSONArray("datarows"), rows(new Object[]{null})); result = - executeQuery( - 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")); - verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); + executeQuery(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, "timestamp")); + verifySome(result.getJSONArray("datarows"), rows(new Object[]{null})); result = - executeQuery( - 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")); - verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); + executeQuery(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, "timestamp")); + verifySome(result.getJSONArray("datarows"), rows(new Object[]{null})); } @Test public void testDateSub() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval " - + " f = date_sub(timestamp('2020-09-16 17:30:00'), interval 1 day)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + JSONObject result = executeQuery(String.format("source=%s | eval " + + " f = date_sub(timestamp('2020-09-16 17:30:00'), interval 1 day)" + + " | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); 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")); - verifySome(result.getJSONArray("datarows"), rows("2020-09-15 17:30:00")); - - result = - executeQuery( - String.format( - "source=%s | eval " - + " f = date_sub(date('2020-09-16'), interval 1 day)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + result = executeQuery(String.format("source=%s | eval " + + " f = date_sub(date('2020-09-16'), interval 1 day)" + + " | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-15 00:00:00")); - result = - executeQuery( - String.format( - "source=%s | eval " - + " f = date_sub(date('2020-09-16'), interval 1 hour)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + result = executeQuery(String.format("source=%s | eval " + + " f = date_sub(date('2020-09-16'), interval 1 hour)" + + " | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-15 23:00:00")); - result = - executeQuery( - String.format( - "source=%s | eval " - + " f = date_sub(TIME('07:40:00'), interval 1 day)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); - verifySome( - result.getJSONArray("datarows"), - rows( - LocalDate.now() - .plusDays(-1) - .atTime(LocalTime.of(7, 40)) - .atZone(systemTz.toZoneId()) - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); - - result = - executeQuery( - String.format( - "source=%s | eval " - + " f = date_sub(TIME('07:40:00'), interval 1 hour)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); - verifySome( - result.getJSONArray("datarows"), - rows( - LocalDate.now() - .atTime(LocalTime.of(6, 40)) - .atZone(systemTz.toZoneId()) - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); + result = executeQuery(String.format("source=%s | eval " + + " f = date_sub(TIME('07:40:00'), interval 1 day)" + + " | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); + verifySome(result.getJSONArray("datarows"), + rows(LocalDate.now().plusDays(-1).atTime(LocalTime.of(7, 40)).atZone(systemTz.toZoneId()) + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); + + result = executeQuery(String.format("source=%s | eval " + + " f = date_sub(TIME('07:40:00'), interval 1 hour)" + + " | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); + verifySome(result.getJSONArray("datarows"), + rows(LocalDate.now().atTime(LocalTime.of(6, 40)).atZone(systemTz.toZoneId()) + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); } @Test public void testDay() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = day(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = day(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(16)); - result = - executeQuery( - String.format("source=%s | eval f = day('2020-09-16') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = day('2020-09-16') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(16)); } @Test public void testDay_of_week() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = day_of_week(date('2020-09-16')) | fields f", - TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = day_of_week(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(4)); - result = - executeQuery( - String.format( - "source=%s | eval f = day_of_week('2020-09-16') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = day_of_week('2020-09-16') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(4)); } @Test public void testDay_of_month() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = day_of_month(date('2020-09-16')) | fields f", - TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = day_of_month(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(16)); - result = - executeQuery( - String.format( - "source=%s | eval f = day_of_month('2020-09-16') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = day_of_month('2020-09-16') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(16)); } @Test public void testDay_of_year() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = day_of_year(date('2020-09-16')) | fields f", - TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = day_of_year(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(260)); - result = - executeQuery( - String.format( - "source=%s | eval f = day_of_year('2020-09-16') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = day_of_year('2020-09-16') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(260)); } @Test public void testDayName() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = dayname(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = dayname(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "string")); verifySome(result.getJSONArray("datarows"), rows("Wednesday")); - result = - executeQuery( - String.format( - "source=%s | eval f = dayname('2020-09-16') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = dayname('2020-09-16') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "string")); verifySome(result.getJSONArray("datarows"), rows("Wednesday")); } @Test public void testDayOfMonth() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = dayofmonth(date('2020-09-16')) | fields f", - TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = dayofmonth(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(16)); - result = - executeQuery( - String.format( - "source=%s | eval f = dayofmonth('2020-09-16') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = dayofmonth('2020-09-16') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(16)); } @Test public void testDayOfWeek() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = dayofweek(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = dayofweek(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(4)); - result = - executeQuery( - String.format( - "source=%s | eval f = dayofweek('2020-09-16') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = dayofweek('2020-09-16') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(4)); } @Test public void testDayOfYear() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = dayofyear(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = dayofyear(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(260)); - result = - executeQuery( - String.format( - "source=%s | eval f = dayofyear('2020-09-16') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = dayofyear('2020-09-16') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(260)); } @Test public void testFromDays() throws IOException { - JSONObject result = - executeQuery( - String.format("source=%s | eval f = from_days(738049) | fields f", TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = from_days(738049) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "date")); verifySome(result.getJSONArray("datarows"), rows("2020-09-16")); } @Test public void testHour() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = hour(timestamp('2020-09-16 17:30:00')) | fields f", - TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = hour(timestamp('2020-09-16 17:30:00')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(17)); - result = - executeQuery( - String.format( - "source=%s | eval f = hour(time('17:30:00')) | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = hour(time('17:30:00')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(17)); - result = - executeQuery( - String.format( - "source=%s | eval f = hour('2020-09-16 17:30:00') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = hour('2020-09-16 17:30:00') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(17)); - result = - executeQuery( - String.format("source=%s | eval f = hour('17:30:00') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = hour('17:30:00') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(17)); } @Test public void testHour_of_day() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = hour_of_day(timestamp('2020-09-16 17:30:00')) | fields f", - TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = hour_of_day(timestamp('2020-09-16 17:30:00')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(17)); - result = - executeQuery( - String.format( - "source=%s | eval f = hour_of_day(time('17:30:00')) | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = hour_of_day(time('17:30:00')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(17)); - result = - executeQuery( - String.format( - "source=%s | eval f = hour_of_day('2020-09-16 17:30:00') | fields f", - TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = hour_of_day('2020-09-16 17:30:00') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(17)); - result = - executeQuery( - String.format( - "source=%s | eval f = hour_of_day('17:30:00') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = hour_of_day('17:30:00') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(17)); } @Test public void testMicrosecond() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = microsecond(timestamp('2020-09-16 17:30:00.123456')) |" - + " fields f", - TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = microsecond(timestamp('2020-09-16 17:30:00.123456')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(123456)); // Explicit timestamp value with less than 6 microsecond digits - result = - executeQuery( - String.format( - "source=%s | eval f = microsecond(timestamp('2020-09-16 17:30:00.1234')) | fields" - + " f", - TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = microsecond(timestamp('2020-09-16 17:30:00.1234')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(123400)); - result = - executeQuery( - String.format( - "source=%s | eval f = microsecond(time('17:30:00.000010')) | fields f", - TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = microsecond(time('17:30:00.000010')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(10)); // Explicit time value with less than 6 microsecond digits - result = - executeQuery( - String.format( - "source=%s | eval f = microsecond(time('17:30:00.1234')) | fields f", - TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = microsecond(time('17:30:00.1234')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(123400)); - result = - executeQuery( - String.format( - "source=%s | eval f = microsecond('2020-09-16 17:30:00.123456') | fields f", - TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = microsecond('2020-09-16 17:30:00.123456') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(123456)); // Implicit timestamp value with less than 6 microsecond digits - result = - executeQuery( - String.format( - "source=%s | eval f = microsecond('2020-09-16 17:30:00.1234') | fields f", - TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = microsecond('2020-09-16 17:30:00.1234') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(123400)); - result = - executeQuery( - String.format( - "source=%s | eval f = microsecond('17:30:00.000010') | fields f", - TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = microsecond('17:30:00.000010') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(10)); // Implicit time value with less than 6 microsecond digits - result = - executeQuery( - String.format( - "source=%s | eval f = microsecond('17:30:00.1234') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = microsecond('17:30:00.1234') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(123400)); } @Test public void testMinute() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = minute(timestamp('2020-09-16 17:30:00')) | fields f", - TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = minute(timestamp('2020-09-16 17:30:00')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(30)); - result = - executeQuery( - String.format( - "source=%s | eval f = minute(time('17:30:00')) | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = minute(time('17:30:00')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(30)); - result = - executeQuery( - String.format( - "source=%s | eval f = minute('2020-09-16 17:30:00') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = minute('2020-09-16 17:30:00') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(30)); - result = - executeQuery( - String.format("source=%s | eval f = minute('17:30:00') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = minute('17:30:00') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(30)); } @Test public void testMinute_of_hour() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = minute_of_hour(timestamp('2020-09-16 17:30:00')) | fields f", - TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = minute_of_hour(timestamp('2020-09-16 17:30:00')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(30)); - result = - executeQuery( - String.format( - "source=%s | eval f = minute_of_hour(time('17:30:00')) | fields f", - TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = minute_of_hour(time('17:30:00')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(30)); - result = - executeQuery( - String.format( - "source=%s | eval f = minute_of_hour('2020-09-16 17:30:00') | fields f", - TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = minute_of_hour('2020-09-16 17:30:00') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(30)); - result = - executeQuery( - String.format( - "source=%s | eval f = minute_of_hour('17:30:00') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = minute_of_hour('17:30:00') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(30)); } @Test public void testMinute_of_day() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = minute_of_day(timestamp('2020-09-16 17:30:00')) | fields f", - TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = minute_of_day(timestamp('2020-09-16 17:30:00')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(1050)); - result = - executeQuery( - String.format( - "source=%s | eval f = minute_of_day(time('17:30:00')) | fields f", - TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = minute_of_day(time('17:30:00')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(1050)); - result = - executeQuery( - String.format( - "source=%s | eval f = minute_of_day('2020-09-16 17:30:00') | fields f", - TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = minute_of_day('2020-09-16 17:30:00') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(1050)); - result = - executeQuery( - String.format( - "source=%s | eval f = minute_of_day('17:30:00') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = minute_of_day('17:30:00') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(1050)); } @Test public void testMonth() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = month(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = month(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(9)); - result = - executeQuery( - String.format("source=%s | eval f = month('2020-09-16') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = month('2020-09-16') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(9)); } @Test public void testMonth_of_year() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = month_of_year(date('2020-09-16')) | fields f", - TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = month_of_year(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(9)); - result = - executeQuery( - String.format( - "source=%s | eval f = month_of_year('2020-09-16') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = month_of_year('2020-09-16') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(9)); } @Test public void testMonthName() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = monthname(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = monthname(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "string")); verifySome(result.getJSONArray("datarows"), rows("September")); - result = - executeQuery( - String.format( - "source=%s | eval f = monthname('2020-09-16') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = monthname('2020-09-16') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "string")); verifySome(result.getJSONArray("datarows"), rows("September")); } @Test public void testQuarter() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = quarter(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = quarter(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(3)); - result = - executeQuery( - String.format( - "source=%s | eval f = quarter('2020-09-16') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = quarter('2020-09-16') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(3)); } @Test public void testSecond() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = second(timestamp('2020-09-16 17:30:00')) | fields f", - TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = second(timestamp('2020-09-16 17:30:00')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(0)); - result = - executeQuery( - String.format( - "source=%s | eval f = second(time('17:30:00')) | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = second(time('17:30:00')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(0)); - result = - executeQuery( - String.format( - "source=%s | eval f = second('2020-09-16 17:30:00') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = second('2020-09-16 17:30:00') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(0)); - result = - executeQuery( - String.format("source=%s | eval f = second('17:30:00') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = second('17:30:00') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(0)); } @Test public void testSecond_of_minute() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = second_of_minute(timestamp('2020-09-16 17:30:00')) | fields" - + " f", - TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = second_of_minute(timestamp('2020-09-16 17:30:00')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(0)); - result = - executeQuery( - String.format( - "source=%s | eval f = second_of_minute(time('17:30:00')) | fields f", - TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = second_of_minute(time('17:30:00')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(0)); - result = - executeQuery( - String.format( - "source=%s | eval f = second_of_minute('2020-09-16 17:30:00') | fields f", - TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = second_of_minute('2020-09-16 17:30:00') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(0)); - result = - executeQuery( - String.format( - "source=%s | eval f = second_of_minute('17:30:00') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = second_of_minute('17:30:00') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(0)); } @Test public void testSubDateDays() throws IOException { - var result = - executeQuery( - String.format( - "source=%s | eval " + " f = subdate(date('2020-09-16'), 1)" + " | fields f", - TEST_INDEX_DATE)); + var result = executeQuery(String.format("source=%s | eval " + + " f = subdate(date('2020-09-16'), 1)" + + " | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "date")); verifySome(result.getJSONArray("datarows"), rows("2020-09-15")); - result = - executeQuery( - String.format( - "source=%s | eval " - + " f = subdate(timestamp('2020-09-16 17:30:00'), 1)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + result = executeQuery(String.format("source=%s | eval " + + " f = subdate(timestamp('2020-09-16 17:30:00'), 1)" + + " | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-15 17:30:00")); - result = - executeQuery( - String.format( - "source=%s | eval " + " f = subdate(date('2020-09-16'), 1)" + " | fields f", - TEST_INDEX_DATE)); + result = executeQuery(String.format("source=%s | eval " + + " f = subdate(date('2020-09-16'), 1)" + + " | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "date")); verifySome(result.getJSONArray("datarows"), rows("2020-09-15")); - result = - executeQuery( - String.format( - "source=%s | eval " + " f = subdate(TIME('07:40:00'), 0)" + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + result = executeQuery(String.format("source=%s | eval " + + " f = subdate(TIME('07:40:00'), 0)" + + " | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(LocalDate.now() + " 07:40:00")); } @Test public void testSubDateInterval() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval " - + " f = subdate(timestamp('2020-09-16 17:30:00'), interval 1 day)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + JSONObject result = executeQuery(String.format("source=%s | eval " + + " f = subdate(timestamp('2020-09-16 17:30:00'), interval 1 day)" + + " | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); 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")); - verifySome(result.getJSONArray("datarows"), rows("2020-09-15 17:30:00")); - - result = - executeQuery( - String.format( - "source=%s | eval " - + " f = subdate(date('2020-09-16'), interval 1 day) " - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + result = executeQuery(String.format("source=%s | eval " + + " f = subdate(date('2020-09-16'), interval 1 day) " + + " | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-15 00:00:00")); - result = - executeQuery( - String.format( - "source=%s | eval " - + " f = subdate(date('2020-09-16'), interval 1 hour)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + result = executeQuery(String.format("source=%s | eval " + + " f = subdate(date('2020-09-16'), interval 1 hour)" + + " | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2020-09-15 23:00:00")); - result = - executeQuery( - String.format( - "source=%s | eval " - + " f = subdate(TIME('07:40:00'), interval 1 day)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); - verifySome( - result.getJSONArray("datarows"), - rows( - LocalDate.now() - .plusDays(-1) - .atTime(LocalTime.of(7, 40)) - .atZone(systemTz.toZoneId()) - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); - - result = - executeQuery( - String.format( - "source=%s | eval " - + " f = subdate(TIME('07:40:00'), interval 1 hour)" - + " | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); - verifySome( - result.getJSONArray("datarows"), - rows( - LocalDate.now() - .atTime(LocalTime.of(6, 40)) - .atZone(systemTz.toZoneId()) - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); + result = executeQuery(String.format("source=%s | eval " + + " f = subdate(TIME('07:40:00'), interval 1 day)" + + " | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); + verifySome(result.getJSONArray("datarows"), + rows(LocalDate.now().plusDays(-1).atTime(LocalTime.of(7, 40)).atZone(systemTz.toZoneId()) + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); + + result = executeQuery(String.format("source=%s | eval " + + " f = subdate(TIME('07:40:00'), interval 1 hour)" + + " | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); + verifySome(result.getJSONArray("datarows"), + rows(LocalDate.now().atTime(LocalTime.of(6, 40)).atZone(systemTz.toZoneId()) + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); } @Test public void testTimeToSec() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = time_to_sec(time('17:30:00')) | fields f", TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = time_to_sec(time('17:30:00')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "long")); verifySome(result.getJSONArray("datarows"), rows(63000)); - result = - executeQuery( - String.format( - "source=%s | eval f = time_to_sec('17:30:00') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = time_to_sec('17:30:00') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "long")); verifySome(result.getJSONArray("datarows"), rows(63000)); } @Test public void testToDays() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = to_days(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = to_days(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "long")); verifySome(result.getJSONArray("datarows"), rows(738049)); - result = - executeQuery( - String.format( - "source=%s | eval f = to_days('2020-09-16') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = to_days('2020-09-16') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "long")); verifySome(result.getJSONArray("datarows"), rows(738049)); } private void week(String date, int mode, int expectedResult) throws IOException { - JSONObject result = - executeQuery( - StringUtils.format( - "source=%s | eval f = week(date('%s'), %d) | fields f", - TEST_INDEX_DATE, date, mode)); + JSONObject result = executeQuery(StringUtils.format( + "source=%s | eval f = week(date('%s'), %d) | fields f", TEST_INDEX_DATE, date, mode)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(expectedResult)); } @Test public void testWeek() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = week(date('2008-02-20')) | fields f", TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = week(date('2008-02-20')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(7)); @@ -1209,46 +855,35 @@ public void testWeek() throws IOException { @Test public void testWeek_of_year() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = week_of_year(date('2008-02-20')) | fields f", - TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = week_of_year(date('2008-02-20')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(7)); } @Test public void testYear() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = year(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); + JSONObject result = executeQuery(String.format( + "source=%s | eval f = year(date('2020-09-16')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(2020)); - result = - executeQuery( - String.format("source=%s | eval f = year('2020-09-16') | fields f", TEST_INDEX_DATE)); + result = executeQuery(String.format( + "source=%s | eval f = year('2020-09-16') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(2020)); } - void verifyDateFormat(String date, String type, String format, String formatted) - throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = date_format(%s('%s'), '%s') | fields f", - TEST_INDEX_DATE, type, date, format)); + void verifyDateFormat(String date, String type, String format, String formatted) throws IOException { + JSONObject result = executeQuery(String.format( + "source=%s | eval f = date_format(%s('%s'), '%s') | fields f", + TEST_INDEX_DATE, type, date, format)); verifySchema(result, schema("f", null, "string")); verifySome(result.getJSONArray("datarows"), rows(formatted)); - result = - executeQuery( - String.format( - "source=%s | eval f = date_format('%s', '%s') | fields f", - TEST_INDEX_DATE, date, format)); + result = executeQuery(String.format( + "source=%s | eval f = date_format('%s', '%s') | fields f", + TEST_INDEX_DATE, date, format)); verifySchema(result, schema("f", null, "string")); verifySome(result.getJSONArray("datarows"), rows(formatted)); } @@ -1256,11 +891,10 @@ void verifyDateFormat(String date, String type, String format, String formatted) @Test public void testDateFormat() throws IOException { String timestamp = "1998-01-31 13:14:15.012345"; - String timestampFormat = - "%a %b %c %D %d %e %f %H %h %I %i %j %k %l %M " + "%m %p %r %S %s %T %% %P"; - String timestampFormatted = - "Sat Jan 01 31st 31 31 012345 13 01 01 14 031 13 1 " - + "January 01 PM 01:14:15 PM 15 15 13:14:15 % P"; + String timestampFormat = "%a %b %c %D %d %e %f %H %h %I %i %j %k %l %M " + + "%m %p %r %S %s %T %% %P"; + String timestampFormatted = "Sat Jan 01 31st 31 31 012345 13 01 01 14 031 13 1 " + + "January 01 PM 01:14:15 PM 15 15 13:14:15 % P"; verifyDateFormat(timestamp, "timestamp", timestampFormat, timestampFormatted); String date = "1998-01-31"; @@ -1284,119 +918,76 @@ public void testDateFormatISO8601() throws IOException { @Test public void testMakeTime() throws IOException { - var result = - executeQuery( - String.format( - "source=%s | eval f1 = MAKETIME(20, 30, 40), f2 = MAKETIME(20.2, 49.5, 42.100502) |" - + " fields f1, f2", - TEST_INDEX_DATE)); + var result = executeQuery(String.format( + "source=%s | eval f1 = MAKETIME(20, 30, 40), f2 = MAKETIME(20.2, 49.5, 42.100502) | fields f1, f2", TEST_INDEX_DATE)); verifySchema(result, schema("f1", null, "time"), schema("f2", null, "time")); verifySome(result.getJSONArray("datarows"), rows("20:30:40", "20:50:42.100502")); } @Test public void testMakeDate() throws IOException { - var result = - executeQuery( - String.format( - "source=%s | eval f1 = MAKEDATE(1945, 5.9), f2 = MAKEDATE(1984, 1984) | fields f1," - + " f2", - TEST_INDEX_DATE)); + var result = executeQuery(String.format( + "source=%s | eval f1 = MAKEDATE(1945, 5.9), f2 = MAKEDATE(1984, 1984) | fields f1, f2", TEST_INDEX_DATE)); verifySchema(result, schema("f1", null, "date"), schema("f2", null, "date")); verifySome(result.getJSONArray("datarows"), rows("1945-01-06", "1989-06-06")); } @Test public void testAddTime() throws IOException { - var result = - executeQuery( - String.format( - "source=%s | eval `'2008-12-12' + 0` = ADDTIME(DATE('2008-12-12')," - + " DATE('2008-11-15')), `'23:59:59' + 0` = ADDTIME(TIME('23:59:59')," - + " 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'))" - + " | 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"), + var result = executeQuery(String.format("source=%s | eval" + + " `'2008-12-12' + 0` = ADDTIME(DATE('2008-12-12'), DATE('2008-11-15'))," + + " `'23:59:59' + 0` = ADDTIME(TIME('23:59:59'), 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'), 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, "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")); - verifySome( - result.getJSONArray("datarows"), - rows( - "2008-12-12 00:00:00", - "23:59:59", - "2004-01-01 23:59:59", - "10:26:12", - "2000-01-01 00:49:13")); + schema("'15:42:13' + '09:07:00'", null, "timestamp")); + verifySome(result.getJSONArray("datarows"), rows("2008-12-12 00:00:00", "23:59:59", "2004-01-01 23:59:59", "10:26:12", "2000-01-01 00:49:13")); } @Test public void testSubTime() throws IOException { - var result = - executeQuery( - String.format( - "source=%s | eval `'2008-12-12' - 0` = SUBTIME(DATE('2008-12-12')," - + " DATE('2008-11-15')), `'23:59:59' - 0` = SUBTIME(TIME('23:59:59')," - + " 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'))" - + " | 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"), + var result = executeQuery(String.format("source=%s | eval" + + " `'2008-12-12' - 0` = SUBTIME(DATE('2008-12-12'), DATE('2008-11-15'))," + + " `'23:59:59' - 0` = SUBTIME(TIME('23:59:59'), 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'), 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, "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")); - verifySome( - result.getJSONArray("datarows"), - rows( - "2008-12-12 00:00:00", - "23:59:59", - "2003-12-31 00:00:01", - "10:14:48", - "1999-12-31 06:35:13")); + schema("'15:42:13' - '09:07:00'", null, "timestamp")); + verifySome(result.getJSONArray("datarows"), rows("2008-12-12 00:00:00", "23:59:59", "2003-12-31 00:00:01", "10:14:48", "1999-12-31 06:35:13")); } @Test public void testFromUnixTime() throws IOException { - var result = - executeQuery( - String.format( - "source=%s | eval f1 = FROM_UNIXTIME(200300400), f2 = FROM_UNIXTIME(12224.12), " - + "f3 = FROM_UNIXTIME(1662601316, '%%T') | fields f1, f2, f3", - TEST_INDEX_DATE)); - verifySchema( - result, - schema("f1", null, "datetime"), - schema("f2", null, "datetime"), + var result = executeQuery(String.format( + "source=%s | eval f1 = FROM_UNIXTIME(200300400), f2 = FROM_UNIXTIME(12224.12), " + + "f3 = FROM_UNIXTIME(1662601316, '%%T') | fields f1, f2, f3", TEST_INDEX_DATE)); + verifySchema(result, + schema("f1", null, "timestamp"), + schema("f2", null, "timestamp"), schema("f3", null, "string")); - verifySome( - result.getJSONArray("datarows"), + verifySome(result.getJSONArray("datarows"), rows("1976-05-07 07:00:00", "1970-01-01 03:23:44.12", "01:41:56")); } @Test public void testUnixTimeStamp() throws IOException { - var result = - executeQuery( - String.format( - "source=%s | eval f1 = UNIX_TIMESTAMP(MAKEDATE(1984, 1984)), " - + "f2 = UNIX_TIMESTAMP(TIMESTAMP('2003-12-31 12:00:00')), " - + "f3 = UNIX_TIMESTAMP(20771122143845) | fields f1, f2, f3", - TEST_INDEX_DATE)); - verifySchema( - result, + var result = executeQuery(String.format( + "source=%s | eval f1 = UNIX_TIMESTAMP(MAKEDATE(1984, 1984)), " + + "f2 = UNIX_TIMESTAMP(TIMESTAMP('2003-12-31 12:00:00')), " + + "f3 = UNIX_TIMESTAMP(20771122143845) | fields f1, f2, f3", TEST_INDEX_DATE)); + verifySchema(result, schema("f1", null, "double"), schema("f2", null, "double"), schema("f3", null, "double")); @@ -1405,43 +996,29 @@ public void testUnixTimeStamp() throws IOException { @Test public void testPeriodAdd() throws IOException { - var result = - executeQuery( - String.format( - "source=%s | eval f1 = PERIOD_ADD(200801, 2), f2 = PERIOD_ADD(200801, -12) | fields" - + " f1, f2", - TEST_INDEX_DATE)); + var result = executeQuery(String.format( + "source=%s | eval f1 = PERIOD_ADD(200801, 2), f2 = PERIOD_ADD(200801, -12) | fields f1, f2", TEST_INDEX_DATE)); verifySchema(result, schema("f1", null, "integer"), schema("f2", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(200803, 200701)); } @Test public void testPeriodDiff() throws IOException { - var result = - executeQuery( - String.format( - "source=%s | eval f1 = PERIOD_DIFF(200802, 200703), f2 = PERIOD_DIFF(200802," - + " 201003) | fields f1, f2", - TEST_INDEX_DATE)); + var result = executeQuery(String.format( + "source=%s | eval f1 = PERIOD_DIFF(200802, 200703), f2 = PERIOD_DIFF(200802, 201003) | fields f1, f2", TEST_INDEX_DATE)); verifySchema(result, schema("f1", null, "integer"), schema("f2", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(11, -25)); } + @Test public void testDateDiff() throws IOException { - var result = - executeQuery( - String.format( - "source=%s | eval `'2000-01-02' - '2000-01-01'` = DATEDIFF(TIMESTAMP('2000-01-02" - + " 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` =" - + " 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`", - TEST_INDEX_DATE)); - verifySchema( - result, + var result = executeQuery(String.format("source=%s | eval" + + " `'2000-01-02' - '2000-01-01'` = DATEDIFF(TIMESTAMP('2000-01-02 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'), 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`", TEST_INDEX_DATE)); + verifySchema(result, schema("'2000-01-02' - '2000-01-01'", null, "long"), schema("'2001-02-01' - '2004-01-01'", null, "long"), schema("'2004-01-01' - '2002-02-01'", null, "long"), @@ -1451,124 +1028,90 @@ public void testDateDiff() throws IOException { @Test public void testTimeDiff() throws IOException { - var result = - executeQuery( - String.format( - "source=%s | eval f = TIMEDIFF('23:59:59', '13:00:00') | fields f", - TEST_INDEX_DATE)); + var result = executeQuery(String.format( + "source=%s | eval f = TIMEDIFF('23:59:59', '13:00:00') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "time")); verifySome(result.getJSONArray("datarows"), rows("10:59:59")); } @Test - public void testGetFormat() throws IOException { - var result = - executeQuery( - String.format( - "source=%s | eval f = date_format('2003-10-03', get_format(DATE,'USA')) | fields f", - TEST_INDEX_DATE)); + public void testGetFormat() throws IOException{ + var result = executeQuery(String.format("source=%s | eval f = date_format('2003-10-03', get_format(DATE,'USA')) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "string")); verifySome(result.getJSONArray("datarows"), rows("10.03.2003")); } @Test - public void testLastDay() throws IOException { - var result = - executeQuery( - String.format( - "source=%s | eval f = last_day('2003-10-03') | fields f", TEST_INDEX_DATE)); + public void testLastDay() throws IOException{ + var result = executeQuery(String.format("source=%s | eval f = last_day('2003-10-03') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "date")); verifySome(result.getJSONArray("datarows"), rows("2003-10-31")); } @Test - public void testSecToTime() throws IOException { - var result = - executeQuery( - String.format("source=%s | eval f = sec_to_time(123456) | fields f", TEST_INDEX_DATE)); + public void testSecToTime() throws IOException{ + var result = executeQuery(String.format("source=%s | eval f = sec_to_time(123456) | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "time")); verifySome(result.getJSONArray("datarows"), rows("10:17:36")); } @Test - public void testYearWeek() throws IOException { - var result = - executeQuery( - String.format( - "source=%s | eval f1 = yearweek('2003-10-03') | eval f2 = yearweek('2003-10-03', 3)" - + " | fields f1, f2", - TEST_INDEX_DATE)); - verifySchema(result, schema("f1", null, "integer"), schema("f2", null, "integer")); + public void testYearWeek() throws IOException{ + var result = executeQuery(String.format("source=%s | eval f1 = yearweek('2003-10-03') | eval f2 = yearweek('2003-10-03', 3) | fields f1, f2", TEST_INDEX_DATE)); + verifySchema(result, + schema("f1", null, "integer"), + schema("f2", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(200339, 200340)); } @Test - public void testWeekDay() throws IOException { - var result = - executeQuery( - String.format( - "source=%s | eval f = weekday('2003-10-03') | fields f", TEST_INDEX_DATE)); + public void testWeekDay() throws IOException{ + var result = executeQuery(String.format("source=%s | eval f = weekday('2003-10-03') | fields f", TEST_INDEX_DATE)); verifySchema(result, schema("f", null, "integer")); verifySome(result.getJSONArray("datarows"), rows(4)); } @Test - public void testToSeconds() throws IOException { - var result = - executeQuery( - 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", - TEST_INDEX_DATE)); - verifySchema( - result, schema("f1", null, "long"), schema("f2", null, "long"), schema("f3", null, "long")); + public void testToSeconds() throws IOException{ + var result = executeQuery(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(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")); verifySome(result.getJSONArray("datarows"), rows(63390556800L, 63767461200L, 63767461200L)); } @Test - public void testStrToDate() throws IOException { - var result = - executeQuery( - 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")); + public void testStrToDate() throws IOException{ + var result = executeQuery(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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2013-05-01 00:00:00")); } @Test - public void testTimeStampAdd() throws IOException { - var result = - executeQuery( - 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")); + public void testTimeStampAdd() throws IOException{ + var result = executeQuery(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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2016-03-06 00:00:00")); } @Test - public void testTimestampDiff() throws IOException { - var result = - executeQuery( - String.format( - "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")); + public void testTimestampDiff() throws IOException{ + var result = executeQuery(String.format("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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows(4)); } @Test - public void testExtract() throws IOException { - var result = - executeQuery( - String.format( - "source=%s | eval f1 = extract(YEAR FROM '1997-01-01 00:00:00') | eval f2 =" - + " extract(MINUTE FROM time('10:17:36')) | fields f1, f2", - TEST_INDEX_DATE)); - verifySchema(result, schema("f1", null, "long"), schema("f2", null, "long")); + public void testExtract() throws IOException{ + var result = executeQuery(String.format("source=%s | eval f1 = extract(YEAR FROM '1997-01-01 00:00:00') | eval f2 = extract(MINUTE FROM time('10:17:36')) | fields f1, f2", TEST_INDEX_DATE)); + verifySchema(result, + schema("f1", null, "long"), + schema("f2", null, "long")); verifySome(result.getJSONArray("datarows"), rows(1997L, 17L)); } + + } 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 fb97da32ab..0f842f2d24 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 @@ -26,157 +26,122 @@ public void init() throws IOException { @Test public void inRangeZeroToStringTZ() throws IOException { - JSONObject result = - executeQuery( - String.format( - "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")); + JSONObject result = executeQuery( + String.format("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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-12-24 21:30:00")); } @Test public void inRangeZeroToPositive() throws IOException { - JSONObject result = - executeQuery( - 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")); + JSONObject result = executeQuery( + 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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-12-25 06:30:00")); } @Test public void inRangeNegativeToPositive() throws IOException { - JSONObject result = - executeQuery( - 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")); + JSONObject result = executeQuery( + 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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-12-25 15:30:00")); } @Test public void inRangeTwentyHourOffset() throws IOException { - JSONObject result = - executeQuery( - 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")); + JSONObject result = executeQuery( + 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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2004-02-29 19:00:00")); } @Test public void inRangeYearChange() throws IOException { - JSONObject result = - executeQuery( - 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")); + JSONObject result = executeQuery( + 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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2007-12-31 06:00:00")); } @Test public void inRangeZeroToMax() throws IOException { - JSONObject result = - executeQuery( - 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")); + JSONObject result = executeQuery( + 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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-12-25 19:30:00")); } @Test public void inRangeNoToTZ() throws IOException { - JSONObject result = - executeQuery( - 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")); + JSONObject result = executeQuery( + 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, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-01-01 02:00:00")); } @Test public void inRangeNoTZ() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = DATETIME('2008-01-01 02:00:00') | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); + JSONObject result = executeQuery( + String.format("source=%s | eval f = DATETIME('2008-01-01 02:00:00') | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); verifySome(result.getJSONArray("datarows"), rows("2008-01-01 02:00:00")); } @Test public void nullField3Over() throws IOException { - JSONObject result = - executeQuery( - 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")); - verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); + JSONObject result = executeQuery( + 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, "timestamp")); + verifySome(result.getJSONArray("datarows"), rows(new Object[]{null})); } @Test public void nullField2Under() throws IOException { - JSONObject result = - executeQuery( - 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")); - verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); + JSONObject result = executeQuery( + 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, "timestamp")); + verifySome(result.getJSONArray("datarows"), rows(new Object[]{null})); } @Test public void nullTField3Over() throws IOException { - JSONObject result = - executeQuery( - 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")); - verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); + JSONObject result = executeQuery( + 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, "timestamp")); + verifySome(result.getJSONArray("datarows"), rows(new Object[]{null})); } @Test public void nullDateTimeInvalidDateValueFebruary() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = DATETIME('2021-02-30 10:00:00') | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); - verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); + JSONObject result = executeQuery( + String.format("source=%s | eval f = DATETIME('2021-02-30 10:00:00') | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); + verifySome(result.getJSONArray("datarows"), rows(new Object[]{null})); } @Test public void nullDateTimeInvalidDateValueApril() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = DATETIME('2021-04-31 10:00:00') | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); - verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); + JSONObject result = executeQuery( + String.format("source=%s | eval f = DATETIME('2021-04-31 10:00:00') | fields f", TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "timestamp")); + verifySome(result.getJSONArray("datarows"), rows(new Object[]{null})); } @Test public void nullDateTimeInvalidDateValueMonth() throws IOException { - JSONObject result = - executeQuery( - String.format( - "source=%s | eval f = DATETIME('2021-13-03 10:00:00') | fields f", - TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "datetime")); - verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); + JSONObject result = executeQuery( + String.format("source=%s | eval f = DATETIME('2021-13-03 10:00:00') | fields f", TEST_INDEX_DATE)); + 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 d2cd140e99..1d19322016 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..86b530ed88 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,13 @@ 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 +480,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 +490,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 +500,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 +591,13 @@ 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 +606,13 @@ 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 +621,13 @@ 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 b719edd5b0..da9ef64731 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 @@ -29,7 +29,7 @@ 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")); + schema("convert_tz('2008-05-15 12:00:00','+00:00','+10:00')", null, "timestamp")); verifyDataRows(result, rows("2008-05-15 22:00:00")); } @@ -38,7 +38,7 @@ 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")); + schema("convert_tz('2021-05-12 00:00:00','-00:00','+00:00')", null, "timestamp")); verifyDataRows(result, rows("2021-05-12 00:00:00")); } @@ -47,7 +47,7 @@ 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")); + schema("convert_tz('2021-05-12 00:00:00','+10:00','+11:00')", null, "timestamp")); verifyDataRows(result, rows("2021-05-12 01:00:00")); } @@ -56,7 +56,7 @@ 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")); + schema("convert_tz('2021-05-12 11:34:50','-08:00','+09:00')", null, "timestamp")); verifyDataRows(result, rows("2021-05-13 04:34:50")); } @@ -65,7 +65,7 @@ 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")); + schema("convert_tz('2021-05-12 11:34:50','+09:00','+09:00')", null, "timestamp")); verifyDataRows(result, rows("2021-05-12 11:34:50")); } @@ -74,7 +74,7 @@ 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")); + schema("convert_tz('2021-05-12 11:34:50','-12:00','+12:00')", null, "timestamp")); verifyDataRows(result, rows("2021-05-13 11:34:50")); } @@ -83,7 +83,7 @@ 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")); + schema("convert_tz('2021-05-12 13:00:00','+09:30','+05:45')", null, "timestamp")); verifyDataRows(result, rows("2021-05-12 09:15:00")); } @@ -92,7 +92,7 @@ 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")); + schema("convert_tz('2021-05-12 13:00:00','+09:31','+05:11')", null, "timestamp")); verifyDataRows(result, rows("2021-05-12 08:40:00")); } @@ -101,7 +101,7 @@ 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")); + schema("convert_tz('2021-05-30 11:34:50','-14:00','+08:00')", null, "timestamp")); verifyDataRows(result, rows(new Object[]{null})); } @@ -110,7 +110,7 @@ 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")); + schema("convert_tz('2021-05-12 11:34:50','-12:00','+14:01')", null, "timestamp")); verifyDataRows(result, rows(new Object[]{null})); } @@ -119,7 +119,7 @@ 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")); + schema("convert_tz('2021-05-12 15:00:00','-13:59','-13:59')", null, "timestamp")); verifyDataRows(result, rows("2021-05-12 15:00:00")); } @@ -132,7 +132,7 @@ 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")); + schema("convert_tz('2021-05-12 11:34:50','+10:0','+14:01')", null, "timestamp")); verifyDataRows(result, rows(new Object[]{null})); } @@ -141,18 +141,18 @@ 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")); + 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 { var result = executeJdbcRequest( "SELECT convert_tz('2021----','+00:00','+00:00')"); verifySchema(result, - schema("convert_tz('2021----','+00:00','+00:00')", null, "datetime")); + schema("convert_tz('2021----','+00:00','+00:00')", null, "timestamp")); verifyDataRows(result, rows(new Object[]{null})); } @@ -161,7 +161,7 @@ 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")); + schema("convert_tz('2021-02-30 10:00:00','+00:00','+00:00')", null, "timestamp")); verifyDataRows(result, rows(new Object[]{null})); } @@ -170,7 +170,7 @@ 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")); + schema("convert_tz('2021-04-31 10:00:00','+00:00','+00:00')", null, "timestamp")); verifyDataRows(result, rows(new Object[]{null})); } @@ -179,7 +179,7 @@ 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")); + 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..e25ca98496 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 @@ -54,10 +54,9 @@ public void resetTimeZone() { private String name; private Boolean expectedResult; - public DateTimeComparisonIT( - @Name("functionCall") String functionCall, - @Name("name") String name, - @Name("expectedResult") Boolean expectedResult) { + public DateTimeComparisonIT(@Name("functionCall") String functionCall, + @Name("name") String name, + @Name("expectedResult") Boolean expectedResult) { this.functionCall = functionCall; this.name = name; this.expectedResult = expectedResult; @@ -65,698 +64,333 @@ public DateTimeComparisonIT( @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareTwoDates() { - return Arrays.asList( - $$( - $("DATE('2020-09-16') = DATE('2020-09-16')", "eq1", true), - $("DATE('2020-09-16') = DATE('1961-04-12')", "eq2", false), - $("DATE('2020-09-16') != DATE('1984-12-15')", "neq1", true), - $("DATE('1961-04-12') != DATE('1984-12-15')", "neq2", true), - $("DATE('1961-04-12') != DATE('1961-04-12')", "neq3", false), - $("DATE('1984-12-15') > DATE('1961-04-12')", "gt1", true), - $("DATE('1984-12-15') > DATE('2020-09-16')", "gt2", false), - $("DATE('1961-04-12') < DATE('1984-12-15')", "lt1", true), - $("DATE('1984-12-15') < DATE('1961-04-12')", "lt2", false), - $("DATE('1984-12-15') >= DATE('1961-04-12')", "gte1", true), - $("DATE('1984-12-15') >= DATE('1984-12-15')", "gte2", true), - $("DATE('1984-12-15') >= DATE('2020-09-16')", "gte3", false), - $("DATE('1961-04-12') <= DATE('1984-12-15')", "lte1", true), - $("DATE('1961-04-12') <= DATE('1961-04-12')", "lte2", true), - $("DATE('2020-09-16') <= DATE('1961-04-12')", "lte3", false))); + return Arrays.asList($$( + $("DATE('2020-09-16') = DATE('2020-09-16')", "eq1", true), + $("DATE('2020-09-16') = DATE('1961-04-12')", "eq2", false), + $("DATE('2020-09-16') != DATE('1984-12-15')", "neq1", true), + $("DATE('1961-04-12') != DATE('1984-12-15')", "neq2", true), + $("DATE('1961-04-12') != DATE('1961-04-12')", "neq3", false), + $("DATE('1984-12-15') > DATE('1961-04-12')", "gt1", true), + $("DATE('1984-12-15') > DATE('2020-09-16')", "gt2", false), + $("DATE('1961-04-12') < DATE('1984-12-15')", "lt1", true), + $("DATE('1984-12-15') < DATE('1961-04-12')", "lt2", false), + $("DATE('1984-12-15') >= DATE('1961-04-12')", "gte1", true), + $("DATE('1984-12-15') >= DATE('1984-12-15')", "gte2", true), + $("DATE('1984-12-15') >= DATE('2020-09-16')", "gte3", false), + $("DATE('1961-04-12') <= DATE('1984-12-15')", "lte1", true), + $("DATE('1961-04-12') <= DATE('1961-04-12')", "lte2", true), + $("DATE('2020-09-16') <= DATE('1961-04-12')", "lte3", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareTwoTimes() { - return Arrays.asList( - $$( - $("TIME('09:16:37') = TIME('09:16:37')", "eq1", true), - $("TIME('09:16:37') = TIME('04:12:42')", "eq2", false), - $("TIME('09:16:37') != TIME('12:15:22')", "neq1", true), - $("TIME('04:12:42') != TIME('12:15:22')", "neq2", true), - $("TIME('04:12:42') != TIME('04:12:42')", "neq3", false), - $("TIME('12:15:22') > TIME('04:12:42')", "gt1", true), - $("TIME('12:15:22') > TIME('19:16:03')", "gt2", false), - $("TIME('04:12:42') < TIME('12:15:22')", "lt1", true), - $("TIME('14:12:38') < TIME('12:15:22')", "lt2", false), - $("TIME('12:15:22') >= TIME('04:12:42')", "gte1", true), - $("TIME('12:15:22') >= TIME('12:15:22')", "gte2", true), - $("TIME('12:15:22') >= TIME('19:16:03')", "gte3", false), - $("TIME('04:12:42') <= TIME('12:15:22')", "lte1", true), - $("TIME('04:12:42') <= TIME('04:12:42')", "lte2", true), - $("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))); + return Arrays.asList($$( + $("TIME('09:16:37') = TIME('09:16:37')", "eq1", true), + $("TIME('09:16:37') = TIME('04:12:42')", "eq2", false), + $("TIME('09:16:37') != TIME('12:15:22')", "neq1", true), + $("TIME('04:12:42') != TIME('12:15:22')", "neq2", true), + $("TIME('04:12:42') != TIME('04:12:42')", "neq3", false), + $("TIME('12:15:22') > TIME('04:12:42')", "gt1", true), + $("TIME('12:15:22') > TIME('19:16:03')", "gt2", false), + $("TIME('04:12:42') < TIME('12:15:22')", "lt1", true), + $("TIME('14:12:38') < TIME('12:15:22')", "lt2", false), + $("TIME('12:15:22') >= TIME('04:12:42')", "gte1", true), + $("TIME('12:15:22') >= TIME('12:15:22')", "gte2", true), + $("TIME('12:15:22') >= TIME('19:16:03')", "gte3", false), + $("TIME('04:12:42') <= TIME('12:15:22')", "lte1", true), + $("TIME('04:12:42') <= TIME('04:12:42')", "lte2", true), + $("TIME('19:16:03') <= TIME('04:12:42')", "lte3", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareTwoTimestamps() { - return Arrays.asList( - $$( - $("TIMESTAMP('2020-09-16 10:20:30') = TIMESTAMP('2020-09-16 10:20:30')", "eq1", true), - $("TIMESTAMP('2020-09-16 10:20:30') = TIMESTAMP('1961-04-12 09:07:00')", "eq2", false), - $("TIMESTAMP('2020-09-16 10:20:30') != TIMESTAMP('1984-12-15 22:15:07')", "neq1", true), - $("TIMESTAMP('1984-12-15 22:15:08') != TIMESTAMP('1984-12-15 22:15:07')", "neq2", true), - $( - "TIMESTAMP('1961-04-12 09:07:00') != TIMESTAMP('1961-04-12 09:07:00')", - "neq3", - false), - $("TIMESTAMP('1984-12-15 22:15:07') > TIMESTAMP('1961-04-12 22:15:07')", "gt1", true), - $("TIMESTAMP('1984-12-15 22:15:07') > TIMESTAMP('1984-12-15 22:15:06')", "gt2", true), - $("TIMESTAMP('1984-12-15 22:15:07') > TIMESTAMP('2020-09-16 10:20:30')", "gt3", false), - $("TIMESTAMP('1961-04-12 09:07:00') < TIMESTAMP('1984-12-15 09:07:00')", "lt1", true), - $("TIMESTAMP('1984-12-15 22:15:07') < TIMESTAMP('1984-12-15 22:15:08')", "lt2", true), - $("TIMESTAMP('1984-12-15 22:15:07') < TIMESTAMP('1961-04-12 09:07:00')", "lt3", false), - $("TIMESTAMP('1984-12-15 22:15:07') >= TIMESTAMP('1961-04-12 09:07:00')", "gte1", true), - $("TIMESTAMP('1984-12-15 22:15:07') >= TIMESTAMP('1984-12-15 22:15:07')", "gte2", true), - $( - "TIMESTAMP('1984-12-15 22:15:07') >= TIMESTAMP('2020-09-16 10:20:30')", - "gte3", - false), - $("TIMESTAMP('1961-04-12 09:07:00') <= TIMESTAMP('1984-12-15 22:15:07')", "lte1", true), - $("TIMESTAMP('1961-04-12 09:07:00') <= TIMESTAMP('1961-04-12 09:07:00')", "lte2", true), - $( - "TIMESTAMP('2020-09-16 10:20:30') <= TIMESTAMP('1961-04-12 09:07:00')", - "lte3", - false))); + return Arrays.asList($$( + $("TIMESTAMP('2020-09-16 10:20:30') = TIMESTAMP('2020-09-16 10:20:30')", "eq1", true), + $("TIMESTAMP('2020-09-16 10:20:30') = TIMESTAMP('1961-04-12 09:07:00')", "eq2", false), + $("TIMESTAMP('2020-09-16 10:20:30') != TIMESTAMP('1984-12-15 22:15:07')", "neq1", true), + $("TIMESTAMP('1984-12-15 22:15:08') != TIMESTAMP('1984-12-15 22:15:07')", "neq2", true), + $("TIMESTAMP('1961-04-12 09:07:00') != TIMESTAMP('1961-04-12 09:07:00')", "neq3", false), + $("TIMESTAMP('1984-12-15 22:15:07') > TIMESTAMP('1961-04-12 22:15:07')", "gt1", true), + $("TIMESTAMP('1984-12-15 22:15:07') > TIMESTAMP('1984-12-15 22:15:06')", "gt2", true), + $("TIMESTAMP('1984-12-15 22:15:07') > TIMESTAMP('2020-09-16 10:20:30')", "gt3", false), + $("TIMESTAMP('1961-04-12 09:07:00') < TIMESTAMP('1984-12-15 09:07:00')", "lt1", true), + $("TIMESTAMP('1984-12-15 22:15:07') < TIMESTAMP('1984-12-15 22:15:08')", "lt2", true), + $("TIMESTAMP('1984-12-15 22:15:07') < TIMESTAMP('1961-04-12 09:07:00')", "lt3", false), + $("TIMESTAMP('1984-12-15 22:15:07') >= TIMESTAMP('1961-04-12 09:07:00')", "gte1", true), + $("TIMESTAMP('1984-12-15 22:15:07') >= TIMESTAMP('1984-12-15 22:15:07')", "gte2", true), + $("TIMESTAMP('1984-12-15 22:15:07') >= TIMESTAMP('2020-09-16 10:20:30')", "gte3", false), + $("TIMESTAMP('1961-04-12 09:07:00') <= TIMESTAMP('1984-12-15 22:15:07')", "lte1", true), + $("TIMESTAMP('1961-04-12 09:07:00') <= TIMESTAMP('1961-04-12 09:07:00')", "lte2", true), + $("TIMESTAMP('2020-09-16 10:20:30') <= TIMESTAMP('1961-04-12 09:07:00')", "lte3", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("DATE('1961-04-12') = TIMESTAMP('1984-12-15 22:15:07')", "d_ts_f", false), - $("TIMESTAMP('" + today + " 10:20:30') = TIME('10:20:30')", "ts_t_t", true), - $("TIME('10:20:30') = TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), - $("TIMESTAMP('2020-09-16 10:20:30') = TIME('09:07:00')", "ts_t_f", false), - $("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))); + return Arrays.asList($$( + $("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), + $("DATE('1961-04-12') = TIMESTAMP('1984-12-15 22:15:07')", "d_ts_f", false), + $("TIMESTAMP('" + today + " 10:20:30') = TIME('10:20:30')", "ts_t_t", true), + $("TIME('10:20:30') = TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), + $("TIMESTAMP('2020-09-16 10:20:30') = TIME('09:07:00')", "ts_t_f", false), + $("TIME('09:07:00') = TIMESTAMP('1984-12-15 22:15:07')", "t_ts_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareEqDateWithOtherTypes() { var today = LocalDate.now().toString(); - return Arrays.asList( - $$( - $("DATE('2020-09-16') = TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), - $("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), - $("TIME('09:07:00') = DATE('" + today + "')", "t_d_f", false))); + return Arrays.asList($$( + $("DATE('2020-09-16') = TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), + $("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('" + 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), + $("TIME('09:07:00') = DATE('" + today + "')", "t_d_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("TIMESTAMP('1984-12-15 10:20:30') = TIME('10:20:30')", "ts_t_f", false), - $("TIME('00:00:00') = DATE('" + today + "')", "t_d_t", true), - $("DATE('" + today + "') = TIME('00:00:00')", "d_t_t", true), - $("TIME('09:07:00') = DATE('" + today + "')", "t_d_f", false), - $("DATE('2020-09-16') = TIME('09:07:00')", "d_t_f", false))); + return Arrays.asList($$( + $("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), + $("TIMESTAMP('1984-12-15 10:20:30') = TIME('10:20:30')", "ts_t_f", false), + $("TIME('00:00:00') = DATE('" + today + "')", "t_d_t", true), + $("DATE('" + today + "') = TIME('00:00:00')", "d_t_t", true), + $("TIME('09:07:00') = DATE('" + today + "')", "t_d_f", false), + $("DATE('2020-09-16') = TIME('09:07:00')", "d_t_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("DATE('2020-09-16') != TIMESTAMP('2020-09-16 00:00:00')", "d_ts_f", false), - $("TIMESTAMP('2020-09-16 10:20:30') != TIME('09:07:00')", "ts_t_t", true), - $("TIME('09:07:00') != TIMESTAMP('1984-12-15 22:15:07')", "t_ts_t", true), - $("TIMESTAMP('" + today + " 10:20:30') != TIME('10:20:30')", "ts_t_f", false), - $("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))); + return Arrays.asList($$( + $("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), + $("DATE('2020-09-16') != TIMESTAMP('2020-09-16 00:00:00')", "d_ts_f", false), + $("TIMESTAMP('2020-09-16 10:20:30') != TIME('09:07:00')", "ts_t_t", true), + $("TIME('09:07:00') != TIMESTAMP('1984-12-15 22:15:07')", "t_ts_t", true), + $("TIMESTAMP('" + today + " 10:20:30') != TIME('10:20:30')", "ts_t_f", false), + $("TIME('10:20:30') != TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareNeqDateWithOtherTypes() { var today = LocalDate.now().toString(); - return Arrays.asList( - $$( - $("DATE('2020-09-16') != TIMESTAMP('1961-04-12 09:07:00')", "d_ts_t", true), - $("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), - $("TIME('00:00:00') != DATE('" + today + "')", "t_d_f", false))); + return Arrays.asList($$( + $("DATE('2020-09-16') != TIMESTAMP('1961-04-12 09:07:00')", "d_ts_t", true), + $("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('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), + $("TIME('00:00:00') != DATE('" + today + "')", "t_d_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("TIMESTAMP('" + today + " 10:20:30') != TIME('10:20:30')", "ts_t_f", false), - $("TIME('09:07:00') != DATE('" + today + "')", "t_d_t", true), - $("DATE('2020-09-16') != TIME('09:07:00')", "d_t_t", true), - $("TIME('00:00:00') != DATE('" + today + "')", "t_d_f", false), - $("DATE('" + today + "') != TIME('00:00:00')", "d_t_f", false))); + return Arrays.asList($$( + $("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), + $("TIMESTAMP('" + today + " 10:20:30') != TIME('10:20:30')", "ts_t_f", false), + $("TIME('09:07:00') != DATE('" + today + "')", "t_d_t", true), + $("DATE('2020-09-16') != TIME('09:07:00')", "d_t_t", true), + $("TIME('00:00:00') != DATE('" + today + "')", "t_d_f", false), + $("DATE('" + today + "') != TIME('00:00:00')", "d_t_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("DATE('2020-09-16') < TIMESTAMP('2020-09-16 00:00:00')", "d_ts_f", false), - $("TIMESTAMP('2020-09-16 10:20:30') < TIME('09:07:00')", "ts_t_t", true), - $("TIME('09:07:00') < TIMESTAMP('3077-12-15 22:15:07')", "t_ts_t", true), - $("TIMESTAMP('" + today + " 10:20:30') < TIME('10:20:30')", "ts_t_f", false), - $("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))); + return Arrays.asList($$( + $("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), + $("DATE('2020-09-16') < TIMESTAMP('2020-09-16 00:00:00')", "d_ts_f", false), + $("TIMESTAMP('2020-09-16 10:20:30') < TIME('09:07:00')", "ts_t_t", true), + $("TIME('09:07:00') < TIMESTAMP('3077-12-15 22:15:07')", "t_ts_t", true), + $("TIMESTAMP('" + today + " 10:20:30') < TIME('10:20:30')", "ts_t_f", false), + $("TIME('20:50:40') < TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareLtDateWithOtherTypes() { - return Arrays.asList( - $$( - $("DATE('2020-09-16') < TIMESTAMP('3077-04-12 09:07:00')", "d_ts_t", true), - $("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), - $("TIME('00:00:00') < DATE('2020-09-16')", "t_d_f", false))); + return Arrays.asList($$( + $("DATE('2020-09-16') < TIMESTAMP('3077-04-12 09:07:00')", "d_ts_t", true), + $("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('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), + $("TIME('00:00:00') < DATE('2020-09-16')", "t_d_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("TIMESTAMP('" + today + " 20:50:42') < TIME('10:20:30')", "ts_t_f", false), - $("TIME('09:07:00') < DATE('3077-04-12')", "t_d_t", true), - $("DATE('2020-09-16') < TIME('09:07:00')", "d_t_t", true), - $("TIME('00:00:00') < DATE('1961-04-12')", "t_d_f", false), - $("DATE('3077-04-12') < TIME('10:20:30')", "d_t_f", false))); + return Arrays.asList($$( + $("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), + $("TIMESTAMP('" + today + " 20:50:42') < TIME('10:20:30')", "ts_t_f", false), + $("TIME('09:07:00') < DATE('3077-04-12')", "t_d_t", true), + $("DATE('2020-09-16') < TIME('09:07:00')", "d_t_t", true), + $("TIME('00:00:00') < DATE('1961-04-12')", "t_d_f", false), + $("DATE('3077-04-12') < TIME('10:20:30')", "d_t_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("DATE('1961-04-12') > TIMESTAMP('1961-04-12 00:00:00')", "d_ts_f", false), - $("TIMESTAMP('3077-07-08 20:20:30') > TIME('10:20:30')", "ts_t_t", true), - $("TIME('20:50:40') > TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), - $("TIMESTAMP('" + today + " 10:20:30') > TIME('10:20:30')", "ts_t_f", false), - $("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))); + return Arrays.asList($$( + $("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), + $("DATE('1961-04-12') > TIMESTAMP('1961-04-12 00:00:00')", "d_ts_f", false), + $("TIMESTAMP('3077-07-08 20:20:30') > TIME('10:20:30')", "ts_t_t", true), + $("TIME('20:50:40') > TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), + $("TIMESTAMP('" + today + " 10:20:30') > TIME('10:20:30')", "ts_t_f", false), + $("TIME('09:07:00') > TIMESTAMP('3077-12-15 22:15:07')", "t_ts_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareGtDateWithOtherTypes() { - return Arrays.asList( - $$( - $("DATE('2020-09-16') > TIMESTAMP('1961-04-12 09:07:00')", "d_ts_t", true), - $("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), - $("TIME('09:07:00') > DATE('3077-04-12')", "t_d_f", false))); + return Arrays.asList($$( + $("DATE('2020-09-16') > TIMESTAMP('1961-04-12 09:07:00')", "d_ts_t", true), + $("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('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), + $("TIME('09:07:00') > DATE('3077-04-12')", "t_d_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("TIMESTAMP('1984-12-15 10:20:30') > TIME('10:20:30')", "ts_t_f", false), - $("TIME('00:00:00') > DATE('1961-04-12')", "t_d_t", true), - $("DATE('3077-04-12') > TIME('10:20:30')", "d_t_t", true), - $("TIME('09:07:00') > DATE('3077-04-12')", "t_d_f", false), - $("DATE('2020-09-16') > TIME('09:07:00')", "d_t_f", false))); + return Arrays.asList($$( + $("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), + $("TIMESTAMP('1984-12-15 10:20:30') > TIME('10:20:30')", "ts_t_f", false), + $("TIME('00:00:00') > DATE('1961-04-12')", "t_d_t", true), + $("DATE('3077-04-12') > TIME('10:20:30')", "d_t_t", true), + $("TIME('09:07:00') > DATE('3077-04-12')", "t_d_f", false), + $("DATE('2020-09-16') > TIME('09:07:00')", "d_t_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("DATE('2077-04-12') <= TIMESTAMP('1984-12-15 22:15:07')", "d_ts_f", false), - $("TIMESTAMP('" + today + " 10:20:30') <= TIME('10:20:30')", "ts_t_t", true), - $("TIME('09:07:00') <= TIMESTAMP('3077-12-15 22:15:07')", "t_ts_t", true), - $("TIMESTAMP('3077-09-16 10:20:30') <= TIME('09:07:00')", "ts_t_f", false), - $("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))); + return Arrays.asList($$( + $("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), + $("DATE('2077-04-12') <= TIMESTAMP('1984-12-15 22:15:07')", "d_ts_f", false), + $("TIMESTAMP('" + today + " 10:20:30') <= TIME('10:20:30')", "ts_t_t", true), + $("TIME('09:07:00') <= TIMESTAMP('3077-12-15 22:15:07')", "t_ts_t", true), + $("TIMESTAMP('3077-09-16 10:20:30') <= TIME('09:07:00')", "ts_t_f", false), + $("TIME('20:50:40') <= TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareLteDateWithOtherTypes() { - return Arrays.asList( - $$( - $("DATE('2020-09-16') <= TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), - $("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), - $("TIME('00:00:00') <= DATE('2020-09-16')", "t_d_f", false))); + return Arrays.asList($$( + $("DATE('2020-09-16') <= TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), + $("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') <= 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), + $("TIME('00:00:00') <= DATE('2020-09-16')", "t_d_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("TIMESTAMP('" + today + " 20:50:42') <= TIME('10:20:30')", "ts_t_f", false), - $("TIME('09:07:00') <= DATE('3077-04-12')", "t_d_t", true), - $("DATE('2020-09-16') <= TIME('09:07:00')", "d_t_t", true), - $("TIME('00:00:00') <= DATE('1961-04-12')", "t_d_f", false), - $("DATE('3077-04-12') <= TIME('10:20:30')", "d_t_f", false))); + return Arrays.asList($$( + $("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), + $("TIMESTAMP('" + today + " 20:50:42') <= TIME('10:20:30')", "ts_t_f", false), + $("TIME('09:07:00') <= DATE('3077-04-12')", "t_d_t", true), + $("DATE('2020-09-16') <= TIME('09:07:00')", "d_t_t", true), + $("TIME('00:00:00') <= DATE('1961-04-12')", "t_d_f", false), + $("DATE('3077-04-12') <= TIME('10:20:30')", "d_t_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("DATE('1961-04-11') >= TIMESTAMP('1961-04-12 00:00:00')", "d_ts_f", false), - $("TIMESTAMP('" + today + " 10:20:30') >= TIME('10:20:30')", "ts_t_t", true), - $("TIME('20:50:40') >= TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), - $("TIMESTAMP('1977-07-08 10:20:30') >= TIME('10:20:30')", "ts_t_f", false), - $("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))); + return Arrays.asList($$( + $("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), + $("DATE('1961-04-11') >= TIMESTAMP('1961-04-12 00:00:00')", "d_ts_f", false), + $("TIMESTAMP('" + today + " 10:20:30') >= TIME('10:20:30')", "ts_t_t", true), + $("TIME('20:50:40') >= TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), + $("TIMESTAMP('1977-07-08 10:20:30') >= TIME('10:20:30')", "ts_t_f", false), + $("TIME('09:07:00') >= TIMESTAMP('3077-12-15 22:15:07')", "t_ts_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareGteDateWithOtherTypes() { - return Arrays.asList( - $$( - $("DATE('2020-09-16') >= TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), - $("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), - $("TIME('09:07:00') >= DATE('3077-04-12')", "t_d_f", false))); + return Arrays.asList($$( + $("DATE('2020-09-16') >= TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), + $("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('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), + $("TIME('09:07:00') >= DATE('3077-04-12')", "t_d_f", false) + )); } @ParametersFactory(argumentFormatting = "%1$s => %3$s") 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), - $("TIMESTAMP('1984-12-15 10:20:30') >= TIME('10:20:30')", "ts_t_f", false), - $("TIME('00:00:00') >= DATE('1961-04-12')", "t_d_t", true), - $("DATE('3077-04-12') >= TIME('10:20:30')", "d_t_t", true), - $("TIME('09:07:00') >= DATE('3077-04-12')", "t_d_f", false), - $("DATE('2020-09-16') >= TIME('09:07:00')", "d_t_f", false))); + return Arrays.asList($$( + $("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), + $("TIMESTAMP('1984-12-15 10:20:30') >= TIME('10:20:30')", "ts_t_f", false), + $("TIME('00:00:00') >= DATE('1961-04-12')", "t_d_t", true), + $("DATE('3077-04-12') >= TIME('10:20:30')", "d_t_t", true), + $("TIME('09:07:00') >= DATE('3077-04-12')", "t_d_f", false), + $("DATE('2020-09-16') >= TIME('09:07:00')", "d_t_f", false) + )); } @Test 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..721024382c 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 @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ + package org.opensearch.sql.sql; import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK; @@ -59,14 +60,12 @@ public void resetTimeZone() { } @Test - public void testDateInGroupBy() throws IOException { + public void testDateInGroupBy() throws IOException{ JSONObject result = - executeQuery( - String.format( - "SELECT DATE(birthdate) FROM %s GROUP BY DATE(birthdate)", TEST_INDEX_BANK)); - verifySchema(result, schema("DATE(birthdate)", null, "date")); - verifyDataRows( - result, + executeQuery(String.format("SELECT DATE(birthdate) FROM %s GROUP BY DATE(birthdate)",TEST_INDEX_BANK) ); + verifySchema(result, + schema("DATE(birthdate)", null, "date")); + verifyDataRows(result, rows("2017-10-23"), rows("2017-11-20"), rows("2018-06-23"), @@ -79,11 +78,9 @@ public void testDateInGroupBy() throws IOException { @Test public void testDateWithHavingClauseOnly() throws IOException { JSONObject result = - executeQuery( - String.format( - "SELECT (TO_DAYS(DATE('2050-01-01')) - 693961) FROM %s HAVING (COUNT(1) > 0)", - TEST_INDEX_BANK)); - verifySchema(result, schema("(TO_DAYS(DATE('2050-01-01')) - 693961)", null, "long")); + executeQuery(String.format("SELECT (TO_DAYS(DATE('2050-01-01')) - 693961) FROM %s HAVING (COUNT(1) > 0)",TEST_INDEX_BANK) ); + verifySchema(result, + schema("(TO_DAYS(DATE('2050-01-01')) - 693961)", null, "long")); verifyDataRows(result, rows(54787)); } @@ -94,15 +91,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")); } @@ -110,98 +107,78 @@ public void testAddDateWithDays() throws IOException { public void testAddDateWithInterval() throws IOException { JSONObject result = 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")); + verifySchema(result, + 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")); - verifyDataRows( - result, - rows( - LocalDate.now() - .plusDays(1) - .atTime(LocalTime.of(7, 40)) - .atZone(systemTz.toZoneId()) - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); + verifySchema(result, + schema("adddate(TIME('07:40:00'), interval 1 day)", null, "timestamp")); + verifyDataRows(result, + rows(LocalDate.now().plusDays(1).atTime(LocalTime.of(7, 40)).atZone(systemTz.toZoneId()) + .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")); - verifyDataRows( - result, - rows( - LocalDate.now() - .atTime(LocalTime.of(8, 40)) - .atZone(systemTz.toZoneId()) - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); + verifySchema(result, + schema("adddate(TIME('07:40:00'), interval 1 hour)", null, "timestamp")); + verifyDataRows(result, + rows(LocalDate.now().atTime(LocalTime.of(8, 40)).atZone(systemTz.toZoneId()) + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); } @Test public void testDateAdd() throws IOException { JSONObject result = 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")); + verifySchema(result, + 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)"); - verifySchema( - result, - schema("date_add(DATETIME('2020-09-16 17:30:00'), interval 1 day)", null, "datetime")); + result = 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, "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")); - verifyDataRows( - result, - rows( - LocalDate.now() - .plusDays(1) - .atTime(LocalTime.of(7, 40)) - .atZone(systemTz.toZoneId()) - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); + verifySchema(result, + schema("date_add(TIME('07:40:00'), interval 1 day)", null, "timestamp")); + verifyDataRows(result, + rows(LocalDate.now().plusDays(1).atTime(LocalTime.of(7, 40)).atZone(systemTz.toZoneId()) + .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")); - verifyDataRows( - result, - rows( - LocalDate.now() - .atTime(LocalTime.of(8, 40)) - .atZone(systemTz.toZoneId()) - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); - - result = - 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")); - verifyDataRows( - result, + verifySchema(result, + schema("date_add(TIME('07:40:00'), interval 1 hour)", null, "timestamp")); + verifyDataRows(result, + rows(LocalDate.now().atTime(LocalTime.of(8, 40)).atZone(systemTz.toZoneId()) + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); + + result = 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, "timestamp")); + verifyDataRows(result, rows("2018-10-23 00:00:00"), rows("2018-11-20 00:00:00"), rows("2019-06-23 00:00:00"), @@ -215,45 +192,38 @@ public void testDateAdd() throws IOException { public void testDateSub() throws IOException { JSONObject result = 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")); + verifySchema(result, + 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)"); - verifySchema( - result, - schema("date_sub(DATETIME('2020-09-16 17:30:00'), interval 1 day)", null, "datetime")); + result = 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, "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")); - verifyDataRows( - result, - rows( - LocalDate.now() - .plusDays(-1) - .atTime(LocalTime.of(7, 40)) - .atZone(systemTz.toZoneId()) - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); + verifySchema(result, + schema("date_sub(TIME('07:40:00'), interval 1 day)", null, "timestamp")); + verifyDataRows(result, + rows(LocalDate.now().plusDays(-1).atTime(LocalTime.of(7, 40)).atZone(systemTz.toZoneId()) + .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")); - verifyDataRows( - result, - rows( - LocalDate.now() - .atTime(LocalTime.of(6, 40)) - .atZone(systemTz.toZoneId()) - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); + verifySchema(result, + schema("date_sub(TIME('07:40:00'), interval 1 hour)", null, "timestamp")); + verifyDataRows(result, + rows(LocalDate.now().atTime(LocalTime.of(6, 40)).atZone(systemTz.toZoneId()) + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); } @Test @@ -307,34 +277,30 @@ public void testDayOfMonthAliasesReturnTheSameResults() throws IOException { verifyDataRows(result1, rows(22)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = executeQuery(String.format("SELECT dayofmonth(date0) FROM %s", TEST_INDEX_CALCS)); - result2 = executeQuery(String.format("SELECT day_of_month(date0) FROM %s", TEST_INDEX_CALCS)); + result1 = executeQuery(String.format( + "SELECT dayofmonth(date0) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT day_of_month(date0) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = - executeQuery( - String.format( - "SELECT dayofmonth(datetime(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)); + result1 = executeQuery(String.format( + "SELECT dayofmonth(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT day_of_month(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = - executeQuery( - String.format("SELECT dayofmonth(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); - result2 = - executeQuery( - String.format("SELECT day_of_month(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); + result1 = executeQuery(String.format( + "SELECT dayofmonth(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT day_of_month(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = executeQuery(String.format("SELECT dayofmonth(datetime0) FROM %s", TEST_INDEX_CALCS)); - result2 = - executeQuery(String.format("SELECT day_of_month(datetime0) FROM %s", TEST_INDEX_CALCS)); + result1 = executeQuery(String.format( + "SELECT dayofmonth(datetime0) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT day_of_month(datetime0) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); } - @Test public void testDayOfWeek() throws IOException { JSONObject result = executeQuery("select dayofweek(date('2020-09-16'))"); @@ -364,31 +330,28 @@ public void testDayOfWeekAliasesReturnTheSameResults() throws IOException { verifyDataRows(result1, rows(3)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = executeQuery(String.format("SELECT dayofweek(date0) FROM %s", TEST_INDEX_CALCS)); - result2 = executeQuery(String.format("SELECT day_of_week(date0) FROM %s", TEST_INDEX_CALCS)); + result1 = executeQuery(String.format( + "SELECT dayofweek(date0) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT day_of_week(date0) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = - executeQuery( - String.format( - "SELECT dayofweek(datetime(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)); + result1 = executeQuery(String.format( + "SELECT dayofweek(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT day_of_week(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = - executeQuery( - String.format("SELECT dayofweek(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); - result2 = - executeQuery( - String.format("SELECT day_of_week(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); + result1 = executeQuery(String.format( + "SELECT dayofweek(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT day_of_week(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = executeQuery(String.format("SELECT dayofweek(datetime0) FROM %s", TEST_INDEX_CALCS)); - result2 = - executeQuery(String.format("SELECT day_of_week(datetime0) FROM %s", TEST_INDEX_CALCS)); + result1 = executeQuery(String.format( + "SELECT dayofweek(datetime0) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT day_of_week(datetime0) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); } @@ -409,8 +372,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'))"); @@ -429,34 +392,30 @@ public void testDayOfYearAlternateSyntaxesReturnTheSameResults() throws IOExcept verifyDataRows(result1, rows(326)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = executeQuery(String.format("SELECT dayofyear(date0) FROM %s", TEST_INDEX_CALCS)); - result2 = executeQuery(String.format("SELECT day_of_year(date0) FROM %s", TEST_INDEX_CALCS)); + result1 = executeQuery(String.format( + "SELECT dayofyear(date0) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT day_of_year(date0) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = - executeQuery( - String.format( - "SELECT dayofyear(datetime(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)); + result1 = executeQuery(String.format( + "SELECT dayofyear(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT day_of_year(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = - executeQuery( - String.format("SELECT dayofyear(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); - result2 = - executeQuery( - String.format("SELECT day_of_year(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); + result1 = executeQuery(String.format( + "SELECT dayofyear(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT day_of_year(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = executeQuery(String.format("SELECT dayofyear(datetime0) FROM %s", TEST_INDEX_CALCS)); - result2 = - executeQuery(String.format("SELECT day_of_year(datetime0) FROM %s", TEST_INDEX_CALCS)); + result1 = executeQuery(String.format( + "SELECT dayofyear(datetime0) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT day_of_year(datetime0) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); } - @Test public void testFromDays() throws IOException { JSONObject result = executeQuery("select from_days(738049)"); @@ -486,11 +445,8 @@ public void testHour() throws IOException { @Test public void testHourOfDayWithUnderscores() throws IOException { JSONObject result = executeQuery("select hour_of_day(timestamp('2020-09-16 17:30:00'))"); - 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")); + 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(time('17:30:00'))"); @@ -508,45 +464,41 @@ public void testHourOfDayWithUnderscores() throws IOException { @Test public void testExtractWithDatetime() throws IOException { - JSONObject datetimeResult = - executeQuery( - String.format( - "SELECT extract(DAY_SECOND FROM datetime(cast(datetime0 AS STRING))) FROM %s LIMIT" - + " 1", - TEST_INDEX_CALCS)); + JSONObject datetimeResult = executeQuery( + String.format( + "SELECT extract(DAY_SECOND FROM timestamp(cast(datetime0 AS STRING))) FROM %s LIMIT 1", + TEST_INDEX_CALCS)); verifyDataRows(datetimeResult, rows(9101735)); } @Test public void testExtractWithTime() throws IOException { - JSONObject timeResult = - executeQuery( - String.format( - "SELECT extract(HOUR_SECOND FROM time0) FROM %s LIMIT 1", TEST_INDEX_CALCS)); + JSONObject timeResult = executeQuery( + String.format( + "SELECT extract(HOUR_SECOND FROM time0) FROM %s LIMIT 1", + TEST_INDEX_CALCS)); verifyDataRows(timeResult, rows(210732)); + } @Test public void testExtractWithDate() throws IOException { - JSONObject dateResult = - executeQuery( - String.format( - "SELECT extract(YEAR_MONTH FROM date0) FROM %s LIMIT 1", TEST_INDEX_CALCS)); + JSONObject dateResult = executeQuery( + String.format( + "SELECT extract(YEAR_MONTH FROM date0) FROM %s LIMIT 1", + TEST_INDEX_CALCS)); verifyDataRows(dateResult, rows(200404)); } @Test public void testExtractWithDifferentTypesReturnSameResult() throws IOException { - JSONObject dateResult = - executeQuery( - String.format( - "SELECT extract(YEAR_MONTH FROM datetime0) FROM %s LIMIT 1", TEST_INDEX_CALCS)); + JSONObject dateResult = executeQuery( + String.format("SELECT extract(YEAR_MONTH FROM datetime0) FROM %s LIMIT 1", TEST_INDEX_CALCS)); - JSONObject datetimeResult = - executeQuery( - String.format( - "SELECT extract(YEAR_MONTH FROM date(datetime0)) FROM %s LIMIT 1", - TEST_INDEX_CALCS)); + JSONObject datetimeResult = executeQuery( + String.format( + "SELECT extract(YEAR_MONTH FROM date(datetime0)) FROM %s LIMIT 1", + TEST_INDEX_CALCS)); dateResult.getJSONArray("datarows").similar(datetimeResult.getJSONArray("datarows")); } @@ -558,55 +510,63 @@ public void testHourFunctionAliasesReturnTheSameResults() throws IOException { verifyDataRows(result1, rows(11)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = - executeQuery( - String.format( - "SELECT hour(datetime(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)); + result1 = executeQuery(String.format( + "SELECT hour(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT hour_of_day(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = - executeQuery(String.format("SELECT hour(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); - result2 = - executeQuery( - String.format("SELECT hour_of_day(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); + result1 = executeQuery(String.format( + "SELECT hour(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT hour_of_day(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = executeQuery(String.format("SELECT hour(datetime0) FROM %s", TEST_INDEX_CALCS)); - result2 = - executeQuery(String.format("SELECT hour_of_day(datetime0) FROM %s", TEST_INDEX_CALCS)); + result1 = executeQuery(String.format( + "SELECT hour(datetime0) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT hour_of_day(datetime0) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); } @Test public void testLastDay() throws IOException { - JSONObject result = - executeQuery(String.format("SELECT last_day(date0) FROM %s LIMIT 3", TEST_INDEX_CALCS)); - verifyDataRows(result, rows("2004-04-30"), rows("1972-07-31"), rows("1975-11-30")); - - result = - executeQuery(String.format("SELECT last_day(date0) FROM %s LIMIT 3", TEST_INDEX_CALCS)); - verifyDataRows(result, rows("2004-04-30"), rows("1972-07-31"), rows("1975-11-30")); - - result = - executeQuery(String.format("SELECT last_day(date0) FROM %s LIMIT 3", TEST_INDEX_CALCS)); - verifyDataRows(result, rows("2004-04-30"), rows("1972-07-31"), rows("1975-11-30")); + JSONObject result = executeQuery( + String.format("SELECT last_day(date0) FROM %s LIMIT 3", + TEST_INDEX_CALCS)); + verifyDataRows(result, + rows("2004-04-30"), + rows("1972-07-31"), + rows("1975-11-30")); + + result = executeQuery( + String.format("SELECT last_day(date0) FROM %s LIMIT 3", + TEST_INDEX_CALCS)); + verifyDataRows(result, + rows("2004-04-30"), + rows("1972-07-31"), + rows("1975-11-30")); + + result = executeQuery( + String.format("SELECT last_day(date0) FROM %s LIMIT 3", + TEST_INDEX_CALCS)); + verifyDataRows(result, + rows("2004-04-30"), + rows("1972-07-31"), + rows("1975-11-30")); } @Test public void testMicrosecond() throws IOException { JSONObject result = executeQuery("select microsecond(timestamp('2020-09-16 17:30:00.123456'))"); - verifySchema( - result, schema("microsecond(timestamp('2020-09-16 17:30:00.123456'))", null, "integer")); + verifySchema(result, + schema("microsecond(timestamp('2020-09-16 17:30:00.123456'))", null, "integer")); verifyDataRows(result, rows(123456)); // Explicit timestamp value with less than 6 microsecond digits result = executeQuery("select microsecond(timestamp('2020-09-16 17:30:00.1234'))"); - verifySchema( - result, schema("microsecond(timestamp('2020-09-16 17:30:00.1234'))", null, "integer")); + verifySchema(result, + schema("microsecond(timestamp('2020-09-16 17:30:00.1234'))", null, "integer")); verifyDataRows(result, rows(123400)); result = executeQuery("select microsecond(time('17:30:00.000010'))"); @@ -656,15 +616,15 @@ public void testMinute() throws IOException { verifyDataRows(result, rows(30)); } + @Test public void testMinuteOfDay() throws IOException { JSONObject 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")); + 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(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'))"); @@ -683,8 +643,8 @@ public void testMinuteOfDay() throws IOException { @Test public void testMinuteOfHour() throws IOException { JSONObject result = executeQuery("select minute_of_hour(timestamp('2020-09-16 17:30:00'))"); - verifySchema( - result, schema("minute_of_hour(timestamp('2020-09-16 17:30:00'))", null, "integer")); + verifySchema(result, schema( + "minute_of_hour(timestamp('2020-09-16 17:30:00'))", null, "integer")); verifyDataRows(result, rows(30)); result = executeQuery("select minute_of_hour(time('17:30:00'))"); @@ -707,29 +667,22 @@ public void testMinuteFunctionAliasesReturnTheSameResults() throws IOException { verifyDataRows(result1, rows(30)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = - executeQuery( - String.format( - "SELECT minute(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); - result2 = - executeQuery( - String.format( - "SELECT minute_of_hour(datetime(CAST(time0 AS STRING))) FROM %s", - TEST_INDEX_CALCS)); + result1 = executeQuery(String.format( + "SELECT minute(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT minute_of_hour(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = - executeQuery( - String.format("SELECT minute(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); - result2 = - executeQuery( - String.format( - "SELECT minute_of_hour(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); + result1 = executeQuery(String.format( + "SELECT minute(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT minute_of_hour(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = executeQuery(String.format("SELECT minute(datetime0) FROM %s", TEST_INDEX_CALCS)); - result2 = - executeQuery(String.format("SELECT minute_of_hour(datetime0) FROM %s", TEST_INDEX_CALCS)); + result1 = executeQuery(String.format( + "SELECT minute(datetime0) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT minute_of_hour(datetime0) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); } @@ -750,13 +703,12 @@ 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'))"); - verifySchema( - result, schema("month_of_year(timestamp('2020-09-16 00:00:00'))", null, "integer")); + 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('2020-09-16')"); @@ -771,31 +723,28 @@ public void testMonthAlternateSyntaxesReturnTheSameResults() throws IOException verifyDataRows(result1, rows(11)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = executeQuery(String.format("SELECT month(date0) FROM %s", TEST_INDEX_CALCS)); - result2 = executeQuery(String.format("SELECT month_of_year(date0) FROM %s", TEST_INDEX_CALCS)); + result1 = executeQuery(String.format( + "SELECT month(date0) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT month_of_year(date0) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = - executeQuery( - String.format( - "SELECT month(datetime(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)); + result1 = executeQuery(String.format( + "SELECT month(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT month_of_year(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = - executeQuery( - String.format("SELECT month(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); - result2 = - executeQuery( - String.format("SELECT month_of_year(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); + result1 = executeQuery(String.format( + "SELECT month(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT month_of_year(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = executeQuery(String.format("SELECT month(datetime0) FROM %s", TEST_INDEX_CALCS)); - result2 = - executeQuery(String.format("SELECT month_of_year(datetime0) FROM %s", TEST_INDEX_CALCS)); + result1 = executeQuery(String.format( + "SELECT month(datetime0) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT month_of_year(datetime0) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); } @@ -823,9 +772,12 @@ public void testQuarter() throws IOException { @Test public void testSecToTime() throws IOException { - JSONObject result = - executeQuery(String.format("SELECT sec_to_time(balance) FROM %s LIMIT 3", TEST_INDEX_BANK)); - verifyDataRows(result, rows("10:53:45"), rows("01:34:46"), rows("09:07:18")); + JSONObject result = executeQuery( + String.format("SELECT sec_to_time(balance) FROM %s LIMIT 3", TEST_INDEX_BANK)); + verifyDataRows(result, + rows("10:53:45"), + rows("01:34:46"), + rows("09:07:18")); } @Test @@ -849,8 +801,7 @@ public void testSecond() throws IOException { public void testSecondOfMinute() throws IOException { JSONObject result = executeQuery("select second_of_minute(timestamp('2020-09-16 17:30:00'))"); - verifySchema( - result, schema("second_of_minute(timestamp('2020-09-16 17:30:00'))", null, "integer")); + verifySchema(result, schema("second_of_minute(timestamp('2020-09-16 17:30:00'))", null, "integer")); verifyDataRows(result, rows(0)); result = executeQuery("select second_of_minute(time('17:30:00'))"); @@ -873,76 +824,78 @@ public void testSecondFunctionAliasesReturnTheSameResults() throws IOException { verifyDataRows(result1, rows(34)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = - executeQuery( - String.format( - "SELECT second(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); - result2 = - executeQuery( - String.format( - "SELECT second_of_minute(datetime(CAST(time0 AS STRING))) FROM %s", - TEST_INDEX_CALCS)); + result1 = executeQuery(String.format( + "SELECT second(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT second_of_minute(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = - executeQuery( - String.format("SELECT second(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); - result2 = - executeQuery( - String.format( - "SELECT second_of_minute(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); + result1 = executeQuery(String.format( + "SELECT second(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT second_of_minute(CAST(time0 AS STRING)) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); - result1 = executeQuery(String.format("SELECT second(datetime0) FROM %s", TEST_INDEX_CALCS)); - result2 = - executeQuery(String.format("SELECT second_of_minute(datetime0) FROM %s", TEST_INDEX_CALCS)); + result1 = executeQuery(String.format( + "SELECT second(datetime0) FROM %s", TEST_INDEX_CALCS)); + result2 = executeQuery(String.format( + "SELECT second_of_minute(datetime0) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); } @Test public void testStrToDate() throws IOException { - // Ideal case - JSONObject result = - executeQuery( - String.format( - "SELECT str_to_date(CAST(birthdate AS STRING)," - + " '%%Y-%%m-%%d %%h:%%i:%%s') FROM %s LIMIT 2", - TEST_INDEX_BANK)); - verifyDataRows(result, rows("2017-10-23 00:00:00"), rows("2017-11-20 00:00:00")); - - // Bad string format case - result = - executeQuery( - String.format( - "SELECT str_to_date(CAST(birthdate AS STRING)," + " '%%Y %%s') FROM %s LIMIT 2", - TEST_INDEX_BANK)); - verifyDataRows(result, rows((Object) null), rows((Object) null)); - - // bad date format case - result = - executeQuery( - String.format( - "SELECT str_to_date(firstname," + " '%%Y-%%m-%%d %%h:%%i:%%s') FROM %s LIMIT 2", - TEST_INDEX_BANK)); - verifyDataRows(result, rows((Object) null), rows((Object) null)); + //Ideal case + JSONObject result = executeQuery( + String.format("SELECT str_to_date(CAST(birthdate AS STRING)," + + " '%%Y-%%m-%%d %%h:%%i:%%s') FROM %s LIMIT 2", + TEST_INDEX_BANK)); + verifyDataRows(result, + rows("2017-10-23 00:00:00"), + rows("2017-11-20 00:00:00") + ); + + //Bad string format case + result = executeQuery( + String.format("SELECT str_to_date(CAST(birthdate AS STRING)," + + " '%%Y %%s') FROM %s LIMIT 2", + TEST_INDEX_BANK)); + verifyDataRows(result, + rows((Object) null), + rows((Object) null) + ); + + //bad date format case + result = executeQuery( + String.format("SELECT str_to_date(firstname," + + " '%%Y-%%m-%%d %%h:%%i:%%s') FROM %s LIMIT 2", + TEST_INDEX_BANK)); + verifyDataRows(result, + rows((Object) null), + rows((Object) null) + ); } @Test public void testSubDateWithDays() throws IOException { - var result = executeQuery("select subdate(date('2020-09-16'), 1)"); - verifySchema(result, schema("subdate(date('2020-09-16'), 1)", null, "date")); + var result = + executeQuery("select subdate(date('2020-09-16'), 1)"); + verifySchema(result, + schema("subdate(date('2020-09-16'), 1)", null, "date")); 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")); + 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, "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")); } @@ -950,68 +903,60 @@ public void testSubDateWithDays() throws IOException { public void testSubDateWithInterval() throws IOException { JSONObject result = 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")); + verifySchema(result, + 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)"); - verifySchema( - result, - schema("subdate(DATETIME('2020-09-16 17:30:00'), interval 1 day)", null, "datetime")); + result = 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, "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")); - verifyDataRows( - result, - rows( - LocalDate.now() - .plusDays(-1) - .atTime(LocalTime.of(7, 40)) - .atZone(systemTz.toZoneId()) - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); + verifySchema(result, + schema("subdate(TIME('07:40:00'), interval 1 day)", null, "timestamp")); + verifyDataRows(result, + rows(LocalDate.now().plusDays(-1).atTime(LocalTime.of(7, 40)).atZone(systemTz.toZoneId()) + .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")); - verifyDataRows( - result, - rows( - LocalDate.now() - .atTime(LocalTime.of(6, 40)) - .atZone(systemTz.toZoneId()) - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); + verifySchema(result, + schema("subdate(TIME('07:40:00'), interval 1 hour)", null, "timestamp")); + verifyDataRows(result, + rows(LocalDate.now().atTime(LocalTime.of(6, 40)).atZone(systemTz.toZoneId()) + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); } @Test - public void testTimstampadd() throws IOException { - JSONObject result = - executeQuery( - String.format("SELECT timestampadd(WEEK, 2, time0) FROM %s LIMIT 3", TEST_INDEX_CALCS)); + public void testTimstampadd() throws IOException { + JSONObject result = executeQuery( + String.format("SELECT timestampadd(WEEK, 2, time0) FROM %s LIMIT 3", TEST_INDEX_CALCS)); - verifyDataRows( - result, + verifyDataRows(result, rows("1900-01-13 21:07:32"), rows("1900-01-15 13:48:48"), rows("1900-01-15 18:21:08")); } @Test - public void testTimstampdiff() throws IOException { - JSONObject result = - executeQuery( - String.format( - "SELECT timestampdiff(DAY, time0, datetime0) FROM %s LIMIT 3", TEST_INDEX_CALCS)); + public void testTimstampdiff() throws IOException { + JSONObject result = executeQuery( + String.format("SELECT timestampdiff(DAY, time0, datetime0) FROM %s LIMIT 3", TEST_INDEX_CALCS)); - verifyDataRows(result, rows(38176), rows(38191), rows(38198)); + verifyDataRows(result, + rows(38176), + rows(38191), + rows(38198)); } @Test @@ -1038,20 +983,16 @@ public void testToDays() throws IOException { @Test public void testToSeconds() throws IOException { - JSONObject result = - executeQuery(String.format("select to_seconds(date0) FROM %s LIMIT 2", TEST_INDEX_CALCS)); + JSONObject result = executeQuery( + String.format("select to_seconds(date0) FROM %s LIMIT 2", TEST_INDEX_CALCS)); verifyDataRows(result, rows(63249206400L), rows(62246275200L)); - result = - executeQuery( - String.format( - "SELECT to_seconds(datetime(cast(datetime0 AS string))) FROM %s LIMIT 2", - TEST_INDEX_CALCS)); + result = executeQuery( + String.format("SELECT to_seconds(timestamp(cast(datetime0 AS string))) FROM %s LIMIT 2", TEST_INDEX_CALCS)); verifyDataRows(result, rows(63256587455L), rows(63258064234L)); - result = - executeQuery( - String.format("select to_seconds(datetime0) FROM %s LIMIT 2", TEST_INDEX_CALCS)); + result = executeQuery(String.format( + "select to_seconds(datetime0) FROM %s LIMIT 2", TEST_INDEX_CALCS)); verifyDataRows(result, rows(63256587455L), rows(63258064234L)); } @@ -1066,14 +1007,11 @@ public void testYear() throws IOException { verifyDataRows(result, rows(2020)); } - private void week(String date, int mode, int expectedResult, String functionName) - throws IOException { - JSONObject result = - executeQuery(StringUtils.format("select %s(date('%s'), %d)", functionName, date, mode)); - verifySchema( - result, - schema( - StringUtils.format("%s(date('%s'), %d)", functionName, date, mode), null, "integer")); + private void week(String date, int mode, int expectedResult, String functionName) throws IOException { + JSONObject result = executeQuery(StringUtils.format("select %s(date('%s'), %d)", functionName, date, + mode)); + verifySchema(result, + schema(StringUtils.format("%s(date('%s'), %d)", functionName, date, mode), null, "integer")); verifyDataRows(result, rows(expectedResult)); } @@ -1092,8 +1030,7 @@ public void testWeek() throws IOException { @Test public void testWeekday() throws IOException { - JSONObject result = - executeQuery(String.format("SELECT weekday(date0) FROM %s LIMIT 3", TEST_INDEX_CALCS)); + JSONObject result = executeQuery(String.format("SELECT weekday(date0) FROM %s LIMIT 3", TEST_INDEX_CALCS)); verifyDataRows(result, rows(3), rows(1), rows(2)); } @@ -1124,9 +1061,12 @@ public void testWeekOfYear() throws IOException { } private void compareWeekResults(String arg, String table) throws IOException { - JSONObject result1 = executeQuery(String.format("SELECT week(%s) FROM %s", arg, table)); - JSONObject result2 = executeQuery(String.format("SELECT week_of_year(%s) FROM %s", arg, table)); - JSONObject result3 = executeQuery(String.format("SELECT weekofyear(%s) FROM %s", arg, table)); + JSONObject result1 = executeQuery(String.format( + "SELECT week(%s) FROM %s", arg, table)); + JSONObject result2 = executeQuery(String.format( + "SELECT week_of_year(%s) FROM %s", arg, table)); + JSONObject result3 = executeQuery(String.format( + "SELECT weekofyear(%s) FROM %s", arg, table)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); result1.getJSONArray("datarows").similar(result3.getJSONArray("datarows")); @@ -1142,23 +1082,20 @@ 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); } @Test public void testYearweek() throws IOException { - JSONObject result = - executeQuery( - String.format( - "SELECT yearweek(time0), yearweek(time0, 4) FROM %s LIMIT 2", TEST_INDEX_CALCS)); + JSONObject result = executeQuery( + String.format("SELECT yearweek(time0), yearweek(time0, 4) FROM %s LIMIT 2", TEST_INDEX_CALCS)); verifyDataRows(result, rows(189952, 189952), rows(189953, 190001)); } - void verifyDateFormat(String date, String type, String format, String formatted) - throws IOException { + void verifyDateFormat(String date, String type, String format, String formatted) throws IOException { String query = String.format("date_format(%s('%s'), '%s')", type, date, format); JSONObject result = executeQuery("select " + query); verifySchema(result, schema(query, null, "keyword")); @@ -1173,11 +1110,10 @@ void verifyDateFormat(String date, String type, String format, String formatted) @Test public void testDateFormat() throws IOException { String timestamp = "1998-01-31 13:14:15.012345"; - String timestampFormat = - "%a %b %c %D %d %e %f %H %h %I %i %j %k %l %M " + "%m %p %r %S %s %T %% %P"; - String timestampFormatted = - "Sat Jan 01 31st 31 31 012345 13 01 01 14 031 13 1 " - + "January 01 PM 01:14:15 PM 15 15 13:14:15 % P"; + String timestampFormat = "%a %b %c %D %d %e %f %H %h %I %i %j %k %l %M " + + "%m %p %r %S %s %T %% %P"; + String timestampFormatted = "Sat Jan 01 31st 31 31 012345 13 01 01 14 031 13 1 " + + "January 01 PM 01:14:15 PM 15 15 13:14:15 % P"; verifyDateFormat(timestamp, "timestamp", timestampFormat, timestampFormatted); String date = "1998-01-31"; @@ -1188,10 +1124,9 @@ public void testDateFormat() throws IOException { @Test public void testMakeTime() throws IOException { - var result = - executeQuery("select MAKETIME(20, 30, 40) as f1, MAKETIME(20.2, 49.5, 42.100502) as f2"); - verifySchema( - result, + var result = executeQuery( + "select MAKETIME(20, 30, 40) as f1, MAKETIME(20.2, 49.5, 42.100502) as f2"); + verifySchema(result, schema("MAKETIME(20, 30, 40)", "f1", "time"), schema("MAKETIME(20.2, 49.5, 42.100502)", "f2", "time")); verifyDataRows(result, rows("20:30:40", "20:50:42.100502")); @@ -1199,9 +1134,9 @@ public void testMakeTime() throws IOException { @Test public void testMakeDate() throws IOException { - var result = executeQuery("select MAKEDATE(1945, 5.9) as f1, MAKEDATE(1984, 1984) as f2"); - verifySchema( - result, + var result = executeQuery( + "select MAKEDATE(1945, 5.9) as f1, MAKEDATE(1984, 1984) as f2"); + verifySchema(result, schema("MAKEDATE(1945, 5.9)", "f1", "date"), schema("MAKEDATE(1984, 1984)", "f2", "date")); verifyDataRows(result, rows("1945-01-06", "1989-06-06")); @@ -1209,35 +1144,30 @@ public void testMakeDate() throws IOException { @Test public void testFromUnixTime() throws IOException { - var result = - executeQuery( - "select FROM_UNIXTIME(200300400) f1, FROM_UNIXTIME(12224.12) f2, " - + "FROM_UNIXTIME(1662601316, '%T') f3"); - verifySchema( - result, - schema("FROM_UNIXTIME(200300400)", "f1", "datetime"), - schema("FROM_UNIXTIME(12224.12)", "f2", "datetime"), + var result = executeQuery( + "select FROM_UNIXTIME(200300400) f1, FROM_UNIXTIME(12224.12) f2, " + + "FROM_UNIXTIME(1662601316, '%T') f3"); + verifySchema(result, + schema("FROM_UNIXTIME(200300400)", "f1", "timestamp"), + schema("FROM_UNIXTIME(12224.12)", "f2", "timestamp"), schema("FROM_UNIXTIME(1662601316, '%T')", "f3", "keyword")); - verifySome( - result.getJSONArray("datarows"), + verifySome(result.getJSONArray("datarows"), rows("1976-05-07 07:00:00", "1970-01-01 03:23:44.12", "01:41:56")); } @Test - public void testGetFormatAsArgument() throws IOException { + public void testGetFormatAsArgument() throws IOException{ var result = executeQuery("SELECT DATE_FORMAT('2003-10-03',GET_FORMAT(DATE,'USA'))"); verifyDataRows(result, rows("10.03.2003")); } @Test public void testUnixTimeStamp() throws IOException { - var result = - executeQuery( - "select UNIX_TIMESTAMP(MAKEDATE(1984, 1984)) f1, " - + "UNIX_TIMESTAMP(TIMESTAMP('2003-12-31 12:00:00')) f2, " - + "UNIX_TIMESTAMP(20771122143845) f3"); - verifySchema( - result, + var result = executeQuery( + "select UNIX_TIMESTAMP(MAKEDATE(1984, 1984)) f1, " + + "UNIX_TIMESTAMP(TIMESTAMP('2003-12-31 12:00:00')) f2, " + + "UNIX_TIMESTAMP(20771122143845) f3"); + verifySchema(result, schema("UNIX_TIMESTAMP(MAKEDATE(1984, 1984))", "f1", "double"), schema("UNIX_TIMESTAMP(TIMESTAMP('2003-12-31 12:00:00'))", "f2", "double"), schema("UNIX_TIMESTAMP(20771122143845)", "f3", "double")); @@ -1246,9 +1176,9 @@ public void testUnixTimeStamp() throws IOException { @Test public void testPeriodAdd() throws IOException { - var result = executeQuery("select PERIOD_ADD(200801, 2) as f1, PERIOD_ADD(200801, -12) as f2"); - verifySchema( - result, + var result = executeQuery( + "select PERIOD_ADD(200801, 2) as f1, PERIOD_ADD(200801, -12) as f2"); + verifySchema(result, schema("PERIOD_ADD(200801, 2)", "f1", "integer"), schema("PERIOD_ADD(200801, -12)", "f2", "integer")); verifyDataRows(result, rows(200803, 200701)); @@ -1256,103 +1186,57 @@ public void testPeriodAdd() throws IOException { @Test public void testPeriodDiff() throws IOException { - var result = - executeQuery("select PERIOD_DIFF(200802, 200703) as f1, PERIOD_DIFF(200802, 201003) as f2"); - verifySchema( - result, + var result = executeQuery( + "select PERIOD_DIFF(200802, 200703) as f1, PERIOD_DIFF(200802, 201003) as f2"); + verifySchema(result, schema("PERIOD_DIFF(200802, 200703)", "f1", "integer"), schema("PERIOD_DIFF(200802, 201003)", "f2", "integer")); verifyDataRows(result, rows(11, -25)); } public void testAddTime() throws IOException { - var result = - executeQuery( - "SELECT ADDTIME(DATE('2008-12-12'), DATE('2008-11-15')) AS `'2008-12-12' + 0`," - + " 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" - + " `'15:42:13' + '09:07:00'`"); - verifySchema( - result, - schema("ADDTIME(DATE('2008-12-12'), DATE('2008-11-15'))", "'2008-12-12' + 0", "datetime"), + var result = executeQuery("SELECT" + + " ADDTIME(DATE('2008-12-12'), DATE('2008-11-15')) AS `'2008-12-12' + 0`," + + " 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'), 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", "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"), + schema("ADDTIME(DATE('2004-01-01'), TIME('23:59:59'))", "'2004-01-01' + '23:59:59'", "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'))", - "'15:42:13' + '09:07:00'", - "datetime")); - verifyDataRows( - result, - rows( - "2008-12-12 00:00:00", - "23:59:59", - "2004-01-01 23:59:59", - "10:26:12", - "2000-01-01 00:49:13")); + schema("ADDTIME(TIMESTAMP('1999-12-31 15:42:13'), TIMESTAMP('1961-04-12 09:07:00'))", "'15:42:13' + '09:07:00'", "timestamp")); + verifyDataRows(result, rows("2008-12-12 00:00:00", "23:59:59", "2004-01-01 23:59:59", "10:26:12", "2000-01-01 00:49:13")); } @Test public void testSubTime() throws IOException { - var result = - executeQuery( - "SELECT SUBTIME(DATE('2008-12-12'), DATE('2008-11-15')) AS `'2008-12-12' - 0`," - + " 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" - + " `'15:42:13' - '09:07:00'`"); - verifySchema( - result, - schema("SUBTIME(DATE('2008-12-12'), DATE('2008-11-15'))", "'2008-12-12' - 0", "datetime"), + var result = executeQuery("SELECT" + + " SUBTIME(DATE('2008-12-12'), DATE('2008-11-15')) AS `'2008-12-12' - 0`," + + " 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'), 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", "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"), + schema("SUBTIME(DATE('2004-01-01'), TIME('23:59:59'))", "'2004-01-01' - '23:59:59'", "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'))", - "'15:42:13' - '09:07:00'", - "datetime")); - verifyDataRows( - result, - rows( - "2008-12-12 00:00:00", - "23:59:59", - "2003-12-31 00:00:01", - "10:14:48", - "1999-12-31 06:35:13")); + schema("SUBTIME(TIMESTAMP('1999-12-31 15:42:13'), TIMESTAMP('1961-04-12 09:07:00'))", "'15:42:13' - '09:07:00'", "timestamp")); + verifyDataRows(result, rows("2008-12-12 00:00:00", "23:59:59", "2003-12-31 00:00:01", "10:14:48", "1999-12-31 06:35:13")); } public void testDateDiff() throws IOException { - var result = - executeQuery( - "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" - + " `'2004-01-01' - '2002-02-01'`, DATEDIFF(TIME('23:59:59'), TIME('00:00:00')) AS" - + " `today - today`"); - verifySchema( - result, - schema( - "DATEDIFF(TIMESTAMP('2000-01-02 00:00:00'), TIMESTAMP('2000-01-01 23:59:59'))", - "'2000-01-02' - '2000-01-01'", - "long"), - schema( - "DATEDIFF(DATE('2001-02-01'), TIMESTAMP('2004-01-01 00:00:00'))", - "'2001-02-01' - '2004-01-01'", - "long"), - schema( - "DATEDIFF(TIMESTAMP('2004-01-01 00:00:00'), DATETIME('2002-02-01 14:25:30'))", - "'2004-01-01' - '2002-02-01'", - "long"), + var result = executeQuery("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'), 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(result, + schema("DATEDIFF(TIMESTAMP('2000-01-02 00:00:00'), TIMESTAMP('2000-01-01 23:59:59'))", "'2000-01-02' - '2000-01-01'", "long"), + schema("DATEDIFF(DATE('2001-02-01'), TIMESTAMP('2004-01-01 00:00:00'))", "'2001-02-01' - '2004-01-01'", "long"), + schema("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")); verifyDataRows(result, rows(1, -1064, 699, 0)); } @@ -1364,8 +1248,7 @@ public void testTimeDiff() throws IOException { verifyDataRows(result, rows("10:59:59")); } - void verifyTimeFormat(String time, String type, String format, String formatted) - throws IOException { + void verifyTimeFormat(String time, String type, String format, String formatted) throws IOException { String query = String.format("time_format(%s('%s'), '%s')", type, time, format); JSONObject result = executeQuery("select " + query); verifySchema(result, schema(query, null, "keyword")); @@ -1446,12 +1329,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 @@ -1468,13 +1351,13 @@ public void testBracketedEquivalent() throws IOException { @Test public void testBracketFails() { - assertThrows(ResponseException.class, () -> executeQuery("select {time '2020-09-16'}")); - assertThrows(ResponseException.class, () -> executeQuery("select {t '2020-09-16'}")); - assertThrows(ResponseException.class, () -> executeQuery("select {date '17:30:00'}")); - assertThrows(ResponseException.class, () -> executeQuery("select {d '17:30:00'}")); - assertThrows(ResponseException.class, () -> executeQuery("select {timestamp '2020-09-16'}")); - assertThrows(ResponseException.class, () -> executeQuery("select {ts '2020-09-16'}")); - assertThrows(ResponseException.class, () -> executeQuery("select {timestamp '17:30:00'}")); - assertThrows(ResponseException.class, () -> executeQuery("select {ts '17:30:00'}")); + assertThrows(ResponseException.class, ()->executeQuery("select {time '2020-09-16'}")); + assertThrows(ResponseException.class, ()->executeQuery("select {t '2020-09-16'}")); + assertThrows(ResponseException.class, ()->executeQuery("select {date '17:30:00'}")); + assertThrows(ResponseException.class, ()->executeQuery("select {d '17:30:00'}")); + assertThrows(ResponseException.class, ()->executeQuery("select {timestamp '2020-09-16'}")); + assertThrows(ResponseException.class, ()->executeQuery("select {ts '2020-09-16'}")); + assertThrows(ResponseException.class, ()->executeQuery("select {timestamp '17:30:00'}")); + assertThrows(ResponseException.class, ()->executeQuery("select {ts '17:30:00'}")); } } 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 750be47de3..1e21017bac 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 @@ -5,15 +5,15 @@ package org.opensearch.sql.sql; -import org.junit.Test; -import org.opensearch.sql.legacy.SQLIntegTestCase; -import java.io.IOException; - import static org.opensearch.sql.util.MatcherUtils.rows; import static org.opensearch.sql.util.MatcherUtils.schema; import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; import static org.opensearch.sql.util.MatcherUtils.verifySchema; +import java.io.IOException; +import org.junit.Test; +import org.opensearch.sql.legacy.SQLIntegTestCase; + public class DateTimeImplementationIT extends SQLIntegTestCase { @@ -25,112 +25,128 @@ public void init() throws Exception { @Test public void inRangeZeroToStringTZ() throws IOException { - var result = - 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")); + var result = 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, "timestamp")); verifyDataRows(result, rows("2008-12-24 21:30:00")); } @Test 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")); + 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, "timestamp")); verifyDataRows(result, rows("2008-12-25 06:30:00")); } @Test 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")); + 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, "timestamp")); verifyDataRows(result, rows("2008-12-25 15:30:00")); } @Test 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")); + 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, "timestamp")); verifyDataRows(result, rows("2004-02-29 19:00:00")); } @Test 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")); + 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, "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")); + 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, "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")); + var result = executeJdbcRequest( + "SELECT DATETIME('2008-01-01 02:00:00')"); + verifySchema(result, + schema("DATETIME('2008-01-01 02:00:00')", null, "timestamp")); verifyDataRows(result, rows("2008-01-01 02:00:00")); } @Test 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")); + 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, "timestamp")); verifyDataRows(result, rows("2007-12-31 02:00:00")); } @Test 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")); + 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, "timestamp")); verifyDataRows(result, rows("2007-12-31 02:01:00")); } @Test 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")); + 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, "timestamp")); verifyDataRows(result, rows("2007-12-31 02:00:00")); } @Test 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")); - verifyDataRows(result, rows(new Object[] {null})); + 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, "timestamp")); + verifyDataRows(result, rows(new Object[]{null})); } @Test 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")); - verifyDataRows(result, rows(new Object[] {null})); + 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, "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")); - verifyDataRows(result, rows(new Object[] {null})); + var result = executeJdbcRequest( + "SELECT DATETIME('2021-02-30 10:00:00')"); + 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")); - verifyDataRows(result, rows(new Object[] {null})); + var result = executeJdbcRequest( + "SELECT DATETIME('2021-04-31 10:00:00')"); + verifySchema(result, + schema("DATETIME('2021-04-31 10:00:00')", null, "timestamp")); + verifyDataRows(result, rows(new Object[]{null})); } @Test @@ -138,7 +154,7 @@ 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")); + 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 4b39e2925c..55b4030fb9 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 @@ -30,14 +30,12 @@ public void typeof_sql_types() { + "typeof(12345), typeof(1234567891011), typeof(INTERVAL 2 DAY);"); verifyDataRows(response, rows("KEYWORD", "UNDEFINED", "DOUBLE", "INTEGER", "LONG", "INTERVAL")); - response = - executeJdbcRequest( - "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")); + response = executeJdbcRequest("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))"); + 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 76947bf720..770f4260cc 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 @@ -357,7 +357,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 4e3e1ec5c0..44de07f979 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 @@ -9,7 +9,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; @@ -128,8 +127,6 @@ public void extendTypeMapping(Map typeMapping) { .put(OpenSearchDateType.of(DATE), OpenSearchExprValueFactory::createOpenSearchDateType) .put(OpenSearchDateType.of(TIMESTAMP), OpenSearchExprValueFactory::createOpenSearchDateType) - .put(OpenSearchDateType.of(DATETIME), - OpenSearchExprValueFactory::createOpenSearchDateType) .put(OpenSearchDataType.of(OpenSearchDataType.MappingType.Ip), (c, dt) -> new OpenSearchExprIpValue(c.stringValue())) .put(OpenSearchDataType.of(OpenSearchDataType.MappingType.GeoPoint), 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 2871bd4a97..73d04dabc9 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 @@ -56,7 +56,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 1a6a82be96..3dec793b0d 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; @@ -71,7 +70,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 a45c535383..af9584aeaf 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 @@ -15,7 +15,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; @@ -204,13 +203,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 -> { if (expr.type().equals(ExprCoreType.STRING)) { return new ExprTimestampValue(expr.valueOf().stringValue()); 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 13393da732..ad15d6ac46 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,7 +42,7 @@ 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); @@ -52,7 +51,7 @@ class OpenSearchDateTypeTest { private static final OpenSearchDateType timeDateType = OpenSearchDateType.of(timeFormatString); private static final OpenSearchDateType datetimeDateType = - OpenSearchDateType.of(datetimeFormatString); + OpenSearchDateType.of(timestampFormatString); @Test public void isCompatible() { @@ -61,25 +60,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)) ); } @@ -91,8 +81,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()) ); } @@ -102,8 +91,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()) ); } @@ -113,8 +101,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()) ); } 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 827606a961..c92b6fe1ef 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 @@ -25,7 +25,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; @@ -51,7 +50,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; @@ -73,7 +71,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()) @@ -321,12 +318,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)), constructFromObject("dateOrEpochMillisV", "1420070400001")), @@ -346,7 +337,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 = @@ -358,11 +349,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")); } @@ -654,7 +645,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 c76567c1e9..3da0fe8164 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 @@ -14,7 +14,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; @@ -151,19 +150,6 @@ void should_build_type_mapping_for_field_reference() { )); } - @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 b98bc538ab..4e1e914ddb 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 @@ -35,7 +35,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; @@ -119,16 +118,6 @@ void can_execute_expression_interpret_dates_for_aggregation() { .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 208904d9c3..97e1bce4dc 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 @@ -135,7 +135,7 @@ void should_build_bucket_with_parse_expression() { } @ParameterizedTest(name = "{0}") - @EnumSource(value = ExprCoreType.class, names = {"TIMESTAMP", "TIME", "DATE", "DATETIME"}) + @EnumSource(value = ExprCoreType.class, 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 61a3e9d35f..7ff368f3f6 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 @@ -16,7 +16,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; @@ -122,15 +121,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 eb07076257..da40f07426 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 @@ -14,7 +14,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; @@ -43,7 +42,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; @@ -1630,8 +1628,9 @@ void cast_to_date_in_filter() { ref("date_value", DATE), DSL.castDate(literal("2021-11-08"))))); assertJsonEquals(json, buildQuery(DSL.equal( ref("date_value", DATE), DSL.castDate(literal(new ExprDateValue("2021-11-08")))))); - assertJsonEquals(json, buildQuery(DSL.equal(ref( - "date_value", DATE), DSL.castDate(literal(new ExprDatetimeValue("2021-11-08 17:00:00")))))); + assertJsonEquals(json, buildQuery(DSL.equal( + ref("date_value", DATE), DSL.castDate( + literal(new ExprTimestampValue("2021-11-08 17:00:00")))))); } @Test @@ -1653,23 +1652,6 @@ void cast_to_time_in_filter() { .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 = "{\n"