diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprDateValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprDateValue.java
index 3f3f67a4fa..c36cd3ea6d 100644
--- a/core/src/main/java/org/opensearch/sql/data/model/ExprDateValue.java
+++ b/core/src/main/java/org/opensearch/sql/data/model/ExprDateValue.java
@@ -6,13 +6,12 @@
package org.opensearch.sql.data.model;
import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL;
-import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID;
import com.google.common.base.Objects;
import java.time.Instant;
import java.time.LocalDate;
-import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
@@ -57,14 +56,9 @@ public LocalTime timeValue() {
return LocalTime.of(0, 0, 0);
}
- @Override
- public LocalDateTime datetimeValue() {
- return LocalDateTime.of(date, timeValue());
- }
-
@Override
public Instant timestampValue() {
- return ZonedDateTime.of(date, timeValue(), UTC_ZONE_ID).toInstant();
+ return ZonedDateTime.of(date, timeValue(), ZoneOffset.UTC).toInstant();
}
@Override
diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprDatetimeValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprDatetimeValue.java
deleted file mode 100644
index 305958043f..0000000000
--- a/core/src/main/java/org/opensearch/sql/data/model/ExprDatetimeValue.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright OpenSearch Contributors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package org.opensearch.sql.data.model;
-
-import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_WITH_TZ;
-import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID;
-
-import com.google.common.base.Objects;
-import java.time.Instant;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.time.ZonedDateTime;
-import java.time.format.DateTimeFormatter;
-import java.time.format.DateTimeParseException;
-import java.time.temporal.ChronoUnit;
-import lombok.RequiredArgsConstructor;
-import org.opensearch.sql.data.type.ExprCoreType;
-import org.opensearch.sql.data.type.ExprType;
-import org.opensearch.sql.exception.SemanticCheckException;
-
-@RequiredArgsConstructor
-public class ExprDatetimeValue extends AbstractExprValue {
- private final LocalDateTime datetime;
-
- /** Constructor with datetime string as input. */
- public ExprDatetimeValue(String datetime) {
- try {
- this.datetime = LocalDateTime.parse(datetime, DATE_TIME_FORMATTER_WITH_TZ);
- } catch (DateTimeParseException e) {
- throw new SemanticCheckException(
- String.format(
- "datetime:%s in unsupported format, please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'",
- datetime));
- }
- }
-
- @Override
- public LocalDateTime datetimeValue() {
- return datetime;
- }
-
- @Override
- public LocalDate dateValue() {
- return datetime.toLocalDate();
- }
-
- @Override
- public LocalTime timeValue() {
- return datetime.toLocalTime();
- }
-
- @Override
- public Instant timestampValue() {
- return ZonedDateTime.of(datetime, UTC_ZONE_ID).toInstant();
- }
-
- @Override
- public boolean isDateTime() {
- return true;
- }
-
- @Override
- public int compare(ExprValue other) {
- return datetime.compareTo(other.datetimeValue());
- }
-
- @Override
- public boolean equal(ExprValue other) {
- return datetime.equals(other.datetimeValue());
- }
-
- @Override
- public String value() {
- return String.format(
- "%s %s",
- DateTimeFormatter.ISO_DATE.format(datetime),
- DateTimeFormatter.ISO_TIME.format(
- (datetime.getNano() == 0) ? datetime.truncatedTo(ChronoUnit.SECONDS) : datetime));
- }
-
- @Override
- public ExprType type() {
- return ExprCoreType.DATETIME;
- }
-
- @Override
- public String toString() {
- return String.format("DATETIME '%s'", value());
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(datetime);
- }
-}
diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprStringValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprStringValue.java
index 7745af62b6..f2e63e986d 100644
--- a/core/src/main/java/org/opensearch/sql/data/model/ExprStringValue.java
+++ b/core/src/main/java/org/opensearch/sql/data/model/ExprStringValue.java
@@ -5,6 +5,7 @@
package org.opensearch.sql.data.model;
+import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
@@ -35,27 +36,20 @@ public String stringValue() {
}
@Override
- public LocalDateTime datetimeValue() {
+ public Instant timestampValue() {
try {
- return new ExprDatetimeValue(value).datetimeValue();
+ return new ExprTimestampValue(value).timestampValue();
} catch (SemanticCheckException e) {
- try {
- return new ExprDatetimeValue(
- LocalDateTime.of(new ExprDateValue(value).dateValue(), LocalTime.of(0, 0, 0)))
- .datetimeValue();
- } catch (SemanticCheckException exception) {
- throw new SemanticCheckException(
- String.format(
- "datetime:%s in unsupported format, please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'",
- value));
- }
+ return new ExprTimestampValue(
+ LocalDateTime.of(new ExprDateValue(value).dateValue(), LocalTime.of(0, 0, 0)))
+ .timestampValue();
}
}
@Override
public LocalDate dateValue() {
try {
- return new ExprDatetimeValue(value).dateValue();
+ return new ExprTimestampValue(value).dateValue();
} catch (SemanticCheckException e) {
return new ExprDateValue(value).dateValue();
}
@@ -64,7 +58,7 @@ public LocalDate dateValue() {
@Override
public LocalTime timeValue() {
try {
- return new ExprDatetimeValue(value).timeValue();
+ return new ExprTimestampValue(value).timeValue();
} catch (SemanticCheckException e) {
return new ExprTimeValue(value).timeValue();
}
diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java
index d808af49b1..6b5a4a7c48 100644
--- a/core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java
+++ b/core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java
@@ -7,12 +7,11 @@
import static java.time.format.DateTimeFormatter.ISO_LOCAL_TIME;
import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL;
-import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID;
import java.time.Instant;
import java.time.LocalDate;
-import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeParseException;
import java.util.Objects;
@@ -57,12 +56,8 @@ public LocalDate dateValue(FunctionProperties functionProperties) {
return LocalDate.now(functionProperties.getQueryStartClock());
}
- public LocalDateTime datetimeValue(FunctionProperties functionProperties) {
- return LocalDateTime.of(dateValue(functionProperties), timeValue());
- }
-
public Instant timestampValue(FunctionProperties functionProperties) {
- return ZonedDateTime.of(dateValue(functionProperties), timeValue(), UTC_ZONE_ID).toInstant();
+ return ZonedDateTime.of(dateValue(functionProperties), timeValue(), ZoneOffset.UTC).toInstant();
}
@Override
diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprTimestampValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprTimestampValue.java
index 455a379b03..e103dc7253 100644
--- a/core/src/main/java/org/opensearch/sql/data/model/ExprTimestampValue.java
+++ b/core/src/main/java/org/opensearch/sql/data/model/ExprTimestampValue.java
@@ -7,12 +7,12 @@
import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_VARIABLE_NANOS;
import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_WITHOUT_NANO;
-import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.time.ZoneOffset;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoUnit;
import java.util.Objects;
@@ -32,7 +32,7 @@ public ExprTimestampValue(String timestamp) {
try {
this.timestamp =
LocalDateTime.parse(timestamp, DATE_TIME_FORMATTER_VARIABLE_NANOS)
- .atZone(UTC_ZONE_ID)
+ .atZone(ZoneOffset.UTC)
.toInstant();
} catch (DateTimeParseException e) {
throw new SemanticCheckException(
@@ -42,13 +42,18 @@ public ExprTimestampValue(String timestamp) {
}
}
+ /** localDateTime Constructor. */
+ public ExprTimestampValue(LocalDateTime localDateTime) {
+ this.timestamp = localDateTime.atZone(ZoneOffset.UTC).toInstant();
+ }
+
@Override
public String value() {
return timestamp.getNano() == 0
? DATE_TIME_FORMATTER_WITHOUT_NANO
- .withZone(UTC_ZONE_ID)
+ .withZone(ZoneOffset.UTC)
.format(timestamp.truncatedTo(ChronoUnit.SECONDS))
- : DATE_TIME_FORMATTER_VARIABLE_NANOS.withZone(UTC_ZONE_ID).format(timestamp);
+ : DATE_TIME_FORMATTER_VARIABLE_NANOS.withZone(ZoneOffset.UTC).format(timestamp);
}
@Override
@@ -63,17 +68,12 @@ public Instant timestampValue() {
@Override
public LocalDate dateValue() {
- return timestamp.atZone(UTC_ZONE_ID).toLocalDate();
+ return timestamp.atZone(ZoneOffset.UTC).toLocalDate();
}
@Override
public LocalTime timeValue() {
- return timestamp.atZone(UTC_ZONE_ID).toLocalTime();
- }
-
- @Override
- public LocalDateTime datetimeValue() {
- return timestamp.atZone(UTC_ZONE_ID).toLocalDateTime();
+ return timestamp.atZone(ZoneOffset.UTC).toLocalTime();
}
@Override
@@ -88,12 +88,12 @@ public String toString() {
@Override
public int compare(ExprValue other) {
- return timestamp.compareTo(other.timestampValue().atZone(UTC_ZONE_ID).toInstant());
+ return timestamp.compareTo(other.timestampValue().atZone(ZoneOffset.UTC).toInstant());
}
@Override
public boolean equal(ExprValue other) {
- return timestamp.equals(other.timestampValue().atZone(UTC_ZONE_ID).toInstant());
+ return timestamp.equals(other.timestampValue().atZone(ZoneOffset.UTC).toInstant());
}
@Override
diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprValue.java
index 86bead77b7..034ed22a75 100644
--- a/core/src/main/java/org/opensearch/sql/data/model/ExprValue.java
+++ b/core/src/main/java/org/opensearch/sql/data/model/ExprValue.java
@@ -8,7 +8,6 @@
import java.io.Serializable;
import java.time.Instant;
import java.time.LocalDate;
-import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.TemporalAmount;
import java.util.List;
@@ -133,12 +132,6 @@ default LocalDate dateValue() {
"invalid to get dateValue from value of type " + type());
}
- /** Get datetime value. */
- default LocalDateTime datetimeValue() {
- throw new ExpressionEvaluationException(
- "invalid to get datetimeValue from value of type " + type());
- }
-
/** Get interval value. */
default TemporalAmount intervalValue() {
throw new ExpressionEvaluationException(
diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprValueUtils.java b/core/src/main/java/org/opensearch/sql/data/model/ExprValueUtils.java
index a259eb9fba..20813045f2 100644
--- a/core/src/main/java/org/opensearch/sql/data/model/ExprValueUtils.java
+++ b/core/src/main/java/org/opensearch/sql/data/model/ExprValueUtils.java
@@ -9,6 +9,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.time.ZoneOffset;
import java.time.temporal.TemporalAmount;
import java.util.ArrayList;
import java.util.LinkedHashMap;
@@ -66,10 +67,6 @@ public static ExprValue dateValue(LocalDate value) {
return new ExprDateValue(value);
}
- public static ExprValue datetimeValue(LocalDateTime value) {
- return new ExprDatetimeValue(value);
- }
-
public static ExprValue timeValue(LocalTime value) {
return new ExprTimeValue(value);
}
@@ -128,14 +125,14 @@ public static ExprValue fromObjectValue(Object o) {
return floatValue((Float) o);
} else if (o instanceof LocalDate) {
return dateValue((LocalDate) o);
- } else if (o instanceof LocalDateTime) {
- return datetimeValue((LocalDateTime) o);
} else if (o instanceof LocalTime) {
return timeValue((LocalTime) o);
} else if (o instanceof Instant) {
return timestampValue((Instant) o);
} else if (o instanceof TemporalAmount) {
return intervalValue((TemporalAmount) o);
+ } else if (o instanceof LocalDateTime) {
+ return timestampValue(((LocalDateTime) o).toInstant(ZoneOffset.UTC));
} else {
throw new ExpressionEvaluationException("unsupported object " + o.getClass());
}
@@ -150,8 +147,6 @@ public static ExprValue fromObjectValue(Object o, ExprCoreType type) {
return new ExprDateValue((String) o);
case TIME:
return new ExprTimeValue((String) o);
- case DATETIME:
- return new ExprDatetimeValue((String) o);
default:
return fromObjectValue(o);
}
diff --git a/core/src/main/java/org/opensearch/sql/data/type/ExprCoreType.java b/core/src/main/java/org/opensearch/sql/data/type/ExprCoreType.java
index f1979d8666..cbc0c98255 100644
--- a/core/src/main/java/org/opensearch/sql/data/type/ExprCoreType.java
+++ b/core/src/main/java/org/opensearch/sql/data/type/ExprCoreType.java
@@ -42,8 +42,7 @@ public enum ExprCoreType implements ExprType {
/** Date. */
DATE(STRING),
TIME(STRING),
- DATETIME(STRING, DATE, TIME),
- TIMESTAMP(STRING, DATETIME),
+ TIMESTAMP(STRING, DATE, TIME),
INTERVAL(UNDEFINED),
/** Struct. */
diff --git a/core/src/main/java/org/opensearch/sql/expression/DSL.java b/core/src/main/java/org/opensearch/sql/expression/DSL.java
index 4341668b69..12a7faafb2 100644
--- a/core/src/main/java/org/opensearch/sql/expression/DSL.java
+++ b/core/src/main/java/org/opensearch/sql/expression/DSL.java
@@ -819,10 +819,6 @@ public static FunctionExpression castTimestamp(Expression value) {
return compile(FunctionProperties.None, BuiltinFunctionName.CAST_TO_TIMESTAMP, value);
}
- public static FunctionExpression castDatetime(Expression value) {
- return compile(FunctionProperties.None, BuiltinFunctionName.CAST_TO_DATETIME, value);
- }
-
public static FunctionExpression typeof(Expression value) {
return compile(FunctionProperties.None, BuiltinFunctionName.TYPEOF, value);
}
diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunction.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunction.java
index 4a1d4d309b..bfc92d73c6 100644
--- a/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunction.java
+++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunction.java
@@ -7,7 +7,6 @@
import static org.opensearch.sql.data.type.ExprCoreType.ARRAY;
import static org.opensearch.sql.data.type.ExprCoreType.DATE;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE;
import static org.opensearch.sql.data.type.ExprCoreType.FLOAT;
import static org.opensearch.sql.data.type.ExprCoreType.INTEGER;
@@ -71,9 +70,6 @@ private static DefaultFunctionResolver avg() {
.put(
new FunctionSignature(functionName, Collections.singletonList(DATE)),
(functionProperties, arguments) -> new AvgAggregator(arguments, DATE))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(DATETIME)),
- (functionProperties, arguments) -> new AvgAggregator(arguments, DATETIME))
.put(
new FunctionSignature(functionName, Collections.singletonList(TIME)),
(functionProperties, arguments) -> new AvgAggregator(arguments, TIME))
@@ -142,9 +138,6 @@ private static DefaultFunctionResolver min() {
.put(
new FunctionSignature(functionName, Collections.singletonList(DATE)),
(functionProperties, arguments) -> new MinAggregator(arguments, DATE))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(DATETIME)),
- (functionProperties, arguments) -> new MinAggregator(arguments, DATETIME))
.put(
new FunctionSignature(functionName, Collections.singletonList(TIME)),
(functionProperties, arguments) -> new MinAggregator(arguments, TIME))
@@ -177,9 +170,6 @@ private static DefaultFunctionResolver max() {
.put(
new FunctionSignature(functionName, Collections.singletonList(DATE)),
(functionProperties, arguments) -> new MaxAggregator(arguments, DATE))
- .put(
- new FunctionSignature(functionName, Collections.singletonList(DATETIME)),
- (functionProperties, arguments) -> new MaxAggregator(arguments, DATETIME))
.put(
new FunctionSignature(functionName, Collections.singletonList(TIME)),
(functionProperties, arguments) -> new MaxAggregator(arguments, TIME))
diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/AvgAggregator.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/AvgAggregator.java
index c528968018..c32ebb6071 100644
--- a/core/src/main/java/org/opensearch/sql/expression/aggregation/AvgAggregator.java
+++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/AvgAggregator.java
@@ -13,7 +13,6 @@
import java.util.List;
import java.util.Locale;
import org.opensearch.sql.data.model.ExprDateValue;
-import org.opensearch.sql.data.model.ExprDatetimeValue;
import org.opensearch.sql.data.model.ExprDoubleValue;
import org.opensearch.sql.data.model.ExprIntegerValue;
import org.opensearch.sql.data.model.ExprNullValue;
@@ -47,8 +46,6 @@ public AvgState create() {
switch (dataType) {
case DATE:
return new DateAvgState();
- case DATETIME:
- return new DateTimeAvgState();
case TIMESTAMP:
return new TimestampAvgState();
case TIME:
@@ -128,28 +125,6 @@ protected AvgState iterate(ExprValue value) {
}
}
- protected static class DateTimeAvgState extends AvgState {
- @Override
- public ExprValue result() {
- if (0 == count.integerValue()) {
- return ExprNullValue.of();
- }
-
- return new ExprDatetimeValue(
- new ExprTimestampValue(
- Instant.ofEpochMilli(
- DSL.divide(DSL.literal(total), DSL.literal(count)).valueOf().longValue()))
- .datetimeValue());
- }
-
- @Override
- protected AvgState iterate(ExprValue value) {
- total =
- DSL.add(DSL.literal(total), DSL.literal(value.timestampValue().toEpochMilli())).valueOf();
- return super.iterate(value);
- }
- }
-
protected static class TimestampAvgState extends AvgState {
@Override
public ExprValue result() {
diff --git a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java
index 13f9a077e4..d23cbc2df3 100644
--- a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java
+++ b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java
@@ -12,6 +12,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.ResolverStyle;
@@ -21,9 +22,9 @@
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.opensearch.sql.data.model.ExprDatetimeValue;
import org.opensearch.sql.data.model.ExprNullValue;
import org.opensearch.sql.data.model.ExprStringValue;
+import org.opensearch.sql.data.model.ExprTimestampValue;
import org.opensearch.sql.data.model.ExprValue;
import org.opensearch.sql.expression.function.FunctionProperties;
@@ -245,12 +246,12 @@ static ExprValue getFormattedString(
/**
* Format the date using the date format String.
*
- * @param dateExpr the date ExprValue of Date/Datetime/Timestamp/String type.
+ * @param dateExpr the date ExprValue of Date/Timestamp/String type.
* @param formatExpr the format ExprValue of String type.
* @return Date formatted using format and returned as a String.
*/
static ExprValue getFormattedDate(ExprValue dateExpr, ExprValue formatExpr) {
- final LocalDateTime date = dateExpr.datetimeValue();
+ final LocalDateTime date = dateExpr.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime();
return getFormattedString(formatExpr, DATE_HANDLERS, date);
}
@@ -364,7 +365,7 @@ static ExprValue parseStringWithDateOrTime(
output = LocalDateTime.of(year, month, day, hour, minute, second);
}
- return new ExprDatetimeValue(output);
+ return new ExprTimestampValue(output);
}
/**
diff --git a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java
index d17d59d358..a42a599ad8 100644
--- a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java
+++ b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java
@@ -14,7 +14,6 @@
import static java.time.temporal.ChronoUnit.WEEKS;
import static java.time.temporal.ChronoUnit.YEARS;
import static org.opensearch.sql.data.type.ExprCoreType.DATE;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE;
import static org.opensearch.sql.data.type.ExprCoreType.FLOAT;
import static org.opensearch.sql.data.type.ExprCoreType.INTEGER;
@@ -41,9 +40,8 @@
import static org.opensearch.sql.utils.DateTimeFormatters.SHORT_DATE_LENGTH;
import static org.opensearch.sql.utils.DateTimeFormatters.SINGLE_DIGIT_MONTH_DATE_LENGTH;
import static org.opensearch.sql.utils.DateTimeFormatters.SINGLE_DIGIT_YEAR_DATE_LENGTH;
-import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID;
import static org.opensearch.sql.utils.DateTimeUtils.extractDate;
-import static org.opensearch.sql.utils.DateTimeUtils.extractDateTime;
+import static org.opensearch.sql.utils.DateTimeUtils.extractTimestamp;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableTable;
@@ -74,13 +72,13 @@
import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.tuple.Pair;
import org.opensearch.sql.data.model.ExprDateValue;
-import org.opensearch.sql.data.model.ExprDatetimeValue;
import org.opensearch.sql.data.model.ExprDoubleValue;
import org.opensearch.sql.data.model.ExprIntegerValue;
import org.opensearch.sql.data.model.ExprLongValue;
import org.opensearch.sql.data.model.ExprNullValue;
import org.opensearch.sql.data.model.ExprStringValue;
import org.opensearch.sql.data.model.ExprTimeValue;
+import org.opensearch.sql.data.model.ExprTimestampValue;
import org.opensearch.sql.data.model.ExprValue;
import org.opensearch.sql.data.type.ExprCoreType;
import org.opensearch.sql.exception.ExpressionEvaluationException;
@@ -110,7 +108,7 @@ public class DateTimeFunction {
// The number of days from year zero to year 1970.
private static final Long DAYS_0000_TO_1970 = (146097 * 5L) - (30L * 365L + 7L);
- // MySQL doesn't process any datetime/timestamp values which are greater than
+ // MySQL doesn't process any timestamp values which are greater than
// 32536771199.999999, or equivalent '3001-01-18 23:59:59.999999' UTC
private static final Double MYSQL_MAX_TIMESTAMP = 32536771200d;
@@ -150,11 +148,6 @@ public class DateTimeFunction {
.put("date", "iso", "%Y-%m-%d")
.put("date", "eur", "%d.%m.%Y")
.put("date", "internal", "%Y%m%d")
- .put("datetime", "usa", "%Y-%m-%d %H.%i.%s")
- .put("datetime", "jis", "%Y-%m-%d %H:%i:%s")
- .put("datetime", "iso", "%Y-%m-%d %H:%i:%s")
- .put("datetime", "eur", "%Y-%m-%d %H.%i.%s")
- .put("datetime", "internal", "%Y%m%d%H%i%s")
.put("time", "usa", "%h:%i:%s %p")
.put("time", "jis", "%H:%i:%s")
.put("time", "iso", "%H:%i:%s")
@@ -255,8 +248,8 @@ private FunctionResolver now(FunctionName functionName) {
functionName,
implWithProperties(
functionProperties ->
- new ExprDatetimeValue(formatNow(functionProperties.getQueryStartClock())),
- DATETIME));
+ new ExprTimestampValue(formatNow(functionProperties.getQueryStartClock())),
+ TIMESTAMP));
}
private FunctionResolver now() {
@@ -280,12 +273,12 @@ private FunctionResolver sysdate() {
return define(
BuiltinFunctionName.SYSDATE.getName(),
implWithProperties(
- functionProperties -> new ExprDatetimeValue(formatNow(Clock.systemDefaultZone())),
- DATETIME),
+ functionProperties -> new ExprTimestampValue(formatNow(Clock.systemDefaultZone())),
+ TIMESTAMP),
FunctionDSL.implWithProperties(
(functionProperties, v) ->
- new ExprDatetimeValue(formatNow(Clock.systemDefaultZone(), v.integerValue())),
- DATETIME,
+ new ExprTimestampValue(formatNow(Clock.systemDefaultZone(), v.integerValue())),
+ TIMESTAMP,
INTEGER));
}
@@ -329,37 +322,34 @@ private FunctionResolver current_date() {
* Specify a start date and add/subtract a temporal amount to/from the date.
* The return type depends on the date type and the interval unit. Detailed supported signatures:
*
- * (DATE/DATETIME/TIMESTAMP/TIME, INTERVAL) -> DATETIME
+ * (DATE/TIMESTAMP/TIME, INTERVAL) -> TIMESTAMP
* MySQL has these signatures too
* (DATE, INTERVAL) -> DATE // when interval has no time part
* (TIME, INTERVAL) -> TIME // when interval has no date part
- * (STRING, INTERVAL) -> STRING // when argument has date or datetime string,
- * // result has date or datetime depending on interval type
+ * (STRING, INTERVAL) -> STRING // when argument has date or timestamp string,
+ * // result has date or timestamp depending on interval type
*/
private Stream> get_date_add_date_sub_signatures(
SerializableTriFunction function) {
return Stream.of(
- implWithProperties(nullMissingHandlingWithProperties(function), DATETIME, DATE, INTERVAL),
- implWithProperties(
- nullMissingHandlingWithProperties(function), DATETIME, DATETIME, INTERVAL),
+ implWithProperties(nullMissingHandlingWithProperties(function), TIMESTAMP, DATE, INTERVAL),
implWithProperties(
- nullMissingHandlingWithProperties(function), DATETIME, TIMESTAMP, INTERVAL),
- implWithProperties(nullMissingHandlingWithProperties(function), DATETIME, TIME, INTERVAL));
+ nullMissingHandlingWithProperties(function), TIMESTAMP, TIMESTAMP, INTERVAL),
+ implWithProperties(nullMissingHandlingWithProperties(function), TIMESTAMP, TIME, INTERVAL));
}
/**
* A common signature for `adddate` and `subdate`.
* Adds/subtracts an integer number of days to/from the first argument.
* (DATE, LONG) -> DATE
- * (TIME/DATETIME/TIMESTAMP, LONG) -> DATETIME
+ * (TIME/TIMESTAMP, LONG) -> TIMESTAMP
*/
private Stream> get_adddate_subdate_signatures(
SerializableTriFunction function) {
return Stream.of(
implWithProperties(nullMissingHandlingWithProperties(function), DATE, DATE, LONG),
- implWithProperties(nullMissingHandlingWithProperties(function), DATETIME, DATETIME, LONG),
- implWithProperties(nullMissingHandlingWithProperties(function), DATETIME, TIMESTAMP, LONG),
- implWithProperties(nullMissingHandlingWithProperties(function), DATETIME, TIME, LONG));
+ implWithProperties(nullMissingHandlingWithProperties(function), TIMESTAMP, TIMESTAMP, LONG),
+ implWithProperties(nullMissingHandlingWithProperties(function), TIMESTAMP, TIME, LONG));
}
private DefaultFunctionResolver adddate() {
@@ -374,8 +364,8 @@ private DefaultFunctionResolver adddate() {
/**
* Adds expr2 to expr1 and returns the result.
- * (TIME, TIME/DATE/DATETIME/TIMESTAMP) -> TIME
- * (DATE/DATETIME/TIMESTAMP, TIME/DATE/DATETIME/TIMESTAMP) -> DATETIME
+ * (TIME, TIME/DATE/TIMESTAMP) -> TIME
+ * (DATE/TIMESTAMP, TIME/DATE/TIMESTAMP) -> TIMESTAMP
* TODO: MySQL has these signatures too
* (STRING, STRING/TIME) -> STRING // second arg - string with time only
* (x, STRING) -> NULL // second arg - string with timestamp
@@ -388,8 +378,6 @@ private DefaultFunctionResolver addtime() {
nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), TIME, TIME, TIME),
implWithProperties(
nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), TIME, TIME, DATE),
- implWithProperties(
- nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), TIME, TIME, DATETIME),
implWithProperties(
nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime),
TIME,
@@ -397,56 +385,32 @@ private DefaultFunctionResolver addtime() {
TIMESTAMP),
implWithProperties(
nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime),
- DATETIME,
- DATETIME,
+ TIMESTAMP,
+ DATE,
TIME),
implWithProperties(
nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime),
- DATETIME,
- DATETIME,
- DATE),
- implWithProperties(
- nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime),
- DATETIME,
- DATETIME,
- DATETIME),
- implWithProperties(
- nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime),
- DATETIME,
- DATETIME,
- TIMESTAMP),
- implWithProperties(
- nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), DATETIME, DATE, TIME),
- implWithProperties(
- nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime), DATETIME, DATE, DATE),
- implWithProperties(
- nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime),
- DATETIME,
+ TIMESTAMP,
DATE,
- DATETIME),
+ DATE),
implWithProperties(
nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime),
- DATETIME,
+ TIMESTAMP,
DATE,
TIMESTAMP),
implWithProperties(
nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime),
- DATETIME,
+ TIMESTAMP,
TIMESTAMP,
TIME),
implWithProperties(
nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime),
- DATETIME,
+ TIMESTAMP,
TIMESTAMP,
DATE),
implWithProperties(
nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime),
- DATETIME,
TIMESTAMP,
- DATETIME),
- implWithProperties(
- nullMissingHandlingWithProperties(DateTimeFunction::exprAddTime),
- DATETIME,
TIMESTAMP,
TIMESTAMP));
}
@@ -454,21 +418,21 @@ private DefaultFunctionResolver addtime() {
/**
* Converts date/time from a specified timezone to another specified timezone.
* The supported signatures:
- * (DATETIME, STRING, STRING) -> DATETIME
- * (STRING, STRING, STRING) -> DATETIME
+ * (TIMESTAMP, STRING, STRING) -> TIMESTAMP
+ * (STRING, STRING, STRING) -> TIMESTAMP
*/
private DefaultFunctionResolver convert_tz() {
return define(
BuiltinFunctionName.CONVERT_TZ.getName(),
impl(
nullMissingHandling(DateTimeFunction::exprConvertTZ),
- DATETIME,
- DATETIME,
+ TIMESTAMP,
+ TIMESTAMP,
STRING,
STRING),
impl(
nullMissingHandling(DateTimeFunction::exprConvertTZ),
- DATETIME,
+ TIMESTAMP,
STRING,
STRING,
STRING));
@@ -476,41 +440,25 @@ private DefaultFunctionResolver convert_tz() {
/**
* Extracts the date part of a date and time value. Also to construct a date type. The supported
- * signatures: STRING/DATE/DATETIME/TIMESTAMP -> DATE
+ * signatures: STRING/DATE/TIMESTAMP -> DATE
*/
private DefaultFunctionResolver date() {
return define(
BuiltinFunctionName.DATE.getName(),
impl(nullMissingHandling(DateTimeFunction::exprDate), DATE, STRING),
impl(nullMissingHandling(DateTimeFunction::exprDate), DATE, DATE),
- impl(nullMissingHandling(DateTimeFunction::exprDate), DATE, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprDate), DATE, TIMESTAMP));
}
- /*
- * Calculates the difference of date part of given values.
- * (DATE/DATETIME/TIMESTAMP/TIME, DATE/DATETIME/TIMESTAMP/TIME) -> LONG
+ /**
+ * Calculates the difference of date part of given values.
+ * (DATE/TIMESTAMP/TIME, DATE/TIMESTAMP/TIME) -> LONG
*/
private DefaultFunctionResolver datediff() {
return define(
BuiltinFunctionName.DATEDIFF.getName(),
implWithProperties(
nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), LONG, DATE, DATE),
- implWithProperties(
- nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff),
- LONG,
- DATETIME,
- DATE),
- implWithProperties(
- nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff),
- LONG,
- DATE,
- DATETIME),
- implWithProperties(
- nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff),
- LONG,
- DATETIME,
- DATETIME),
implWithProperties(
nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff), LONG, DATE, TIME),
implWithProperties(
@@ -541,40 +489,20 @@ private DefaultFunctionResolver datediff() {
nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff),
LONG,
TIME,
- TIMESTAMP),
- implWithProperties(
- nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff),
- LONG,
- TIMESTAMP,
- DATETIME),
- implWithProperties(
- nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff),
- LONG,
- DATETIME,
- TIMESTAMP),
- implWithProperties(
- nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff),
- LONG,
- TIME,
- DATETIME),
- implWithProperties(
- nullMissingHandlingWithProperties(DateTimeFunction::exprDateDiff),
- LONG,
- DATETIME,
- TIME));
+ TIMESTAMP));
}
/**
* Specify a datetime with time zone field and a time zone to convert to.
- * Returns a local date time.
- * (STRING, STRING) -> DATETIME
- * (STRING) -> DATETIME
+ * Returns a local datetime.
+ * (STRING, STRING) -> TIMESTAMP
+ * (STRING) -> TIMESTAMP
*/
private FunctionResolver datetime() {
return define(
BuiltinFunctionName.DATETIME.getName(),
- impl(nullMissingHandling(DateTimeFunction::exprDateTime), DATETIME, STRING, STRING),
- impl(nullMissingHandling(DateTimeFunction::exprDateTimeNoTimezone), DATETIME, STRING));
+ impl(nullMissingHandling(DateTimeFunction::exprDateTime), TIMESTAMP, STRING, STRING),
+ impl(nullMissingHandling(DateTimeFunction::exprDateTimeNoTimezone), TIMESTAMP, STRING));
}
private DefaultFunctionResolver date_add() {
@@ -593,30 +521,28 @@ private DefaultFunctionResolver date_sub() {
.toArray(SerializableFunction, ?>[]::new));
}
- /** DAY(STRING/DATE/DATETIME/TIMESTAMP). return the day of the month (1-31). */
+ /** DAY(STRING/DATE/TIMESTAMP). return the day of the month (1-31). */
private DefaultFunctionResolver day() {
return define(
BuiltinFunctionName.DAY.getName(),
impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, DATE),
- impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, TIMESTAMP),
impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, STRING));
}
/**
- * DAYNAME(STRING/DATE/DATETIME/TIMESTAMP). return the name of the weekday for date, including
+ * DAYNAME(STRING/DATE/TIMESTAMP). return the name of the weekday for date, including
* Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.
*/
private DefaultFunctionResolver dayName() {
return define(
BuiltinFunctionName.DAYNAME.getName(),
impl(nullMissingHandling(DateTimeFunction::exprDayName), STRING, DATE),
- impl(nullMissingHandling(DateTimeFunction::exprDayName), STRING, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprDayName), STRING, TIMESTAMP),
impl(nullMissingHandling(DateTimeFunction::exprDayName), STRING, STRING));
}
- /** DAYOFMONTH(STRING/DATE/DATETIME/TIMESTAMP). return the day of the month (1-31). */
+ /** DAYOFMONTH(STRING/DATE/TIMESTAMP). return the day of the month (1-31). */
private DefaultFunctionResolver dayOfMonth(BuiltinFunctionName name) {
return define(
name.getName(),
@@ -627,14 +553,13 @@ private DefaultFunctionResolver dayOfMonth(BuiltinFunctionName name) {
INTEGER,
TIME),
impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, DATE),
- impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, STRING),
impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, TIMESTAMP));
}
/**
- * DAYOFWEEK(STRING/DATE/DATETIME/TIME/TIMESTAMP). return the weekday index for date (1 = Sunday,
- * 2 = Monday, ..., 7 = Saturday).
+ * DAYOFWEEK(STRING/DATE/TIME/TIMESTAMP). return the weekday index for date (1 = Sunday, 2 =
+ * Monday, ..., 7 = Saturday).
*/
private DefaultFunctionResolver dayOfWeek(FunctionName name) {
return define(
@@ -646,12 +571,11 @@ private DefaultFunctionResolver dayOfWeek(FunctionName name) {
INTEGER,
TIME),
impl(nullMissingHandling(DateTimeFunction::exprDayOfWeek), INTEGER, DATE),
- impl(nullMissingHandling(DateTimeFunction::exprDayOfWeek), INTEGER, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprDayOfWeek), INTEGER, TIMESTAMP),
impl(nullMissingHandling(DateTimeFunction::exprDayOfWeek), INTEGER, STRING));
}
- /** DAYOFYEAR(STRING/DATE/DATETIME/TIMESTAMP). return the day of the year for date (1-366). */
+ /** DAYOFYEAR(STRING/DATE/TIMESTAMP). return the day of the year for date (1-366). */
private DefaultFunctionResolver dayOfYear(BuiltinFunctionName dayOfYear) {
return define(
dayOfYear.getName(),
@@ -662,7 +586,6 @@ private DefaultFunctionResolver dayOfYear(BuiltinFunctionName dayOfYear) {
INTEGER,
TIME),
impl(nullMissingHandling(DateTimeFunction::exprDayOfYear), INTEGER, DATE),
- impl(nullMissingHandling(DateTimeFunction::exprDayOfYear), INTEGER, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprDayOfYear), INTEGER, TIMESTAMP),
impl(nullMissingHandling(DateTimeFunction::exprDayOfYear), INTEGER, STRING));
}
@@ -676,7 +599,6 @@ private DefaultFunctionResolver extract() {
STRING,
TIME),
impl(nullMissingHandling(DateTimeFunction::exprExtract), LONG, STRING, DATE),
- impl(nullMissingHandling(DateTimeFunction::exprExtract), LONG, STRING, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprExtract), LONG, STRING, TIMESTAMP),
impl(nullMissingHandling(DateTimeFunction::exprExtract), LONG, STRING, STRING));
}
@@ -691,7 +613,7 @@ private DefaultFunctionResolver from_days() {
private FunctionResolver from_unixtime() {
return define(
BuiltinFunctionName.FROM_UNIXTIME.getName(),
- impl(nullMissingHandling(DateTimeFunction::exprFromUnixTime), DATETIME, DOUBLE),
+ impl(nullMissingHandling(DateTimeFunction::exprFromUnixTime), TIMESTAMP, DOUBLE),
impl(
nullMissingHandling(DateTimeFunction::exprFromUnixTimeFormat), STRING, DOUBLE, STRING));
}
@@ -702,14 +624,13 @@ private DefaultFunctionResolver get_format() {
impl(nullMissingHandling(DateTimeFunction::exprGetFormat), STRING, STRING, STRING));
}
- /** HOUR(STRING/TIME/DATETIME/DATE/TIMESTAMP). return the hour value for time. */
+ /** HOUR(STRING/TIME/DATE/TIMESTAMP). return the hour value for time. */
private DefaultFunctionResolver hour(BuiltinFunctionName name) {
return define(
name.getName(),
impl(nullMissingHandling(DateTimeFunction::exprHour), INTEGER, STRING),
impl(nullMissingHandling(DateTimeFunction::exprHour), INTEGER, TIME),
impl(nullMissingHandling(DateTimeFunction::exprHour), INTEGER, DATE),
- impl(nullMissingHandling(DateTimeFunction::exprHour), INTEGER, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprHour), INTEGER, TIMESTAMP));
}
@@ -724,7 +645,6 @@ private DefaultFunctionResolver last_day() {
DATE,
TIME),
impl(nullMissingHandling(DateTimeFunction::exprLastDay), DATE, DATE),
- impl(nullMissingHandling(DateTimeFunction::exprLastDay), DATE, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprLastDay), DATE, TIMESTAMP));
}
@@ -740,39 +660,36 @@ private FunctionResolver maketime() {
impl(nullMissingHandling(DateTimeFunction::exprMakeTime), TIME, DOUBLE, DOUBLE, DOUBLE));
}
- /** MICROSECOND(STRING/TIME/DATETIME/TIMESTAMP). return the microsecond value for time. */
+ /** MICROSECOND(STRING/TIME/TIMESTAMP). return the microsecond value for time. */
private DefaultFunctionResolver microsecond() {
return define(
BuiltinFunctionName.MICROSECOND.getName(),
impl(nullMissingHandling(DateTimeFunction::exprMicrosecond), INTEGER, STRING),
impl(nullMissingHandling(DateTimeFunction::exprMicrosecond), INTEGER, TIME),
- impl(nullMissingHandling(DateTimeFunction::exprMicrosecond), INTEGER, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprMicrosecond), INTEGER, TIMESTAMP));
}
- /** MINUTE(STRING/TIME/DATETIME/TIMESTAMP). return the minute value for time. */
+ /** MINUTE(STRING/TIME/TIMESTAMP). return the minute value for time. */
private DefaultFunctionResolver minute(BuiltinFunctionName name) {
return define(
name.getName(),
impl(nullMissingHandling(DateTimeFunction::exprMinute), INTEGER, STRING),
impl(nullMissingHandling(DateTimeFunction::exprMinute), INTEGER, TIME),
- impl(nullMissingHandling(DateTimeFunction::exprMinute), INTEGER, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprMinute), INTEGER, DATE),
impl(nullMissingHandling(DateTimeFunction::exprMinute), INTEGER, TIMESTAMP));
}
- /** MINUTE(STRING/TIME/DATETIME/TIMESTAMP). return the minute value for time. */
+ /** MINUTE(STRING/TIME/TIMESTAMP). return the minute value for time. */
private DefaultFunctionResolver minute_of_day() {
return define(
BuiltinFunctionName.MINUTE_OF_DAY.getName(),
impl(nullMissingHandling(DateTimeFunction::exprMinuteOfDay), INTEGER, STRING),
impl(nullMissingHandling(DateTimeFunction::exprMinuteOfDay), INTEGER, TIME),
impl(nullMissingHandling(DateTimeFunction::exprMinuteOfDay), INTEGER, DATE),
- impl(nullMissingHandling(DateTimeFunction::exprMinuteOfDay), INTEGER, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprMinuteOfDay), INTEGER, TIMESTAMP));
}
- /** MONTH(STRING/DATE/DATETIME/TIMESTAMP). return the month for date (1-12). */
+ /** MONTH(STRING/DATE/TIMESTAMP). return the month for date (1-12). */
private DefaultFunctionResolver month(BuiltinFunctionName month) {
return define(
month.getName(),
@@ -783,17 +700,15 @@ private DefaultFunctionResolver month(BuiltinFunctionName month) {
INTEGER,
TIME),
impl(nullMissingHandling(DateTimeFunction::exprMonth), INTEGER, DATE),
- impl(nullMissingHandling(DateTimeFunction::exprMonth), INTEGER, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprMonth), INTEGER, TIMESTAMP),
impl(nullMissingHandling(DateTimeFunction::exprMonth), INTEGER, STRING));
}
- /** MONTHNAME(STRING/DATE/DATETIME/TIMESTAMP). return the full name of the month for date. */
+ /** MONTHNAME(STRING/DATE/TIMESTAMP). return the full name of the month for date. */
private DefaultFunctionResolver monthName() {
return define(
BuiltinFunctionName.MONTHNAME.getName(),
impl(nullMissingHandling(DateTimeFunction::exprMonthName), STRING, DATE),
- impl(nullMissingHandling(DateTimeFunction::exprMonthName), STRING, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprMonthName), STRING, TIMESTAMP),
impl(nullMissingHandling(DateTimeFunction::exprMonthName), STRING, STRING));
}
@@ -819,12 +734,11 @@ private DefaultFunctionResolver period_diff() {
impl(nullMissingHandling(DateTimeFunction::exprPeriodDiff), INTEGER, INTEGER, INTEGER));
}
- /** QUARTER(STRING/DATE/DATETIME/TIMESTAMP). return the month for date (1-4). */
+ /** QUARTER(STRING/DATE/TIMESTAMP). return the month for date (1-4). */
private DefaultFunctionResolver quarter() {
return define(
BuiltinFunctionName.QUARTER.getName(),
impl(nullMissingHandling(DateTimeFunction::exprQuarter), INTEGER, DATE),
- impl(nullMissingHandling(DateTimeFunction::exprQuarter), INTEGER, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprQuarter), INTEGER, TIMESTAMP),
impl(nullMissingHandling(DateTimeFunction::exprQuarter), INTEGER, STRING));
}
@@ -838,14 +752,13 @@ private DefaultFunctionResolver sec_to_time() {
impl((nullMissingHandling(DateTimeFunction::exprSecToTimeWithNanos)), TIME, FLOAT));
}
- /** SECOND(STRING/TIME/DATETIME/TIMESTAMP). return the second value for time. */
+ /** SECOND(STRING/TIME/TIMESTAMP). return the second value for time. */
private DefaultFunctionResolver second(BuiltinFunctionName name) {
return define(
name.getName(),
impl(nullMissingHandling(DateTimeFunction::exprSecond), INTEGER, STRING),
impl(nullMissingHandling(DateTimeFunction::exprSecond), INTEGER, TIME),
impl(nullMissingHandling(DateTimeFunction::exprSecond), INTEGER, DATE),
- impl(nullMissingHandling(DateTimeFunction::exprSecond), INTEGER, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprSecond), INTEGER, TIMESTAMP));
}
@@ -861,8 +774,8 @@ private DefaultFunctionResolver subdate() {
/**
* Subtracts expr2 from expr1 and returns the result.
- * (TIME, TIME/DATE/DATETIME/TIMESTAMP) -> TIME
- * (DATE/DATETIME/TIMESTAMP, TIME/DATE/DATETIME/TIMESTAMP) -> DATETIME
+ * (TIME, TIME/DATE/TIMESTAMP) -> TIME
+ * (DATE/TIMESTAMP, TIME/DATE/TIMESTAMP) -> TIMESTAMP
* TODO: MySQL has these signatures too
* (STRING, STRING/TIME) -> STRING // second arg - string with time only
* (x, STRING) -> NULL // second arg - string with timestamp
@@ -875,8 +788,6 @@ private DefaultFunctionResolver subtime() {
nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), TIME, TIME, TIME),
implWithProperties(
nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), TIME, TIME, DATE),
- implWithProperties(
- nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), TIME, TIME, DATETIME),
implWithProperties(
nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime),
TIME,
@@ -884,62 +795,38 @@ private DefaultFunctionResolver subtime() {
TIMESTAMP),
implWithProperties(
nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime),
- DATETIME,
- DATETIME,
+ TIMESTAMP,
+ TIMESTAMP,
TIME),
implWithProperties(
nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime),
- DATETIME,
- DATETIME,
+ TIMESTAMP,
+ TIMESTAMP,
DATE),
implWithProperties(
nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime),
- DATETIME,
- DATETIME,
- DATETIME),
- implWithProperties(
- nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime),
- DATETIME,
- DATETIME,
- TIMESTAMP),
- implWithProperties(
- nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), DATETIME, DATE, TIME),
- implWithProperties(
- nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime), DATETIME, DATE, DATE),
- implWithProperties(
- nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime),
- DATETIME,
- DATE,
- DATETIME),
- implWithProperties(
- nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime),
- DATETIME,
- DATE,
- TIMESTAMP),
- implWithProperties(
- nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime),
- DATETIME,
TIMESTAMP,
+ DATE,
TIME),
implWithProperties(
nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime),
- DATETIME,
TIMESTAMP,
+ DATE,
DATE),
implWithProperties(
nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime),
- DATETIME,
TIMESTAMP,
- DATETIME),
+ DATE,
+ TIMESTAMP),
implWithProperties(
nullMissingHandlingWithProperties(DateTimeFunction::exprSubTime),
- DATETIME,
+ TIMESTAMP,
TIMESTAMP,
TIMESTAMP));
}
/**
- * Extracts a date, time, or datetime from the given string. It accomplishes this using another
+ * Extracts a date, time, or timestamp from the given string. It accomplishes this using another
* string which specifies the input format.
*/
private DefaultFunctionResolver str_to_date() {
@@ -949,21 +836,20 @@ private DefaultFunctionResolver str_to_date() {
nullMissingHandlingWithProperties(
(functionProperties, arg, format) ->
DateTimeFunction.exprStrToDate(functionProperties, arg, format)),
- DATETIME,
+ TIMESTAMP,
STRING,
STRING));
}
/**
* Extracts the time part of a date and time value. Also to construct a time type. The supported
- * signatures: STRING/DATE/DATETIME/TIME/TIMESTAMP -> TIME
+ * signatures: STRING/DATE/TIME/TIMESTAMP -> TIME
*/
private DefaultFunctionResolver time() {
return define(
BuiltinFunctionName.TIME.getName(),
impl(nullMissingHandling(DateTimeFunction::exprTime), TIME, STRING),
impl(nullMissingHandling(DateTimeFunction::exprTime), TIME, DATE),
- impl(nullMissingHandling(DateTimeFunction::exprTime), TIME, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprTime), TIME, TIME),
impl(nullMissingHandling(DateTimeFunction::exprTime), TIME, TIMESTAMP));
}
@@ -973,7 +859,6 @@ private DefaultFunctionResolver time() {
* (TIME, TIME) -> TIME
* MySQL has these signatures too
* (DATE, DATE) -> TIME // result is > 24 hours
- * (DATETIME, DATETIME) -> TIME // result is > 24 hours
* (TIMESTAMP, TIMESTAMP) -> TIME // result is > 24 hours
* (x, x) -> NULL // when args have different types
* (STRING, STRING) -> TIME // argument strings contain same types only
@@ -985,23 +870,20 @@ private DefaultFunctionResolver timediff() {
impl(nullMissingHandling(DateTimeFunction::exprTimeDiff), TIME, TIME, TIME));
}
- /**
- * TIME_TO_SEC(STRING/TIME/DATETIME/TIMESTAMP). return the time argument, converted to seconds.
- */
+ /** TIME_TO_SEC(STRING/TIME/TIMESTAMP). return the time argument, converted to seconds. */
private DefaultFunctionResolver time_to_sec() {
return define(
BuiltinFunctionName.TIME_TO_SEC.getName(),
impl(nullMissingHandling(DateTimeFunction::exprTimeToSec), LONG, STRING),
impl(nullMissingHandling(DateTimeFunction::exprTimeToSec), LONG, TIME),
- impl(nullMissingHandling(DateTimeFunction::exprTimeToSec), LONG, TIMESTAMP),
- impl(nullMissingHandling(DateTimeFunction::exprTimeToSec), LONG, DATETIME));
+ impl(nullMissingHandling(DateTimeFunction::exprTimeToSec), LONG, TIMESTAMP));
}
/**
* Extracts the timestamp of a date and time value.
* Input strings may contain a timestamp only in format 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'
- * STRING/DATE/TIME/DATETIME/TIMESTAMP -> TIMESTAMP
- * STRING/DATE/TIME/DATETIME/TIMESTAMP, STRING/DATE/TIME/DATETIME/TIMESTAMP -> TIMESTAMP
+ * STRING/DATE/TIME/TIMESTAMP -> TIMESTAMP
+ * STRING/DATE/TIME/TIMESTAMP, STRING/DATE/TIME/TIMESTAMP -> TIMESTAMP
* All types are converted to TIMESTAMP actually before the function call - it is responsibility
*
* of the automatic cast mechanism defined in `ExprCoreType` and performed by `TypeCastOperator`.
@@ -1020,27 +902,20 @@ private DefaultFunctionResolver timestamp() {
}
/**
- * Adds an interval of time to the provided DATE/DATETIME/TIME/TIMESTAMP/STRING argument. The
- * interval of time added is determined by the given first and second arguments. The first
- * argument is an interval type, and must be one of the tokens below... [MICROSECOND, SECOND,
- * MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR] The second argument is the amount of the
- * interval type to be added. The third argument is the DATE/DATETIME/TIME/TIMESTAMP/STRING to add
- * to.
+ * Adds an interval of time to the provided DATE/TIME/TIMESTAMP/STRING argument. The interval of
+ * time added is determined by the given first and second arguments. The first argument is an
+ * interval type, and must be one of the tokens below... [MICROSECOND, SECOND, MINUTE, HOUR, DAY,
+ * WEEK, MONTH, QUARTER, YEAR] The second argument is the amount of the interval type to be added.
+ * The third argument is the DATE/TIME/TIMESTAMP/STRING to add to.
*
- * @return The DATETIME representing the summed DATE/DATETIME/TIME/TIMESTAMP and interval.
+ * @return The TIMESTAMP representing the summed DATE/TIME/TIMESTAMP and interval.
*/
private DefaultFunctionResolver timestampadd() {
return define(
BuiltinFunctionName.TIMESTAMPADD.getName(),
impl(
nullMissingHandling(DateTimeFunction::exprTimestampAdd),
- DATETIME,
- STRING,
- INTEGER,
- DATETIME),
- impl(
- nullMissingHandling(DateTimeFunction::exprTimestampAdd),
- DATETIME,
+ TIMESTAMP,
STRING,
INTEGER,
TIMESTAMP),
@@ -1049,18 +924,18 @@ private DefaultFunctionResolver timestampadd() {
(functionProperties, part, amount, time) ->
exprTimestampAddForTimeType(
functionProperties.getQueryStartClock(), part, amount, time)),
- DATETIME,
+ TIMESTAMP,
STRING,
INTEGER,
TIME));
}
/**
- * Finds the difference between provided DATE/DATETIME/TIME/TIMESTAMP/STRING arguments. The first
- * argument is an interval type, and must be one of the tokens below... [MICROSECOND, SECOND,
- * MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR] The second argument the
- * DATE/DATETIME/TIME/TIMESTAMP/STRING representing the start time. The third argument is the
- * DATE/DATETIME/TIME/TIMESTAMP/STRING representing the end time.
+ * Finds the difference between provided DATE/TIME/TIMESTAMP/STRING arguments. The first argument
+ * is an interval type, and must be one of the tokens below... [MICROSECOND, SECOND, MINUTE, HOUR,
+ * DAY, WEEK, MONTH, QUARTER, YEAR] The second argument the DATE/TIME/TIMESTAMP/STRING
+ * representing the start time. The third argument is the DATE/TIME/TIMESTAMP/STRING representing
+ * the end time.
*
* @return A LONG representing the difference between arguments, using the given interval type.
*/
@@ -1069,25 +944,7 @@ private DefaultFunctionResolver timestampdiff() {
BuiltinFunctionName.TIMESTAMPDIFF.getName(),
impl(
nullMissingHandling(DateTimeFunction::exprTimestampDiff),
- DATETIME,
- STRING,
- DATETIME,
- DATETIME),
- impl(
- nullMissingHandling(DateTimeFunction::exprTimestampDiff),
- DATETIME,
- STRING,
- DATETIME,
- TIMESTAMP),
- impl(
- nullMissingHandling(DateTimeFunction::exprTimestampDiff),
- DATETIME,
- STRING,
TIMESTAMP,
- DATETIME),
- impl(
- nullMissingHandling(DateTimeFunction::exprTimestampDiff),
- DATETIME,
STRING,
TIMESTAMP,
TIMESTAMP),
@@ -1095,20 +952,19 @@ private DefaultFunctionResolver timestampdiff() {
nullMissingHandlingWithProperties(
(functionProperties, part, startTime, endTime) ->
exprTimestampDiffForTimeType(functionProperties, part, startTime, endTime)),
- DATETIME,
+ TIMESTAMP,
STRING,
TIME,
TIME));
}
- /** TO_DAYS(STRING/DATE/DATETIME/TIMESTAMP). return the day number of the given date. */
+ /** TO_DAYS(STRING/DATE/TIMESTAMP). return the day number of the given date. */
private DefaultFunctionResolver to_days() {
return define(
BuiltinFunctionName.TO_DAYS.getName(),
impl(nullMissingHandling(DateTimeFunction::exprToDays), LONG, STRING),
impl(nullMissingHandling(DateTimeFunction::exprToDays), LONG, TIMESTAMP),
- impl(nullMissingHandling(DateTimeFunction::exprToDays), LONG, DATE),
- impl(nullMissingHandling(DateTimeFunction::exprToDays), LONG, DATETIME));
+ impl(nullMissingHandling(DateTimeFunction::exprToDays), LONG, DATE));
}
/**
@@ -1131,7 +987,6 @@ private FunctionResolver unix_timestamp() {
DateTimeFunction.unixTimeStamp(functionProperties.getQueryStartClock()),
LONG),
impl(nullMissingHandling(DateTimeFunction::unixTimeStampOf), DOUBLE, DATE),
- impl(nullMissingHandling(DateTimeFunction::unixTimeStampOf), DOUBLE, DATETIME),
impl(nullMissingHandling(DateTimeFunction::unixTimeStampOf), DOUBLE, TIMESTAMP),
impl(nullMissingHandling(DateTimeFunction::unixTimeStampOf), DOUBLE, DOUBLE));
}
@@ -1154,7 +1009,7 @@ private DefaultFunctionResolver utc_time() {
private DefaultFunctionResolver utc_timestamp() {
return define(
BuiltinFunctionName.UTC_TIMESTAMP.getName(),
- implWithProperties(functionProperties -> exprUtcTimeStamp(functionProperties), DATETIME));
+ implWithProperties(functionProperties -> exprUtcTimeStamp(functionProperties), TIMESTAMP));
}
/** WEEK(DATE[,mode]). return the week number for date. */
@@ -1169,7 +1024,6 @@ private DefaultFunctionResolver week(BuiltinFunctionName week) {
INTEGER,
TIME),
impl(nullMissingHandling(DateTimeFunction::exprWeekWithoutMode), INTEGER, DATE),
- impl(nullMissingHandling(DateTimeFunction::exprWeekWithoutMode), INTEGER, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprWeekWithoutMode), INTEGER, TIMESTAMP),
impl(nullMissingHandling(DateTimeFunction::exprWeekWithoutMode), INTEGER, STRING),
implWithProperties(
@@ -1181,7 +1035,6 @@ private DefaultFunctionResolver week(BuiltinFunctionName week) {
TIME,
INTEGER),
impl(nullMissingHandling(DateTimeFunction::exprWeek), INTEGER, DATE, INTEGER),
- impl(nullMissingHandling(DateTimeFunction::exprWeek), INTEGER, DATETIME, INTEGER),
impl(nullMissingHandling(DateTimeFunction::exprWeek), INTEGER, TIMESTAMP, INTEGER),
impl(nullMissingHandling(DateTimeFunction::exprWeek), INTEGER, STRING, INTEGER));
}
@@ -1198,17 +1051,15 @@ private DefaultFunctionResolver weekday() {
INTEGER,
TIME),
impl(nullMissingHandling(DateTimeFunction::exprWeekday), INTEGER, DATE),
- impl(nullMissingHandling(DateTimeFunction::exprWeekday), INTEGER, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprWeekday), INTEGER, TIMESTAMP),
impl(nullMissingHandling(DateTimeFunction::exprWeekday), INTEGER, STRING));
}
- /** YEAR(STRING/DATE/DATETIME/TIMESTAMP). return the year for date (1000-9999). */
+ /** YEAR(STRING/DATE/TIMESTAMP). return the year for date (1000-9999). */
private DefaultFunctionResolver year() {
return define(
BuiltinFunctionName.YEAR.getName(),
impl(nullMissingHandling(DateTimeFunction::exprYear), INTEGER, DATE),
- impl(nullMissingHandling(DateTimeFunction::exprYear), INTEGER, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprYear), INTEGER, TIMESTAMP),
impl(nullMissingHandling(DateTimeFunction::exprYear), INTEGER, STRING));
}
@@ -1225,7 +1076,6 @@ private DefaultFunctionResolver yearweek() {
INTEGER,
TIME),
impl(nullMissingHandling(DateTimeFunction::exprYearweekWithoutMode), INTEGER, DATE),
- impl(nullMissingHandling(DateTimeFunction::exprYearweekWithoutMode), INTEGER, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprYearweekWithoutMode), INTEGER, TIMESTAMP),
impl(nullMissingHandling(DateTimeFunction::exprYearweekWithoutMode), INTEGER, STRING),
implWithProperties(
@@ -1236,7 +1086,6 @@ private DefaultFunctionResolver yearweek() {
TIME,
INTEGER),
impl(nullMissingHandling(DateTimeFunction::exprYearweek), INTEGER, DATE, INTEGER),
- impl(nullMissingHandling(DateTimeFunction::exprYearweek), INTEGER, DATETIME, INTEGER),
impl(nullMissingHandling(DateTimeFunction::exprYearweek), INTEGER, TIMESTAMP, INTEGER),
impl(nullMissingHandling(DateTimeFunction::exprYearweek), INTEGER, STRING, INTEGER));
}
@@ -1246,7 +1095,6 @@ private DefaultFunctionResolver yearweek() {
* Detailed supported signatures:
* (STRING, STRING) -> STRING
* (DATE, STRING) -> STRING
- * (DATETIME, STRING) -> STRING
* (TIME, STRING) -> STRING
* (TIMESTAMP, STRING) -> STRING
*/
@@ -1255,8 +1103,6 @@ private DefaultFunctionResolver date_format() {
BuiltinFunctionName.DATE_FORMAT.getName(),
impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedDate), STRING, STRING, STRING),
impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedDate), STRING, DATE, STRING),
- impl(
- nullMissingHandling(DateTimeFormatterUtil::getFormattedDate), STRING, DATETIME, STRING),
implWithProperties(
nullMissingHandlingWithProperties(
(functionProperties, time, formatString) ->
@@ -1299,9 +1145,9 @@ private ExprValue dayOfWeekToday(Clock clock) {
* DATE_ADD function implementation for ExprValue.
*
* @param functionProperties An FunctionProperties object.
- * @param datetime ExprValue of Date/Time/Datetime/Timestamp type.
+ * @param datetime ExprValue of Date/Time/Timestamp type.
* @param interval ExprValue of Interval type, the temporal amount to add.
- * @return Datetime resulted from `interval` added to `datetime`.
+ * @return Timestamp resulted from `interval` added to `timestamp`.
*/
private ExprValue exprAddDateInterval(
FunctionProperties functionProperties, ExprValue datetime, ExprValue interval) {
@@ -1309,21 +1155,22 @@ private ExprValue exprAddDateInterval(
}
/**
- * Adds or subtracts `interval` to/from `datetime`.
+ * Adds or subtracts `interval` to/from `timestamp`.
*
* @param functionProperties An FunctionProperties object.
- * @param datetime A Date/Time/Datetime/Timestamp value to change.
+ * @param datetime A Date/Time/Timestamp value to change.
* @param interval An Interval to isAdd or subtract.
* @param isAdd A flag: true to isAdd, false to subtract.
- * @return Datetime calculated.
+ * @return Timestamp calculated.
*/
private ExprValue exprDateApplyInterval(
FunctionProperties functionProperties,
ExprValue datetime,
TemporalAmount interval,
Boolean isAdd) {
- var dt = extractDateTime(datetime, functionProperties);
- return new ExprDatetimeValue(isAdd ? dt.plus(interval) : dt.minus(interval));
+ var dt =
+ extractTimestamp(datetime, functionProperties).atZone(ZoneOffset.UTC).toLocalDateTime();
+ return new ExprTimestampValue(isAdd ? dt.plus(interval) : dt.minus(interval));
}
/**
@@ -1331,7 +1178,6 @@ private ExprValue exprDateApplyInterval(
* Detailed supported signatures:
* (STRING, STRING) -> STRING
* (DATE, STRING) -> STRING
- * (DATETIME, STRING) -> STRING
* (TIME, STRING) -> STRING
* (TIMESTAMP, STRING) -> STRING
*/
@@ -1340,8 +1186,6 @@ private DefaultFunctionResolver time_format() {
BuiltinFunctionName.TIME_FORMAT.getName(),
impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedTime), STRING, STRING, STRING),
impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedTime), STRING, DATE, STRING),
- impl(
- nullMissingHandling(DateTimeFormatterUtil::getFormattedTime), STRING, DATETIME, STRING),
impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedTime), STRING, TIME, STRING),
impl(
nullMissingHandling(DateTimeFormatterUtil::getFormattedTime),
@@ -1354,9 +1198,9 @@ private DefaultFunctionResolver time_format() {
* ADDDATE function implementation for ExprValue.
*
* @param functionProperties An FunctionProperties object.
- * @param datetime ExprValue of Time/Date/Datetime/Timestamp type.
+ * @param datetime ExprValue of Time/Date/Timestamp type.
* @param days ExprValue of Long type, representing the number of days to add.
- * @return Date/Datetime resulted from days added to `datetime`.
+ * @return Date/Timestamp resulted from days added to `timestamp`.
*/
private ExprValue exprAddDateDays(
FunctionProperties functionProperties, ExprValue datetime, ExprValue days) {
@@ -1364,13 +1208,13 @@ private ExprValue exprAddDateDays(
}
/**
- * Adds or subtracts `days` to/from `datetime`.
+ * Adds or subtracts `days` to/from `timestamp`.
*
* @param functionProperties An FunctionProperties object.
- * @param datetime A Date/Time/Datetime/Timestamp value to change.
+ * @param datetime A Date/Time/Timestamp value to change.
* @param days A days amount to add or subtract.
* @param isAdd A flag: true to add, false to subtract.
- * @return Datetime calculated.
+ * @return Timestamp calculated.
*/
private ExprValue exprDateApplyDays(
FunctionProperties functionProperties, ExprValue datetime, Long days, Boolean isAdd) {
@@ -1378,16 +1222,17 @@ private ExprValue exprDateApplyDays(
return new ExprDateValue(
isAdd ? datetime.dateValue().plusDays(days) : datetime.dateValue().minusDays(days));
}
- var dt = extractDateTime(datetime, functionProperties);
- return new ExprDatetimeValue(isAdd ? dt.plusDays(days) : dt.minusDays(days));
+ var dt =
+ extractTimestamp(datetime, functionProperties).atZone(ZoneOffset.UTC).toLocalDateTime();
+ return new ExprTimestampValue(isAdd ? dt.plusDays(days) : dt.minusDays(days));
}
/**
* Adds or subtracts time to/from date and returns the result.
*
* @param functionProperties A FunctionProperties object.
- * @param temporal A Date/Time/Datetime/Timestamp value to change.
- * @param temporalDelta A Date/Time/Datetime/Timestamp object to add/subtract time from.
+ * @param temporal A Date/Time/Timestamp value to change.
+ * @param temporalDelta A Date/Time/Timestamp object to add/subtract time from.
* @param isAdd A flag: true to add, false to subtract.
* @return A value calculated.
*/
@@ -1399,19 +1244,19 @@ private ExprValue exprApplyTime(
var interval = Duration.between(LocalTime.MIN, temporalDelta.timeValue());
var result =
isAdd
- ? extractDateTime(temporal, functionProperties).plus(interval)
- : extractDateTime(temporal, functionProperties).minus(interval);
+ ? extractTimestamp(temporal, functionProperties).plus(interval)
+ : extractTimestamp(temporal, functionProperties).minus(interval);
return temporal.type() == TIME
- ? new ExprTimeValue(result.toLocalTime())
- : new ExprDatetimeValue(result);
+ ? new ExprTimeValue(result.atZone(ZoneOffset.UTC).toLocalTime())
+ : new ExprTimestampValue(result);
}
/**
* Adds time to date and returns the result.
*
* @param functionProperties A FunctionProperties object.
- * @param temporal A Date/Time/Datetime/Timestamp value to change.
- * @param temporalDelta A Date/Time/Datetime/Timestamp object to add time from.
+ * @param temporal A Date/Time/Timestamp value to change.
+ * @param temporalDelta A Date/Time/Timestamp object to add time from.
* @return A value calculated.
*/
private ExprValue exprAddTime(
@@ -1423,10 +1268,10 @@ private ExprValue exprAddTime(
* CONVERT_TZ function implementation for ExprValue. Returns null for time zones outside of +13:00
* and -12:00.
*
- * @param startingDateTime ExprValue of DateTime that is being converted from
+ * @param startingDateTime ExprValue of Timestamp that is being converted from
* @param fromTz ExprValue of time zone, representing the time to convert from.
* @param toTz ExprValue of time zone, representing the time to convert to.
- * @return DateTime that has been converted to the to_tz timezone.
+ * @return Timestamp that has been converted to the to_tz timezone.
*/
private ExprValue exprConvertTZ(ExprValue startingDateTime, ExprValue fromTz, ExprValue toTz) {
if (startingDateTime.type() == ExprCoreType.STRING) {
@@ -1442,8 +1287,10 @@ private ExprValue exprConvertTZ(ExprValue startingDateTime, ExprValue fromTz, Ex
|| !DateTimeUtils.isValidMySqlTimeZoneId(convertedToTz)) {
return ExprNullValue.of();
}
- ZonedDateTime zonedDateTime = startingDateTime.datetimeValue().atZone(convertedFromTz);
- return new ExprDatetimeValue(
+ ZonedDateTime zonedDateTime =
+ (startingDateTime.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime())
+ .atZone(convertedFromTz);
+ return new ExprTimestampValue(
zonedDateTime.withZoneSameInstant(convertedToTz).toLocalDateTime());
// Catches exception for invalid timezones.
@@ -1484,43 +1331,43 @@ private ExprValue exprDateDiff(
}
/**
- * DateTime implementation for ExprValue.
+ * Timestamp implementation for ExprValue.
*
- * @param dateTime ExprValue of String type.
+ * @param timestamp ExprValue of String type.
* @param timeZone ExprValue of String type (or null).
* @return ExprValue of date type.
*/
- private ExprValue exprDateTime(ExprValue dateTime, ExprValue timeZone) {
+ private ExprValue exprDateTime(ExprValue timestamp, ExprValue timeZone) {
String defaultTimeZone = TimeZone.getDefault().getID();
try {
LocalDateTime ldtFormatted =
- LocalDateTime.parse(dateTime.stringValue(), DATE_TIME_FORMATTER_STRICT_WITH_TZ);
+ LocalDateTime.parse(timestamp.stringValue(), DATE_TIME_FORMATTER_STRICT_WITH_TZ);
if (timeZone.isNull()) {
- return new ExprDatetimeValue(ldtFormatted);
+ return new ExprTimestampValue(ldtFormatted);
}
- // Used if datetime field is invalid format.
+ // Used if timestamp field is invalid format.
} catch (DateTimeParseException e) {
return ExprNullValue.of();
}
ExprValue convertTZResult;
- ExprDatetimeValue ldt;
+ ExprTimestampValue tz;
String toTz;
try {
ZonedDateTime zdtWithZoneOffset =
- ZonedDateTime.parse(dateTime.stringValue(), DATE_TIME_FORMATTER_STRICT_WITH_TZ);
+ ZonedDateTime.parse(timestamp.stringValue(), DATE_TIME_FORMATTER_STRICT_WITH_TZ);
ZoneId fromTZ = zdtWithZoneOffset.getZone();
- ldt = new ExprDatetimeValue(zdtWithZoneOffset.toLocalDateTime());
+ tz = new ExprTimestampValue(zdtWithZoneOffset.toLocalDateTime());
toTz = String.valueOf(fromTZ);
} catch (DateTimeParseException e) {
- ldt = new ExprDatetimeValue(dateTime.stringValue());
+ tz = new ExprTimestampValue(timestamp.stringValue());
toTz = defaultTimeZone;
}
- convertTZResult = exprConvertTZ(ldt, new ExprStringValue(toTz), timeZone);
+ convertTZResult = exprConvertTZ(tz, new ExprStringValue(toTz), timeZone);
return convertTZResult;
}
@@ -1549,7 +1396,7 @@ private ExprValue exprDayName(ExprValue date) {
/**
* Day of Month implementation for ExprValue.
*
- * @param date ExprValue of Date/Datetime/String/Time/Timestamp type.
+ * @param date ExprValue of Date/String/Time/Timestamp type.
* @return ExprValue.
*/
private ExprValue exprDayOfMonth(ExprValue date) {
@@ -1559,7 +1406,7 @@ private ExprValue exprDayOfMonth(ExprValue date) {
/**
* Day of Week implementation for ExprValue.
*
- * @param date ExprValue of Date/Datetime/String/Timstamp type.
+ * @param date ExprValue of Date/String/Timstamp type.
* @return ExprValue.
*/
private ExprValue exprDayOfWeek(ExprValue date) {
@@ -1577,15 +1424,15 @@ private ExprValue exprDayOfYear(ExprValue date) {
}
/**
- * Obtains a formatted long value for a specified part and datetime for the 'extract' function.
+ * Obtains a formatted long value for a specified part and timestamp for the 'extract' function.
*
* @param part is an ExprValue which comes from a defined list of accepted values.
- * @param datetime the date to be formatted as an ExprValue.
+ * @param timestamp the date to be formatted as an ExprValue.
* @return is a LONG formatted according to the input arguments.
*/
- public ExprLongValue formatExtractFunction(ExprValue part, ExprValue datetime) {
+ public ExprLongValue formatExtractFunction(ExprValue part, ExprValue timestamp) {
String partName = part.stringValue().toUpperCase();
- LocalDateTime arg = datetime.datetimeValue();
+ LocalDateTime arg = timestamp.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime();
String text =
arg.format(DateTimeFormatter.ofPattern(extract_formats.get(partName), Locale.ENGLISH));
@@ -1596,11 +1443,11 @@ public ExprLongValue formatExtractFunction(ExprValue part, ExprValue datetime) {
* Implements extract function. Returns a LONG formatted according to the 'part' argument.
*
* @param part Literal that determines the format of the outputted LONG.
- * @param datetime The date/datetime to be formatted.
+ * @param timestamp The Date/Timestamp to be formatted.
* @return A LONG
*/
- private ExprValue exprExtract(ExprValue part, ExprValue datetime) {
- return formatExtractFunction(part, datetime);
+ private ExprValue exprExtract(ExprValue part, ExprValue timestamp) {
+ return formatExtractFunction(part, timestamp);
}
/**
@@ -1613,7 +1460,7 @@ private ExprValue exprExtract(ExprValue part, ExprValue datetime) {
private ExprValue exprExtractForTime(
FunctionProperties functionProperties, ExprValue part, ExprValue time) {
return formatExtractFunction(
- part, new ExprDatetimeValue(extractDateTime(time, functionProperties)));
+ part, new ExprTimestampValue(extractTimestamp(time, functionProperties)));
}
/**
@@ -1637,12 +1484,12 @@ private ExprValue exprFromUnixTime(ExprValue time) {
if (MYSQL_MAX_TIMESTAMP <= time.doubleValue()) {
return ExprNullValue.of();
}
- return new ExprDatetimeValue(exprFromUnixTimeImpl(time));
+ return new ExprTimestampValue(exprFromUnixTimeImpl(time));
}
private LocalDateTime exprFromUnixTimeImpl(ExprValue time) {
return LocalDateTime.ofInstant(
- Instant.ofEpochSecond((long) Math.floor(time.doubleValue())), UTC_ZONE_ID)
+ Instant.ofEpochSecond((long) Math.floor(time.doubleValue())), ZoneOffset.UTC)
.withNano((int) ((time.doubleValue() % 1) * 1E9));
}
@@ -1694,11 +1541,11 @@ private LocalDate getLastDay(LocalDate today) {
/**
* Returns a DATE for the last day of the month of a given argument.
*
- * @param datetime A DATE/DATETIME/TIMESTAMP/STRING ExprValue.
+ * @param timestamp A DATE/TIMESTAMP/STRING ExprValue.
* @return An DATE value corresponding to the last day of the month of the given argument.
*/
- private ExprValue exprLastDay(ExprValue datetime) {
- return new ExprDateValue(getLastDay(datetime.dateValue()));
+ private ExprValue exprLastDay(ExprValue timestamp) {
+ return new ExprDateValue(getLastDay(timestamp.dateValue()));
}
/**
@@ -1932,9 +1779,9 @@ private ExprValue exprSecond(ExprValue time) {
* SUBDATE function implementation for ExprValue.
*
* @param functionProperties An FunctionProperties object.
- * @param date ExprValue of Time/Date/Datetime/Timestamp type.
+ * @param date ExprValue of Time/Date/Timestamp type.
* @param days ExprValue of Long type, representing the number of days to subtract.
- * @return Date/Datetime resulted from days subtracted to date.
+ * @return Date/Timestamp resulted from days subtracted to date.
*/
private ExprValue exprSubDateDays(
FunctionProperties functionProperties, ExprValue date, ExprValue days) {
@@ -1945,9 +1792,9 @@ private ExprValue exprSubDateDays(
* DATE_SUB function implementation for ExprValue.
*
* @param functionProperties An FunctionProperties object.
- * @param datetime ExprValue of Time/Date/Datetime/Timestamp type.
+ * @param datetime ExprValue of Time/Date/Timestamp type.
* @param expr ExprValue of Interval type, the temporal amount to subtract.
- * @return Datetime resulted from expr subtracted to `datetime`.
+ * @return Timestamp resulted from expr subtracted to `timestamp`.
*/
private ExprValue exprSubDateInterval(
FunctionProperties functionProperties, ExprValue datetime, ExprValue expr) {
@@ -1957,8 +1804,8 @@ private ExprValue exprSubDateInterval(
/**
* Subtracts expr2 from expr1 and returns the result.
*
- * @param temporal A Date/Time/Datetime/Timestamp value to change.
- * @param temporalDelta A Date/Time/Datetime/Timestamp to subtract time from.
+ * @param temporal A Date/Time/Timestamp value to change.
+ * @param temporalDelta A Date/Time/Timestamp to subtract time from.
* @return A value calculated.
*/
private ExprValue exprSubTime(
@@ -2012,7 +1859,8 @@ private ExprValue exprTimestampAdd(
ExprValue partExpr, ExprValue amountExpr, ExprValue datetimeExpr) {
String part = partExpr.stringValue();
int amount = amountExpr.integerValue();
- LocalDateTime datetime = datetimeExpr.datetimeValue();
+ LocalDateTime timestamp =
+ datetimeExpr.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime();
ChronoUnit temporalUnit;
switch (part) {
@@ -2047,13 +1895,13 @@ private ExprValue exprTimestampAdd(
default:
return ExprNullValue.of();
}
- return new ExprDatetimeValue(datetime.plus(amount, temporalUnit));
+ return new ExprTimestampValue(timestamp.plus(amount, temporalUnit));
}
private ExprValue exprTimestampAddForTimeType(
Clock clock, ExprValue partExpr, ExprValue amountExpr, ExprValue timeExpr) {
LocalDateTime datetime = LocalDateTime.of(formatNow(clock).toLocalDate(), timeExpr.timeValue());
- return exprTimestampAdd(partExpr, amountExpr, new ExprDatetimeValue(datetime));
+ return exprTimestampAdd(partExpr, amountExpr, new ExprTimestampValue(datetime));
}
private ExprValue getTimeDifference(String part, LocalDateTime startTime, LocalDateTime endTime) {
@@ -2095,15 +1943,17 @@ private ExprValue getTimeDifference(String part, LocalDateTime startTime, LocalD
private ExprValue exprTimestampDiff(
ExprValue partExpr, ExprValue startTimeExpr, ExprValue endTimeExpr) {
return getTimeDifference(
- partExpr.stringValue(), startTimeExpr.datetimeValue(), endTimeExpr.datetimeValue());
+ partExpr.stringValue(),
+ startTimeExpr.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime(),
+ endTimeExpr.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime());
}
private ExprValue exprTimestampDiffForTimeType(
FunctionProperties fp, ExprValue partExpr, ExprValue startTimeExpr, ExprValue endTimeExpr) {
return getTimeDifference(
partExpr.stringValue(),
- extractDateTime(startTimeExpr, fp),
- extractDateTime(endTimeExpr, fp));
+ extractTimestamp(startTimeExpr, fp).atZone(ZoneOffset.UTC).toLocalDateTime(),
+ extractTimestamp(endTimeExpr, fp).atZone(ZoneOffset.UTC).toLocalDateTime());
}
/**
@@ -2134,8 +1984,9 @@ private ExprValue exprUtcTime(FunctionProperties functionProperties) {
*/
private ExprValue exprUtcTimeStamp(FunctionProperties functionProperties) {
var zdt =
- ZonedDateTime.now(functionProperties.getQueryStartClock()).withZoneSameInstant(UTC_ZONE_ID);
- return new ExprDatetimeValue(zdt.toLocalDateTime());
+ ZonedDateTime.now(functionProperties.getQueryStartClock())
+ .withZoneSameInstant(ZoneOffset.UTC);
+ return new ExprTimestampValue(zdt.toLocalDateTime());
}
/**
@@ -2151,12 +2002,13 @@ private ExprValue exprToDays(ExprValue date) {
/**
* To_seconds implementation for ExprValue.
*
- * @param date ExprValue of Date/Datetime/Timestamp/String type.
+ * @param date ExprValue of Date/Timestamp/String type.
* @return ExprValue.
*/
private ExprValue exprToSeconds(ExprValue date) {
return new ExprLongValue(
- date.datetimeValue().toEpochSecond(ZoneOffset.UTC) + DAYS_0000_TO_1970 * SECONDS_PER_DAY);
+ date.timestampValue().atOffset(ZoneOffset.UTC).toEpochSecond()
+ + DAYS_0000_TO_1970 * SECONDS_PER_DAY);
}
/**
@@ -2226,7 +2078,7 @@ private ExprValue exprToSecondsForIntType(ExprValue dateExpr) {
/**
* Week for date implementation for ExprValue.
*
- * @param date ExprValue of Date/Datetime/Timestamp/String type.
+ * @param date ExprValue of Date/Timestamp/String type.
* @param mode ExprValue of Integer type.
*/
private ExprValue exprWeek(ExprValue date, ExprValue mode) {
@@ -2237,7 +2089,7 @@ private ExprValue exprWeek(ExprValue date, ExprValue mode) {
/**
* Weekday implementation for ExprValue.
*
- * @param date ExprValue of Date/Datetime/String/Timstamp type.
+ * @param date ExprValue of Date/String/Timstamp type.
* @return ExprValue.
*/
private ExprValue exprWeekday(ExprValue date) {
@@ -2270,9 +2122,6 @@ private Double unixTimeStampOfImpl(ExprValue value) {
switch ((ExprCoreType) value.type()) {
case DATE:
return value.dateValue().toEpochSecond(LocalTime.MIN, ZoneOffset.UTC) + 0d;
- case DATETIME:
- return value.datetimeValue().toEpochSecond(ZoneOffset.UTC)
- + value.datetimeValue().getNano() / 1E9;
case TIMESTAMP:
return value.timestampValue().getEpochSecond() + value.timestampValue().getNano() / 1E9;
default:
@@ -2323,7 +2172,7 @@ private Double unixTimeStampOfImpl(ExprValue value) {
* Week for date implementation for ExprValue. When mode is not specified default value mode 0 is
* used for default_week_format.
*
- * @param date ExprValue of Date/Datetime/Timestamp/String type.
+ * @param date ExprValue of Date/Timestamp/String type.
* @return ExprValue.
*/
private ExprValue exprWeekWithoutMode(ExprValue date) {
@@ -2363,7 +2212,7 @@ private ExprIntegerValue extractYearweek(LocalDate date, int mode) {
/**
* Yearweek for date implementation for ExprValue.
*
- * @param date ExprValue of Date/Datetime/Time/Timestamp/String type.
+ * @param date ExprValue of Date/Time/Timestamp/String type.
* @param mode ExprValue of Integer type.
*/
private ExprValue exprYearweek(ExprValue date, ExprValue mode) {
@@ -2374,7 +2223,7 @@ private ExprValue exprYearweek(ExprValue date, ExprValue mode) {
* Yearweek for date implementation for ExprValue. When mode is not specified default value mode 0
* is used.
*
- * @param date ExprValue of Date/Datetime/Time/Timestamp/String type.
+ * @param date ExprValue of Date/Time/Timestamp/String type.
* @return ExprValue.
*/
private ExprValue exprYearweekWithoutMode(ExprValue date) {
diff --git a/core/src/main/java/org/opensearch/sql/expression/operator/convert/TypeCastOperator.java b/core/src/main/java/org/opensearch/sql/expression/operator/convert/TypeCastOperator.java
index 7c3565f69c..db4b29f3b9 100644
--- a/core/src/main/java/org/opensearch/sql/expression/operator/convert/TypeCastOperator.java
+++ b/core/src/main/java/org/opensearch/sql/expression/operator/convert/TypeCastOperator.java
@@ -8,7 +8,6 @@
import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN;
import static org.opensearch.sql.data.type.ExprCoreType.BYTE;
import static org.opensearch.sql.data.type.ExprCoreType.DATE;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE;
import static org.opensearch.sql.data.type.ExprCoreType.FLOAT;
import static org.opensearch.sql.data.type.ExprCoreType.INTEGER;
@@ -29,7 +28,6 @@
import org.opensearch.sql.data.model.ExprBooleanValue;
import org.opensearch.sql.data.model.ExprByteValue;
import org.opensearch.sql.data.model.ExprDateValue;
-import org.opensearch.sql.data.model.ExprDatetimeValue;
import org.opensearch.sql.data.model.ExprDoubleValue;
import org.opensearch.sql.data.model.ExprFloatValue;
import org.opensearch.sql.data.model.ExprIntegerValue;
@@ -58,7 +56,6 @@ public static void register(BuiltinFunctionRepository repository) {
repository.register(castToDate());
repository.register(castToTime());
repository.register(castToTimestamp());
- repository.register(castToDatetime());
}
private static DefaultFunctionResolver castToString() {
@@ -66,8 +63,7 @@ private static DefaultFunctionResolver castToString() {
BuiltinFunctionName.CAST_TO_STRING.getName(),
Stream.concat(
Arrays.asList(
- BYTE, SHORT, INTEGER, LONG, FLOAT, DOUBLE, BOOLEAN, TIME, DATE, TIMESTAMP,
- DATETIME)
+ BYTE, SHORT, INTEGER, LONG, FLOAT, DOUBLE, BOOLEAN, TIME, DATE, TIMESTAMP)
.stream()
.map(
type ->
@@ -180,7 +176,6 @@ private static DefaultFunctionResolver castToDate() {
return FunctionDSL.define(
BuiltinFunctionName.CAST_TO_DATE.getName(),
impl(nullMissingHandling((v) -> new ExprDateValue(v.stringValue())), DATE, STRING),
- impl(nullMissingHandling((v) -> new ExprDateValue(v.dateValue())), DATE, DATETIME),
impl(nullMissingHandling((v) -> new ExprDateValue(v.dateValue())), DATE, TIMESTAMP),
impl(nullMissingHandling((v) -> v), DATE, DATE));
}
@@ -189,21 +184,16 @@ private static DefaultFunctionResolver castToTime() {
return FunctionDSL.define(
BuiltinFunctionName.CAST_TO_TIME.getName(),
impl(nullMissingHandling((v) -> new ExprTimeValue(v.stringValue())), TIME, STRING),
- impl(nullMissingHandling((v) -> new ExprTimeValue(v.timeValue())), TIME, DATETIME),
impl(nullMissingHandling((v) -> new ExprTimeValue(v.timeValue())), TIME, TIMESTAMP),
impl(nullMissingHandling((v) -> v), TIME, TIME));
}
- // `DATE`/`TIME`/`DATETIME` -> `DATETIME`/TIMESTAMP` cast tested in BinaryPredicateOperatorTest
+ // `DATE`/`TIME` -> `TIMESTAMP` cast tested in BinaryPredicateOperatorTest
private static DefaultFunctionResolver castToTimestamp() {
return FunctionDSL.define(
BuiltinFunctionName.CAST_TO_TIMESTAMP.getName(),
impl(
nullMissingHandling((v) -> new ExprTimestampValue(v.stringValue())), TIMESTAMP, STRING),
- impl(
- nullMissingHandling((v) -> new ExprTimestampValue(v.timestampValue())),
- TIMESTAMP,
- DATETIME),
impl(
nullMissingHandling((v) -> new ExprTimestampValue(v.timestampValue())),
TIMESTAMP,
@@ -215,21 +205,4 @@ private static DefaultFunctionResolver castToTimestamp() {
TIME),
impl(nullMissingHandling((v) -> v), TIMESTAMP, TIMESTAMP));
}
-
- private static DefaultFunctionResolver castToDatetime() {
- return FunctionDSL.define(
- BuiltinFunctionName.CAST_TO_DATETIME.getName(),
- impl(nullMissingHandling((v) -> new ExprDatetimeValue(v.stringValue())), DATETIME, STRING),
- impl(
- nullMissingHandling((v) -> new ExprDatetimeValue(v.datetimeValue())),
- DATETIME,
- TIMESTAMP),
- impl(nullMissingHandling((v) -> new ExprDatetimeValue(v.datetimeValue())), DATETIME, DATE),
- implWithProperties(
- nullMissingHandlingWithProperties(
- (fp, v) -> new ExprDatetimeValue(((ExprTimeValue) v).datetimeValue(fp))),
- DATETIME,
- TIME),
- impl(nullMissingHandling((v) -> v), DATETIME, DATETIME));
- }
}
diff --git a/core/src/main/java/org/opensearch/sql/planner/physical/collector/Rounding.java b/core/src/main/java/org/opensearch/sql/planner/physical/collector/Rounding.java
index 81a1a0230f..82c8af52cd 100644
--- a/core/src/main/java/org/opensearch/sql/planner/physical/collector/Rounding.java
+++ b/core/src/main/java/org/opensearch/sql/planner/physical/collector/Rounding.java
@@ -6,17 +6,15 @@
package org.opensearch.sql.planner.physical.collector;
import static org.opensearch.sql.data.type.ExprCoreType.DATE;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE;
import static org.opensearch.sql.data.type.ExprCoreType.LONG;
import static org.opensearch.sql.data.type.ExprCoreType.TIME;
import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP;
-import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID;
import java.time.Instant;
import java.time.LocalDate;
-import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.time.ZoneOffset;
import java.time.temporal.ChronoField;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
@@ -24,7 +22,6 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.opensearch.sql.data.model.ExprDateValue;
-import org.opensearch.sql.data.model.ExprDatetimeValue;
import org.opensearch.sql.data.model.ExprTimeValue;
import org.opensearch.sql.data.model.ExprTimestampValue;
import org.opensearch.sql.data.model.ExprValue;
@@ -49,9 +46,6 @@ public static Rounding> createRounding(SpanExpression span) {
if (DOUBLE.isCompatible(type)) {
return new DoubleRounding(interval);
}
- if (type.equals(DATETIME)) {
- return new DatetimeRounding(interval, span.getUnit().getName());
- }
if (type.equals(TIMESTAMP)) {
return new TimestampRounding(interval, span.getUnit().getName());
}
@@ -84,26 +78,6 @@ public ExprValue round(ExprValue var) {
}
}
- static class DatetimeRounding extends Rounding {
- private final ExprValue interval;
- private final DateTimeUnit dateTimeUnit;
-
- public DatetimeRounding(ExprValue interval, String unit) {
- this.interval = interval;
- this.dateTimeUnit = DateTimeUnit.resolve(unit);
- }
-
- @Override
- public ExprValue round(ExprValue var) {
- Instant instant =
- Instant.ofEpochMilli(
- dateTimeUnit.round(
- var.datetimeValue().atZone(UTC_ZONE_ID).toInstant().toEpochMilli(),
- interval.integerValue()));
- return new ExprDatetimeValue(instant.atZone(UTC_ZONE_ID).toLocalDateTime());
- }
- }
-
static class DateRounding extends Rounding {
private final ExprValue interval;
private final DateTimeUnit dateTimeUnit;
@@ -118,9 +92,9 @@ public ExprValue round(ExprValue var) {
Instant instant =
Instant.ofEpochMilli(
dateTimeUnit.round(
- var.dateValue().atStartOfDay().atZone(UTC_ZONE_ID).toInstant().toEpochMilli(),
+ var.dateValue().atStartOfDay().atZone(ZoneOffset.UTC).toInstant().toEpochMilli(),
interval.integerValue()));
- return new ExprDateValue(instant.atZone(UTC_ZONE_ID).toLocalDate());
+ return new ExprDateValue(instant.atZone(ZoneOffset.UTC).toLocalDate());
}
}
@@ -144,7 +118,7 @@ public ExprValue round(ExprValue var) {
Instant.ofEpochMilli(
dateTimeUnit.round(
var.timeValue().getLong(ChronoField.MILLI_OF_DAY), interval.integerValue()));
- return new ExprTimeValue(instant.atZone(UTC_ZONE_ID).toLocalTime());
+ return new ExprTimeValue(instant.atZone(ZoneOffset.UTC).toLocalTime());
}
}
diff --git a/core/src/main/java/org/opensearch/sql/utils/DateTimeUtils.java b/core/src/main/java/org/opensearch/sql/utils/DateTimeUtils.java
index 593b4c4471..62d5f0246d 100644
--- a/core/src/main/java/org/opensearch/sql/utils/DateTimeUtils.java
+++ b/core/src/main/java/org/opensearch/sql/utils/DateTimeUtils.java
@@ -9,6 +9,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
+import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import lombok.experimental.UtilityClass;
import org.opensearch.sql.data.model.ExprTimeValue;
@@ -48,9 +49,9 @@ public static long roundWeek(long utcMillis, int interval) {
* @return Rounded date/time value in utc millis
*/
public static long roundMonth(long utcMillis, int interval) {
- ZonedDateTime initDateTime = ZonedDateTime.of(1970, 1, 1, 0, 0, 0, 0, UTC_ZONE_ID);
+ ZonedDateTime initDateTime = ZonedDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
ZonedDateTime zonedDateTime =
- Instant.ofEpochMilli(utcMillis).atZone(UTC_ZONE_ID).plusMonths(interval);
+ Instant.ofEpochMilli(utcMillis).atZone(ZoneOffset.UTC).plusMonths(interval);
long monthDiff =
(zonedDateTime.getYear() - initDateTime.getYear()) * 12L
+ zonedDateTime.getMonthValue()
@@ -67,9 +68,9 @@ public static long roundMonth(long utcMillis, int interval) {
* @return Rounded date/time value in utc millis
*/
public static long roundQuarter(long utcMillis, int interval) {
- ZonedDateTime initDateTime = ZonedDateTime.of(1970, 1, 1, 0, 0, 0, 0, UTC_ZONE_ID);
+ ZonedDateTime initDateTime = ZonedDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
ZonedDateTime zonedDateTime =
- Instant.ofEpochMilli(utcMillis).atZone(UTC_ZONE_ID).plusMonths(interval * 3L);
+ Instant.ofEpochMilli(utcMillis).atZone(ZoneOffset.UTC).plusMonths(interval * 3L);
long monthDiff =
((zonedDateTime.getYear() - initDateTime.getYear()) * 12L
+ zonedDateTime.getMonthValue()
@@ -86,8 +87,8 @@ public static long roundQuarter(long utcMillis, int interval) {
* @return Rounded date/time value in utc millis
*/
public static long roundYear(long utcMillis, int interval) {
- ZonedDateTime initDateTime = ZonedDateTime.of(1970, 1, 1, 0, 0, 0, 0, UTC_ZONE_ID);
- ZonedDateTime zonedDateTime = Instant.ofEpochMilli(utcMillis).atZone(UTC_ZONE_ID);
+ ZonedDateTime initDateTime = ZonedDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
+ ZonedDateTime zonedDateTime = Instant.ofEpochMilli(utcMillis).atZone(ZoneOffset.UTC);
int yearDiff = zonedDateTime.getYear() - initDateTime.getYear();
int yearToAdd = (yearDiff / interval) * interval;
return initDateTime.plusYears(yearToAdd).toInstant().toEpochMilli();
@@ -136,11 +137,10 @@ public Boolean isValidMySqlTimeZoneId(ZoneId zone) {
* Extracts LocalDateTime from a datetime ExprValue. Uses `FunctionProperties` for
* `ExprTimeValue`.
*/
- public static LocalDateTime extractDateTime(
- ExprValue value, FunctionProperties functionProperties) {
+ public static Instant extractTimestamp(ExprValue value, FunctionProperties functionProperties) {
return value instanceof ExprTimeValue
- ? ((ExprTimeValue) value).datetimeValue(functionProperties)
- : value.datetimeValue();
+ ? ((ExprTimeValue) value).timestampValue(functionProperties)
+ : value.timestampValue();
}
/**
@@ -151,6 +151,4 @@ public static LocalDate extractDate(ExprValue value, FunctionProperties function
? ((ExprTimeValue) value).dateValue(functionProperties)
: value.dateValue();
}
-
- public static final ZoneId UTC_ZONE_ID = ZoneId.of("UTC");
}
diff --git a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java
index 2f4d6e8ada..8d935b11d2 100644
--- a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java
+++ b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java
@@ -157,7 +157,7 @@ public void filter_relation_with_invalid_qualifiedName_ExpressionEvaluationExcep
assertEquals(
"= function expected {[BYTE,BYTE],[SHORT,SHORT],[INTEGER,INTEGER],[LONG,LONG],"
+ "[FLOAT,FLOAT],[DOUBLE,DOUBLE],[STRING,STRING],[BOOLEAN,BOOLEAN],[DATE,DATE],"
- + "[TIME,TIME],[DATETIME,DATETIME],[TIMESTAMP,TIMESTAMP],[INTERVAL,INTERVAL],"
+ + "[TIME,TIME],[TIMESTAMP,TIMESTAMP],[INTERVAL,INTERVAL],"
+ "[STRUCT,STRUCT],[ARRAY,ARRAY]}, but get [STRING,INTEGER]",
exception.getMessage());
}
diff --git a/core/src/test/java/org/opensearch/sql/data/model/DateTimeValueTest.java b/core/src/test/java/org/opensearch/sql/data/model/DateTimeValueTest.java
index 01fe4a5e4e..b5a3d61211 100644
--- a/core/src/test/java/org/opensearch/sql/data/model/DateTimeValueTest.java
+++ b/core/src/test/java/org/opensearch/sql/data/model/DateTimeValueTest.java
@@ -10,11 +10,11 @@
import static org.opensearch.sql.data.model.ExprValueUtils.integerValue;
import static org.opensearch.sql.data.type.ExprCoreType.TIME;
import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP;
-import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import org.junit.jupiter.api.Test;
import org.opensearch.sql.exception.ExpressionEvaluationException;
@@ -36,8 +36,6 @@ public void timeValueInterfaceTest() {
// without a FunctionProperties object
var exception = assertThrows(ExpressionEvaluationException.class, timeValue::dateValue);
assertEquals("invalid to get dateValue from value of type TIME", exception.getMessage());
- exception = assertThrows(ExpressionEvaluationException.class, timeValue::datetimeValue);
- assertEquals("invalid to get datetimeValue from value of type TIME", exception.getMessage());
exception = assertThrows(ExpressionEvaluationException.class, timeValue::timestampValue);
assertEquals("invalid to get timestampValue from value of type TIME", exception.getMessage());
@@ -45,9 +43,11 @@ public void timeValueInterfaceTest() {
var today = LocalDate.now(functionProperties.getQueryStartClock());
assertEquals(today, timeValue.dateValue(functionProperties));
- assertEquals(today.atTime(1, 1, 1), timeValue.datetimeValue(functionProperties));
assertEquals(
- ZonedDateTime.of(LocalTime.parse("01:01:01").atDate(today), UTC_ZONE_ID).toInstant(),
+ today.atTime(1, 1, 1),
+ LocalDateTime.ofInstant(timeValue.timestampValue(functionProperties), ZoneOffset.UTC));
+ assertEquals(
+ ZonedDateTime.of(LocalTime.parse("01:01:01").atDate(today), ZoneOffset.UTC).toInstant(),
timeValue.timestampValue(functionProperties));
assertEquals("01:01:01", timeValue.value());
@@ -63,13 +63,15 @@ public void timestampValueInterfaceTest() {
assertEquals(TIMESTAMP, timestampValue.type());
assertEquals(
- ZonedDateTime.of(LocalDateTime.parse("2020-07-07T01:01:01"), UTC_ZONE_ID).toInstant(),
+ ZonedDateTime.of(LocalDateTime.parse("2020-07-07T01:01:01"), ZoneOffset.UTC).toInstant(),
timestampValue.timestampValue());
assertEquals("2020-07-07 01:01:01", timestampValue.value());
assertEquals("TIMESTAMP '2020-07-07 01:01:01'", timestampValue.toString());
assertEquals(LocalDate.parse("2020-07-07"), timestampValue.dateValue());
assertEquals(LocalTime.parse("01:01:01"), timestampValue.timeValue());
- assertEquals(LocalDateTime.parse("2020-07-07T01:01:01"), timestampValue.datetimeValue());
+ assertEquals(
+ LocalDateTime.parse("2020-07-07T01:01:01"),
+ LocalDateTime.ofInstant(timestampValue.timestampValue(), ZoneOffset.UTC));
assertThrows(
ExpressionEvaluationException.class,
() -> integerValue(1).timestampValue(),
@@ -82,32 +84,17 @@ public void dateValueInterfaceTest() {
assertEquals(LocalDate.parse("2012-07-07"), dateValue.dateValue());
assertEquals(LocalTime.parse("00:00:00"), dateValue.timeValue());
- assertEquals(LocalDateTime.parse("2012-07-07T00:00:00"), dateValue.datetimeValue());
assertEquals(
- ZonedDateTime.of(LocalDateTime.parse("2012-07-07T00:00:00"), UTC_ZONE_ID).toInstant(),
+ LocalDateTime.parse("2012-07-07T00:00:00"),
+ LocalDateTime.ofInstant(dateValue.timestampValue(), ZoneOffset.UTC));
+ assertEquals(
+ ZonedDateTime.of(LocalDateTime.parse("2012-07-07T00:00:00"), ZoneOffset.UTC).toInstant(),
dateValue.timestampValue());
ExpressionEvaluationException exception =
assertThrows(ExpressionEvaluationException.class, () -> integerValue(1).dateValue());
assertEquals("invalid to get dateValue from value of type INTEGER", exception.getMessage());
}
- @Test
- public void datetimeValueInterfaceTest() {
- ExprValue datetimeValue = new ExprDatetimeValue("2020-08-17 19:44:00");
-
- assertEquals(LocalDateTime.parse("2020-08-17T19:44:00"), datetimeValue.datetimeValue());
- assertEquals(LocalDate.parse("2020-08-17"), datetimeValue.dateValue());
- assertEquals(LocalTime.parse("19:44:00"), datetimeValue.timeValue());
- assertEquals(
- ZonedDateTime.of(LocalDateTime.parse("2020-08-17T19:44:00"), UTC_ZONE_ID).toInstant(),
- datetimeValue.timestampValue());
- assertEquals("DATETIME '2020-08-17 19:44:00'", datetimeValue.toString());
- assertThrows(
- ExpressionEvaluationException.class,
- () -> integerValue(1).datetimeValue(),
- "invalid to get datetimeValue from value of type INTEGER");
- }
-
@Test
public void dateInUnsupportedFormat() {
SemanticCheckException exception =
@@ -137,21 +124,12 @@ public void timestampInUnsupportedFormat() {
}
@Test
- public void datetimeInUnsupportedFormat() {
- SemanticCheckException exception =
- assertThrows(
- SemanticCheckException.class, () -> new ExprDatetimeValue("2020-07-07T01:01:01Z"));
- assertEquals(
- "datetime:2020-07-07T01:01:01Z in unsupported format, "
- + "please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'",
- exception.getMessage());
- }
-
- @Test
- public void stringDateTimeValue() {
+ public void stringTimestampValue() {
ExprValue stringValue = new ExprStringValue("2020-08-17 19:44:00");
- assertEquals(LocalDateTime.parse("2020-08-17T19:44:00"), stringValue.datetimeValue());
+ assertEquals(
+ LocalDateTime.parse("2020-08-17T19:44:00").atZone(ZoneOffset.UTC).toInstant(),
+ stringValue.timestampValue());
assertEquals(LocalDate.parse("2020-08-17"), stringValue.dateValue());
assertEquals(LocalTime.parse("19:44:00"), stringValue.timeValue());
assertEquals("\"2020-08-17 19:44:00\"", stringValue.toString());
@@ -159,10 +137,9 @@ public void stringDateTimeValue() {
SemanticCheckException exception =
assertThrows(
SemanticCheckException.class,
- () -> new ExprStringValue("2020-07-07T01:01:01Z").datetimeValue());
+ () -> new ExprStringValue("2020-07-07T01:01:01Z").timestampValue());
assertEquals(
- "datetime:2020-07-07T01:01:01Z in unsupported format, "
- + "please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'",
+ "date:2020-07-07T01:01:01Z in unsupported format, " + "please use 'yyyy-MM-dd'",
exception.getMessage());
}
@@ -170,7 +147,8 @@ public void stringDateTimeValue() {
public void stringDateValue() {
ExprValue stringValue = new ExprStringValue("2020-08-17");
- assertEquals(LocalDateTime.parse("2020-08-17T00:00:00"), stringValue.datetimeValue());
+ assertEquals(
+ ZonedDateTime.parse("2020-08-17T00:00:00Z").toInstant(), stringValue.timestampValue());
assertEquals(LocalDate.parse("2020-08-17"), stringValue.dateValue());
assertEquals("\"2020-08-17\"", stringValue.toString());
@@ -228,28 +206,9 @@ public void timestampWithVariableNanoPrecision() {
assertEquals(LocalDate.parse(dateValue), timestampValue.dateValue());
assertEquals(LocalTime.parse(timeWithNanos), timestampValue.timeValue());
String localDateTime = String.format("%sT%s", dateValue, timeWithNanos);
- assertEquals(LocalDateTime.parse(localDateTime), timestampValue.datetimeValue());
- }
- }
-
- @Test
- public void datetimeWithVariableNanoPrecision() {
- String dateValue = "2020-08-17";
- String timeWithNanosFormat = "10:11:12.%s";
-
- // Check all lengths of nanosecond precision, up to max precision accepted
- StringBuilder nanos = new StringBuilder();
- for (int nanoPrecision = 1; nanoPrecision <= NANOS_PRECISION_MAX; nanoPrecision++) {
- nanos.append(nanoPrecision);
- String timeWithNanos = String.format(timeWithNanosFormat, nanos);
-
- String datetimeString = String.format("%s %s", dateValue, timeWithNanos);
- ExprValue datetimeValue = new ExprDatetimeValue(datetimeString);
-
- assertEquals(LocalDate.parse(dateValue), datetimeValue.dateValue());
- assertEquals(LocalTime.parse(timeWithNanos), datetimeValue.timeValue());
- String localDateTime = String.format("%sT%s", dateValue, timeWithNanos);
- assertEquals(LocalDateTime.parse(localDateTime), datetimeValue.datetimeValue());
+ assertEquals(
+ LocalDateTime.parse(localDateTime),
+ LocalDateTime.ofInstant(timestampValue.timestampValue(), ZoneOffset.UTC));
}
}
@@ -265,18 +224,6 @@ public void timestampOverMaxNanoPrecision() {
exception.getMessage());
}
- @Test
- public void datetimeOverMaxNanoPrecision() {
- SemanticCheckException exception =
- assertThrows(
- SemanticCheckException.class,
- () -> new ExprDatetimeValue("2020-07-07 01:01:01.1234567890"));
- assertEquals(
- "datetime:2020-07-07 01:01:01.1234567890 in unsupported format, "
- + "please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'",
- exception.getMessage());
- }
-
@Test
public void timeOverMaxNanoPrecision() {
SemanticCheckException exception =
diff --git a/core/src/test/java/org/opensearch/sql/data/model/ExprValueCompareTest.java b/core/src/test/java/org/opensearch/sql/data/model/ExprValueCompareTest.java
index b965dff643..ee30a0f0c6 100644
--- a/core/src/test/java/org/opensearch/sql/data/model/ExprValueCompareTest.java
+++ b/core/src/test/java/org/opensearch/sql/data/model/ExprValueCompareTest.java
@@ -11,7 +11,7 @@
import static org.opensearch.sql.data.model.ExprValueUtils.LITERAL_FALSE;
import static org.opensearch.sql.data.model.ExprValueUtils.LITERAL_MISSING;
import static org.opensearch.sql.data.model.ExprValueUtils.LITERAL_NULL;
-import static org.opensearch.sql.utils.DateTimeUtils.extractDateTime;
+import static org.opensearch.sql.utils.DateTimeUtils.extractTimestamp;
import java.time.LocalDate;
import java.time.Period;
@@ -39,22 +39,6 @@ public void dateValueCompare() {
assertEquals(-1, new ExprDateValue("2012-08-07").compareTo(new ExprDateValue("2012-08-08")));
}
- @Test
- public void datetimeValueCompare() {
- assertEquals(
- 0,
- new ExprDatetimeValue("2012-08-07 18:00:00")
- .compareTo(new ExprDatetimeValue("2012-08-07 18:00:00")));
- assertEquals(
- 1,
- new ExprDatetimeValue("2012-08-07 19:00:00")
- .compareTo(new ExprDatetimeValue("2012-08-07 18:00:00")));
- assertEquals(
- -1,
- new ExprDatetimeValue("2012-08-07 18:00:00")
- .compareTo(new ExprDatetimeValue("2012-08-07 19:00:00")));
- }
-
@Test
public void timestampValueCompare() {
assertEquals(
@@ -73,26 +57,14 @@ public void timestampValueCompare() {
private static Stream getEqualDatetimeValuesOfDifferentTypes() {
return Stream.of(
- Arguments.of(
- new ExprTimestampValue("1961-04-12 09:07:00"),
- new ExprDatetimeValue("1961-04-12 09:07:00")),
Arguments.of(
new ExprTimestampValue("1984-11-22 00:00:00"), new ExprDateValue("1984-11-22")),
Arguments.of(
new ExprTimestampValue(LocalDate.now() + " 00:00:00"),
new ExprDateValue(LocalDate.now())),
- Arguments.of(
- new ExprDatetimeValue(LocalDate.now() + " 17:42:15"), new ExprTimeValue("17:42:15")),
- Arguments.of(
- new ExprDatetimeValue("2012-08-07 19:14:38"),
- new ExprTimestampValue("2012-08-07 19:14:38")),
- Arguments.of(new ExprDateValue("2012-08-07"), new ExprDatetimeValue("2012-08-07 00:00:00")),
- Arguments.of(new ExprDateValue("2007-01-27"), new ExprDatetimeValue("2007-01-27 00:00:00")),
Arguments.of(new ExprDateValue(LocalDate.now()), new ExprTimeValue("00:00:00")),
Arguments.of(
new ExprTimestampValue("1984-11-22 00:00:00"), new ExprDateValue("1984-11-22")),
- Arguments.of(
- new ExprTimeValue("19:14:38"), new ExprDatetimeValue(LocalDate.now() + " 19:14:38")),
Arguments.of(
new ExprTimeValue("17:42:15"), new ExprTimestampValue(LocalDate.now() + " 17:42:15")));
}
@@ -106,34 +78,17 @@ private static Stream getEqualDatetimeValuesOfDifferentTypes() {
public void compareEqDifferentDateTimeValueTypes(ExprValue left, ExprValue right) {
assertEquals(
0,
- extractDateTime(left, functionProperties)
- .compareTo(extractDateTime(right, functionProperties)));
- assertEquals(
- 0,
- extractDateTime(right, functionProperties)
- .compareTo(extractDateTime(left, functionProperties)));
+ extractTimestamp(left, functionProperties)
+ .compareTo(extractTimestamp(right, functionProperties)));
}
private static Stream getNotEqualDatetimeValuesOfDifferentTypes() {
return Stream.of(
- Arguments.of(
- new ExprDatetimeValue("2012-08-07 19:14:38"),
- new ExprTimestampValue("1961-04-12 09:07:00")),
- Arguments.of(new ExprDatetimeValue("2012-08-07 19:14:38"), new ExprTimeValue("09:07:00")),
- Arguments.of(
- new ExprDatetimeValue(LocalDate.now() + " 19:14:38"), new ExprTimeValue("09:07:00")),
- Arguments.of(new ExprDatetimeValue("2012-08-07 00:00:00"), new ExprDateValue("1961-04-12")),
- Arguments.of(new ExprDatetimeValue("1961-04-12 19:14:38"), new ExprDateValue("1961-04-12")),
- Arguments.of(new ExprDateValue("1984-11-22"), new ExprDatetimeValue("1961-04-12 19:14:38")),
Arguments.of(
new ExprDateValue("1984-11-22"), new ExprTimestampValue("2020-09-16 17:30:00")),
Arguments.of(new ExprDateValue("1984-11-22"), new ExprTimeValue("19:14:38")),
Arguments.of(new ExprTimeValue("19:14:38"), new ExprDateValue(LocalDate.now())),
- Arguments.of(new ExprTimeValue("19:14:38"), new ExprDatetimeValue("2012-08-07 09:07:00")),
Arguments.of(new ExprTimeValue("19:14:38"), new ExprTimestampValue("1984-02-03 04:05:07")),
- Arguments.of(
- new ExprTimestampValue("2012-08-07 19:14:38"),
- new ExprDatetimeValue("1961-04-12 09:07:00")),
Arguments.of(new ExprTimestampValue("2012-08-07 19:14:38"), new ExprTimeValue("09:07:00")),
Arguments.of(
new ExprTimestampValue(LocalDate.now() + " 19:14:38"), new ExprTimeValue("09:07:00")),
@@ -152,12 +107,8 @@ private static Stream getNotEqualDatetimeValuesOfDifferentTypes() {
public void compareNeqDifferentDateTimeValueTypes(ExprValue left, ExprValue right) {
assertNotEquals(
0,
- extractDateTime(left, functionProperties)
- .compareTo(extractDateTime(right, functionProperties)));
- assertNotEquals(
- 0,
- extractDateTime(right, functionProperties)
- .compareTo(extractDateTime(left, functionProperties)));
+ extractTimestamp(left, functionProperties)
+ .compareTo(extractTimestamp(right, functionProperties)));
}
@Test
diff --git a/core/src/test/java/org/opensearch/sql/data/model/ExprValueUtilsTest.java b/core/src/test/java/org/opensearch/sql/data/model/ExprValueUtilsTest.java
index c879384955..0baf5052e4 100644
--- a/core/src/test/java/org/opensearch/sql/data/model/ExprValueUtilsTest.java
+++ b/core/src/test/java/org/opensearch/sql/data/model/ExprValueUtilsTest.java
@@ -13,13 +13,11 @@
import static org.opensearch.sql.data.type.ExprCoreType.ARRAY;
import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN;
import static org.opensearch.sql.data.type.ExprCoreType.DATE;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
import static org.opensearch.sql.data.type.ExprCoreType.INTERVAL;
import static org.opensearch.sql.data.type.ExprCoreType.STRING;
import static org.opensearch.sql.data.type.ExprCoreType.STRUCT;
import static org.opensearch.sql.data.type.ExprCoreType.TIME;
import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP;
-import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -29,6 +27,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.AbstractMap;
import java.util.ArrayList;
@@ -70,7 +69,6 @@ public class ExprValueUtilsTest {
new ExprTupleValue(testTuple),
new ExprDateValue("2012-08-07"),
new ExprTimeValue("18:00:00"),
- new ExprDatetimeValue("2012-08-07 18:00:00"),
new ExprTimestampValue("2012-08-07 18:00:00"),
new ExprIntervalValue(Duration.ofSeconds(100)));
@@ -95,7 +93,6 @@ public class ExprValueUtilsTest {
Arrays.asList(
ExprValue::dateValue,
ExprValue::timeValue,
- ExprValue::datetimeValue,
ExprValue::timestampValue,
ExprValue::intervalValue);
private static List> allValueExtractor =
@@ -113,7 +110,7 @@ public class ExprValueUtilsTest {
ExprCoreType.DOUBLE);
private static List nonNumberTypes = Arrays.asList(STRING, BOOLEAN, ARRAY, STRUCT);
private static List dateAndTimeTypes =
- Arrays.asList(DATE, TIME, DATETIME, TIMESTAMP, INTERVAL);
+ Arrays.asList(DATE, TIME, TIMESTAMP, INTERVAL);
private static List allTypes =
Lists.newArrayList(Iterables.concat(numberTypes, nonNumberTypes, dateAndTimeTypes));
@@ -132,8 +129,8 @@ private static Stream getValueTestArgumentStream() {
ImmutableMap.of("1", integerValue(1)),
LocalDate.parse("2012-08-07"),
LocalTime.parse("18:00:00"),
- LocalDateTime.parse("2012-08-07T18:00:00"),
- ZonedDateTime.of(LocalDateTime.parse("2012-08-07T18:00:00"), UTC_ZONE_ID).toInstant(),
+ ZonedDateTime.of(LocalDateTime.parse("2012-08-07T18:00:00"), ZoneOffset.UTC)
+ .toInstant(),
Duration.ofSeconds(100));
Stream.Builder builder = Stream.builder();
for (int i = 0; i < expectedValues.size(); i++) {
@@ -237,9 +234,6 @@ public void constructDateAndTimeValue() {
assertEquals(
new ExprDateValue("2012-07-07"), ExprValueUtils.fromObjectValue("2012-07-07", DATE));
assertEquals(new ExprTimeValue("01:01:01"), ExprValueUtils.fromObjectValue("01:01:01", TIME));
- assertEquals(
- new ExprDatetimeValue("2012-07-07 01:01:01"),
- ExprValueUtils.fromObjectValue("2012-07-07 01:01:01", DATETIME));
assertEquals(
new ExprTimestampValue("2012-07-07 01:01:01"),
ExprValueUtils.fromObjectValue("2012-07-07 01:01:01", TIMESTAMP));
@@ -260,9 +254,6 @@ public void hashCodeTest() {
new ExprDateValue("2012-08-07").hashCode(), new ExprDateValue("2012-08-07").hashCode());
assertEquals(
new ExprTimeValue("18:00:00").hashCode(), new ExprTimeValue("18:00:00").hashCode());
- assertEquals(
- new ExprDatetimeValue("2012-08-07 18:00:00").hashCode(),
- new ExprDatetimeValue("2012-08-07 18:00:00").hashCode());
assertEquals(
new ExprTimestampValue("2012-08-07 18:00:00").hashCode(),
new ExprTimestampValue("2012-08-07 18:00:00").hashCode());
diff --git a/core/src/test/java/org/opensearch/sql/data/type/ExprTypeTest.java b/core/src/test/java/org/opensearch/sql/data/type/ExprTypeTest.java
index 1def15cc6f..ec45c3dfec 100644
--- a/core/src/test/java/org/opensearch/sql/data/type/ExprTypeTest.java
+++ b/core/src/test/java/org/opensearch/sql/data/type/ExprTypeTest.java
@@ -12,7 +12,6 @@
import static org.opensearch.sql.data.type.ExprCoreType.ARRAY;
import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN;
import static org.opensearch.sql.data.type.ExprCoreType.DATE;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE;
import static org.opensearch.sql.data.type.ExprCoreType.FLOAT;
import static org.opensearch.sql.data.type.ExprCoreType.INTEGER;
@@ -45,7 +44,6 @@ public void isCompatible() {
assertTrue(TIMESTAMP.isCompatible(STRING));
assertTrue(DATE.isCompatible(STRING));
assertTrue(TIME.isCompatible(STRING));
- assertTrue(DATETIME.isCompatible(STRING));
}
@Test
diff --git a/core/src/test/java/org/opensearch/sql/expression/aggregation/AvgAggregatorTest.java b/core/src/test/java/org/opensearch/sql/expression/aggregation/AvgAggregatorTest.java
index f465a6477e..10551d43a5 100644
--- a/core/src/test/java/org/opensearch/sql/expression/aggregation/AvgAggregatorTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/aggregation/AvgAggregatorTest.java
@@ -9,7 +9,6 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opensearch.sql.data.type.ExprCoreType.DATE;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE;
import static org.opensearch.sql.data.type.ExprCoreType.INTEGER;
import static org.opensearch.sql.data.type.ExprCoreType.STRING;
@@ -19,6 +18,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.time.ZoneOffset;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.opensearch.sql.data.model.ExprValue;
@@ -89,12 +89,6 @@ public void avg_date_no_values() {
assertTrue(result.isNull());
}
- @Test
- public void avg_datetime_no_values() {
- ExprValue result = aggregation(DSL.avg(DSL.ref("dummy", DATETIME)), List.of());
- assertTrue(result.isNull());
- }
-
@Test
public void avg_timestamp_no_values() {
ExprValue result = aggregation(DSL.avg(DSL.ref("dummy", TIMESTAMP)), List.of());
@@ -113,12 +107,6 @@ public void avg_date() {
assertEquals(LocalDate.of(2007, 7, 2), result.dateValue());
}
- @Test
- public void avg_datetime() {
- var result = aggregation(DSL.avg(DSL.datetime(DSL.ref("datetime_value", STRING))), tuples);
- assertEquals(LocalDateTime.of(2012, 7, 2, 3, 30), result.datetimeValue());
- }
-
@Test
public void avg_time() {
ExprValue result = aggregation(DSL.avg(DSL.time(DSL.ref("time_value", STRING))), tuples);
@@ -129,7 +117,9 @@ public void avg_time() {
public void avg_timestamp() {
var result = aggregation(DSL.avg(DSL.timestamp(DSL.ref("timestamp_value", STRING))), tuples);
assertEquals(TIMESTAMP, result.type());
- assertEquals(LocalDateTime.of(2012, 7, 2, 3, 30), result.datetimeValue());
+ assertEquals(
+ LocalDateTime.of(2012, 7, 2, 3, 30),
+ result.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime());
}
@Test
diff --git a/core/src/test/java/org/opensearch/sql/expression/aggregation/CountAggregatorTest.java b/core/src/test/java/org/opensearch/sql/expression/aggregation/CountAggregatorTest.java
index 50bd3fedfe..2159780dc0 100644
--- a/core/src/test/java/org/opensearch/sql/expression/aggregation/CountAggregatorTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/aggregation/CountAggregatorTest.java
@@ -10,7 +10,6 @@
import static org.opensearch.sql.data.type.ExprCoreType.ARRAY;
import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN;
import static org.opensearch.sql.data.type.ExprCoreType.DATE;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE;
import static org.opensearch.sql.data.type.ExprCoreType.FLOAT;
import static org.opensearch.sql.data.type.ExprCoreType.INTEGER;
@@ -63,12 +62,6 @@ public void count_timestamp_field_expression() {
assertEquals(4, result.value());
}
- @Test
- public void count_datetime_field_expression() {
- ExprValue result = aggregation(DSL.count(DSL.ref("datetime_value", DATETIME)), tuples);
- assertEquals(4, result.value());
- }
-
@Test
public void count_arithmetic_expression() {
ExprValue result =
diff --git a/core/src/test/java/org/opensearch/sql/expression/aggregation/MaxAggregatorTest.java b/core/src/test/java/org/opensearch/sql/expression/aggregation/MaxAggregatorTest.java
index c6cd380ad5..f952eff982 100644
--- a/core/src/test/java/org/opensearch/sql/expression/aggregation/MaxAggregatorTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/aggregation/MaxAggregatorTest.java
@@ -9,7 +9,6 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opensearch.sql.data.type.ExprCoreType.DATE;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE;
import static org.opensearch.sql.data.type.ExprCoreType.FLOAT;
import static org.opensearch.sql.data.type.ExprCoreType.INTEGER;
@@ -62,12 +61,6 @@ public void test_max_date() {
assertEquals("2040-01-01", result.value());
}
- @Test
- public void test_max_datetime() {
- ExprValue result = aggregation(DSL.max(DSL.ref("datetime_value", DATETIME)), tuples);
- assertEquals("2040-01-01 07:00:00", result.value());
- }
-
@Test
public void test_max_time() {
ExprValue result = aggregation(DSL.max(DSL.ref("time_value", TIME)), tuples);
diff --git a/core/src/test/java/org/opensearch/sql/expression/aggregation/MinAggregatorTest.java b/core/src/test/java/org/opensearch/sql/expression/aggregation/MinAggregatorTest.java
index 1aee0f3a6c..8a3f3d15a3 100644
--- a/core/src/test/java/org/opensearch/sql/expression/aggregation/MinAggregatorTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/aggregation/MinAggregatorTest.java
@@ -9,7 +9,6 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opensearch.sql.data.type.ExprCoreType.DATE;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE;
import static org.opensearch.sql.data.type.ExprCoreType.FLOAT;
import static org.opensearch.sql.data.type.ExprCoreType.INTEGER;
@@ -62,12 +61,6 @@ public void test_min_date() {
assertEquals("1970-01-01", result.value());
}
- @Test
- public void test_min_datetime() {
- ExprValue result = aggregation(DSL.min(DSL.ref("datetime_value", DATETIME)), tuples);
- assertEquals("1970-01-01 19:00:00", result.value());
- }
-
@Test
public void test_min_time() {
ExprValue result = aggregation(DSL.min(DSL.ref("time_value", TIME)), tuples);
diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/AddTimeAndSubTimeTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/AddTimeAndSubTimeTest.java
index eed83f4fa9..49947976b4 100644
--- a/core/src/test/java/org/opensearch/sql/expression/datetime/AddTimeAndSubTimeTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/datetime/AddTimeAndSubTimeTest.java
@@ -6,13 +6,14 @@
package org.opensearch.sql.expression.datetime;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
import static org.opensearch.sql.data.type.ExprCoreType.TIME;
+import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.time.ZoneOffset;
import java.time.temporal.Temporal;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
@@ -23,7 +24,7 @@
public class AddTimeAndSubTimeTest extends DateTimeTestBase {
@Test
- // (TIME, TIME/DATE/DATETIME/TIMESTAMP) -> TIME
+ // (TIME, TIME/DATE/TIMESTAMP) -> TIME
public void return_time_when_first_arg_is_time() {
var res = addtime(LocalTime.of(21, 0), LocalTime.of(0, 5));
assertEquals(TIME, res.type());
@@ -70,31 +71,10 @@ public void time_limited_by_24_hours() {
}
// Function signature is:
- // (DATE/DATETIME/TIMESTAMP, TIME/DATE/DATETIME/TIMESTAMP) -> DATETIME
+ // (DATE/TIMESTAMP, TIME/DATE/TIMESTAMP) -> TIMESTAMP
private static Stream getTestData() {
return Stream.of(
- // DATETIME and TIME/DATE/DATETIME/TIMESTAMP
- Arguments.of(
- LocalDateTime.of(1961, 4, 12, 9, 7),
- LocalTime.of(1, 48),
- LocalDateTime.of(1961, 4, 12, 10, 55),
- LocalDateTime.of(1961, 4, 12, 7, 19)),
- Arguments.of(
- LocalDateTime.of(1961, 4, 12, 9, 7),
- LocalDate.of(2000, 1, 1),
- LocalDateTime.of(1961, 4, 12, 9, 7),
- LocalDateTime.of(1961, 4, 12, 9, 7)),
- Arguments.of(
- LocalDateTime.of(1961, 4, 12, 9, 7),
- LocalDateTime.of(1235, 5, 6, 1, 48),
- LocalDateTime.of(1961, 4, 12, 10, 55),
- LocalDateTime.of(1961, 4, 12, 7, 19)),
- Arguments.of(
- LocalDateTime.of(1961, 4, 12, 9, 7),
- Instant.ofEpochSecond(42),
- LocalDateTime.of(1961, 4, 12, 9, 7, 42),
- LocalDateTime.of(1961, 4, 12, 9, 6, 18)),
- // DATE and TIME/DATE/DATETIME/TIMESTAMP
+ // DATE and TIME/DATE/TIMESTAMP
Arguments.of(
LocalDate.of(1961, 4, 12),
LocalTime.of(9, 7),
@@ -115,7 +95,7 @@ private static Stream getTestData() {
Instant.ofEpochSecond(42),
LocalDateTime.of(1961, 4, 12, 0, 0, 42),
LocalDateTime.of(1961, 4, 11, 23, 59, 18)),
- // TIMESTAMP and TIME/DATE/DATETIME/TIMESTAMP
+ // TIMESTAMP and TIME/DATE/TIMESTAMP
Arguments.of(
Instant.ofEpochSecond(42),
LocalTime.of(9, 7),
@@ -154,11 +134,13 @@ public void return_datetime_when_first_arg_is_not_time(
LocalDateTime addTimeExpectedResult,
LocalDateTime subTimeExpectedResult) {
var res = addtime(arg1, arg2);
- assertEquals(DATETIME, res.type());
- assertEquals(addTimeExpectedResult, res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(
+ addTimeExpectedResult, res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime());
res = subtime(arg1, arg2);
- assertEquals(DATETIME, res.type());
- assertEquals(subTimeExpectedResult, res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(
+ subTimeExpectedResult, res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime());
}
}
diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/ConvertTZTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/ConvertTZTest.java
index 17ff4f67ab..707f995138 100644
--- a/core/src/test/java/org/opensearch/sql/expression/datetime/ConvertTZTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/datetime/ConvertTZTest.java
@@ -6,11 +6,13 @@
package org.opensearch.sql.expression.datetime;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.opensearch.sql.data.model.ExprValueUtils.nullValue;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
+import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP;
import org.junit.jupiter.api.Test;
-import org.opensearch.sql.data.model.ExprDatetimeValue;
+import org.opensearch.sql.data.model.ExprTimestampValue;
+import org.opensearch.sql.exception.SemanticCheckException;
import org.opensearch.sql.expression.DSL;
import org.opensearch.sql.expression.ExpressionTestBase;
import org.opensearch.sql.expression.FunctionExpression;
@@ -21,32 +23,32 @@ class ConvertTZTest extends ExpressionTestBase {
public void invalidDate() {
FunctionExpression expr =
DSL.convert_tz(
- DSL.datetime(DSL.literal("2021-04-31 10:00:00")),
+ DSL.timestamp(DSL.literal("2021-04-31 10:00:00")),
DSL.literal("+00:00"),
DSL.literal("+00:00"));
- assertEquals(DATETIME, expr.type());
- assertEquals(nullValue(), expr.valueOf());
+ assertEquals(TIMESTAMP, expr.type());
+ assertThrows(SemanticCheckException.class, expr::valueOf);
}
@Test
public void conversionFromNoOffset() {
FunctionExpression expr =
DSL.convert_tz(
- DSL.datetime(DSL.literal("2008-05-15 22:00:00")),
+ DSL.timestamp(DSL.literal("2008-05-15 22:00:00")),
DSL.literal("+00:00"),
DSL.literal("+10:00"));
- assertEquals(DATETIME, expr.type());
- assertEquals(new ExprDatetimeValue("2008-05-16 08:00:00"), expr.valueOf());
+ assertEquals(TIMESTAMP, expr.type());
+ assertEquals(new ExprTimestampValue("2008-05-16 08:00:00"), expr.valueOf());
}
@Test
public void conversionToInvalidInput3Over() {
FunctionExpression expr =
DSL.convert_tz(
- DSL.datetime(DSL.literal("2008-05-15 22:00:00")),
+ DSL.timestamp(DSL.literal("2008-05-15 22:00:00")),
DSL.literal("+00:00"),
DSL.literal("+16:00"));
- assertEquals(DATETIME, expr.type());
+ assertEquals(TIMESTAMP, expr.type());
assertEquals(nullValue(), expr.valueOf());
}
@@ -54,10 +56,10 @@ public void conversionToInvalidInput3Over() {
public void conversionToInvalidInput3Under() {
FunctionExpression expr =
DSL.convert_tz(
- DSL.datetime(DSL.literal("2008-05-15 22:00:00")),
+ DSL.timestamp(DSL.literal("2008-05-15 22:00:00")),
DSL.literal("+00:00"),
DSL.literal("-16:00"));
- assertEquals(DATETIME, expr.type());
+ assertEquals(TIMESTAMP, expr.type());
assertEquals(nullValue(), expr.valueOf());
}
@@ -65,10 +67,10 @@ public void conversionToInvalidInput3Under() {
public void conversionFromPositiveToPositive() {
FunctionExpression expr =
DSL.convert_tz(
- DSL.datetime(DSL.literal("2008-05-15 22:00:00")),
+ DSL.timestamp(DSL.literal("2008-05-15 22:00:00")),
DSL.literal("+15:00"),
DSL.literal("+01:00"));
- assertEquals(DATETIME, expr.type());
+ assertEquals(TIMESTAMP, expr.type());
assertEquals(nullValue(), expr.valueOf());
}
@@ -76,10 +78,10 @@ public void conversionFromPositiveToPositive() {
public void invalidInput2Under() {
FunctionExpression expr =
DSL.convert_tz(
- DSL.datetime(DSL.literal("2008-05-15 22:00:00")),
+ DSL.timestamp(DSL.literal("2008-05-15 22:00:00")),
DSL.literal("-15:00"),
DSL.literal("+01:00"));
- assertEquals(DATETIME, expr.type());
+ assertEquals(TIMESTAMP, expr.type());
assertEquals(nullValue(), expr.valueOf());
}
@@ -87,10 +89,10 @@ public void invalidInput2Under() {
public void invalidInput3Over() {
FunctionExpression expr =
DSL.convert_tz(
- DSL.datetime(DSL.literal("2008-05-15 22:00:00")),
+ DSL.timestamp(DSL.literal("2008-05-15 22:00:00")),
DSL.literal("-12:00"),
DSL.literal("+15:00"));
- assertEquals(DATETIME, expr.type());
+ assertEquals(TIMESTAMP, expr.type());
assertEquals(nullValue(), expr.valueOf());
}
@@ -98,32 +100,32 @@ public void invalidInput3Over() {
public void conversionToPositiveEdge() {
FunctionExpression expr =
DSL.convert_tz(
- DSL.datetime(DSL.literal("2008-05-15 22:00:00")),
+ DSL.timestamp(DSL.literal("2008-05-15 22:00:00")),
DSL.literal("+00:00"),
DSL.literal("+14:00"));
- assertEquals(DATETIME, expr.type());
- assertEquals(new ExprDatetimeValue("2008-05-16 12:00:00"), expr.valueOf());
+ assertEquals(TIMESTAMP, expr.type());
+ assertEquals(new ExprTimestampValue("2008-05-16 12:00:00"), expr.valueOf());
}
@Test
public void conversionToNegativeEdge() {
FunctionExpression expr =
DSL.convert_tz(
- DSL.datetime(DSL.literal("2008-05-15 22:00:00")),
+ DSL.timestamp(DSL.literal("2008-05-15 22:00:00")),
DSL.literal("+00:01"),
DSL.literal("-13:59"));
- assertEquals(DATETIME, expr.type());
- assertEquals(new ExprDatetimeValue("2008-05-15 08:00:00"), expr.valueOf());
+ assertEquals(TIMESTAMP, expr.type());
+ assertEquals(new ExprTimestampValue("2008-05-15 08:00:00"), expr.valueOf());
}
@Test
public void invalidInput2() {
FunctionExpression expr =
DSL.convert_tz(
- DSL.datetime(DSL.literal("2008-05-15 22:00:00")),
+ DSL.timestamp(DSL.literal("2008-05-15 22:00:00")),
DSL.literal("+)()"),
DSL.literal("+12:00"));
- assertEquals(DATETIME, expr.type());
+ assertEquals(TIMESTAMP, expr.type());
assertEquals(nullValue(), expr.valueOf());
}
@@ -131,10 +133,10 @@ public void invalidInput2() {
public void invalidInput3() {
FunctionExpression expr =
DSL.convert_tz(
- DSL.datetime(DSL.literal("2008-05-15 22:00:00")),
+ DSL.timestamp(DSL.literal("2008-05-15 22:00:00")),
DSL.literal("+00:00"),
DSL.literal("test"));
- assertEquals(DATETIME, expr.type());
+ assertEquals(TIMESTAMP, expr.type());
assertEquals(nullValue(), expr.valueOf());
}
@@ -142,7 +144,7 @@ public void invalidInput3() {
public void invalidInput1() {
FunctionExpression expr =
DSL.convert_tz(DSL.literal("test"), DSL.literal("+00:00"), DSL.literal("+00:00"));
- assertEquals(DATETIME, expr.type());
+ assertEquals(TIMESTAMP, expr.type());
assertEquals(nullValue(), expr.valueOf());
}
@@ -150,32 +152,32 @@ public void invalidInput1() {
public void invalidDateFeb30() {
FunctionExpression expr =
DSL.convert_tz(
- DSL.datetime(DSL.literal("2021-02-30 10:00:00")),
+ DSL.timestamp(DSL.literal("2021-02-30 10:00:00")),
DSL.literal("+00:00"),
DSL.literal("+00:00"));
- assertEquals(DATETIME, expr.type());
- assertEquals(nullValue(), expr.valueOf());
+ assertEquals(TIMESTAMP, expr.type());
+ assertThrows(SemanticCheckException.class, expr::valueOf);
}
@Test
public void invalidDateApril31() {
FunctionExpression expr =
DSL.convert_tz(
- DSL.datetime(DSL.literal("2021-04-31 10:00:00")),
+ DSL.timestamp(DSL.literal("2021-04-31 10:00:00")),
DSL.literal("+00:00"),
DSL.literal("+00:00"));
- assertEquals(DATETIME, expr.type());
- assertEquals(nullValue(), expr.valueOf());
+ assertEquals(TIMESTAMP, expr.type());
+ assertThrows(SemanticCheckException.class, expr::valueOf);
}
@Test
public void invalidMonth13() {
FunctionExpression expr =
DSL.convert_tz(
- DSL.datetime(DSL.literal("2021-13-03 10:00:00")),
+ DSL.timestamp(DSL.literal("2021-13-03 10:00:00")),
DSL.literal("+00:00"),
DSL.literal("+00:00"));
- assertEquals(DATETIME, expr.type());
- assertEquals(nullValue(), expr.valueOf());
+ assertEquals(TIMESTAMP, expr.type());
+ assertThrows(SemanticCheckException.class, expr::valueOf);
}
}
diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/DateAddAndAddDateTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/DateAddAndAddDateTest.java
index 52db0a17e5..519e97bdc6 100644
--- a/core/src/test/java/org/opensearch/sql/expression/datetime/DateAddAndAddDateTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/datetime/DateAddAndAddDateTest.java
@@ -8,7 +8,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.opensearch.sql.data.type.ExprCoreType.DATE;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
+import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP;
import java.time.Duration;
import java.time.Instant;
@@ -29,81 +29,99 @@ private LocalDate today() {
@Test
public void adddate_returns_datetime_when_args_are_time_and_time_interval() {
var res = adddate(LocalTime.MIN, Duration.ofHours(1).plusMinutes(2));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalTime.of(1, 2).atDate(today()), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(
+ LocalTime.of(1, 2).atDate(today()),
+ res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime());
}
@Test
public void date_add_returns_datetime_when_args_are_time_and_time_interval() {
var res =
date_add(LocalTime.of(10, 20, 30), Duration.ofHours(1).plusMinutes(2).plusSeconds(42));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalTime.of(11, 23, 12).atDate(today()), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(
+ LocalTime.of(11, 23, 12).atDate(today()),
+ res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime());
}
@Test
public void adddate_time_limited_by_24_hours() {
var res = adddate(LocalTime.MAX, Duration.ofNanos(1));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalTime.MIN, res.datetimeValue().toLocalTime());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(LocalTime.MIN, res.timestampValue().atZone(ZoneOffset.UTC).toLocalTime());
}
@Test
public void date_add_time_limited_by_24_hours() {
var res =
date_add(LocalTime.of(10, 20, 30), Duration.ofHours(20).plusMinutes(50).plusSeconds(7));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalTime.of(7, 10, 37), res.datetimeValue().toLocalTime());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(
+ LocalTime.of(7, 10, 37), res.timestampValue().atZone(ZoneOffset.UTC).toLocalTime());
}
@Test
public void adddate_returns_datetime_when_args_are_date_and_date_interval() {
var res = adddate(LocalDate.of(2020, 2, 20), Period.of(3, 11, 21));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalDate.of(2024, 2, 10).atStartOfDay(), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(
+ LocalDate.of(2024, 2, 10).atStartOfDay(),
+ res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime());
}
@Test
public void date_add_returns_datetime_when_args_are_date_and_date_interval() {
var res = date_add(LocalDate.of(1961, 4, 12), Period.of(50, 50, 50));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalDate.of(2015, 8, 1).atStartOfDay(), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(
+ LocalDate.of(2015, 8, 1).atStartOfDay(),
+ res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime());
}
@Test
public void adddate_returns_datetime_when_args_are_date_and_time_interval() {
var res = adddate(LocalDate.of(2020, 2, 20), Duration.ofHours(1).plusMinutes(2));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalDateTime.of(2020, 2, 20, 1, 2), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(
+ LocalDateTime.of(2020, 2, 20, 1, 2),
+ res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime());
}
@Test
public void date_add_returns_datetime_when_args_are_date_and_time_interval() {
var res = date_add(LocalDate.of(1961, 4, 12), Duration.ofHours(9).plusMinutes(7));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalDateTime.of(1961, 4, 12, 9, 7), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(
+ LocalDateTime.of(1961, 4, 12, 9, 7),
+ res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime());
}
@Test
public void adddate_returns_datetime_when_args_are_time_and_date_interval() {
// Date based on today
var res = adddate(LocalTime.of(1, 2, 0), Period.ofDays(1));
- assertEquals(DATETIME, res.type());
- assertEquals(today().plusDays(1).atTime(LocalTime.of(1, 2, 0)), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(
+ today().plusDays(1).atTime(LocalTime.of(1, 2, 0)),
+ res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime());
}
@Test
public void date_add_returns_datetime_when_args_are_time_and_date_interval() {
var res = date_add(LocalTime.MIDNIGHT, Period.ofDays(0));
- assertEquals(DATETIME, res.type());
- assertEquals(today().atStartOfDay(), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(
+ today().atStartOfDay(), res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime());
}
@Test
public void adddate_returns_datetime_when_first_arg_is_datetime() {
var res = adddate(LocalDateTime.of(1961, 4, 12, 9, 7), Duration.ofMinutes(108));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalDateTime.of(1961, 4, 12, 10, 55), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(
+ LocalDateTime.of(1961, 4, 12, 10, 55),
+ res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime());
}
@Test
@@ -111,30 +129,34 @@ public void date_add_returns_datetime_when_first_arg_is_timestamp() {
var res =
date_add(
LocalDateTime.of(1961, 4, 12, 9, 7).toInstant(ZoneOffset.UTC), Duration.ofMinutes(108));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalDateTime.of(1961, 4, 12, 10, 55), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(
+ LocalDateTime.of(1961, 4, 12, 10, 55),
+ res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime());
}
@Test
public void adddate_accepts_negative_interval() {
var res = adddate(LocalDateTime.of(2020, 10, 20, 14, 42), Duration.ofDays(-10));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalDateTime.of(2020, 10, 10, 14, 42), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(
+ LocalDateTime.of(2020, 10, 10, 14, 42),
+ res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime());
assertEquals(subdate(LocalDateTime.of(2020, 10, 20, 14, 42), Duration.ofDays(10)), res);
}
@Test
public void adddate_has_second_signature_but_not_date_add() {
var res = adddate(LocalDateTime.of(1961, 4, 12, 9, 7), 100500);
- assertEquals(DATETIME, res.type());
+ assertEquals(TIMESTAMP, res.type());
var exception =
assertThrows(
ExpressionEvaluationException.class,
() -> date_add(LocalDateTime.of(1961, 4, 12, 9, 7), 100500));
assertEquals(
- "date_add function expected {[DATE,INTERVAL],[DATETIME,INTERVAL],"
- + "[TIMESTAMP,INTERVAL],[TIME,INTERVAL]}, but get [DATETIME,INTEGER]",
+ "date_add function expected {[DATE,INTERVAL],[TIMESTAMP,INTERVAL],"
+ + "[TIME,INTERVAL]}, but get [TIMESTAMP,INTEGER]",
exception.getMessage());
}
@@ -148,23 +170,29 @@ public void adddate_returns_date_when_args_are_date_and_days() {
@Test
public void adddate_returns_datetime_when_args_are_date_but_days() {
var res = adddate(LocalDate.of(2000, 1, 1).atStartOfDay(), 2);
- assertEquals(DATETIME, res.type());
- assertEquals(LocalDateTime.of(2000, 1, 3, 0, 0), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(
+ LocalDateTime.of(2000, 1, 3, 0, 0),
+ res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime());
res = adddate(LocalTime.now(), 2);
- assertEquals(DATETIME, res.type());
+ assertEquals(TIMESTAMP, res.type());
assertEquals(today().plusDays(2), res.dateValue());
res = adddate(Instant.ofEpochSecond(42), 2);
- assertEquals(DATETIME, res.type());
- assertEquals(LocalDateTime.of(1970, 1, 3, 0, 0, 42), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(
+ LocalDateTime.of(1970, 1, 3, 0, 0, 42),
+ res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime());
}
@Test
public void adddate_accepts_negative_days() {
var res = adddate(LocalDateTime.of(2020, 10, 20, 8, 16, 32), -40);
- assertEquals(DATETIME, res.type());
- assertEquals(LocalDateTime.of(2020, 10, 20, 8, 16, 32).minusDays(40), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(
+ LocalDateTime.of(2020, 10, 20, 8, 16, 32).minusDays(40),
+ res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime());
assertEquals(subdate(LocalDateTime.of(2020, 10, 20, 8, 16, 32), 40), res);
}
}
diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/DateDiffTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/DateDiffTest.java
index a630758456..16d585d73e 100644
--- a/core/src/test/java/org/opensearch/sql/expression/datetime/DateDiffTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/datetime/DateDiffTest.java
@@ -33,7 +33,7 @@ public class DateDiffTest extends DateTimeTestBase {
private static final LocalDateTime dateTimeSample2 = LocalDateTime.of(1993, 3, 4, 5, 6);
// Function signature is:
- // (DATE/DATETIME/TIMESTAMP/TIME, DATE/DATETIME/TIMESTAMP/TIME) -> LONG
+ // (DATE/TIMESTAMP/TIME, DATE/TIMESTAMP/TIME) -> LONG
private static Stream getTestData() {
// Arguments are: first argument for `DATE_DIFF` function, second argument and expected result.
return Stream.of(
diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/DateSubAndSubDateTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/DateSubAndSubDateTest.java
index 460e12384b..123ecda0bd 100644
--- a/core/src/test/java/org/opensearch/sql/expression/datetime/DateSubAndSubDateTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/datetime/DateSubAndSubDateTest.java
@@ -8,7 +8,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.opensearch.sql.data.type.ExprCoreType.DATE;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
+import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP;
import java.time.Duration;
import java.time.Instant;
@@ -18,10 +18,15 @@
import java.time.Period;
import java.time.ZoneOffset;
import org.junit.jupiter.api.Test;
+import org.opensearch.sql.data.model.ExprValue;
import org.opensearch.sql.exception.ExpressionEvaluationException;
public class DateSubAndSubDateTest extends DateTimeTestBase {
+ private LocalDateTime toLocalDateTime(ExprValue res) {
+ return res.timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime();
+ }
+
private LocalDate today() {
return LocalDate.now(functionProperties.getQueryStartClock());
}
@@ -29,81 +34,82 @@ private LocalDate today() {
@Test
public void subdate_returns_datetime_when_args_are_time_and_time_interval() {
var res = subdate(LocalTime.of(21, 0), Duration.ofHours(1).plusMinutes(2));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalTime.of(19, 58).atDate(today()), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(LocalTime.of(19, 58).atDate(today()), toLocalDateTime(res));
}
@Test
public void date_sub_returns_datetime_when_args_are_time_and_time_interval() {
var res =
date_sub(LocalTime.of(10, 20, 30), Duration.ofHours(1).plusMinutes(2).plusSeconds(42));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalTime.of(9, 17, 48).atDate(today()), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(LocalTime.of(9, 17, 48).atDate(today()), toLocalDateTime(res));
}
@Test
public void subdate_time_limited_by_24_hours() {
var res = subdate(LocalTime.MIN, Duration.ofNanos(1));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalTime.MAX, res.datetimeValue().toLocalTime());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(LocalTime.MAX, res.timestampValue().atZone(ZoneOffset.UTC).toLocalTime());
}
@Test
public void date_sub_time_limited_by_24_hours() {
var res =
date_sub(LocalTime.of(10, 20, 30), Duration.ofHours(20).plusMinutes(50).plusSeconds(7));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalTime.of(13, 30, 23), res.datetimeValue().toLocalTime());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(
+ LocalTime.of(13, 30, 23), res.timestampValue().atZone(ZoneOffset.UTC).toLocalTime());
}
@Test
public void subdate_returns_datetime_when_args_are_date_and_date_interval() {
var res = subdate(LocalDate.of(2020, 2, 20), Period.of(3, 11, 21));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalDate.of(2016, 2, 28).atStartOfDay(), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(LocalDate.of(2016, 2, 28).atStartOfDay(), toLocalDateTime(res));
}
@Test
public void date_sub_returns_datetime_when_args_are_date_and_date_interval() {
var res = date_sub(LocalDate.of(1961, 4, 12), Period.of(50, 50, 50));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalDate.of(1906, 12, 24).atStartOfDay(), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(LocalDate.of(1906, 12, 24).atStartOfDay(), toLocalDateTime(res));
}
@Test
public void subdate_returns_datetime_when_args_are_date_and_time_interval() {
var res = subdate(LocalDate.of(2020, 2, 20), Duration.ofHours(1).plusMinutes(2));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalDateTime.of(2020, 2, 19, 22, 58), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(LocalDateTime.of(2020, 2, 19, 22, 58), toLocalDateTime(res));
}
@Test
public void date_sub_returns_datetime_when_args_are_date_and_time_interval() {
var res = date_sub(LocalDate.of(1961, 4, 12), Duration.ofHours(9).plusMinutes(7));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalDateTime.of(1961, 4, 11, 14, 53), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(LocalDateTime.of(1961, 4, 11, 14, 53), toLocalDateTime(res));
}
@Test
public void subdate_returns_datetime_when_args_are_time_and_date_interval() {
// Date based on today
var res = subdate(LocalTime.of(1, 2, 0), Period.ofDays(1));
- assertEquals(DATETIME, res.type());
- assertEquals(today().minusDays(1).atTime(LocalTime.of(1, 2, 0)), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(today().minusDays(1).atTime(LocalTime.of(1, 2, 0)), toLocalDateTime(res));
}
@Test
public void date_sub_returns_datetime_when_args_are_time_and_date_interval() {
var res = date_sub(LocalTime.MIDNIGHT, Period.ofDays(0));
- assertEquals(DATETIME, res.type());
- assertEquals(today().atStartOfDay(), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(today().atStartOfDay(), toLocalDateTime(res));
}
@Test
public void subdate_returns_datetime_when_first_arg_is_datetime() {
var res = subdate(LocalDateTime.of(1961, 4, 12, 9, 7), Duration.ofMinutes(108));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalDateTime.of(1961, 4, 12, 7, 19), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(LocalDateTime.of(1961, 4, 12, 7, 19), toLocalDateTime(res));
}
@Test
@@ -111,30 +117,30 @@ public void date_sub_returns_datetime_when_first_arg_is_timestamp() {
var res =
date_sub(
LocalDateTime.of(1961, 4, 12, 9, 7).toInstant(ZoneOffset.UTC), Duration.ofMinutes(108));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalDateTime.of(1961, 4, 12, 7, 19), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(LocalDateTime.of(1961, 4, 12, 7, 19), toLocalDateTime(res));
}
@Test
public void subdate_accepts_negative_interval() {
var res = subdate(LocalDateTime.of(2020, 10, 20, 14, 42), Duration.ofDays(-10));
- assertEquals(DATETIME, res.type());
- assertEquals(LocalDateTime.of(2020, 10, 30, 14, 42), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(LocalDateTime.of(2020, 10, 30, 14, 42), toLocalDateTime(res));
assertEquals(adddate(LocalDateTime.of(2020, 10, 20, 14, 42), Duration.ofDays(10)), res);
}
@Test
public void subdate_has_second_signature_but_not_date_sub() {
var res = subdate(LocalDateTime.of(1961, 4, 12, 9, 7), 100500);
- assertEquals(DATETIME, res.type());
+ assertEquals(TIMESTAMP, res.type());
var exception =
assertThrows(
ExpressionEvaluationException.class,
() -> date_sub(LocalDateTime.of(1961, 4, 12, 9, 7), 100500));
assertEquals(
- "date_sub function expected {[DATE,INTERVAL],[DATETIME,INTERVAL],"
- + "[TIMESTAMP,INTERVAL],[TIME,INTERVAL]}, but get [DATETIME,INTEGER]",
+ "date_sub function expected {[DATE,INTERVAL],[TIMESTAMP,INTERVAL],[TIME,INTERVAL]}, but get"
+ + " [TIMESTAMP,INTEGER]",
exception.getMessage());
}
@@ -148,23 +154,23 @@ public void subdate_returns_date_when_args_are_date_and_days() {
@Test
public void subdate_returns_datetime_when_args_are_date_but_days() {
var res = subdate(LocalDate.of(2000, 1, 1).atStartOfDay(), 2);
- assertEquals(DATETIME, res.type());
- assertEquals(LocalDateTime.of(1999, 12, 30, 0, 0), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(LocalDateTime.of(1999, 12, 30, 0, 0), toLocalDateTime(res));
res = subdate(LocalTime.now(), 2);
- assertEquals(DATETIME, res.type());
+ assertEquals(TIMESTAMP, res.type());
assertEquals(today().minusDays(2), res.dateValue());
res = subdate(Instant.ofEpochSecond(42), 2);
- assertEquals(DATETIME, res.type());
- assertEquals(LocalDateTime.of(1969, 12, 30, 0, 0, 42), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(LocalDateTime.of(1969, 12, 30, 0, 0, 42), toLocalDateTime(res));
}
@Test
public void subdate_accepts_negative_days() {
var res = subdate(LocalDateTime.of(2020, 10, 20, 8, 16, 32), -40);
- assertEquals(DATETIME, res.type());
- assertEquals(LocalDateTime.of(2020, 10, 20, 8, 16, 32).plusDays(40), res.datetimeValue());
+ assertEquals(TIMESTAMP, res.type());
+ assertEquals(LocalDateTime.of(2020, 10, 20, 8, 16, 32).plusDays(40), toLocalDateTime(res));
assertEquals(adddate(LocalDateTime.of(2020, 10, 20, 8, 16, 32), 40), res);
}
}
diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java
index c2a6129626..d4ee7c44da 100644
--- a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java
@@ -32,7 +32,6 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.opensearch.sql.data.model.ExprDateValue;
-import org.opensearch.sql.data.model.ExprDatetimeValue;
import org.opensearch.sql.data.model.ExprDoubleValue;
import org.opensearch.sql.data.model.ExprIntegerValue;
import org.opensearch.sql.data.model.ExprLongValue;
@@ -398,10 +397,6 @@ private static Stream getTestDataForDayOfYear() {
return Stream.of(
Arguments.of(
DSL.literal(new ExprDateValue("2020-08-07")), "day_of_year(DATE '2020-08-07')", 220),
- Arguments.of(
- DSL.literal(new ExprDatetimeValue("2020-08-07 12:23:34")),
- "day_of_year(DATETIME '2020-08-07 12:23:34')",
- 220),
Arguments.of(
DSL.literal(new ExprTimestampValue("2020-08-07 12:23:34")),
"day_of_year(TIMESTAMP '2020-08-07 12:23:34')",
@@ -519,11 +514,6 @@ private static Stream getTestDataForGetFormat() {
Arguments.of("DATE", "ISO", "%Y-%m-%d"),
Arguments.of("DATE", "EUR", "%d.%m.%Y"),
Arguments.of("DATE", "INTERNAL", "%Y%m%d"),
- Arguments.of("DATETIME", "USA", "%Y-%m-%d %H.%i.%s"),
- Arguments.of("DATETIME", "JIS", "%Y-%m-%d %H:%i:%s"),
- Arguments.of("DATETIME", "ISO", "%Y-%m-%d %H:%i:%s"),
- Arguments.of("DATETIME", "EUR", "%Y-%m-%d %H.%i.%s"),
- Arguments.of("DATETIME", "INTERNAL", "%Y%m%d%H%i%s"),
Arguments.of("TIME", "USA", "%h:%i:%s %p"),
Arguments.of("TIME", "JIS", "%H:%i:%s"),
Arguments.of("TIME", "ISO", "%H:%i:%s"),
@@ -572,11 +562,6 @@ public void hour() {
assertEquals(integerValue(1), expression.valueOf());
assertEquals("hour(TIMESTAMP '2020-08-17 01:02:03')", expression.toString());
- expression = DSL.hour(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03")));
- assertEquals(INTEGER, expression.type());
- assertEquals(integerValue(1), expression.valueOf());
- assertEquals("hour(DATETIME '2020-08-17 01:02:03')", expression.toString());
-
expression = DSL.hour(DSL.literal("2020-08-17 01:02:03"));
assertEquals(INTEGER, expression.type());
assertEquals(integerValue(1), expression.valueOf());
@@ -617,9 +602,7 @@ public void hourOfDay() {
FunctionExpression expression2 = DSL.hour_of_day(DSL.literal("01:02:03"));
FunctionExpression expression3 =
DSL.hour_of_day(DSL.literal(new ExprTimestampValue("2020-08-17 01:02:03")));
- FunctionExpression expression4 =
- DSL.hour_of_day(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03")));
- FunctionExpression expression5 = DSL.hour_of_day(DSL.literal("2020-08-17 01:02:03"));
+ FunctionExpression expression4 = DSL.hour_of_day(DSL.literal("2020-08-17 01:02:03"));
assertAll(
() -> hourOfDayQuery(expression1, 1),
@@ -629,9 +612,7 @@ public void hourOfDay() {
() -> hourOfDayQuery(expression3, 1),
() -> assertEquals("hour_of_day(TIMESTAMP '2020-08-17 01:02:03')", expression3.toString()),
() -> hourOfDayQuery(expression4, 1),
- () -> assertEquals("hour_of_day(DATETIME '2020-08-17 01:02:03')", expression4.toString()),
- () -> hourOfDayQuery(expression5, 1),
- () -> assertEquals("hour_of_day(\"2020-08-17 01:02:03\")", expression5.toString()));
+ () -> assertEquals("hour_of_day(\"2020-08-17 01:02:03\")", expression4.toString()));
}
private void invalidHourOfDayQuery(String time) {
@@ -731,15 +712,10 @@ public void microsecond() {
assertEquals(integerValue(120000), eval(expression));
assertEquals("microsecond(\"01:02:03.12\")", expression.toString());
- expression = DSL.microsecond(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03.000010")));
- assertEquals(INTEGER, expression.type());
- assertEquals(integerValue(10), expression.valueOf());
- assertEquals("microsecond(DATETIME '2020-08-17 01:02:03.00001')", expression.toString());
-
- expression = DSL.microsecond(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03.123456")));
+ expression = DSL.microsecond(DSL.literal(new ExprTimestampValue("2020-08-17 01:02:03.123456")));
assertEquals(INTEGER, expression.type());
assertEquals(integerValue(123456), expression.valueOf());
- assertEquals("microsecond(DATETIME '2020-08-17 01:02:03.123456')", expression.toString());
+ assertEquals("microsecond(TIMESTAMP '2020-08-17 01:02:03.123456')", expression.toString());
expression = DSL.microsecond(DSL.literal("2020-08-17 01:02:03.123456"));
assertEquals(INTEGER, expression.type());
@@ -769,11 +745,6 @@ public void minute() {
assertEquals(integerValue(2), expression.valueOf());
assertEquals("minute(TIMESTAMP '2020-08-17 01:02:03')", expression.toString());
- expression = DSL.minute(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03")));
- assertEquals(INTEGER, expression.type());
- assertEquals(integerValue(2), expression.valueOf());
- assertEquals("minute(DATETIME '2020-08-17 01:02:03')", expression.toString());
-
expression = DSL.minute(DSL.literal("2020-08-17 01:02:03"));
assertEquals(INTEGER, expression.type());
assertEquals(integerValue(2), expression.valueOf());
@@ -803,11 +774,6 @@ public void minuteOfDay() {
assertEquals(integerValue(62), expression.valueOf());
assertEquals("minute_of_day(TIMESTAMP '2020-08-17 01:02:03')", expression.toString());
- expression = DSL.minute_of_day(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03")));
- assertEquals(INTEGER, expression.type());
- assertEquals(integerValue(62), expression.valueOf());
- assertEquals("minute_of_day(DATETIME '2020-08-17 01:02:03')", expression.toString());
-
expression = DSL.minute_of_day(DSL.literal("2020-08-17 01:02:03"));
assertEquals(INTEGER, expression.type());
assertEquals(integerValue(62), expression.valueOf());
@@ -833,10 +799,6 @@ private static Stream getTestDataForMinuteOfHour() {
DSL.literal(new ExprTimestampValue("2020-08-17 01:02:03")),
2,
"minute_of_hour(TIMESTAMP '2020-08-17 01:02:03')"),
- Arguments.of(
- DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03")),
- 2,
- "minute_of_hour(DATETIME '2020-08-17 01:02:03')"),
Arguments.of(
DSL.literal("2020-08-17 01:02:03"), 2, "minute_of_hour(\"2020-08-17 01:02:03\")"));
}
@@ -894,10 +856,6 @@ private static Stream getTestDataForMonthOfYear() {
return Stream.of(
Arguments.of(
DSL.literal(new ExprDateValue("2020-08-07")), "month_of_year(DATE '2020-08-07')", 8),
- Arguments.of(
- DSL.literal(new ExprDatetimeValue("2020-08-07 12:23:34")),
- "month_of_year(DATETIME '2020-08-07 12:23:34')",
- 8),
Arguments.of(
DSL.literal(new ExprTimestampValue("2020-08-07 12:23:34")),
"month_of_year(TIMESTAMP '2020-08-07 12:23:34')",
@@ -1052,11 +1010,6 @@ public void second() {
assertEquals(INTEGER, expression.type());
assertEquals(integerValue(3), expression.valueOf());
assertEquals("second(TIMESTAMP '2020-08-17 01:02:03')", expression.toString());
-
- expression = DSL.second(DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03")));
- assertEquals(INTEGER, expression.type());
- assertEquals(integerValue(3), expression.valueOf());
- assertEquals("second(DATETIME '2020-08-17 01:02:03')", expression.toString());
}
private void secondOfMinuteQuery(FunctionExpression dateExpression, int second, String testExpr) {
@@ -1075,11 +1028,7 @@ private static Stream getTestDataForSecondOfMinute() {
Arguments.of(
DSL.literal(new ExprTimestampValue("2020-08-17 01:02:03")),
3,
- "second_of_minute(TIMESTAMP '2020-08-17 01:02:03')"),
- Arguments.of(
- DSL.literal(new ExprDatetimeValue("2020-08-17 01:02:03")),
- 3,
- "second_of_minute(DATETIME '2020-08-17 01:02:03')"));
+ "second_of_minute(TIMESTAMP '2020-08-17 01:02:03')"));
}
@ParameterizedTest(name = "{2}")
@@ -1253,10 +1202,6 @@ private void validateStringFormat(
private static Stream getTestDataForWeekFormats() {
return Stream.of(
Arguments.of(DSL.literal(new ExprDateValue("2019-01-05")), "DATE '2019-01-05'", 0),
- Arguments.of(
- DSL.literal(new ExprDatetimeValue("2019-01-05 01:02:03")),
- "DATETIME '2019-01-05 01:02:03'",
- 0),
Arguments.of(
DSL.literal(new ExprTimestampValue("2019-01-05 01:02:03")),
"TIMESTAMP '2019-01-05 01:02:03'",
diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTest.java
index d857122534..4bec093b57 100644
--- a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTest.java
@@ -7,7 +7,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.opensearch.sql.data.model.ExprValueUtils.nullValue;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
+import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP;
import java.time.LocalDateTime;
import java.time.ZoneId;
@@ -15,7 +15,7 @@
import java.time.format.DateTimeFormatter;
import java.util.TimeZone;
import org.junit.jupiter.api.Test;
-import org.opensearch.sql.data.model.ExprDatetimeValue;
+import org.opensearch.sql.data.model.ExprTimestampValue;
import org.opensearch.sql.expression.DSL;
import org.opensearch.sql.expression.ExpressionTestBase;
import org.opensearch.sql.expression.FunctionExpression;
@@ -25,23 +25,23 @@ class DateTimeTest extends ExpressionTestBase {
@Test
public void noTimeZoneNoField2() {
FunctionExpression expr = DSL.datetime(DSL.literal("2008-05-15 22:00:00"));
- assertEquals(DATETIME, expr.type());
- assertEquals(new ExprDatetimeValue("2008-05-15 22:00:00"), expr.valueOf());
+ assertEquals(TIMESTAMP, expr.type());
+ assertEquals(new ExprTimestampValue("2008-05-15 22:00:00"), expr.valueOf());
}
@Test
public void positiveTimeZoneNoField2() {
FunctionExpression expr = DSL.datetime(DSL.literal("2008-05-15 22:00:00+01:00"));
- assertEquals(DATETIME, expr.type());
- assertEquals(new ExprDatetimeValue("2008-05-15 22:00:00"), expr.valueOf());
+ assertEquals(TIMESTAMP, expr.type());
+ assertEquals(new ExprTimestampValue("2008-05-15 22:00:00"), expr.valueOf());
}
@Test
public void positiveField1WrittenField2() {
FunctionExpression expr =
DSL.datetime(DSL.literal("2008-05-15 22:00:00+01:00"), DSL.literal("America/Los_Angeles"));
- assertEquals(DATETIME, expr.type());
- assertEquals(new ExprDatetimeValue("2008-05-15 14:00:00"), expr.valueOf());
+ assertEquals(TIMESTAMP, expr.type());
+ assertEquals(new ExprTimestampValue("2008-05-15 14:00:00"), expr.valueOf());
}
// When no timezone argument is passed inside the datetime field, it assumes local time.
@@ -57,23 +57,23 @@ public void localDateTimeConversion() {
.atZone(ZoneId.of(TimeZone.getDefault().getID()))
.withZoneSameInstant(ZoneId.of(timeZone));
FunctionExpression expr = DSL.datetime(DSL.literal(dt), DSL.literal(timeZone));
- assertEquals(DATETIME, expr.type());
- assertEquals(new ExprDatetimeValue(timeZoneLocal.toLocalDateTime()), expr.valueOf());
+ assertEquals(TIMESTAMP, expr.type());
+ assertEquals(new ExprTimestampValue(timeZoneLocal.toLocalDateTime()), expr.valueOf());
}
@Test
public void negativeField1WrittenField2() {
FunctionExpression expr =
DSL.datetime(DSL.literal("2008-05-15 22:00:00-11:00"), DSL.literal("America/Los_Angeles"));
- assertEquals(DATETIME, expr.type());
- assertEquals(new ExprDatetimeValue("2008-05-16 02:00:00"), expr.valueOf());
+ assertEquals(TIMESTAMP, expr.type());
+ assertEquals(new ExprTimestampValue("2008-05-16 02:00:00"), expr.valueOf());
}
@Test
public void negativeField1PositiveField2() {
FunctionExpression expr =
DSL.datetime(DSL.literal("2008-05-15 22:00:00-12:00"), DSL.literal("+15:00"));
- assertEquals(DATETIME, expr.type());
+ assertEquals(TIMESTAMP, expr.type());
assertEquals(nullValue(), expr.valueOf());
}
@@ -81,7 +81,7 @@ public void negativeField1PositiveField2() {
public void twentyFourHourDifference() {
FunctionExpression expr =
DSL.datetime(DSL.literal("2008-05-15 22:00:00-14:00"), DSL.literal("+10:00"));
- assertEquals(DATETIME, expr.type());
+ assertEquals(TIMESTAMP, expr.type());
assertEquals(nullValue(), expr.valueOf());
}
@@ -89,14 +89,14 @@ public void twentyFourHourDifference() {
public void negativeToNull() {
FunctionExpression expr =
DSL.datetime(DSL.literal("2008-05-15 22:00:00-11:00"), DSL.literal(nullValue()));
- assertEquals(DATETIME, expr.type());
+ assertEquals(TIMESTAMP, expr.type());
assertEquals(nullValue(), expr.valueOf());
}
@Test
public void invalidDate() {
FunctionExpression expr = DSL.datetime(DSL.literal("2008-04-31 22:00:00-11:00"));
- assertEquals(DATETIME, expr.type());
+ assertEquals(TIMESTAMP, expr.type());
assertEquals(nullValue(), expr.valueOf());
}
}
diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTestBase.java b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTestBase.java
index 023a3574aa..865c162f76 100644
--- a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTestBase.java
+++ b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeTestBase.java
@@ -11,10 +11,10 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.time.ZoneOffset;
import java.time.temporal.Temporal;
import java.util.List;
import org.opensearch.sql.data.model.ExprDateValue;
-import org.opensearch.sql.data.model.ExprDatetimeValue;
import org.opensearch.sql.data.model.ExprTimeValue;
import org.opensearch.sql.data.model.ExprTimestampValue;
import org.opensearch.sql.data.model.ExprValue;
@@ -91,7 +91,8 @@ protected Long datediff(Temporal first, Temporal second) {
}
protected LocalDateTime fromUnixTime(Double value) {
- return fromUnixTime(DSL.literal(value)).valueOf().datetimeValue();
+ return LocalDateTime.ofInstant(
+ fromUnixTime(DSL.literal(value)).valueOf().timestampValue(), ZoneOffset.UTC);
}
protected FunctionExpression fromUnixTime(Expression value) {
@@ -109,7 +110,8 @@ protected FunctionExpression fromUnixTime(Expression value, Expression format) {
}
protected LocalDateTime fromUnixTime(Long value) {
- return fromUnixTime(DSL.literal(value)).valueOf().datetimeValue();
+ return LocalDateTime.ofInstant(
+ fromUnixTime(DSL.literal(value)).valueOf().timestampValue(), ZoneOffset.UTC);
}
protected String fromUnixTime(Long value, String format) {
@@ -223,7 +225,7 @@ protected Double unixTimeStampOf(LocalDate value) {
}
protected Double unixTimeStampOf(LocalDateTime value) {
- return unixTimeStampOf(DSL.literal(new ExprDatetimeValue(value))).valueOf().doubleValue();
+ return unixTimeStampOf(DSL.literal(new ExprTimestampValue(value))).valueOf().doubleValue();
}
protected Double unixTimeStampOf(Instant value) {
diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/ExtractTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/ExtractTest.java
index 820158b722..02d50d0b59 100644
--- a/core/src/test/java/org/opensearch/sql/expression/datetime/ExtractTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/datetime/ExtractTest.java
@@ -16,8 +16,8 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.opensearch.sql.data.model.ExprDateValue;
-import org.opensearch.sql.data.model.ExprDatetimeValue;
import org.opensearch.sql.data.model.ExprTimeValue;
+import org.opensearch.sql.data.model.ExprTimestampValue;
import org.opensearch.sql.data.model.ExprValue;
import org.opensearch.sql.expression.DSL;
import org.opensearch.sql.expression.Expression;
@@ -72,12 +72,12 @@ private static Stream getDateResultsForExtractFunction() {
})
public void testExtractWithDatetime(String part, long expected) {
FunctionExpression datetimeExpression =
- DSL.extract(DSL.literal(part), DSL.literal(new ExprDatetimeValue(datetimeInput)));
+ DSL.extract(DSL.literal(part), DSL.literal(new ExprTimestampValue(datetimeInput)));
assertEquals(LONG, datetimeExpression.type());
assertEquals(expected, eval(datetimeExpression).longValue());
assertEquals(
- String.format("extract(\"%s\", DATETIME '2023-02-11 10:11:12.123')", part),
+ String.format("extract(\"%s\", TIMESTAMP '2023-02-11 10:11:12.123')", part),
datetimeExpression.toString());
}
diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/FromUnixTimeTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/FromUnixTimeTest.java
index 8fcc6904b2..a6d1da003f 100644
--- a/core/src/test/java/org/opensearch/sql/expression/datetime/FromUnixTimeTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/datetime/FromUnixTimeTest.java
@@ -46,7 +46,9 @@ public void checkOfLong(Long value) {
LocalDateTime.of(1970, 1, 1, 0, 0, 0).plus(value, ChronoUnit.SECONDS), fromUnixTime(value));
assertEquals(
LocalDateTime.of(1970, 1, 1, 0, 0, 0).plus(value, ChronoUnit.SECONDS),
- eval(fromUnixTime(DSL.literal(new ExprLongValue(value)))).datetimeValue());
+ LocalDateTime.ofInstant(
+ eval(fromUnixTime(DSL.literal(new ExprLongValue(value)))).timestampValue(),
+ ZoneOffset.UTC));
}
private static Stream getDoubleSamples() {
@@ -76,7 +78,9 @@ public void checkOfDouble(Double value) {
valueAsString);
assertEquals(
LocalDateTime.ofEpochSecond(intPart, (int) Math.round(fracPart * 1E9), ZoneOffset.UTC),
- eval(fromUnixTime(DSL.literal(new ExprDoubleValue(value)))).datetimeValue(),
+ LocalDateTime.ofInstant(
+ eval(fromUnixTime(DSL.literal(new ExprDoubleValue(value)))).timestampValue(),
+ ZoneOffset.UTC),
valueAsString);
}
diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/NowLikeFunctionTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/NowLikeFunctionTest.java
index 0e5c00084f..8b795786c0 100644
--- a/core/src/test/java/org/opensearch/sql/expression/datetime/NowLikeFunctionTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/datetime/NowLikeFunctionTest.java
@@ -9,13 +9,13 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.opensearch.sql.data.type.ExprCoreType.DATE;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
import static org.opensearch.sql.data.type.ExprCoreType.TIME;
-import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID;
+import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
@@ -45,7 +45,7 @@ class NowLikeFunctionTest extends ExpressionTestBase {
void now() {
test_now_like_functions(
DSL::now,
- DATETIME,
+ TIMESTAMP,
false,
() -> LocalDateTime.now(functionProperties.getQueryStartClock()));
}
@@ -54,7 +54,7 @@ void now() {
void current_timestamp() {
test_now_like_functions(
DSL::current_timestamp,
- DATETIME,
+ TIMESTAMP,
false,
() -> LocalDateTime.now(functionProperties.getQueryStartClock()));
}
@@ -63,7 +63,7 @@ void current_timestamp() {
void localtimestamp() {
test_now_like_functions(
DSL::localtimestamp,
- DATETIME,
+ TIMESTAMP,
false,
() -> LocalDateTime.now(functionProperties.getQueryStartClock()));
}
@@ -72,14 +72,14 @@ void localtimestamp() {
void localtime() {
test_now_like_functions(
DSL::localtime,
- DATETIME,
+ TIMESTAMP,
false,
() -> LocalDateTime.now(functionProperties.getQueryStartClock()));
}
@Test
void sysdate() {
- test_now_like_functions(DSL::sysdate, DATETIME, true, LocalDateTime::now);
+ test_now_like_functions(DSL::sysdate, TIMESTAMP, true, LocalDateTime::now);
}
@Test
@@ -128,14 +128,14 @@ void utc_time() {
@Test
void utc_timestamp() {
test_now_like_functions(
- DSL::utc_timestamp, DATETIME, false, () -> utcDateTimeNow(functionProperties));
+ DSL::utc_timestamp, TIMESTAMP, false, () -> utcDateTimeNow(functionProperties));
}
private static LocalDateTime utcDateTimeNow(FunctionProperties functionProperties) {
ZonedDateTime zonedDateTime =
LocalDateTime.now(functionProperties.getQueryStartClock())
.atZone(TimeZone.getDefault().toZoneId());
- return zonedDateTime.withZoneSameInstant(UTC_ZONE_ID).toLocalDateTime();
+ return zonedDateTime.withZoneSameInstant(ZoneOffset.UTC).toLocalDateTime();
}
/**
@@ -249,8 +249,8 @@ private Temporal extractValue(FunctionExpression func) {
switch ((ExprCoreType) func.type()) {
case DATE:
return func.valueOf().dateValue();
- case DATETIME:
- return func.valueOf().datetimeValue();
+ case TIMESTAMP:
+ return LocalDateTime.ofInstant(func.valueOf().timestampValue(), ZoneOffset.UTC);
case TIME:
return func.valueOf().timeValue();
// unreachable code
diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/StrToDateTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/StrToDateTest.java
index 42d4aab1f6..7f0861d9c3 100644
--- a/core/src/test/java/org/opensearch/sql/expression/datetime/StrToDateTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/datetime/StrToDateTest.java
@@ -6,21 +6,23 @@
package org.opensearch.sql.expression.datetime;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
+import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP;
import static org.opensearch.sql.data.type.ExprCoreType.UNDEFINED;
+import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.time.ZoneOffset;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
-import org.opensearch.sql.data.model.ExprDatetimeValue;
import org.opensearch.sql.data.model.ExprNullValue;
import org.opensearch.sql.data.model.ExprStringValue;
import org.opensearch.sql.data.model.ExprTimeValue;
+import org.opensearch.sql.data.model.ExprTimestampValue;
import org.opensearch.sql.data.model.ExprValue;
import org.opensearch.sql.data.type.ExprCoreType;
import org.opensearch.sql.expression.DSL;
@@ -34,23 +36,23 @@ private static Stream getTestDataForStrToDate() {
return Stream.of(
// Date arguments
Arguments.of(
- "01,5,2013", "%d,%m,%Y", new ExprDatetimeValue("2013-05-01 00:00:00"), DATETIME),
+ "01,5,2013", "%d,%m,%Y", new ExprTimestampValue("2013-05-01 00:00:00"), TIMESTAMP),
Arguments.of(
- "May 1, 2013", "%M %d, %Y", new ExprDatetimeValue("2013-05-01 00:00:00"), DATETIME),
+ "May 1, 2013", "%M %d, %Y", new ExprTimestampValue("2013-05-01 00:00:00"), TIMESTAMP),
Arguments.of(
"May 1, 2013 - 9,23,11",
"%M %d, %Y - %h,%i,%s",
- new ExprDatetimeValue("2013-05-01 09:23:11"),
- DATETIME),
+ new ExprTimestampValue("2013-05-01 09:23:11"),
+ TIMESTAMP),
Arguments.of(
- "2000,1,1", "%Y,%m,%d", new ExprDatetimeValue("2000-01-01 00:00:00"), DATETIME),
+ "2000,1,1", "%Y,%m,%d", new ExprTimestampValue("2000-01-01 00:00:00"), TIMESTAMP),
Arguments.of(
- "2000,1,1,10", "%Y,%m,%d,%h", new ExprDatetimeValue("2000-01-01 10:00:00"), DATETIME),
+ "2000,1,1,10", "%Y,%m,%d,%h", new ExprTimestampValue("2000-01-01 10:00:00"), TIMESTAMP),
Arguments.of(
"2000,1,1,10,11",
"%Y,%m,%d,%h,%i",
- new ExprDatetimeValue("2000-01-01 10:11:00"),
- DATETIME),
+ new ExprTimestampValue("2000-01-01 10:11:00"),
+ TIMESTAMP),
// Invalid Arguments (should return null)
Arguments.of("a09:30:17", "a%h:%i:%s", ExprNullValue.of(), UNDEFINED),
@@ -108,20 +110,22 @@ public void test_str_to_date_with_time_type(String parsed, String format) {
ExprValue result = eval(expression);
- assertEquals(DATETIME, result.type());
- assertEquals(getExpectedTimeResult(9, 23, 11), result.datetimeValue());
+ assertEquals(TIMESTAMP, result.type());
+ assertEquals(
+ getExpectedTimeResult(9, 23, 11),
+ LocalDateTime.ofInstant(result.timestampValue(), ZoneOffset.UTC));
}
@Test
public void test_str_to_date_with_date_format() {
- LocalDateTime arg = LocalDateTime.of(2023, 2, 27, 10, 11, 12);
+ Instant arg = Instant.parse("2023-02-27T10:11:12Z");
String format = "%Y,%m,%d %h,%i,%s";
FunctionExpression dateFormatExpr =
DSL.date_format(
functionProperties,
- DSL.literal(new ExprDatetimeValue(arg)),
+ DSL.literal(new ExprTimestampValue(arg)),
DSL.literal(new ExprStringValue(format)));
String dateFormatResult = eval(dateFormatExpr).stringValue();
@@ -130,7 +134,7 @@ public void test_str_to_date_with_date_format() {
functionProperties,
DSL.literal(new ExprStringValue(dateFormatResult)),
DSL.literal(new ExprStringValue(format)));
- LocalDateTime strToDateResult = eval(strToDateExpr).datetimeValue();
+ Instant strToDateResult = eval(strToDateExpr).timestampValue();
assertEquals(arg, strToDateResult);
}
@@ -156,7 +160,8 @@ public void test_str_to_date_with_time_format() {
functionProperties,
DSL.literal(new ExprStringValue(timeFormatResult)),
DSL.literal(new ExprStringValue(format)));
- LocalDateTime strToDateResult = eval(strToDateExpr).datetimeValue();
+ LocalDateTime strToDateResult =
+ LocalDateTime.ofInstant(eval(strToDateExpr).timestampValue(), ZoneOffset.UTC);
assertEquals(getExpectedTimeResult(HOURS, MINUTES, SECONDS), strToDateResult);
}
diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/TimeStampAddTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/TimeStampAddTest.java
index 243eb6bb7b..13f4f20704 100644
--- a/core/src/test/java/org/opensearch/sql/expression/datetime/TimeStampAddTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/datetime/TimeStampAddTest.java
@@ -18,7 +18,6 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.opensearch.sql.data.model.ExprDateValue;
-import org.opensearch.sql.data.model.ExprDatetimeValue;
import org.opensearch.sql.data.model.ExprIntegerValue;
import org.opensearch.sql.data.model.ExprNullValue;
import org.opensearch.sql.data.model.ExprStringValue;
@@ -43,12 +42,6 @@ private static Stream getTestDataForTimestampAdd() {
Arguments.of("MINUTE", 1, new ExprDateValue("2003-01-02"), "2003-01-02 00:01:00"),
Arguments.of("WEEK", 1, new ExprDateValue("2003-01-02"), "2003-01-09 00:00:00"),
- // Datetime
- Arguments.of(
- "MINUTE", 1, new ExprDatetimeValue("2003-01-02 00:00:00"), "2003-01-02 00:01:00"),
- Arguments.of(
- "WEEK", 1, new ExprDatetimeValue("2003-01-02 00:00:00"), "2003-01-09 00:00:00"),
-
// Timestamp
Arguments.of(
"MINUTE", 1, new ExprTimestampValue("2003-01-02 00:00:00"), "2003-01-02 00:01:00"),
@@ -125,7 +118,7 @@ private static FunctionExpression timestampaddQuery(
@MethodSource("getTestDataForTimestampAdd")
public void testTimestampadd(String unit, int amount, ExprValue datetimeExpr, String expected) {
FunctionExpression expr = timestampaddQuery(unit, amount, datetimeExpr);
- assertEquals(new ExprDatetimeValue(expected), eval(expr));
+ assertEquals(new ExprTimestampValue(expected), eval(expr));
}
private static Stream getTestDataForTestAddingDatePartToTime() {
@@ -165,7 +158,7 @@ public void testAddingDatePartToTime(
LocalDateTime expected1 = LocalDateTime.of(expectedDate, LocalTime.parse(timeArg));
- assertEquals(new ExprDatetimeValue(expected1), eval(expr));
+ assertEquals(new ExprTimestampValue(expected1), eval(expr));
}
@Test
@@ -184,7 +177,7 @@ public void testAddingTimePartToTime() {
LocalDateTime expected =
LocalDateTime.of(LocalDate.now(), LocalTime.parse(timeArg).plusMinutes(addedInterval));
- assertEquals(new ExprDatetimeValue(expected), eval(expr));
+ assertEquals(new ExprTimestampValue(expected), eval(expr));
}
@Test
@@ -196,15 +189,11 @@ public void testDifferentInputTypesHaveSameResult() {
FunctionExpression stringExpr =
timestampaddQuery(part, amount, new ExprStringValue("2000-01-01 00:00:00"));
- FunctionExpression datetimeExpr =
- timestampaddQuery(part, amount, new ExprDatetimeValue("2000-01-01 00:00:00"));
-
FunctionExpression timestampExpr =
timestampaddQuery(part, amount, new ExprTimestampValue("2000-01-01 00:00:00"));
assertAll(
() -> assertEquals(eval(dateExpr), eval(stringExpr)),
- () -> assertEquals(eval(dateExpr), eval(datetimeExpr)),
() -> assertEquals(eval(dateExpr), eval(timestampExpr)));
}
diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/TimeStampDiffTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/TimeStampDiffTest.java
index 061420ceee..b5ac3b078f 100644
--- a/core/src/test/java/org/opensearch/sql/expression/datetime/TimeStampDiffTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/datetime/TimeStampDiffTest.java
@@ -21,7 +21,6 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.opensearch.sql.data.model.ExprDateValue;
-import org.opensearch.sql.data.model.ExprDatetimeValue;
import org.opensearch.sql.data.model.ExprNullValue;
import org.opensearch.sql.data.model.ExprStringValue;
import org.opensearch.sql.data.model.ExprTimeValue;
@@ -80,8 +79,6 @@ private static ExprValue generateArg(
return new ExprTimestampValue(arg.toInstant(ZoneOffset.UTC));
case "DATE":
return new ExprDateValue(arg.toLocalDate());
- case "DATETIME":
- return new ExprDatetimeValue(arg);
case "STRING":
return new ExprStringValue(
String.format(
@@ -118,7 +115,7 @@ private static Stream getGeneralTestDataForTimestampDiff() {
final String[] intervalTypes = ArrayUtils.addAll(timeIntervalTypes, dateIntervalTypes);
// TIME type not included here as it is a special case handled by a different test
- final String[] expressionTypes = {"DATE", "DATETIME", "TIMESTAMP", "STRING"};
+ final String[] expressionTypes = {"DATE", "TIMESTAMP", "STRING"};
final LocalDateTime baseDateTime = LocalDateTime.of(2000, 1, 1, 0, 0, 0);
final int intervalDifference = 5;
@@ -159,30 +156,30 @@ private static Stream getCornerCaseTestDataForTimestampDiff() {
// Test around Leap Year
Arguments.of(
"DAY",
- new ExprDatetimeValue("2019-02-28 00:00:00"),
- new ExprDatetimeValue("2019-03-01 00:00:00"),
+ new ExprTimestampValue("2019-02-28 00:00:00"),
+ new ExprTimestampValue("2019-03-01 00:00:00"),
1),
Arguments.of(
"DAY",
- new ExprDatetimeValue("2020-02-28 00:00:00"),
- new ExprDatetimeValue("2020-03-01 00:00:00"),
+ new ExprTimestampValue("2020-02-28 00:00:00"),
+ new ExprTimestampValue("2020-03-01 00:00:00"),
2),
// Test around year change
Arguments.of(
"SECOND",
- new ExprDatetimeValue("2019-12-31 23:59:59"),
- new ExprDatetimeValue("2020-01-01 00:00:00"),
+ new ExprTimestampValue("2019-12-31 23:59:59"),
+ new ExprTimestampValue("2020-01-01 00:00:00"),
1),
Arguments.of(
"DAY",
- new ExprDatetimeValue("2019-12-31 23:59:59"),
- new ExprDatetimeValue("2020-01-01 00:00:00"),
+ new ExprTimestampValue("2019-12-31 23:59:59"),
+ new ExprTimestampValue("2020-01-01 00:00:00"),
0),
Arguments.of(
"DAY",
- new ExprDatetimeValue("2019-12-31 00:00:00"),
- new ExprDatetimeValue("2020-01-01 00:00:00"),
+ new ExprTimestampValue("2019-12-31 00:00:00"),
+ new ExprTimestampValue("2020-01-01 00:00:00"),
1));
}
@@ -295,13 +292,6 @@ public void testDifferentInputTypesHaveSameResult() {
new ExprStringValue("2000-01-01 00:00:00"),
new ExprStringValue("2000-01-02 00:00:00"));
- FunctionExpression datetimeExpr =
- timestampdiffQuery(
- functionProperties,
- part,
- new ExprDatetimeValue("2000-01-01 00:00:00"),
- new ExprDatetimeValue("2000-01-02 00:00:00"));
-
FunctionExpression timestampExpr =
timestampdiffQuery(
functionProperties,
@@ -311,7 +301,6 @@ public void testDifferentInputTypesHaveSameResult() {
assertAll(
() -> assertEquals(eval(dateExpr), eval(stringExpr)),
- () -> assertEquals(eval(dateExpr), eval(datetimeExpr)),
() -> assertEquals(eval(dateExpr), eval(timestampExpr)));
}
diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/TimestampTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/TimestampTest.java
index 7d25c0041b..5aebec9e78 100644
--- a/core/src/test/java/org/opensearch/sql/expression/datetime/TimestampTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/datetime/TimestampTest.java
@@ -8,12 +8,12 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP;
-import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.time.ZoneOffset;
import java.util.stream.Stream;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
@@ -39,7 +39,9 @@ public void timestamp_one_arg_string() {
expr = DSL.timestamp(functionProperties, DSL.literal("1961-04-12 09:07:00.123456"));
assertEquals(TIMESTAMP, expr.type());
- assertEquals(LocalDateTime.of(1961, 4, 12, 9, 7, 0, 123456000), expr.valueOf().datetimeValue());
+ assertEquals(
+ LocalDateTime.of(1961, 4, 12, 9, 7, 0, 123456000),
+ expr.valueOf().timestampValue().atZone(ZoneOffset.UTC).toLocalDateTime());
}
/**
@@ -71,7 +73,8 @@ public void timestamp_one_arg_string_invalid_format(String value, String testNam
public void timestamp_one_arg_time() {
var expr = DSL.timestamp(functionProperties, DSL.time(DSL.literal("22:33:44")));
assertEquals(TIMESTAMP, expr.type());
- var refValue = LocalDate.now().atTime(LocalTime.of(22, 33, 44)).atZone(UTC_ZONE_ID).toInstant();
+ var refValue =
+ LocalDate.now().atTime(LocalTime.of(22, 33, 44)).atZone(ZoneOffset.UTC).toInstant();
assertEquals(new ExprTimestampValue(refValue), expr.valueOf());
}
@@ -79,17 +82,10 @@ public void timestamp_one_arg_time() {
public void timestamp_one_arg_date() {
var expr = DSL.timestamp(functionProperties, DSL.date(DSL.literal("2077-12-15")));
assertEquals(TIMESTAMP, expr.type());
- var refValue = LocalDate.of(2077, 12, 15).atStartOfDay().atZone(UTC_ZONE_ID).toInstant();
+ var refValue = LocalDate.of(2077, 12, 15).atStartOfDay().atZone(ZoneOffset.UTC).toInstant();
assertEquals(new ExprTimestampValue(refValue), expr.valueOf());
}
- @Test
- public void timestamp_one_arg_datetime() {
- var expr = DSL.timestamp(functionProperties, DSL.datetime(DSL.literal("1961-04-12 09:07:00")));
- assertEquals(TIMESTAMP, expr.type());
- assertEquals(LocalDateTime.of(1961, 4, 12, 9, 7, 0), expr.valueOf().datetimeValue());
- }
-
@Test
public void timestamp_one_arg_timestamp() {
var refValue = new ExprTimestampValue(Instant.ofEpochSecond(10050042));
@@ -100,7 +96,7 @@ public void timestamp_one_arg_timestamp() {
}
private static Instant dateTime2Instant(LocalDateTime dt) {
- return dt.atZone(UTC_ZONE_ID).toInstant();
+ return dt.atZone(ZoneOffset.UTC).toInstant();
}
private static ExprTimestampValue dateTime2ExprTs(LocalDateTime dt) {
diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/ToSecondsTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/ToSecondsTest.java
index 7aa824e61d..910fe42a52 100644
--- a/core/src/test/java/org/opensearch/sql/expression/datetime/ToSecondsTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/datetime/ToSecondsTest.java
@@ -20,7 +20,6 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.opensearch.sql.data.model.ExprDateValue;
-import org.opensearch.sql.data.model.ExprDatetimeValue;
import org.opensearch.sql.data.model.ExprIntervalValue;
import org.opensearch.sql.data.model.ExprLongValue;
import org.opensearch.sql.data.model.ExprNullValue;
@@ -52,7 +51,6 @@ private static Stream getTestDataForToSeconds() {
Arguments.of(new ExprStringValue("2009-11-29 00:00:00"), new ExprLongValue(63426672000L)),
Arguments.of(new ExprStringValue("2009-11-29 13:43:32"), new ExprLongValue(63426721412L)),
Arguments.of(new ExprDateValue("2009-11-29"), new ExprLongValue(63426672000L)),
- Arguments.of(new ExprDatetimeValue("2009-11-29 13:43:32"), new ExprLongValue(63426721412L)),
Arguments.of(
new ExprTimestampValue("2009-11-29 13:43:32"), new ExprLongValue(63426721412L)));
}
diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/UnixTimeStampTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/UnixTimeStampTest.java
index c979b68302..7373b126c5 100644
--- a/core/src/test/java/org/opensearch/sql/expression/datetime/UnixTimeStampTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/datetime/UnixTimeStampTest.java
@@ -20,7 +20,6 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.opensearch.sql.data.model.ExprDateValue;
-import org.opensearch.sql.data.model.ExprDatetimeValue;
import org.opensearch.sql.data.model.ExprDoubleValue;
import org.opensearch.sql.data.model.ExprNullValue;
import org.opensearch.sql.data.model.ExprTimestampValue;
@@ -81,7 +80,7 @@ public void checkOfDateTime(LocalDateTime value) {
assertEquals(value.toEpochSecond(ZoneOffset.UTC), unixTimeStampOf(value));
assertEquals(
value.toEpochSecond(ZoneOffset.UTC),
- eval(unixTimeStampOf(DSL.literal(new ExprDatetimeValue(value)))).longValue());
+ eval(unixTimeStampOf(DSL.literal(new ExprTimestampValue(value)))).longValue());
}
private static Stream getInstantSamples() {
diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/UnixTwoWayConversionTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/UnixTwoWayConversionTest.java
index c74b062fba..75aed94e03 100644
--- a/core/src/test/java/org/opensearch/sql/expression/datetime/UnixTwoWayConversionTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/datetime/UnixTwoWayConversionTest.java
@@ -6,17 +6,17 @@
package org.opensearch.sql.expression.datetime;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID;
import java.time.LocalDateTime;
+import java.time.ZoneOffset;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
-import org.opensearch.sql.data.model.ExprDatetimeValue;
import org.opensearch.sql.data.model.ExprDoubleValue;
import org.opensearch.sql.data.model.ExprLongValue;
+import org.opensearch.sql.data.model.ExprTimestampValue;
import org.opensearch.sql.expression.DSL;
public class UnixTwoWayConversionTest extends DateTimeTestBase {
@@ -28,11 +28,14 @@ public void checkConvertNow() {
@Test
public void checkConvertNow_with_eval() {
- assertEquals(getExpectedNow(), eval(fromUnixTime(unixTimeStampExpr())).datetimeValue());
+ assertEquals(
+ getExpectedNow(),
+ LocalDateTime.ofInstant(
+ eval(fromUnixTime(unixTimeStampExpr())).timestampValue(), ZoneOffset.UTC));
}
private LocalDateTime getExpectedNow() {
- return LocalDateTime.now(functionProperties.getQueryStartClock().withZone(UTC_ZONE_ID))
+ return LocalDateTime.now(functionProperties.getQueryStartClock().withZone(ZoneOffset.UTC))
.withNano(0);
}
@@ -86,7 +89,9 @@ public void convertDateTime2Epoch2DateTime(LocalDateTime value) {
assertEquals(value, fromUnixTime(unixTimeStampOf(value)));
assertEquals(
value,
- eval(fromUnixTime(unixTimeStampOf(DSL.literal(new ExprDatetimeValue(value)))))
- .datetimeValue());
+ LocalDateTime.ofInstant(
+ eval(fromUnixTime(unixTimeStampOf(DSL.literal(new ExprTimestampValue(value)))))
+ .timestampValue(),
+ ZoneOffset.UTC));
}
}
diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/YearweekTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/YearweekTest.java
index 4f7208d141..3533886f9c 100644
--- a/core/src/test/java/org/opensearch/sql/expression/datetime/YearweekTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/datetime/YearweekTest.java
@@ -19,8 +19,8 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.opensearch.sql.data.model.ExprDateValue;
-import org.opensearch.sql.data.model.ExprDatetimeValue;
import org.opensearch.sql.data.model.ExprTimeValue;
+import org.opensearch.sql.data.model.ExprTimestampValue;
import org.opensearch.sql.data.model.ExprValue;
import org.opensearch.sql.exception.SemanticCheckException;
import org.opensearch.sql.expression.DSL;
@@ -137,7 +137,7 @@ public void yearweekModeInUnsupportedFormat() {
FunctionExpression expression1 =
DSL.yearweek(
functionProperties,
- DSL.literal(new ExprDatetimeValue("2019-01-05 10:11:12")),
+ DSL.literal(new ExprTimestampValue("2019-01-05 10:11:12")),
DSL.literal(8));
SemanticCheckException exception =
assertThrows(SemanticCheckException.class, () -> eval(expression1));
@@ -146,7 +146,7 @@ public void yearweekModeInUnsupportedFormat() {
FunctionExpression expression2 =
DSL.yearweek(
functionProperties,
- DSL.literal(new ExprDatetimeValue("2019-01-05 10:11:12")),
+ DSL.literal(new ExprTimestampValue("2019-01-05 10:11:12")),
DSL.literal(-1));
exception = assertThrows(SemanticCheckException.class, () -> eval(expression2));
assertEquals("mode:-1 is invalid, please use mode value between 0-7", exception.getMessage());
diff --git a/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java b/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java
index 3ee12f59d4..237477050d 100644
--- a/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/function/BuiltinFunctionRepositoryTest.java
@@ -16,10 +16,10 @@
import static org.mockito.Mockito.when;
import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN;
import static org.opensearch.sql.data.type.ExprCoreType.BYTE;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
import static org.opensearch.sql.data.type.ExprCoreType.INTEGER;
import static org.opensearch.sql.data.type.ExprCoreType.STRING;
import static org.opensearch.sql.data.type.ExprCoreType.STRUCT;
+import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP;
import static org.opensearch.sql.data.type.ExprCoreType.UNDEFINED;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.CAST_TO_BOOLEAN;
@@ -126,7 +126,7 @@ void resolve_should_not_cast_arguments_in_cast_function() {
FunctionImplementation function =
repo.resolve(
Collections.emptyList(),
- registerFunctionResolver(CAST_TO_BOOLEAN.getName(), DATETIME, BOOLEAN))
+ registerFunctionResolver(CAST_TO_BOOLEAN.getName(), TIMESTAMP, BOOLEAN))
.apply(functionProperties, ImmutableList.of(mockExpression));
assertEquals("cast_to_boolean(string)", function.toString());
}
diff --git a/core/src/test/java/org/opensearch/sql/expression/function/WideningTypeRuleTest.java b/core/src/test/java/org/opensearch/sql/expression/function/WideningTypeRuleTest.java
index 3b6e5f7586..9de1e65108 100644
--- a/core/src/test/java/org/opensearch/sql/expression/function/WideningTypeRuleTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/function/WideningTypeRuleTest.java
@@ -10,7 +10,6 @@
import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN;
import static org.opensearch.sql.data.type.ExprCoreType.BYTE;
import static org.opensearch.sql.data.type.ExprCoreType.DATE;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE;
import static org.opensearch.sql.data.type.ExprCoreType.FLOAT;
import static org.opensearch.sql.data.type.ExprCoreType.INTEGER;
@@ -58,12 +57,8 @@ class WideningTypeRuleTest {
.put(STRING, TIMESTAMP, 1)
.put(STRING, DATE, 1)
.put(STRING, TIME, 1)
- .put(STRING, DATETIME, 1)
- .put(DATE, DATETIME, 1)
- .put(TIME, DATETIME, 1)
- .put(DATE, TIMESTAMP, 2)
- .put(TIME, TIMESTAMP, 2)
- .put(DATETIME, TIMESTAMP, 1)
+ .put(DATE, TIMESTAMP, 1)
+ .put(TIME, TIMESTAMP, 1)
.put(UNDEFINED, BYTE, 1)
.put(UNDEFINED, SHORT, 2)
.put(UNDEFINED, INTEGER, 3)
diff --git a/core/src/test/java/org/opensearch/sql/expression/operator/convert/TypeCastOperatorTest.java b/core/src/test/java/org/opensearch/sql/expression/operator/convert/TypeCastOperatorTest.java
index 7803a4dbca..44a3ccabbd 100644
--- a/core/src/test/java/org/opensearch/sql/expression/operator/convert/TypeCastOperatorTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/operator/convert/TypeCastOperatorTest.java
@@ -10,7 +10,6 @@
import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN;
import static org.opensearch.sql.data.type.ExprCoreType.BYTE;
import static org.opensearch.sql.data.type.ExprCoreType.DATE;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE;
import static org.opensearch.sql.data.type.ExprCoreType.FLOAT;
import static org.opensearch.sql.data.type.ExprCoreType.INTEGER;
@@ -27,7 +26,6 @@
import org.opensearch.sql.data.model.ExprBooleanValue;
import org.opensearch.sql.data.model.ExprByteValue;
import org.opensearch.sql.data.model.ExprDateValue;
-import org.opensearch.sql.data.model.ExprDatetimeValue;
import org.opensearch.sql.data.model.ExprDoubleValue;
import org.opensearch.sql.data.model.ExprFloatValue;
import org.opensearch.sql.data.model.ExprIntegerValue;
@@ -72,12 +70,8 @@ private static Stream timestamp() {
return Stream.of(new ExprTimestampValue("2020-12-24 01:01:01"));
}
- private static Stream datetime() {
- return Stream.of(new ExprDatetimeValue("2020-12-24 01:01:01"));
- }
-
@ParameterizedTest(name = "castString({0})")
- @MethodSource({"numberData", "stringData", "boolData", "date", "time", "timestamp", "datetime"})
+ @MethodSource({"numberData", "stringData", "boolData", "date", "time", "timestamp"})
void castToString(ExprValue value) {
FunctionExpression expression = DSL.castString(DSL.literal(value));
assertEquals(STRING, expression.type());
@@ -299,7 +293,7 @@ void castToDate() {
assertEquals(DATE, expression.type());
assertEquals(new ExprDateValue("2012-08-07"), expression.valueOf());
- expression = DSL.castDate(DSL.literal(new ExprDatetimeValue("2012-08-07 01:01:01")));
+ expression = DSL.castDate(DSL.literal(new ExprTimestampValue("2012-08-07 01:01:01")));
assertEquals(DATE, expression.type());
assertEquals(new ExprDateValue("2012-08-07"), expression.valueOf());
@@ -318,7 +312,7 @@ void castToTime() {
assertEquals(TIME, expression.type());
assertEquals(new ExprTimeValue("01:01:01"), expression.valueOf());
- expression = DSL.castTime(DSL.literal(new ExprDatetimeValue("2012-08-07 01:01:01")));
+ expression = DSL.castTime(DSL.literal(new ExprTimestampValue("2012-08-07 01:01:01")));
assertEquals(TIME, expression.type());
assertEquals(new ExprTimeValue("01:01:01"), expression.valueOf());
@@ -337,7 +331,7 @@ void castToTimestamp() {
assertEquals(TIMESTAMP, expression.type());
assertEquals(new ExprTimestampValue("2012-08-07 01:01:01"), expression.valueOf());
- expression = DSL.castTimestamp(DSL.literal(new ExprDatetimeValue("2012-08-07 01:01:01")));
+ expression = DSL.castTimestamp(DSL.literal(new ExprTimestampValue("2012-08-07 01:01:01")));
assertEquals(TIMESTAMP, expression.type());
assertEquals(new ExprTimestampValue("2012-08-07 01:01:01"), expression.valueOf());
@@ -345,19 +339,4 @@ void castToTimestamp() {
assertEquals(TIMESTAMP, expression.type());
assertEquals(new ExprTimestampValue("2012-08-07 01:01:01"), expression.valueOf());
}
-
- @Test
- void castToDatetime() {
- FunctionExpression expression = DSL.castDatetime(DSL.literal("2012-08-07 01:01:01"));
- assertEquals(DATETIME, expression.type());
- assertEquals(new ExprDatetimeValue("2012-08-07 01:01:01"), expression.valueOf());
-
- expression = DSL.castDatetime(DSL.literal(new ExprTimestampValue("2012-08-07 01:01:01")));
- assertEquals(DATETIME, expression.type());
- assertEquals(new ExprDatetimeValue("2012-08-07 01:01:01"), expression.valueOf());
-
- expression = DSL.castDatetime(DSL.literal(new ExprDateValue("2012-08-07")));
- assertEquals(DATETIME, expression.type());
- assertEquals(new ExprDatetimeValue("2012-08-07 00:00:00"), expression.valueOf());
- }
}
diff --git a/core/src/test/java/org/opensearch/sql/expression/operator/predicate/BinaryPredicateOperatorTest.java b/core/src/test/java/org/opensearch/sql/expression/operator/predicate/BinaryPredicateOperatorTest.java
index e6290553ce..55dfbd35c2 100644
--- a/core/src/test/java/org/opensearch/sql/expression/operator/predicate/BinaryPredicateOperatorTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/operator/predicate/BinaryPredicateOperatorTest.java
@@ -18,7 +18,6 @@
import static org.opensearch.sql.data.model.ExprValueUtils.fromObjectValue;
import static org.opensearch.sql.data.type.ExprCoreType.ARRAY;
import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
import static org.opensearch.sql.data.type.ExprCoreType.INTEGER;
import static org.opensearch.sql.data.type.ExprCoreType.STRUCT;
import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP;
@@ -472,11 +471,10 @@ private void assertStringRepr(
if (v1.type() == v2.type()) {
assertEquals(String.format("%s(%s, %s)", function, v1, v2), functionExpression.toString());
} else {
- var widerType = v1.type() == TIMESTAMP || v2.type() == TIMESTAMP ? TIMESTAMP : DATETIME;
assertEquals(
String.format(
"%s(%s, %s)",
- function, getExpectedStringRepr(widerType, v1), getExpectedStringRepr(widerType, v2)),
+ function, getExpectedStringRepr(TIMESTAMP, v1), getExpectedStringRepr(TIMESTAMP, v2)),
functionExpression.toString());
}
}
diff --git a/core/src/test/java/org/opensearch/sql/expression/system/SystemFunctionsTest.java b/core/src/test/java/org/opensearch/sql/expression/system/SystemFunctionsTest.java
index ac4153f59f..4b15704c77 100644
--- a/core/src/test/java/org/opensearch/sql/expression/system/SystemFunctionsTest.java
+++ b/core/src/test/java/org/opensearch/sql/expression/system/SystemFunctionsTest.java
@@ -11,7 +11,6 @@
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
-import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.LinkedHashMap;
import java.util.List;
@@ -21,7 +20,6 @@
import org.opensearch.sql.data.model.ExprByteValue;
import org.opensearch.sql.data.model.ExprCollectionValue;
import org.opensearch.sql.data.model.ExprDateValue;
-import org.opensearch.sql.data.model.ExprDatetimeValue;
import org.opensearch.sql.data.model.ExprDoubleValue;
import org.opensearch.sql.data.model.ExprFloatValue;
import org.opensearch.sql.data.model.ExprIntegerValue;
@@ -49,7 +47,6 @@ void typeof() {
assertEquals("BOOLEAN", typeofGetValue(ExprBooleanValue.of(false)));
assertEquals("BYTE", typeofGetValue(new ExprByteValue(0)));
assertEquals("DATE", typeofGetValue(new ExprDateValue(LocalDate.now())));
- assertEquals("DATETIME", typeofGetValue(new ExprDatetimeValue(LocalDateTime.now())));
assertEquals("DOUBLE", typeofGetValue(new ExprDoubleValue(0)));
assertEquals("FLOAT", typeofGetValue(new ExprFloatValue(0)));
assertEquals("INTEGER", typeofGetValue(new ExprIntegerValue(0)));
diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/AggregationOperatorTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/AggregationOperatorTest.java
index 0f3f4bd61f..ee784045d0 100644
--- a/core/src/test/java/org/opensearch/sql/planner/physical/AggregationOperatorTest.java
+++ b/core/src/test/java/org/opensearch/sql/planner/physical/AggregationOperatorTest.java
@@ -10,7 +10,6 @@
import static org.hamcrest.Matchers.containsInRelativeOrder;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.opensearch.sql.data.type.ExprCoreType.DATE;
-import static org.opensearch.sql.data.type.ExprCoreType.DATETIME;
import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE;
import static org.opensearch.sql.data.type.ExprCoreType.FLOAT;
import static org.opensearch.sql.data.type.ExprCoreType.INTEGER;
@@ -25,7 +24,6 @@
import java.util.List;
import org.junit.jupiter.api.Test;
import org.opensearch.sql.data.model.ExprDateValue;
-import org.opensearch.sql.data.model.ExprDatetimeValue;
import org.opensearch.sql.data.model.ExprStringValue;
import org.opensearch.sql.data.model.ExprTimeValue;
import org.opensearch.sql.data.model.ExprTimestampValue;
@@ -153,21 +151,21 @@ public void minute_span() {
PhysicalPlan plan =
new AggregationOperator(
testScan(datetimeInputs),
- Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("minute", DATETIME)))),
+ Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("minute", TIMESTAMP)))),
Collections.singletonList(
- DSL.named("span", DSL.span(DSL.ref("minute", DATETIME), DSL.literal(5), "m"))));
+ DSL.named("span", DSL.span(DSL.ref("minute", TIMESTAMP), DSL.literal(5), "m"))));
List result = execute(plan);
assertEquals(3, result.size());
assertThat(
result,
containsInRelativeOrder(
ExprValueUtils.tupleValue(
- ImmutableMap.of("span", new ExprDatetimeValue("2020-12-31 23:50:00"), "count", 1)),
+ ImmutableMap.of("span", new ExprTimestampValue("2020-12-31 23:50:00"), "count", 1)),
ExprValueUtils.tupleValue(
- ImmutableMap.of("span", new ExprDatetimeValue("2021-01-01 00:00:00"), "count", 3)),
+ ImmutableMap.of("span", new ExprTimestampValue("2021-01-01 00:00:00"), "count", 3)),
ExprValueUtils.tupleValue(
ImmutableMap.of(
- "span", new ExprDatetimeValue("2021-01-01 00:05:00"), "count", 1))));
+ "span", new ExprTimestampValue("2021-01-01 00:05:00"), "count", 1))));
plan =
new AggregationOperator(
@@ -296,23 +294,23 @@ public void month_span() {
plan =
new AggregationOperator(
testScan(dateInputs),
- Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", DATETIME)))),
+ Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))),
Collections.singletonList(
- DSL.named("span", DSL.span(DSL.ref("quarter", DATETIME), DSL.literal(2), "M"))));
+ DSL.named("span", DSL.span(DSL.ref("quarter", TIMESTAMP), DSL.literal(2), "M"))));
result = execute(plan);
assertEquals(4, result.size());
assertThat(
result,
containsInRelativeOrder(
ExprValueUtils.tupleValue(
- ImmutableMap.of("span", new ExprDatetimeValue("2020-09-01 00:00:00"), "count", 1)),
+ ImmutableMap.of("span", new ExprTimestampValue("2020-09-01 00:00:00"), "count", 1)),
ExprValueUtils.tupleValue(
- ImmutableMap.of("span", new ExprDatetimeValue("2020-11-01 00:00:00"), "count", 1)),
+ ImmutableMap.of("span", new ExprTimestampValue("2020-11-01 00:00:00"), "count", 1)),
ExprValueUtils.tupleValue(
- ImmutableMap.of("span", new ExprDatetimeValue("2021-01-01 00:00:00"), "count", 1)),
+ ImmutableMap.of("span", new ExprTimestampValue("2021-01-01 00:00:00"), "count", 1)),
ExprValueUtils.tupleValue(
ImmutableMap.of(
- "span", new ExprDatetimeValue("2021-05-01 00:00:00"), "count", 2))));
+ "span", new ExprTimestampValue("2021-05-01 00:00:00"), "count", 2))));
plan =
new AggregationOperator(
@@ -340,19 +338,19 @@ public void quarter_span() {
PhysicalPlan plan =
new AggregationOperator(
testScan(dateInputs),
- Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", DATETIME)))),
+ Collections.singletonList(DSL.named("count", DSL.count(DSL.ref("quarter", TIMESTAMP)))),
Collections.singletonList(
- DSL.named("span", DSL.span(DSL.ref("quarter", DATETIME), DSL.literal(2), "q"))));
+ DSL.named("span", DSL.span(DSL.ref("quarter", TIMESTAMP), DSL.literal(2), "q"))));
List result = execute(plan);
assertEquals(2, result.size());
assertThat(
result,
containsInRelativeOrder(
ExprValueUtils.tupleValue(
- ImmutableMap.of("span", new ExprDatetimeValue("2020-07-01 00:00:00"), "count", 2)),
+ ImmutableMap.of("span", new ExprTimestampValue("2020-07-01 00:00:00"), "count", 2)),
ExprValueUtils.tupleValue(
ImmutableMap.of(
- "span", new ExprDatetimeValue("2021-01-01 00:00:00"), "count", 3))));
+ "span", new ExprTimestampValue("2021-01-01 00:00:00"), "count", 3))));
plan =
new AggregationOperator(
diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanTestBase.java b/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanTestBase.java
index 003e59959f..6399f945ed 100644
--- a/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanTestBase.java
+++ b/core/src/test/java/org/opensearch/sql/planner/physical/PhysicalPlanTestBase.java
@@ -14,7 +14,6 @@
import java.util.List;
import java.util.Map;
import org.opensearch.sql.data.model.ExprDateValue;
-import org.opensearch.sql.data.model.ExprDatetimeValue;
import org.opensearch.sql.data.model.ExprTimeValue;
import org.opensearch.sql.data.model.ExprTimestampValue;
import org.opensearch.sql.data.model.ExprValue;
@@ -109,35 +108,35 @@ public class PhysicalPlanTestBase {
ImmutableMap.of(
"day", new ExprDateValue("2021-01-03"),
"month", new ExprDateValue("2021-02-04"),
- "quarter", new ExprDatetimeValue("2021-01-01 12:25:02"),
+ "quarter", new ExprTimestampValue("2021-01-01 12:25:02"),
"year", new ExprTimestampValue("2013-01-01 12:25:02"))))
.add(
ExprValueUtils.tupleValue(
ImmutableMap.of(
"day", new ExprDateValue("2021-01-01"),
"month", new ExprDateValue("2021-03-17"),
- "quarter", new ExprDatetimeValue("2021-05-17 12:25:01"),
+ "quarter", new ExprTimestampValue("2021-05-17 12:25:01"),
"year", new ExprTimestampValue("2021-01-01 12:25:02"))))
.add(
ExprValueUtils.tupleValue(
ImmutableMap.of(
"day", new ExprDateValue("2021-01-04"),
"month", new ExprDateValue("2021-02-08"),
- "quarter", new ExprDatetimeValue("2021-06-08 12:25:02"),
+ "quarter", new ExprTimestampValue("2021-06-08 12:25:02"),
"year", new ExprTimestampValue("2016-01-01 12:25:02"))))
.add(
ExprValueUtils.tupleValue(
ImmutableMap.of(
"day", new ExprDateValue("2021-01-02"),
"month", new ExprDateValue("2020-12-12"),
- "quarter", new ExprDatetimeValue("2020-12-12 12:25:03"),
+ "quarter", new ExprTimestampValue("2020-12-12 12:25:03"),
"year", new ExprTimestampValue("1999-01-01 12:25:02"))))
.add(
ExprValueUtils.tupleValue(
ImmutableMap.of(
"day", new ExprDateValue("2021-01-01"),
"month", new ExprDateValue("2021-02-28"),
- "quarter", new ExprDatetimeValue("2020-09-28 12:25:01"),
+ "quarter", new ExprTimestampValue("2020-09-28 12:25:01"),
"year", new ExprTimestampValue("2018-01-01 12:25:02"))))
.build();
@@ -147,31 +146,31 @@ public class PhysicalPlanTestBase {
ExprValueUtils.tupleValue(
ImmutableMap.of(
"hour", new ExprTimeValue("17:17:00"),
- "minute", new ExprDatetimeValue("2020-12-31 23:54:12"),
+ "minute", new ExprTimestampValue("2020-12-31 23:54:12"),
"second", new ExprTimestampValue("2021-01-01 00:00:05"))))
.add(
ExprValueUtils.tupleValue(
ImmutableMap.of(
"hour", new ExprTimeValue("18:17:00"),
- "minute", new ExprDatetimeValue("2021-01-01 00:05:12"),
+ "minute", new ExprTimestampValue("2021-01-01 00:05:12"),
"second", new ExprTimestampValue("2021-01-01 00:00:12"))))
.add(
ExprValueUtils.tupleValue(
ImmutableMap.of(
"hour", new ExprTimeValue("17:15:00"),
- "minute", new ExprDatetimeValue("2021-01-01 00:03:12"),
+ "minute", new ExprTimestampValue("2021-01-01 00:03:12"),
"second", new ExprTimestampValue("2021-01-01 00:00:17"))))
.add(
ExprValueUtils.tupleValue(
ImmutableMap.of(
"hour", new ExprTimeValue("19:01:00"),
- "minute", new ExprDatetimeValue("2021-01-01 00:02:12"),
+ "minute", new ExprTimestampValue("2021-01-01 00:02:12"),
"second", new ExprTimestampValue("2021-01-01 00:00:03"))))
.add(
ExprValueUtils.tupleValue(
ImmutableMap.of(
"hour", new ExprTimeValue("18:50:00"),
- "minute", new ExprDatetimeValue("2021-01-01 00:00:12"),
+ "minute", new ExprTimestampValue("2021-01-01 00:00:12"),
"second", new ExprTimestampValue("2021-01-01 00:00:13"))))
.build();
diff --git a/core/src/test/java/org/opensearch/sql/utils/ComparisonUtil.java b/core/src/test/java/org/opensearch/sql/utils/ComparisonUtil.java
index b25f4d1053..0d9fe80339 100644
--- a/core/src/test/java/org/opensearch/sql/utils/ComparisonUtil.java
+++ b/core/src/test/java/org/opensearch/sql/utils/ComparisonUtil.java
@@ -10,7 +10,7 @@
import static org.opensearch.sql.data.model.ExprValueUtils.getIntegerValue;
import static org.opensearch.sql.data.model.ExprValueUtils.getLongValue;
import static org.opensearch.sql.data.model.ExprValueUtils.getStringValue;
-import static org.opensearch.sql.utils.DateTimeUtils.extractDateTime;
+import static org.opensearch.sql.utils.DateTimeUtils.extractTimestamp;
import org.opensearch.sql.data.model.ExprValue;
import org.opensearch.sql.data.type.ExprCoreType;
@@ -29,8 +29,8 @@ public static int compare(FunctionProperties functionProperties, ExprValue v1, E
} else if (v1.isNull() || v2.isNull()) {
throw new ExpressionEvaluationException("invalid to call compare operation on null value");
} else if (v1.type() != v2.type() && v1.isDateTime() && v2.isDateTime()) {
- return extractDateTime(v1, functionProperties)
- .compareTo(extractDateTime(v2, functionProperties));
+ return extractTimestamp(v1, functionProperties)
+ .compareTo(extractTimestamp(v2, functionProperties));
}
return compare(v1, v2);
}
@@ -67,8 +67,6 @@ public static int compare(ExprValue v1, ExprValue v2) {
return v1.timeValue().compareTo(v2.timeValue());
case DATE:
return v1.dateValue().compareTo(v2.dateValue());
- case DATETIME:
- return v1.datetimeValue().compareTo(v2.datetimeValue());
case TIMESTAMP:
return v1.timestampValue().compareTo(v2.timestampValue());
default:
diff --git a/docs/dev/img/type-hierarchy-tree-final.png b/docs/dev/img/type-hierarchy-tree-final.png
new file mode 100644
index 0000000000..883e581efb
Binary files /dev/null and b/docs/dev/img/type-hierarchy-tree-final.png differ
diff --git a/docs/user/dql/expressions.rst b/docs/user/dql/expressions.rst
index af264b2f16..123bba046a 100644
--- a/docs/user/dql/expressions.rst
+++ b/docs/user/dql/expressions.rst
@@ -168,7 +168,7 @@ Here is an example for different type of comparison operators::
| True | True | False | True | False | False |
+---------+----------+---------+----------+----------+---------+
-It is possible to compare datetimes. When comparing different datetime types, for example `DATE` and `TIME`, both converted to `DATETIME`.
+It is possible to compare datetimes. When comparing different datetime types, for example `DATE` and `TIME`, both converted to `TIMESTAMP`.
The following rule is applied on coversion: a `TIME` applied to today's date; `DATE` is interpreted at midnight. See example below::
os> SELECT current_time() > current_date() AS `now.time > today`, typeof(current_time()) AS `now.time.type`, typeof(current_date()) AS `now.date.type`;
@@ -184,7 +184,7 @@ The following rule is applied on coversion: a `TIME` applied to today's date; `D
+------------------+-----------------+------------+
| now.time = now | now.time.type | now.type |
|------------------+-----------------+------------|
- | True | TIME | DATETIME |
+ | True | TIME | TIMESTAMP |
+------------------+-----------------+------------+
os> SELECT subtime(now(), current_time()) = current_date() AS `midnight = now.date`, typeof(subtime(now(), current_time())) AS `midnight.type`, typeof(current_date()) AS `now.date.type`;
@@ -192,7 +192,7 @@ The following rule is applied on coversion: a `TIME` applied to today's date; `D
+-----------------------+-----------------+-----------------+
| midnight = now.date | midnight.type | now.date.type |
|-----------------------+-----------------+-----------------|
- | True | DATETIME | DATE |
+ | True | TIMESTAMP | DATE |
+-----------------------+-----------------+-----------------+
diff --git a/docs/user/dql/functions.rst b/docs/user/dql/functions.rst
index 19260e8bea..5af21df2bf 100644
--- a/docs/user/dql/functions.rst
+++ b/docs/user/dql/functions.rst
@@ -1145,15 +1145,15 @@ Description
Usage: adddate(date, INTERVAL expr unit)/ adddate(date, expr) adds the time interval of second argument to date; adddate(date, days) adds the second argument as integer number of days to date.
If first argument is TIME, today's date is used; if first argument is DATE, time at midnight is used.
-Argument type: DATE/DATETIME/TIMESTAMP/TIME, INTERVAL/LONG
+Argument type: DATE/TIMESTAMP/TIME, INTERVAL/LONG
Return type map:
-(DATE/DATETIME/TIMESTAMP/TIME, INTERVAL) -> DATETIME
+(DATE/TIMESTAMP/TIME, INTERVAL) -> TIMESTAMP
(DATE, LONG) -> DATE
-(DATETIME/TIMESTAMP/TIME, LONG) -> DATETIME
+(TIMESTAMP/TIME, LONG) -> TIMESTAMP
Synonyms: `DATE_ADD`_ when invoked with the INTERVAL form of the second argument.
@@ -1178,13 +1178,13 @@ Description
Usage: addtime(expr1, expr2) adds expr2 to expr1 and returns the result. If argument is TIME, today's date is used; if argument is DATE, time at midnight is used.
-Argument type: DATE/DATETIME/TIMESTAMP/TIME, DATE/DATETIME/TIMESTAMP/TIME
+Argument type: DATE/TIMESTAMP/TIME, DATE/TIMESTAMP/TIME
Return type map:
-(DATE/DATETIME/TIMESTAMP, DATE/DATETIME/TIMESTAMP/TIME) -> DATETIME
+(DATE/TIMESTAMP, DATE/TIMESTAMP/TIME) -> TIMESTAMP
-(TIME, DATE/DATETIME/TIMESTAMP/TIME) -> TIME
+(TIME, DATE/TIMESTAMP/TIME) -> TIME
Antonyms: `SUBTIME`_
@@ -1222,7 +1222,7 @@ Example::
| 10:26:12 |
+---------------------------+
- os> SELECT ADDTIME(TIMESTAMP('2007-02-28 10:20:30'), DATETIME('2002-03-04 20:40:50')) AS `'2007-02-28 10:20:30' + '20:40:50'`
+ os> SELECT ADDTIME(TIMESTAMP('2007-02-28 10:20:30'), TIMESTAMP('2002-03-04 20:40:50')) AS `'2007-02-28 10:20:30' + '20:40:50'`
fetched rows / total rows = 1/1
+--------------------------------------+
| '2007-02-28 10:20:30' + '20:40:50' |
@@ -1237,11 +1237,11 @@ CONVERT_TZ
Description
>>>>>>>>>>>
-Usage: convert_tz(datetime, from_timezone, to_timezone) constructs a datetime object converted from the from_timezone to the to_timezone.
+Usage: convert_tz(timestamp, from_timezone, to_timezone) constructs a timestamp object converted from the from_timezone to the to_timezone.
-Argument type: DATETIME, STRING, STRING
+Argument type: TIMESTAMP, STRING, STRING
-Return type: DATETIME
+Return type: TIMESTAMP
Example::
@@ -1262,7 +1262,7 @@ Example::
| 2010-10-09 23:10:10 |
+---------------------------------------------------------+
-When the datedate, or either of the two time zone fields are invalid format, then the result is null. In this example any datetime that is not will result in null.
+When the datedate, or either of the two time zone fields are invalid format, then the result is null. In this example any timestamp that is not will result in null.
Example::
os> SELECT CONVERT_TZ("test", "+01:00", "-10:00")
@@ -1273,7 +1273,7 @@ Example::
| null |
+------------------------------------------+
-When the datetime, or either of the two time zone fields are invalid format, then the result is null. In this example any timezone that is not <+HH:mm> or <-HH:mm> will result in null.
+When the timestamp, or either of the two time zone fields are invalid format, then the result is null. In this example any timezone that is not <+HH:mm> or <-HH:mm> will result in null.
Example::
os> SELECT CONVERT_TZ("2010-10-10 10:10:10", "test", "-10:00")
@@ -1440,9 +1440,9 @@ DATE
Description
>>>>>>>>>>>
-Usage: date(expr) constructs a date type with the input string expr as a date. If the argument is of date/datetime/timestamp, it extracts the date value part from the expression.
+Usage: date(expr) constructs a date type with the input string expr as a date. If the argument is of date/timestamp, it extracts the date value part from the expression.
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: DATE
@@ -1463,15 +1463,15 @@ DATETIME
Description
>>>>>>>>>>>
-Usage: datetime(datetime)/ datetime(date, to_timezone) Converts the datetime to a new timezone
+Usage: datetime(timestamp)/ datetime(timestamp, to_timezone) Converts the timestamp to a new timezone
-Argument type: DATETIME/STRING
+Argument type: TIMESTAMP/STRING
Return type map:
-(DATETIME, STRING) -> DATETIME
+(TIMESTAMP, STRING) -> TIMESTAMP
-(DATETIME) -> DATETIME
+(TIMESTAMP) -> TIMESTAMP
Example::
@@ -1560,9 +1560,9 @@ Description
Usage: date_add(date, INTERVAL expr unit) adds the interval expr to date. If first argument is TIME, today's date is used; if first argument is DATE, time at midnight is used.
-Argument type: DATE/DATETIME/TIMESTAMP/TIME, INTERVAL
+Argument type: DATE/TIMESTAMP/TIME, INTERVAL
-Return type: DATETIME
+Return type: TIMESTAMP
Synonyms: `ADDDATE`_
@@ -1663,7 +1663,7 @@ If an argument of type TIME is provided, the local date is used.
* - x
- x, for any smallcase/uppercase alphabet except [aydmshiHIMYDSEL]
-Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP, STRING
+Argument type: STRING/DATE/TIME/TIMESTAMP, STRING
Return type: STRING
@@ -1686,9 +1686,9 @@ Description
Usage: date_sub(date, INTERVAL expr unit) subtracts the interval expr from date. If first argument is TIME, today's date is used; if first argument is DATE, time at midnight is used.
-Argument type: DATE/DATETIME/TIMESTAMP/TIME, INTERVAL
+Argument type: DATE/TIMESTAMP/TIME, INTERVAL
-Return type: DATETIME
+Return type: TIMESTAMP
Synonyms: `SUBDATE`_
@@ -1710,7 +1710,7 @@ DATEDIFF
Usage: Calculates the difference of date parts of the given values. If the first argument is time, today's date is used.
-Argument type: DATE/DATETIME/TIMESTAMP/TIME, DATE/DATETIME/TIMESTAMP/TIME
+Argument type: DATE/TIMESTAMP/TIME, DATE/TIMESTAMP/TIME
Return type: LONG
@@ -1733,7 +1733,7 @@ Description
Usage: day(date) extracts the day of the month for date, in the range 1 to 31.
-Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP
+Argument type: STRING/DATE/TIME/TIMESTAMP
Return type: INTEGER
@@ -1758,7 +1758,7 @@ Description
Usage: dayname(date) returns the name of the weekday for date, including Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: STRING
@@ -1781,7 +1781,7 @@ Description
Usage: dayofmonth(date) extracts the day of the month for date, in the range 1 to 31.
-Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP
+Argument type: STRING/DATE/TIME/TIMESTAMP
Return type: INTEGER
@@ -1806,7 +1806,7 @@ Description
Usage: day_of_month(date) extracts the day of the month for date, in the range 1 to 31.
-Argument type: STRING/DATE/TIME/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIME/TIMESTAMP
Return type: INTEGER
@@ -1833,7 +1833,7 @@ Usage: dayofweek(date) returns the weekday index for date (1 = Sunday, 2 = Monda
The `day_of_week` function is also provided as an alias.
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: INTEGER
@@ -1858,7 +1858,7 @@ Usage: dayofyear(date) returns the day of the year for date, in the range 1 to
If an argument of type `TIME` is given, the function will use the current date.
The function `day_of_year`_ is also provided as an alias.
-Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP
+Argument type: STRING/DATE/TIME/TIMESTAMP
Return type: INTEGER
@@ -1872,14 +1872,6 @@ Example::
| 239 |
+---------------------------------+
- os> SELECT DAYOFYEAR(DATETIME('2020-08-26 00:00:00'))
- fetched rows / total rows = 1/1
- +----------------------------------------------+
- | DAYOFYEAR(DATETIME('2020-08-26 00:00:00')) |
- |----------------------------------------------|
- | 239 |
- +----------------------------------------------+
-
os> SELECT DAYOFYEAR(TIMESTAMP('2020-08-26 00:00:00'))
fetched rows / total rows = 1/1
+-----------------------------------------------+
@@ -1898,7 +1890,7 @@ Description
If an argument of type `TIME` is given, the function will use the current date.
This function is an alias to the `dayofyear`_ function
-Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP
+Argument type: STRING/DATE/TIME/TIMESTAMP
Return type: INTEGER
@@ -1912,14 +1904,6 @@ Example::
| 239 |
+-----------------------------------+
- os> SELECT DAY_OF_YEAR(DATETIME('2020-08-26 00:00:00'))
- fetched rows / total rows = 1/1
- +------------------------------------------------+
- | DAY_OF_YEAR(DATETIME('2020-08-26 00:00:00')) |
- |------------------------------------------------|
- | 239 |
- +------------------------------------------------+
-
os> SELECT DAY_OF_YEAR(TIMESTAMP('2020-08-26 00:00:00'))
fetched rows / total rows = 1/1
+-------------------------------------------------+
@@ -2030,7 +2014,7 @@ FROM_UNIXTIME
Description
>>>>>>>>>>>
-Usage: Returns a representation of the argument given as a datetime or character string value. Perform reverse conversion for `UNIX_TIMESTAMP`_ function.
+Usage: Returns a representation of the argument given as a timestamp or character string value. Perform reverse conversion for `UNIX_TIMESTAMP`_ function.
If second argument is provided, it is used to format the result in the same way as the format string used for the `DATE_FORMAT`_ function.
If timestamp is outside of range 1970-01-01 00:00:00 - 3001-01-18 23:59:59.999999 (0 to 32536771199.999999 epoch time), function returns NULL.
@@ -2038,7 +2022,7 @@ Argument type: DOUBLE, STRING
Return type map:
-DOUBLE -> DATETIME
+DOUBLE -> TIMESTAMP
DOUBLE, STRING -> STRING
@@ -2070,7 +2054,7 @@ Description
Usage: Returns a string value containing string format specifiers based on the input arguments.
Argument type: TYPE, STRING
-TYPE must be one of the following tokens: [DATE, TIME, DATETIME, TIMESTAMP].
+TYPE must be one of the following tokens: [DATE, TIME, TIMESTAMP].
STRING must be one of the following tokens: ["USA", "JIS", "ISO", "EUR", "INTERNAL"] (" can be replaced by ').
Examples::
@@ -2093,7 +2077,7 @@ Description
Usage: hour(time) extracts the hour value for time. Different from the time of day value, the time value has a large range and can be greater than 23, so the return value of hour(time) can be also greater than 23.
The function `hour_of_day` is also provided as an alias.
-Argument type: STRING/TIME/DATETIME/TIMESTAMP
+Argument type: STRING/TIME/TIMESTAMP
Return type: INTEGER
@@ -2113,7 +2097,7 @@ LAST_DAY
Usage: Returns the last day of the month as a DATE for a valid argument.
-Argument type: DATE/DATETIME/STRING/TIMESTAMP/TIME
+Argument type: DATE/STRING/TIMESTAMP/TIME
Return type: DATE
@@ -2238,9 +2222,9 @@ MICROSECOND
Description
>>>>>>>>>>>
-Usage: microsecond(expr) returns the microseconds from the time or datetime expression expr as a number in the range from 0 to 999999.
+Usage: microsecond(expr) returns the microseconds from the time or timestamp expression expr as a number in the range from 0 to 999999.
-Argument type: STRING/TIME/DATETIME/TIMESTAMP
+Argument type: STRING/TIME/TIMESTAMP
Return type: INTEGER
@@ -2264,7 +2248,7 @@ Description
Usage: minute(time) returns the minute for time, in the range 0 to 59.
The `minute_of_hour` function is provided as an alias.
-Argument type: STRING/TIME/DATETIME/TIMESTAMP
+Argument type: STRING/TIME/TIMESTAMP
Return type: INTEGER
@@ -2287,7 +2271,7 @@ Description
Usage: minute_of_day(time) returns the minute value for time within a 24 hour day, in the range 0 to 1439.
-Argument type: STRING/TIME/DATETIME/TIMESTAMP
+Argument type: STRING/TIME/TIMESTAMP
Return type: INTEGER
@@ -2312,7 +2296,7 @@ Usage: month(date) returns the month for date, in the range 1 to 12 for January
If an argument of type `TIME` is given, the function will use the current date.
The function `month_of_year` is also provided as an alias.
-Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP
+Argument type: STRING/DATE/TIME/TIMESTAMP
Return type: INTEGER
@@ -2344,7 +2328,7 @@ Description
Usage: monthname(date) returns the full name of the month for date.
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: STRING
@@ -2368,9 +2352,9 @@ Description
Returns the current date and time as a value in 'YYYY-MM-DD hh:mm:ss' format. The value is expressed in the cluster time zone.
`NOW()` returns a constant time that indicates the time at which the statement began to execute. This differs from the behavior for `SYSDATE() <#sysdate>`_, which returns the exact time at which it executes.
-Return type: DATETIME
+Return type: TIMESTAMP
-Specification: NOW() -> DATETIME
+Specification: NOW() -> TIMESTAMP
Example::
@@ -2437,7 +2421,7 @@ Description
Usage: quarter(date) returns the quarter of the year for date, in the range 1 to 4.
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: INTEGER
@@ -2503,7 +2487,7 @@ Description
Usage: second(time) returns the second for time, in the range 0 to 59.
The function `second_of_minute` is provided as an alias
-Argument type: STRING/TIME/DATETIME/TIMESTAMP
+Argument type: STRING/TIME/TIMESTAMP
Return type: INTEGER
@@ -2532,14 +2516,14 @@ STR_TO_DATE
Description
>>>>>>>>>>>
-Usage: str_to_date(string, string) is used to extract a DATETIME from the first argument string using the formats specified in the second argument string.
-The input argument must have enough information to be parsed as a DATE, DATETIME, or TIME.
+Usage: str_to_date(string, string) is used to extract a TIMESTAMP from the first argument string using the formats specified in the second argument string.
+The input argument must have enough information to be parsed as a DATE, TIMESTAMP, or TIME.
Acceptable string format specifiers are the same as those used in the `DATE_FORMAT`_ function.
-It returns NULL when a statement cannot be parsed due to an invalid pair of arguments, and when 0 is provided for any DATE field. Otherwise, it will return a DATETIME with the parsed values (as well as default values for any field that was not parsed).
+It returns NULL when a statement cannot be parsed due to an invalid pair of arguments, and when 0 is provided for any DATE field. Otherwise, it will return a TIMESTAMP with the parsed values (as well as default values for any field that was not parsed).
Argument type: STRING, STRING
-Return type: DATETIME
+Return type: TIMESTAMP
Example::
@@ -2561,15 +2545,15 @@ Description
Usage: subdate(date, INTERVAL expr unit) / subdate(date, days) subtracts the time interval expr from date; subdate(date, days) subtracts the second argument as integer number of days from date.
If first argument is TIME, today's date is used; if first argument is DATE, time at midnight is used.
-Argument type: DATE/DATETIME/TIMESTAMP/TIME, INTERVAL/LONG
+Argument type: DATE/TIMESTAMP/TIME, INTERVAL/LONG
Return type map:
-(DATE/DATETIME/TIMESTAMP/TIME, INTERVAL) -> DATETIME
+(DATE/TIMESTAMP/TIME, INTERVAL) -> TIMESTAMP
(DATE, LONG) -> DATE
-(DATETIME/TIMESTAMP/TIME, LONG) -> DATETIME
+(TIMESTAMP/TIME, LONG) -> TIMESTAMP
Synonyms: `DATE_SUB`_ when invoked with the INTERVAL form of the second argument.
@@ -2594,13 +2578,13 @@ Description
Usage: subtime(expr1, expr2) subtracts expr2 from expr1 and returns the result. If argument is TIME, today's date is used; if argument is DATE, time at midnight is used.
-Argument type: DATE/DATETIME/TIMESTAMP/TIME, DATE/DATETIME/TIMESTAMP/TIME
+Argument type: DATE/TIMESTAMP/TIME, DATE/TIMESTAMP/TIME
Return type map:
-(DATE/DATETIME/TIMESTAMP, DATE/DATETIME/TIMESTAMP/TIME) -> DATETIME
+(DATE/TIMESTAMP, DATE/TIMESTAMP/TIME) -> TIMESTAMP
-(TIME, DATE/DATETIME/TIMESTAMP/TIME) -> TIME
+(TIME, DATE/TIMESTAMP/TIME) -> TIME
Antonyms: `ADDTIME`_
@@ -2638,7 +2622,7 @@ Example::
| 10:14:48 |
+---------------------------+
- os> SELECT SUBTIME(TIMESTAMP('2007-03-01 10:20:30'), DATETIME('2002-03-04 20:40:50')) AS `'2007-03-01 10:20:30' - '20:40:50'`
+ os> SELECT SUBTIME(TIMESTAMP('2007-03-01 10:20:30'), TIMESTAMP('2002-03-04 20:40:50')) AS `'2007-03-01 10:20:30' - '20:40:50'`
fetched rows / total rows = 1/1
+--------------------------------------+
| '2007-03-01 10:20:30' - '20:40:50' |
@@ -2659,9 +2643,9 @@ If the argument is given, it specifies a fractional seconds precision from 0 to
Optional argument type: INTEGER
-Return type: DATETIME
+Return type: TIMESTAMP
-Specification: SYSDATE([INTEGER]) -> DATETIME
+Specification: SYSDATE([INTEGER]) -> TIMESTAMP
Example::
@@ -2680,9 +2664,9 @@ TIME
Description
>>>>>>>>>>>
-Usage: time(expr) constructs a time type with the input string expr as a time. If the argument is of date/datetime/time/timestamp, it extracts the time value part from the expression.
+Usage: time(expr) constructs a time type with the input string expr as a time. If the argument is of date/time/timestamp, it extracts the time value part from the expression.
-Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP
+Argument type: STRING/DATE/TIME/TIMESTAMP
Return type: TIME
@@ -2706,7 +2690,7 @@ Usage: time_format(time, format) formats the time argument using the specifiers
This supports a subset of the time format specifiers available for the `date_format`_ function.
Using date format specifiers supported by `date_format`_ will return 0 or null.
Acceptable format specifiers are listed in the table below.
-If an argument of type DATE is passed in, it is treated as a DATETIME at midnight (i.e., 00:00:00).
+If an argument of type DATE is passed in, it is treated as a TIMESTAMP at midnight (i.e., 00:00:00).
.. list-table:: The following table describes the available specifier arguments.
:widths: 20 80
@@ -2736,7 +2720,7 @@ If an argument of type DATE is passed in, it is treated as a DATETIME at midnigh
- Time, 24-hour (hh:mm:ss)
-Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP, STRING
+Argument type: STRING/DATE/TIME/TIMESTAMP, STRING
Return type: STRING
@@ -2759,7 +2743,7 @@ Description
Usage: time_to_sec(time) returns the time argument, converted to seconds.
-Argument type: STRING/TIME/DATETIME/TIMESTAMP
+Argument type: STRING/TIME/TIMESTAMP
Return type: LONG
@@ -2804,15 +2788,15 @@ Description
>>>>>>>>>>>
Usage: timestamp(expr) constructs a timestamp type with the input string `expr` as an timestamp. If the argument is not a string, it casts `expr` to timestamp type with default timezone UTC. If argument is a time, it applies today's date before cast.
-With two arguments `timestamp(expr1, expr2)` adds the time expression `expr2` to the date or datetime expression `expr1` and returns the result as a timestamp value.
+With two arguments `timestamp(expr1, expr2)` adds the time expression `expr2` to the date or timestamp expression `expr1` and returns the result as a timestamp value.
-Argument type: STRING/DATE/TIME/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIME/TIMESTAMP
Return type map:
-(STRING/DATE/TIME/DATETIME/TIMESTAMP) -> TIMESTAMP
+(STRING/DATE/TIME/TIMESTAMP) -> TIMESTAMP
-(STRING/DATE/TIME/DATETIME/TIMESTAMP, STRING/DATE/TIME/DATETIME/TIMESTAMP) -> TIMESTAMP
+(STRING/DATE/TIME/TIMESTAMP, STRING/DATE/TIME/TIMESTAMP) -> TIMESTAMP
Example::
@@ -2831,11 +2815,11 @@ TIMESTAMPADD
Description
>>>>>>>>>>>
-Usage: Returns a DATETIME value based on a passed in DATE/DATETIME/TIME/TIMESTAMP/STRING argument and an INTERVAL and INTEGER argument which determine the amount of time to be added.
-If the third argument is a STRING, it must be formatted as a valid DATETIME. If only a TIME is provided, a DATETIME is still returned with the DATE portion filled in using the current date.
-If the third argument is a DATE, it will be automatically converted to a DATETIME.
+Usage: Returns a TIMESTAMP value based on a passed in DATE/TIME/TIMESTAMP/STRING argument and an INTERVAL and INTEGER argument which determine the amount of time to be added.
+If the third argument is a STRING, it must be formatted as a valid TIMESTAMP. If only a TIME is provided, a TIMESTAMP is still returned with the DATE portion filled in using the current date.
+If the third argument is a DATE, it will be automatically converted to a TIMESTAMP.
-Argument type: INTERVAL, INTEGER, DATE/DATETIME/TIME/TIMESTAMP/STRING
+Argument type: INTERVAL, INTEGER, DATE/TIME/TIMESTAMP/STRING
INTERVAL must be one of the following tokens: [MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR]
Examples::
@@ -2856,11 +2840,11 @@ Description
>>>>>>>>>>>
Usage: TIMESTAMPDIFF(interval, start, end) returns the difference between the start and end date/times in interval units.
-If a TIME is provided as an argument, it will be converted to a DATETIME with the DATE portion filled in using the current date.
-Arguments will be automatically converted to a DATETIME/TIME/TIMESTAMP when appropriate.
-Any argument that is a STRING must be formatted as a valid DATETIME.
+If a TIME is provided as an argument, it will be converted to a TIMESTAMP with the DATE portion filled in using the current date.
+Arguments will be automatically converted to a TIME/TIMESTAMP when appropriate.
+Any argument that is a STRING must be formatted as a valid TIMESTAMP.
-Argument type: INTERVAL, DATE/DATETIME/TIME/TIMESTAMP/STRING, DATE/DATETIME/TIME/TIMESTAMP/STRING
+Argument type: INTERVAL, DATE/TIME/TIMESTAMP/STRING, DATE/TIME/TIMESTAMP/STRING
INTERVAL must be one of the following tokens: [MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR]
Examples::
@@ -2882,7 +2866,7 @@ Description
Usage: to_days(date) returns the day number (the number of days since year 0) of the given date. Returns NULL if date is invalid.
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: LONG
@@ -2906,7 +2890,7 @@ Description
Usage: to_seconds(date) returns the number of seconds since the year 0 of the given value. Returns NULL if value is invalid.
An argument of a LONG type can be used. It must be formatted as YMMDD, YYMMDD, YYYMMDD or YYYYMMDD. Note that a LONG type argument cannot have leading 0s as it will be parsed using an octal numbering system.
-Argument type: STRING/LONG/DATE/DATETIME/TIME/TIMESTAMP
+Argument type: STRING/LONG/DATE/TIME/TIMESTAMP
Return type: LONG
@@ -2928,11 +2912,11 @@ Description
>>>>>>>>>>>
Usage: Converts given argument to Unix time (seconds since January 1st, 1970 at 00:00:00 UTC). If no argument given, it returns current Unix time.
-The date argument may be a DATE, DATETIME, or TIMESTAMP string, or a number in YYMMDD, YYMMDDhhmmss, YYYYMMDD, or YYYYMMDDhhmmss format. If the argument includes a time part, it may optionally include a fractional seconds part.
+The date argument may be a DATE, TIMESTAMP, or TIMESTAMP string, or a number in YYMMDD, YYMMDDhhmmss, YYYYMMDD, or YYYYMMDDhhmmss format. If the argument includes a time part, it may optionally include a fractional seconds part.
If argument is in invalid format or outside of range 1970-01-01 00:00:00 - 3001-01-18 23:59:59.999999 (0 to 32536771199.999999 epoch time), function returns NULL.
You can use `FROM_UNIXTIME`_ to do reverse conversion.
-Argument type: /DOUBLE/DATE/DATETIME/TIMESTAMP
+Argument type: /DOUBLE/DATE/TIMESTAMP
Return type: DOUBLE
@@ -3009,9 +2993,9 @@ Description
Returns the current UTC timestamp as a value in 'YYYY-MM-DD hh:mm:ss'.
-Return type: DATETIME
+Return type: TIMESTAMP
-Specification: UTC_TIMESTAMP() -> DATETIME
+Specification: UTC_TIMESTAMP() -> TIMESTAMP
Example::
@@ -3075,7 +3059,7 @@ The functions `weekofyear` and `week_of_year` is also provided as an alias.
- 1-53
- with a Monday in this year
-Argument type: DATE/DATETIME/TIME/TIMESTAMP/STRING
+Argument type: DATE/TIME/TIMESTAMP/STRING
Return type: INTEGER
@@ -3100,7 +3084,7 @@ Usage: weekday(date) returns the weekday index for date (0 = Monday, 1 = Tuesday
It is similar to the `dayofweek`_ function, but returns different indexes for each day.
-Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP
+Argument type: STRING/DATE/TIME/TIMESTAMP
Return type: INTEGER
@@ -3124,7 +3108,7 @@ Description
The week_of_year function is a synonym for the `week`_ function.
If an argument of type `TIME` is given, the function will use the current date.
-Argument type: DATE/DATETIME/TIME/TIMESTAMP/STRING
+Argument type: DATE/TIME/TIMESTAMP/STRING
Return type: INTEGER
@@ -3148,7 +3132,7 @@ Description
The weekofyear function is a synonym for the `week`_ function.
If an argument of type `TIME` is given, the function will use the current date.
-Argument type: DATE/DATETIME/TIME/TIMESTAMP/STRING
+Argument type: DATE/TIME/TIMESTAMP/STRING
Return type: INTEGER
@@ -3171,7 +3155,7 @@ Description
Usage: year(date) returns the year for date, in the range 1000 to 9999, or 0 for the “zero” date.
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: INTEGER
@@ -3194,7 +3178,7 @@ Description
Usage: yearweek(date) returns the year and week for date as an integer. It accepts and optional mode arguments aligned with those available for the `WEEK`_ function.
-Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP
+Argument type: STRING/DATE/TIME/TIMESTAMP
Return type: INTEGER
@@ -4514,6 +4498,6 @@ Example::
+----------------+---------------+-----------------+------------------+
| typeof(date) | typeof(int) | typeof(now()) | typeof(column) |
|----------------+---------------+-----------------+------------------|
- | DATE | INTEGER | DATETIME | OBJECT |
+ | DATE | INTEGER | TIMESTAMP | OBJECT |
+----------------+---------------+-----------------+------------------+
diff --git a/docs/user/general/datatypes.rst b/docs/user/general/datatypes.rst
index a265ffd4c9..c423bd7b10 100644
--- a/docs/user/general/datatypes.rst
+++ b/docs/user/general/datatypes.rst
@@ -40,8 +40,6 @@ The OpenSearch SQL Engine support the following data types.
+---------------------+
| timestamp |
+---------------------+
-| datetime |
-+---------------------+
| date |
+---------------------+
| date_nanos |
@@ -128,53 +126,51 @@ Type Conversion Matrix
The following matrix illustrates the conversions allowed by our query engine for all the built-in data types as well as types provided by OpenSearch storage engine.
-+--------------+------------------------------------------------+---------+------------------------------+-----------------------------------------------+--------------------------+---------------------+
-| Data Types | Numeric Type Family | BOOLEAN | String Type Family | Datetime Type Family | OpenSearch Type Family | Complex Type Family |
-| +------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
-| | BYTE | SHORT | INTEGER | LONG | FLOAT | DOUBLE | BOOLEAN | TEXT_KEYWORD | TEXT | STRING | TIMESTAMP | DATE | TIME | DATETIME | INTERVAL | GEO_POINT | IP | BINARY | STRUCT | ARRAY |
-+==============+======+=======+=========+======+=======+========+=========+==============+======+========+===========+======+======+==========+==========+===========+=====+========+===========+=========+
-| UNDEFINED | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE |
-+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
-| BYTE | N/A | IE | IE | IE | IE | IE | X | X | X | E | X | X | X | X | X | X | X | X | X | X |
-+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
-| SHORT | E | N/A | IE | IE | IE | IE | X | X | X | E | X | X | X | X | X | X | X | X | X | X |
-+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
-| INTEGER | E | E | N/A | IE | IE | IE | X | X | X | E | X | X | X | X | X | X | X | X | X | X |
-+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
-| LONG | E | E | E | N/A | IE | IE | X | X | X | E | X | X | X | X | X | X | X | X | X | X |
-+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
-| FLOAT | E | E | E | E | N/A | IE | X | X | X | E | X | X | X | X | X | X | X | X | X | X |
-+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
-| DOUBLE | E | E | E | E | E | N/A | X | X | X | E | X | X | X | X | X | X | X | X | X | X |
-+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
-| BOOLEAN | E | E | E | E | E | E | N/A | X | X | E | X | X | X | X | X | X | X | X | X | X |
-+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
-| TEXT_KEYWORD | | | | | | | | N/A | | IE | | | | X | X | X | X | X | X | X |
-+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
-| TEXT | | | | | | | | | N/A | IE | | | | X | X | X | X | X | X | X |
-+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
-| STRING | E | E | E | E | E | E | IE | X | X | N/A | IE | IE | IE | IE | X | X | X | X | X | X |
-+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
-| TIMESTAMP | X | X | X | X | X | X | X | X | X | E | N/A | IE | IE | IE | X | X | X | X | X | X |
-+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
-| DATE | X | X | X | X | X | X | X | X | X | E | E | N/A | IE | E | X | X | X | X | X | X |
-+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
-| TIME | X | X | X | X | X | X | X | X | X | E | E | E | N/A | E | X | X | X | X | X | X |
-+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
-| DATETIME | X | X | X | X | X | X | X | X | X | E | E | E | E | N/A | X | X | X | X | X | X |
-+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
-| INTERVAL | X | X | X | X | X | X | X | X | X | E | X | X | X | X | N/A | X | X | X | X | X |
-+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
-| GEO_POINT | X | X | X | X | X | X | X | X | X | | X | X | X | X | X | N/A | X | X | X | X |
-+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
-| IP | X | X | X | X | X | X | X | X | X | | X | X | X | X | X | X | N/A | X | X | X |
-+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
-| BINARY | X | X | X | X | X | X | X | X | X | | X | X | X | X | X | X | X | N/A | X | X |
-+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
-| STRUCT | X | X | X | X | X | X | X | X | X | | X | X | X | X | X | X | X | X | N/A | X |
-+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
-| ARRAY | X | X | X | X | X | X | X | X | X | | X | X | X | X | X | X | X | X | X | N/A |
-+--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+----------+-----------+-----+--------+-----------+---------+
++--------------+------------------------------------------------+---------+------------------------------+------------------------------------+--------------------------+---------------------+
+| Data Types | Numeric Type Family | BOOLEAN | String Type Family | Datetime Type Family | OpenSearch Type Family | Complex Type Family |
+| +------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+
+| | BYTE | SHORT | INTEGER | LONG | FLOAT | DOUBLE | BOOLEAN | TEXT_KEYWORD | TEXT | STRING | TIMESTAMP | DATE | TIME | INTERVAL | GEO_POINT | IP | BINARY | STRUCT | ARRAY |
++==============+======+=======+=========+======+=======+========+=========+==============+======+========+===========+======+======+==========+===========+=====+========+===========+=========+
+| UNDEFINED | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE | IE |
++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+
+| BYTE | N/A | IE | IE | IE | IE | IE | X | X | X | E | X | X | X | X | X | X | X | X | X |
++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+
+| SHORT | E | N/A | IE | IE | IE | IE | X | X | X | E | X | X | X | X | X | X | X | X | X |
++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+
+| INTEGER | E | E | N/A | IE | IE | IE | X | X | X | E | X | X | X | X | X | X | X | X | X |
++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+
+| LONG | E | E | E | N/A | IE | IE | X | X | X | E | X | X | X | X | X | X | X | X | X |
++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+
+| FLOAT | E | E | E | E | N/A | IE | X | X | X | E | X | X | X | X | X | X | X | X | X |
++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+
+| DOUBLE | E | E | E | E | E | N/A | X | X | X | E | X | X | X | X | X | X | X | X | X |
++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+--------------+-----------+---------+
+| BOOLEAN | E | E | E | E | E | E | N/A | X | X | E | X | X | X | X | X | X | X | X | X |
++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+
+| TEXT_KEYWORD | | | | | | | | N/A | | IE | | | | X | X | X | X | X | X |
++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+
+| TEXT | | | | | | | | | N/A | IE | | | | X | X | X | X | X | X |
++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+
+| STRING | E | E | E | E | E | E | IE | X | X | N/A | IE | IE | IE | X | X | X | X | X | X |
++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+
+| TIMESTAMP | X | X | X | X | X | X | X | X | X | E | N/A | IE | IE | X | X | X | X | X | X |
++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+
+| DATE | X | X | X | X | X | X | X | X | X | E | E | N/A | IE | X | X | X | X | X | X |
++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+
+| TIME | X | X | X | X | X | X | X | X | X | E | E | E | N/A | X | X | X | X | X | X |
++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+
+| INTERVAL | X | X | X | X | X | X | X | X | X | E | X | X | X | N/A | X | X | X | X | X |
++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+
+| GEO_POINT | X | X | X | X | X | X | X | X | X | | X | X | X | X | N/A | X | X | X | X |
++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+
+| IP | X | X | X | X | X | X | X | X | X | | X | X | X | X | X | N/A | X | X | X |
++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+
+| BINARY | X | X | X | X | X | X | X | X | X | | X | X | X | X | X | X | N/A | X | X |
++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+
+| STRUCT | X | X | X | X | X | X | X | X | X | | X | X | X | X | X | X | X | N/A | X |
++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+
+| ARRAY | X | X | X | X | X | X | X | X | X | | X | X | X | X | X | X | X | X | N/A |
++--------------+------+-------+---------+------+-------+--------+---------+--------------+------+--------+-----------+------+------+----------+-----------+-----+--------+-----------+---------+
Note that:
@@ -236,7 +232,7 @@ Numeric values ranged from -2147483648 to +2147483647 are recognized as integer
Date and Time Data Types
========================
-The datetime types supported by the SQL plugin are ``DATE``, ``TIME``, ``DATETIME``, ``TIMESTAMP``, and ``INTERVAL``, with date and time being used to represent temporal values. By default, the OpenSearch DSL uses ``date`` type as the only date and time related type as it contains all information about an absolute time point. To integrate with SQL language each of the types other than timestamp hold part of the temporal or timezone information. This information can be used to explicitly clarify the date and time types reflected in the datetime functions (see `Functions `_ for details), where some functions might have restrictions in the input argument type.
+The datetime types supported by the SQL plugin are ``DATE``, ``TIME``, ``TIMESTAMP``, and ``INTERVAL``, with date and time being used to represent temporal values. By default, the OpenSearch DSL uses ``date`` type as the only date and time related type as it contains all information about an absolute time point. To integrate with SQL language each of the types other than timestamp hold part of the temporal or timezone information. This information can be used to explicitly clarify the date and time types reflected in the datetime functions (see `Functions `_ for details), where some functions might have restrictions in the input argument type.
Date
----
@@ -262,19 +258,6 @@ Time represents the time on the clock or watch with no regard for which timezone
+------+-----------------------+----------------------------------------------+
-Datetime
---------
-
-Datetime type is the combination of date and time. The conversion rule of date or time to datetime is described in `Conversion between date and time types`_. Datetime type does not contain timezone information. For an absolute time point that contains both date time and timezone information, see `Timestamp`_.
-
-+----------+----------------------------------+--------------------------------------------------------------------+
-| Type | Syntax | Range |
-+==========+==================================+====================================================================+
-| Datetime | 'yyyy-MM-dd hh:mm:ss[.fraction]' | '0001-01-01 00:00:00.000000000' to '9999-12-31 23:59:59.999999999' |
-+----------+----------------------------------+--------------------------------------------------------------------+
-
-
-
Timestamp
---------
@@ -304,16 +287,14 @@ The expr is any expression that can be iterated to a quantity value eventually,
Conversion between date and time types
--------------------------------------
-Basically the date and time types except interval can be converted to each other, but might suffer some alteration of the value or some information loss, for example extracting the time value from a datetime value, or convert a date value to a datetime value and so forth. Here lists the summary of the conversion rules that SQL plugin supports for each of the types:
+Basically the date and time types except interval can be converted to each other, but might suffer some alteration of the value or some information loss, for example extracting the time value from a timestamp value, or convert a date value to a timestamp value and so forth. Here lists the summary of the conversion rules that SQL plugin supports for each of the types:
Conversion from DATE
>>>>>>>>>>>>>>>>>>>>
- Since the date value does not have any time information, conversion to `Time`_ type is not useful, and will always return a zero time value '00:00:00'.
-- Conversion from date to datetime has a data fill-up due to the lack of time information, and it attaches the time '00:00:00' to the original date by default and forms a datetime instance. For example, the result to covert date '2020-08-17' to datetime type is datetime '2020-08-17 00:00:00'.
-
-- Conversion to timestamp is to alternate both the time value and the timezone information, and it attaches the zero time value '00:00:00' and the session timezone (UTC by default) to the date. For example, the result to covert date '2020-08-17' to datetime type with session timezone UTC is datetime '2020-08-17 00:00:00' UTC.
+- Conversion to timestamp is to alternate both the time value and the timezone information, and it attaches the zero time value '00:00:00' and the session timezone (UTC by default) to the date. For example, the result to covert date '2020-08-17' to timestamp type with session timezone UTC is timestamp '2020-08-17 00:00:00' UTC.
Conversion from TIME
@@ -322,20 +303,10 @@ Conversion from TIME
- When time value is converted to any other datetime types, the date part of the new value is filled up with today's date, like with the `CURDATE` function. For example, a time value X converted to a timestamp would produce today's date at time X.
-Conversion from DATETIME
->>>>>>>>>>>>>>>>>>>>>>>>
-
-- Conversion from datetime to date is to extract the date part from the datetime value. For example, the result to convert datetime '2020-08-17 14:09:00' to date is date '2020-08-08'.
-
-- Conversion to time is to extract the time part from the datetime value. For example, the result to convert datetime '2020-08-17 14:09:00' to time is time '14:09:00'.
-
-- Since the datetime type does not contain timezone information, the conversion to timestamp needs to fill up the timezone part with the session timezone. For example, the result to convert datetime '2020-08-17 14:09:00' with system timezone of UTC, to timestamp is timestamp '2020-08-17 14:09:00' UTC.
-
-
Conversion from TIMESTAMP
>>>>>>>>>>>>>>>>>>>>>>>>>
-- Conversion from timestamp is much more straightforward. To convert it to date is to extract the date value, and conversion to time is to extract the time value. Conversion to datetime, it will extracts the datetime value and leave the timezone information over. For example, the result to convert datetime '2020-08-17 14:09:00' UTC to date is date '2020-08-17', to time is '14:09:00' and to datetime is datetime '2020-08-17 14:09:00'.
+- Conversion from timestamp is much more straightforward. To convert it to date is to extract the date value, and conversion to time is to extract the time value. For example, the result to convert timestamp '2020-08-17 14:09:00' UTC to date is date '2020-08-17', to time is '14:09:00'.
Conversion from string to date and time types
---------------------------------------------
diff --git a/docs/user/ppl/functions/datetime.rst b/docs/user/ppl/functions/datetime.rst
index f7c4091753..9e75e41136 100644
--- a/docs/user/ppl/functions/datetime.rst
+++ b/docs/user/ppl/functions/datetime.rst
@@ -17,15 +17,15 @@ Description
Usage: adddate(date, INTERVAL expr unit) / adddate(date, days) adds the interval of second argument to date; adddate(date, days) adds the second argument as integer number of days to date.
If first argument is TIME, today's date is used; if first argument is DATE, time at midnight is used.
-Argument type: DATE/DATETIME/TIMESTAMP/TIME, INTERVAL/LONG
+Argument type: DATE/TIMESTAMP/TIME, INTERVAL/LONG
Return type map:
-(DATE/DATETIME/TIMESTAMP/TIME, INTERVAL) -> DATETIME
+(DATE/TIMESTAMP/TIME, INTERVAL) -> TIMESTAMP
(DATE, LONG) -> DATE
-(DATETIME/TIMESTAMP/TIME, LONG) -> DATETIME
+(TIMESTAMP/TIME, LONG) -> TIMESTAMP
Synonyms: `DATE_ADD`_ when invoked with the INTERVAL form of the second argument.
@@ -51,13 +51,13 @@ Description
Usage: addtime(expr1, expr2) adds expr2 to expr1 and returns the result. If argument is TIME, today's date is used; if argument is DATE, time at midnight is used.
-Argument type: DATE/DATETIME/TIMESTAMP/TIME, DATE/DATETIME/TIMESTAMP/TIME
+Argument type: DATE/TIMESTAMP/TIME, DATE/TIMESTAMP/TIME
Return type map:
-(DATE/DATETIME/TIMESTAMP, DATE/DATETIME/TIMESTAMP/TIME) -> DATETIME
+(DATE/TIMESTAMP, DATE/TIMESTAMP/TIME) -> TIMESTAMP
-(TIME, DATE/DATETIME/TIMESTAMP/TIME) -> TIME
+(TIME, DATE/TIMESTAMP/TIME) -> TIME
Antonyms: `SUBTIME`_
@@ -95,7 +95,7 @@ Example::
| 10:26:12 |
+---------------------------+
- os> source=people | eval `'2007-02-28 10:20:30' + '20:40:50'` = ADDTIME(TIMESTAMP('2007-02-28 10:20:30'), DATETIME('2002-03-04 20:40:50')) | fields `'2007-02-28 10:20:30' + '20:40:50'`
+ os> source=people | eval `'2007-02-28 10:20:30' + '20:40:50'` = ADDTIME(TIMESTAMP('2007-02-28 10:20:30'), TIMESTAMP('2002-03-04 20:40:50')) | fields `'2007-02-28 10:20:30' + '20:40:50'`
fetched rows / total rows = 1/1
+--------------------------------------+
| '2007-02-28 10:20:30' + '20:40:50' |
@@ -110,13 +110,13 @@ CONVERT_TZ
Description
>>>>>>>>>>>
-Usage: convert_tz(datetime, from_timezone, to_timezone) constructs a local datetime converted from the from_timezone to the to_timezone. CONVERT_TZ returns null when any of the three function arguments are invalid, i.e. datetime is not in the format yyyy-MM-dd HH:mm:ss or the timeszone is not in (+/-)HH:mm. It also is invalid for invalid dates, such as February 30th and invalid timezones, which are ones outside of -13:59 and +14:00.
+Usage: convert_tz(timestamp, from_timezone, to_timezone) constructs a local timestamp converted from the from_timezone to the to_timezone. CONVERT_TZ returns null when any of the three function arguments are invalid, i.e. timestamp is not in the format yyyy-MM-dd HH:mm:ss or the timeszone is not in (+/-)HH:mm. It also is invalid for invalid dates, such as February 30th and invalid timezones, which are ones outside of -13:59 and +14:00.
-Argument type: DATETIME, STRING, STRING
+Argument type: TIMESTAMP, STRING, STRING
-Return type: DATETIME
+Return type: TIMESTAMP
-Conversion from +00:00 timezone to +10:00 timezone. Returns the datetime argument converted from +00:00 to +10:00
+Conversion from +00:00 timezone to +10:00 timezone. Returns the timestamp argument converted from +00:00 to +10:00
Example::
os> source=people | eval `convert_tz('2008-05-15 12:00:00','+00:00','+10:00')` = convert_tz('2008-05-15 12:00:00','+00:00','+10:00') | fields `convert_tz('2008-05-15 12:00:00','+00:00','+10:00')`
@@ -349,9 +349,9 @@ DATE
Description
>>>>>>>>>>>
-Usage: date(expr) constructs a date type with the input string expr as a date. If the argument is of date/datetime/timestamp, it extracts the date value part from the expression.
+Usage: date(expr) constructs a date type with the input string expr as a date. If the argument is of date/timestamp, it extracts the date value part from the expression.
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: DATE
@@ -398,9 +398,9 @@ Description
Usage: date_add(date, INTERVAL expr unit) adds the interval expr to date. If first argument is TIME, today's date is used; if first argument is DATE, time at midnight is used.
-Argument type: DATE/DATETIME/TIMESTAMP/TIME, INTERVAL
+Argument type: DATE/TIMESTAMP/TIME, INTERVAL
-Return type: DATETIME
+Return type: TIMESTAMP
Synonyms: `ADDDATE`_
@@ -501,7 +501,7 @@ If an argument of type TIME is provided, the local date is used.
* - x
- x, for any smallcase/uppercase alphabet except [aydmshiHIMYDSEL]
-Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP, STRING
+Argument type: STRING/DATE/TIME/TIMESTAMP, STRING
Return type: STRING
@@ -522,18 +522,18 @@ DATETIME
Description
>>>>>>>>>>>
-Usage: DATETIME(datetime)/ DATETIME(date, to_timezone) Converts the datetime to a new timezone
+Usage: DATETIME(timestamp)/ DATETIME(date, to_timezone) Converts the datetime to a new timezone
-Argument type: DATETIME/STRING
+Argument type: timestamp/STRING
Return type map:
-(DATETIME, STRING) -> DATETIME
+(TIMESTAMP, STRING) -> TIMESTAMP
-(DATETIME) -> DATETIME
+(TIMESTAMP) -> TIMESTAMP
-Converting datetime with timezone to the second argument timezone.
+Converting timestamp with timezone to the second argument timezone.
Example::
os> source=people | eval `DATETIME('2004-02-28 23:00:00-10:00', '+10:00')` = DATETIME('2004-02-28 23:00:00-10:00', '+10:00') | fields `DATETIME('2004-02-28 23:00:00-10:00', '+10:00')`
@@ -545,7 +545,7 @@ Example::
+---------------------------------------------------+
- The valid timezone range for convert_tz is (-13:59, +14:00) inclusive. Timezones outside of the range will result in null.
+The valid timezone range for convert_tz is (-13:59, +14:00) inclusive. Timezones outside of the range will result in null.
Example::
os> source=people | eval `DATETIME('2008-01-01 02:00:00', '-14:00')` = DATETIME('2008-01-01 02:00:00', '-14:00') | fields `DATETIME('2008-01-01 02:00:00', '-14:00')`
@@ -556,17 +556,6 @@ Example::
| null |
+---------------------------------------------+
-The valid timezone range for convert_tz is (-13:59, +14:00) inclusive. Timezones outside of the range will result in null.
-Example::
-
- os> source=people | eval `DATETIME('2008-02-30 02:00:00', '-00:00')` = DATETIME('2008-02-30 02:00:00', '-00:00') | fields `DATETIME('2008-02-30 02:00:00', '-00:00')`
- fetched rows / total rows = 1/1
- +---------------------------------------------+
- | DATETIME('2008-02-30 02:00:00', '-00:00') |
- |---------------------------------------------|
- | null |
- +---------------------------------------------+
-
DATE_SUB
--------
@@ -576,9 +565,9 @@ Description
Usage: date_sub(date, INTERVAL expr unit) subtracts the interval expr from date. If first argument is TIME, today's date is used; if first argument is DATE, time at midnight is used.
-Argument type: DATE/DATETIME/TIMESTAMP/TIME, INTERVAL
+Argument type: DATE/TIMESTAMP/TIME, INTERVAL
-Return type: DATETIME
+Return type: TIMESTAMP
Synonyms: `SUBDATE`_
@@ -600,7 +589,7 @@ DATEDIFF
Usage: Calculates the difference of date parts of given values. If the first argument is time, today's date is used.
-Argument type: DATE/DATETIME/TIMESTAMP/TIME, DATE/DATETIME/TIMESTAMP/TIME
+Argument type: DATE/TIMESTAMP/TIME, DATE/TIMESTAMP/TIME
Return type: LONG
@@ -623,7 +612,7 @@ Description
Usage: day(date) extracts the day of the month for date, in the range 1 to 31.
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: INTEGER
@@ -648,7 +637,7 @@ Description
Usage: dayname(date) returns the name of the weekday for date, including Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: STRING
@@ -671,7 +660,7 @@ Description
Usage: dayofmonth(date) extracts the day of the month for date, in the range 1 to 31.
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: INTEGER
@@ -696,7 +685,7 @@ Description
Usage: day_of_month(date) extracts the day of the month for date, in the range 1 to 31.
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: INTEGER
@@ -721,7 +710,7 @@ Description
Usage: dayofweek(date) returns the weekday index for date (1 = Sunday, 2 = Monday, ..., 7 = Saturday).
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: INTEGER
@@ -746,7 +735,7 @@ Description
Usage: day_of_week(date) returns the weekday index for date (1 = Sunday, 2 = Monday, ..., 7 = Saturday).
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: INTEGER
@@ -771,7 +760,7 @@ Description
Usage: dayofyear(date) returns the day of the year for date, in the range 1 to 366.
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: INTEGER
@@ -796,7 +785,7 @@ Description
Usage: day_of_year(date) returns the day of the year for date, in the range 1 to 366.
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: INTEGER
@@ -913,14 +902,14 @@ FROM_UNIXTIME
Description
>>>>>>>>>>>
-Usage: Returns a representation of the argument given as a datetime or character string value. Perform reverse conversion for `UNIX_TIMESTAMP`_ function.
+Usage: Returns a representation of the argument given as a timestamp or character string value. Perform reverse conversion for `UNIX_TIMESTAMP`_ function.
If second argument is provided, it is used to format the result in the same way as the format string used for the `DATE_FORMAT`_ function.
If timestamp is outside of range 1970-01-01 00:00:00 - 3001-01-18 23:59:59.999999 (0 to 32536771199.999999 epoch time), function returns NULL.
Argument type: DOUBLE, STRING
Return type map:
-DOUBLE -> DATETIME
+DOUBLE -> TIMESTAMP
DOUBLE, STRING -> STRING
@@ -951,7 +940,7 @@ Description
Usage: Returns a string value containing string format specifiers based on the input arguments.
-Argument type: TYPE, STRING, where TYPE must be one of the following tokens: [DATE, TIME, DATETIME, TIMESTAMP], and
+Argument type: TYPE, STRING, where TYPE must be one of the following tokens: [DATE, TIME, TIMESTAMP], and
STRING must be one of the following tokens: ["USA", "JIS", "ISO", "EUR", "INTERNAL"] (" can be replaced by ').
Examples::
@@ -973,7 +962,7 @@ Description
Usage: hour(time) extracts the hour value for time. Different from the time of day value, the time value has a large range and can be greater than 23, so the return value of hour(time) can be also greater than 23.
-Argument type: STRING/TIME/DATETIME/TIMESTAMP
+Argument type: STRING/TIME/TIMESTAMP
Return type: INTEGER
@@ -998,7 +987,7 @@ Description
Usage: hour_of_day(time) extracts the hour value for time. Different from the time of day value, the time value has a large range and can be greater than 23, so the return value of hour_of_day(time) can be also greater than 23.
-Argument type: STRING/TIME/DATETIME/TIMESTAMP
+Argument type: STRING/TIME/TIMESTAMP
Return type: INTEGER
@@ -1020,7 +1009,7 @@ LAST_DAY
Usage: Returns the last day of the month as a DATE for a valid argument.
-Argument type: DATE/DATETIME/STRING/TIMESTAMP/TIME
+Argument type: DATE/STRING/TIMESTAMP/TIME
Return type: DATE
@@ -1145,9 +1134,9 @@ MICROSECOND
Description
>>>>>>>>>>>
-Usage: microsecond(expr) returns the microseconds from the time or datetime expression expr as a number in the range from 0 to 999999.
+Usage: microsecond(expr) returns the microseconds from the time or timestamp expression expr as a number in the range from 0 to 999999.
-Argument type: STRING/TIME/DATETIME/TIMESTAMP
+Argument type: STRING/TIME/TIMESTAMP
Return type: INTEGER
@@ -1170,7 +1159,7 @@ Description
Usage: minute(time) returns the minute for time, in the range 0 to 59.
-Argument type: STRING/TIME/DATETIME/TIMESTAMP
+Argument type: STRING/TIME/TIMESTAMP
Return type: INTEGER
@@ -1195,7 +1184,7 @@ Description
Usage: minute(time) returns the amount of minutes in the day, in the range of 0 to 1439.
-Argument type: STRING/TIME/DATETIME/TIMESTAMP
+Argument type: STRING/TIME/TIMESTAMP
Return type: INTEGER
@@ -1218,7 +1207,7 @@ Description
Usage: minute(time) returns the minute for time, in the range 0 to 59.
-Argument type: STRING/TIME/DATETIME/TIMESTAMP
+Argument type: STRING/TIME/TIMESTAMP
Return type: INTEGER
@@ -1243,7 +1232,7 @@ Description
Usage: month(date) returns the month for date, in the range 1 to 12 for January to December.
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: INTEGER
@@ -1268,7 +1257,7 @@ Description
Usage: month_of_year(date) returns the month for date, in the range 1 to 12 for January to December.
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: INTEGER
@@ -1293,7 +1282,7 @@ Description
Usage: monthname(date) returns the full name of the month for date.
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: STRING
@@ -1317,9 +1306,9 @@ Description
Returns the current date and time as a value in 'YYYY-MM-DD hh:mm:ss' format. The value is expressed in the cluster time zone.
`NOW()` returns a constant time that indicates the time at which the statement began to execute. This differs from the behavior for `SYSDATE() <#sysdate>`_, which returns the exact time at which it executes.
-Return type: DATETIME
+Return type: TIMESTAMP
-Specification: NOW() -> DATETIME
+Specification: NOW() -> TIMESTAMP
Example::
@@ -1386,7 +1375,7 @@ Description
Usage: quarter(date) returns the quarter of the year for date, in the range 1 to 4.
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: INTEGER
@@ -1435,7 +1424,7 @@ Description
Usage: second(time) returns the second for time, in the range 0 to 59.
-Argument type: STRING/TIME/DATETIME/TIMESTAMP
+Argument type: STRING/TIME/TIMESTAMP
Return type: INTEGER
@@ -1460,7 +1449,7 @@ Description
Usage: second_of_minute(time) returns the second for time, in the range 0 to 59.
-Argument type: STRING/TIME/DATETIME/TIMESTAMP
+Argument type: STRING/TIME/TIMESTAMP
Return type: INTEGER
@@ -1483,14 +1472,14 @@ STR_TO_DATE
Description
>>>>>>>>>>>
-Usage: str_to_date(string, string) is used to extract a DATETIME from the first argument string using the formats specified in the second argument string.
-The input argument must have enough information to be parsed as a DATE, DATETIME, or TIME.
+Usage: str_to_date(string, string) is used to extract a TIMESTAMP from the first argument string using the formats specified in the second argument string.
+The input argument must have enough information to be parsed as a DATE, TIMESTAMP, or TIME.
Acceptable string format specifiers are the same as those used in the `DATE_FORMAT`_ function.
-It returns NULL when a statement cannot be parsed due to an invalid pair of arguments, and when 0 is provided for any DATE field. Otherwise, it will return a DATETIME with the parsed values (as well as default values for any field that was not parsed).
+It returns NULL when a statement cannot be parsed due to an invalid pair of arguments, and when 0 is provided for any DATE field. Otherwise, it will return a TIMESTAMP with the parsed values (as well as default values for any field that was not parsed).
Argument type: STRING, STRING
-Return type: DATETIME
+Return type: TIMESTAMP
Example::
@@ -1512,15 +1501,15 @@ Description
Usage: subdate(date, INTERVAL expr unit) / subdate(date, days) subtracts the interval expr from date; subdate(date, days) subtracts the second argument as integer number of days from date.
If first argument is TIME, today's date is used; if first argument is DATE, time at midnight is used.
-Argument type: DATE/DATETIME/TIMESTAMP/TIME, INTERVAL/LONG
+Argument type: DATE/TIMESTAMP/TIME, INTERVAL/LONG
Return type map:
-(DATE/DATETIME/TIMESTAMP/TIME, INTERVAL) -> DATETIME
+(DATE/TIMESTAMP/TIME, INTERVAL) -> TIMESTAMP
(DATE, LONG) -> DATE
-(DATETIME/TIMESTAMP/TIME, LONG) -> DATETIME
+(TIMESTAMP/TIME, LONG) -> TIMESTAMP
Synonyms: `DATE_SUB`_ when invoked with the INTERVAL form of the second argument.
@@ -1545,13 +1534,13 @@ Description
Usage: subtime(expr1, expr2) subtracts expr2 from expr1 and returns the result. If argument is TIME, today's date is used; if argument is DATE, time at midnight is used.
-Argument type: DATE/DATETIME/TIMESTAMP/TIME, DATE/DATETIME/TIMESTAMP/TIME
+Argument type: DATE/TIMESTAMP/TIME, DATE/TIMESTAMP/TIME
Return type map:
-(DATE/DATETIME/TIMESTAMP, DATE/DATETIME/TIMESTAMP/TIME) -> DATETIME
+(DATE/TIMESTAMP, DATE/TIMESTAMP/TIME) -> TIMESTAMP
-(TIME, DATE/DATETIME/TIMESTAMP/TIME) -> TIME
+(TIME, DATE/TIMESTAMP/TIME) -> TIME
Antonyms: `ADDTIME`_
@@ -1589,7 +1578,7 @@ Example::
| 10:14:48 |
+---------------------------+
- os> source=people | eval `'2007-03-01 10:20:30' - '20:40:50'` = SUBTIME(TIMESTAMP('2007-03-01 10:20:30'), DATETIME('2002-03-04 20:40:50')) | fields `'2007-03-01 10:20:30' - '20:40:50'`
+ os> source=people | eval `'2007-03-01 10:20:30' - '20:40:50'` = SUBTIME(TIMESTAMP('2007-03-01 10:20:30'), TIMESTAMP('2002-03-04 20:40:50')) | fields `'2007-03-01 10:20:30' - '20:40:50'`
fetched rows / total rows = 1/1
+--------------------------------------+
| '2007-03-01 10:20:30' - '20:40:50' |
@@ -1610,9 +1599,9 @@ If the argument is given, it specifies a fractional seconds precision from 0 to
Optional argument type: INTEGER
-Return type: DATETIME
+Return type: TIMESTAMP
-Specification: SYSDATE([INTEGER]) -> DATETIME
+Specification: SYSDATE([INTEGER]) -> TIMESTAMP
Example::
@@ -1631,9 +1620,9 @@ TIME
Description
>>>>>>>>>>>
-Usage: time(expr) constructs a time type with the input string expr as a time. If the argument is of date/datetime/time/timestamp, it extracts the time value part from the expression.
+Usage: time(expr) constructs a time type with the input string expr as a time. If the argument is of date/time/timestamp, it extracts the time value part from the expression.
-Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP
+Argument type: STRING/DATE/TIME/TIMESTAMP
Return type: TIME
@@ -1682,7 +1671,7 @@ Usage: time_format(time, format) formats the time argument using the specifiers
This supports a subset of the time format specifiers available for the `date_format`_ function.
Using date format specifiers supported by `date_format`_ will return 0 or null.
Acceptable format specifiers are listed in the table below.
-If an argument of type DATE is passed in, it is treated as a DATETIME at midnight (i.e., 00:00:00).
+If an argument of type DATE is passed in, it is treated as a TIMESTAMP at midnight (i.e., 00:00:00).
.. list-table:: The following table describes the available specifier arguments.
:widths: 20 80
@@ -1712,7 +1701,7 @@ If an argument of type DATE is passed in, it is treated as a DATETIME at midnigh
- Time, 24-hour (hh:mm:ss)
-Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP, STRING
+Argument type: STRING/DATE/TIME/TIMESTAMP, STRING
Return type: STRING
@@ -1735,7 +1724,7 @@ Description
Usage: time_to_sec(time) returns the time argument, converted to seconds.
-Argument type: STRING/TIME/DATETIME/TIMESTAMP
+Argument type: STRING/TIME/TIMESTAMP
Return type: LONG
@@ -1780,15 +1769,15 @@ Description
>>>>>>>>>>>
Usage: timestamp(expr) constructs a timestamp type with the input string `expr` as an timestamp. If the argument is not a string, it casts `expr` to timestamp type with default timezone UTC. If argument is a time, it applies today's date before cast.
-With two arguments `timestamp(expr1, expr2)` adds the time expression `expr2` to the date or datetime expression `expr1` and returns the result as a timestamp value.
+With two arguments `timestamp(expr1, expr2)` adds the time expression `expr2` to the date or timestamp expression `expr1` and returns the result as a timestamp value.
-Argument type: STRING/DATE/TIME/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIME/TIMESTAMP
Return type map:
-(STRING/DATE/TIME/DATETIME/TIMESTAMP) -> TIMESTAMP
+(STRING/DATE/TIME/TIMESTAMP) -> TIMESTAMP
-(STRING/DATE/TIME/DATETIME/TIMESTAMP, STRING/DATE/TIME/DATETIME/TIMESTAMP) -> TIMESTAMP
+(STRING/DATE/TIME/TIMESTAMP, STRING/DATE/TIME/TIMESTAMP) -> TIMESTAMP
Example::
@@ -1807,11 +1796,11 @@ TIMESTAMPADD
Description
>>>>>>>>>>>
-Usage: Returns a DATETIME value based on a passed in DATE/DATETIME/TIME/TIMESTAMP/STRING argument and an INTERVAL and INTEGER argument which determine the amount of time to be added.
-If the third argument is a STRING, it must be formatted as a valid DATETIME. If only a TIME is provided, a DATETIME is still returned with the DATE portion filled in using the current date.
-If the third argument is a DATE, it will be automatically converted to a DATETIME.
+Usage: Returns a TIMESTAMP value based on a passed in DATE/TIME/TIMESTAMP/STRING argument and an INTERVAL and INTEGER argument which determine the amount of time to be added.
+If the third argument is a STRING, it must be formatted as a valid TIMESTAMP. If only a TIME is provided, a TIMESTAMP is still returned with the DATE portion filled in using the current date.
+If the third argument is a DATE, it will be automatically converted to a TIMESTAMP.
-Argument type: INTERVAL, INTEGER, DATE/DATETIME/TIME/TIMESTAMP/STRING
+Argument type: INTERVAL, INTEGER, DATE/TIME/TIMESTAMP/STRING
INTERVAL must be one of the following tokens: [MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR]
@@ -1833,11 +1822,11 @@ Description
>>>>>>>>>>>
Usage: TIMESTAMPDIFF(interval, start, end) returns the difference between the start and end date/times in interval units.
-If a TIME is provided as an argument, it will be converted to a DATETIME with the DATE portion filled in using the current date.
-Arguments will be automatically converted to a DATETIME/TIME/TIMESTAMP when appropriate.
-Any argument that is a STRING must be formatted as a valid DATETIME.
+If a TIME is provided as an argument, it will be converted to a TIMESTAMP with the DATE portion filled in using the current date.
+Arguments will be automatically converted to a TIME/TIMESTAMP when appropriate.
+Any argument that is a STRING must be formatted as a valid TIMESTAMP.
-Argument type: INTERVAL, DATE/DATETIME/TIME/TIMESTAMP/STRING, DATE/DATETIME/TIME/TIMESTAMP/STRING
+Argument type: INTERVAL, DATE/TIME/TIMESTAMP/STRING, DATE/TIME/TIMESTAMP/STRING
INTERVAL must be one of the following tokens: [MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR]
@@ -1860,7 +1849,7 @@ Description
Usage: to_days(date) returns the day number (the number of days since year 0) of the given date. Returns NULL if date is invalid.
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: LONG
@@ -1884,7 +1873,7 @@ Description
Usage: to_seconds(date) returns the number of seconds since the year 0 of the given value. Returns NULL if value is invalid.
An argument of a LONG type can be used. It must be formatted as YMMDD, YYMMDD, YYYMMDD or YYYYMMDD. Note that a LONG type argument cannot have leading 0s as it will be parsed using an octal numbering system.
-Argument type: STRING/LONG/DATE/DATETIME/TIME/TIMESTAMP
+Argument type: STRING/LONG/DATE/TIME/TIMESTAMP
Return type: LONG
@@ -1906,11 +1895,11 @@ Description
>>>>>>>>>>>
Usage: Converts given argument to Unix time (seconds since Epoch - very beginning of year 1970). If no argument given, it returns the current Unix time.
-The date argument may be a DATE, DATETIME, or TIMESTAMP string, or a number in YYMMDD, YYMMDDhhmmss, YYYYMMDD, or YYYYMMDDhhmmss format. If the argument includes a time part, it may optionally include a fractional seconds part.
+The date argument may be a DATE, or TIMESTAMP string, or a number in YYMMDD, YYMMDDhhmmss, YYYYMMDD, or YYYYMMDDhhmmss format. If the argument includes a time part, it may optionally include a fractional seconds part.
If argument is in invalid format or outside of range 1970-01-01 00:00:00 - 3001-01-18 23:59:59.999999 (0 to 32536771199.999999 epoch time), function returns NULL.
You can use `FROM_UNIXTIME`_ to do reverse conversion.
-Argument type: /DOUBLE/DATE/DATETIME/TIMESTAMP
+Argument type: /DOUBLE/DATE/TIMESTAMP
Return type: DOUBLE
@@ -1979,9 +1968,9 @@ Description
Returns the current UTC timestamp as a value in 'YYYY-MM-DD hh:mm:ss'.
-Return type: DATETIME
+Return type: TIMESTAMP
-Specification: UTC_TIMESTAMP() -> DATETIME
+Specification: UTC_TIMESTAMP() -> TIMESTAMP
Example::
@@ -2043,7 +2032,7 @@ Usage: week(date[, mode]) returns the week number for date. If the mode argument
- 1-53
- with a Monday in this year
-Argument type: DATE/DATETIME/TIMESTAMP/STRING
+Argument type: DATE/TIMESTAMP/STRING
Return type: INTEGER
@@ -2070,7 +2059,7 @@ Usage: weekday(date) returns the weekday index for date (0 = Monday, 1 = Tuesday
It is similar to the `dayofweek`_ function, but returns different indexes for each day.
-Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP
+Argument type: STRING/DATE/TIME/TIMESTAMP
Return type: INTEGER
@@ -2134,7 +2123,7 @@ Usage: week_of_year(date[, mode]) returns the week number for date. If the mode
- 1-53
- with a Monday in this year
-Argument type: DATE/DATETIME/TIMESTAMP/STRING
+Argument type: DATE/TIMESTAMP/STRING
Return type: INTEGER
@@ -2159,7 +2148,7 @@ Description
Usage: year(date) returns the year for date, in the range 1000 to 9999, or 0 for the “zero” date.
-Argument type: STRING/DATE/DATETIME/TIMESTAMP
+Argument type: STRING/DATE/TIMESTAMP
Return type: INTEGER
@@ -2182,7 +2171,7 @@ Description
Usage: yearweek(date) returns the year and week for date as an integer. It accepts and optional mode arguments aligned with those available for the `WEEK`_ function.
-Argument type: STRING/DATE/DATETIME/TIME/TIMESTAMP
+Argument type: STRING/DATE/TIME/TIMESTAMP
Return type: INTEGER
diff --git a/docs/user/ppl/functions/system.rst b/docs/user/ppl/functions/system.rst
index fbe9860dce..cfe0414c49 100644
--- a/docs/user/ppl/functions/system.rst
+++ b/docs/user/ppl/functions/system.rst
@@ -27,5 +27,5 @@ Example::
+----------------+---------------+-----------------+------------------+
| typeof(date) | typeof(int) | typeof(now()) | typeof(column) |
|----------------+---------------+-----------------+------------------|
- | DATE | INTEGER | DATETIME | OBJECT |
+ | DATE | INTEGER | TIMESTAMP | OBJECT |
+----------------+---------------+-----------------+------------------+
diff --git a/docs/user/ppl/general/datatypes.rst b/docs/user/ppl/general/datatypes.rst
index cabc689526..18555dec3d 100644
--- a/docs/user/ppl/general/datatypes.rst
+++ b/docs/user/ppl/general/datatypes.rst
@@ -39,8 +39,6 @@ The PPL support the following data types.
+---------------+
| timestamp |
+---------------+
-| datetime |
-+---------------+
| date |
+---------------+
| time |
@@ -114,7 +112,7 @@ Numeric values ranged from -2147483648 to +2147483647 are recognized as integer
Date and Time Data Types
========================
-The date and time data types are the types that represent temporal values and PPL plugin supports types including DATE, TIME, DATETIME, TIMESTAMP and INTERVAL. By default, the OpenSearch DSL uses date type as the only date and time related type, which has contained all information about an absolute time point. To integrate with PPL language, each of the types other than timestamp is holding part of temporal or timezone information, and the usage to explicitly clarify the date and time types is reflected in the datetime functions (see `Functions `_ for details), where some functions might have restrictions in the input argument type.
+The date and time data types are the types that represent temporal values and PPL plugin supports types including DATE, TIME, TIMESTAMP and INTERVAL. By default, the OpenSearch DSL uses date type as the only date and time related type, which has contained all information about an absolute time point. To integrate with PPL language, each of the types other than timestamp is holding part of temporal or timezone information, and the usage to explicitly clarify the date and time types is reflected in the datetime functions (see `Functions `_ for details), where some functions might have restrictions in the input argument type.
Date
@@ -141,19 +139,6 @@ Time represents the time on the clock or watch with no regard for which timezone
+------+-----------------------+----------------------------------------+
-Datetime
---------
-
-Datetime type is the combination of date and time. The conversion rule of date or time to datetime is described in `Conversion between date and time types`_. Datetime type does not contain timezone information. For an absolute time point that contains both date time and timezone information, see `Timestamp`_.
-
-+----------+----------------------------------+--------------------------------------------------------------+
-| Type | Syntax | Range |
-+==========+==================================+==============================================================+
-| Datetime | 'yyyy-MM-dd hh:mm:ss[.fraction]' | '0001-01-01 00:00:00.000000' to '9999-12-31 23:59:59.999999' |
-+----------+----------------------------------+--------------------------------------------------------------+
-
-
-
Timestamp
---------
@@ -183,38 +168,26 @@ The expr is any expression that can be iterated to a quantity value eventually,
Conversion between date and time types
--------------------------------------
-Basically the date and time types except interval can be converted to each other, but might suffer some alteration of the value or some information loss, for example extracting the time value from a datetime value, or convert a date value to a datetime value and so forth. Here lists the summary of the conversion rules that PPL plugin supports for each of the types:
+Basically the date and time types except interval can be converted to each other, but might suffer some alteration of the value or some information loss, for example extracting the time value from a timestamp value, or convert a date value to a timestamp value and so forth. Here lists the summary of the conversion rules that PPL plugin supports for each of the types:
Conversion from DATE
>>>>>>>>>>>>>>>>>>>>
- Since the date value does not have any time information, conversion to `Time`_ type is not useful, and will always return a zero time value '00:00:00'.
-- Conversion from date to datetime has a data fill-up due to the lack of time information, and it attaches the time '00:00:00' to the original date by default and forms a datetime instance. For example, the result to covert date '2020-08-17' to datetime type is datetime '2020-08-17 00:00:00'.
-
-- Conversion to timestamp is to alternate both the time value and the timezone information, and it attaches the zero time value '00:00:00' and the session timezone (UTC by default) to the date. For example, the result to covert date '2020-08-17' to datetime type with session timezone UTC is datetime '2020-08-17 00:00:00' UTC.
+- Conversion to timestamp is to alternate both the time value and the timezone information, and it attaches the zero time value '00:00:00' and the session timezone (UTC by default) to the date. For example, the result to covert date '2020-08-17' to timestamp type with session timezone UTC is timestamp '2020-08-17 00:00:00' UTC.
Conversion from TIME
>>>>>>>>>>>>>>>>>>>>
-- Time value cannot be converted to any other date and time types since it does not contain any date information, so it is not meaningful to give no date info to a date/datetime/timestamp instance.
-
-
-Conversion from DATETIME
->>>>>>>>>>>>>>>>>>>>>>>>
-
-- Conversion from datetime to date is to extract the date part from the datetime value. For example, the result to convert datetime '2020-08-17 14:09:00' to date is date '2020-08-08'.
-
-- Conversion to time is to extract the time part from the datetime value. For example, the result to convert datetime '2020-08-17 14:09:00' to time is time '14:09:00'.
-
-- Since the datetime type does not contain timezone information, the conversion to timestamp needs to fill up the timezone part with the session timezone. For example, the result to convert datetime '2020-08-17 14:09:00' with system timezone of UTC, to timestamp is timestamp '2020-08-17 14:09:00' UTC.
+- Time value cannot be converted to any other date and time types since it does not contain any date information, so it is not meaningful to give no date info to a date/timestamp instance.
Conversion from TIMESTAMP
>>>>>>>>>>>>>>>>>>>>>>>>>
-- Conversion from timestamp is much more straightforward. To convert it to date is to extract the date value, and conversion to time is to extract the time value. Conversion to datetime, it will extracts the datetime value and leave the timezone information over. For example, the result to convert datetime '2020-08-17 14:09:00' UTC to date is date '2020-08-17', to time is '14:09:00' and to datetime is datetime '2020-08-17 14:09:00'.
+- Conversion from timestamp is much more straightforward. To convert it to date is to extract the date value, and conversion to time is to extract the time value. For example, the result to convert timestamp '2020-08-17 14:09:00' UTC to date is date '2020-08-17', to time is '14:09:00'.
String Data Types
diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/ConvertTZFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/ConvertTZFunctionIT.java
index 105669c7ca..a0749387d5 100644
--- a/integ-test/src/test/java/org/opensearch/sql/ppl/ConvertTZFunctionIT.java
+++ b/integ-test/src/test/java/org/opensearch/sql/ppl/ConvertTZFunctionIT.java
@@ -30,7 +30,7 @@ public void inRangeZeroToPositive() throws IOException {
"source=%s | eval f = convert_tz('2008-05-15 12:00:00','+00:00','+10:00') | fields"
+ " f",
TEST_INDEX_DATE));
- verifySchema(result, schema("f", null, "datetime"));
+ verifySchema(result, schema("f", null, "timestamp"));
verifySome(result.getJSONArray("datarows"), rows("2008-05-15 22:00:00"));
}
@@ -42,7 +42,7 @@ public void inRangeZeroToZero() throws IOException {
"source=%s | eval f = convert_tz('2021-05-12 00:00:00','-00:00','+00:00') | fields"
+ " f",
TEST_INDEX_DATE));
- verifySchema(result, schema("f", null, "datetime"));
+ verifySchema(result, schema("f", null, "timestamp"));
verifySome(result.getJSONArray("datarows"), rows("2021-05-12 00:00:00"));
}
@@ -54,7 +54,7 @@ public void inRangePositiveToPositive() throws IOException {
"source=%s | eval f = convert_tz('2021-05-12 00:00:00','+10:00','+11:00') | fields"
+ " f",
TEST_INDEX_DATE));
- verifySchema(result, schema("f", null, "datetime"));
+ verifySchema(result, schema("f", null, "timestamp"));
verifySome(result.getJSONArray("datarows"), rows("2021-05-12 01:00:00"));
}
@@ -66,7 +66,7 @@ public void inRangeNegativeToPositive() throws IOException {
"source=%s | eval f = convert_tz('2021-05-12 11:34:50','-08:00','+09:00') | fields"
+ " f",
TEST_INDEX_DATE));
- verifySchema(result, schema("f", null, "datetime"));
+ verifySchema(result, schema("f", null, "timestamp"));
verifySome(result.getJSONArray("datarows"), rows("2021-05-13 04:34:50"));
}
@@ -78,7 +78,7 @@ public void inRangeNoTZChange() throws IOException {
"source=%s | eval f = convert_tz('2021-05-12 11:34:50','+09:00','+09:00') | fields"
+ " f",
TEST_INDEX_DATE));
- verifySchema(result, schema("f", null, "datetime"));
+ verifySchema(result, schema("f", null, "timestamp"));
verifySome(result.getJSONArray("datarows"), rows("2021-05-12 11:34:50"));
}
@@ -90,7 +90,7 @@ public void inRangeTwentyFourHourChange() throws IOException {
"source=%s | eval f = convert_tz('2021-05-12 11:34:50','-12:00','+12:00') | fields"
+ " f",
TEST_INDEX_DATE));
- verifySchema(result, schema("f", null, "datetime"));
+ verifySchema(result, schema("f", null, "timestamp"));
verifySome(result.getJSONArray("datarows"), rows("2021-05-13 11:34:50"));
}
@@ -102,7 +102,7 @@ public void inRangeFifteenMinuteTZ() throws IOException {
"source=%s | eval f = convert_tz('2021-05-12 13:00:00','+09:30','+05:45') | fields"
+ " f",
TEST_INDEX_DATE));
- verifySchema(result, schema("f", null, "datetime"));
+ verifySchema(result, schema("f", null, "timestamp"));
verifySome(result.getJSONArray("datarows"), rows("2021-05-12 09:15:00"));
}
@@ -114,7 +114,7 @@ public void nullFromFieldUnder() throws IOException {
"source=%s | eval f = convert_tz('2021-05-30 11:34:50','-17:00','+08:00') | fields"
+ " f",
TEST_INDEX_DATE));
- verifySchema(result, schema("f", null, "datetime"));
+ verifySchema(result, schema("f", null, "timestamp"));
verifySome(result.getJSONArray("datarows"), rows(new Object[] {null}));
}
@@ -126,7 +126,7 @@ public void nullToFieldOver() throws IOException {
"source=%s | eval f = convert_tz('2021-05-12 11:34:50','-12:00','+15:00') | fields"
+ " f",
TEST_INDEX_DATE));
- verifySchema(result, schema("f", null, "datetime"));
+ verifySchema(result, schema("f", null, "timestamp"));
verifySome(result.getJSONArray("datarows"), rows(new Object[] {null}));
}
@@ -137,7 +137,7 @@ public void nullFromGarbageInput1() throws IOException {
String.format(
"source=%s | eval f = convert_tz('2021-05-12 11:34:50','-12:00','test') | fields f",
TEST_INDEX_DATE));
- verifySchema(result, schema("f", null, "datetime"));
+ verifySchema(result, schema("f", null, "timestamp"));
verifySome(result.getJSONArray("datarows"), rows(new Object[] {null}));
}
@@ -148,7 +148,7 @@ public void nullFromGarbageInput2() throws IOException {
String.format(
"source=%s | eval f = convert_tz('2021test','-12:00','+00:00') | fields f",
TEST_INDEX_DATE));
- verifySchema(result, schema("f", null, "datetime"));
+ verifySchema(result, schema("f", null, "timestamp"));
verifySome(result.getJSONArray("datarows"), rows(new Object[] {null}));
}
@@ -160,7 +160,7 @@ public void nullDateTimeInvalidDateValueFebruary() throws IOException {
"source=%s | eval f = convert_tz('2021-02-30 10:00:00','+00:00','+00:00') | fields"
+ " f",
TEST_INDEX_DATE));
- verifySchema(result, schema("f", null, "datetime"));
+ verifySchema(result, schema("f", null, "timestamp"));
verifySome(result.getJSONArray("datarows"), rows(new Object[] {null}));
}
@@ -172,7 +172,7 @@ public void nullDateTimeInvalidDateValueApril() throws IOException {
"source=%s | eval f = convert_tz('2021-04-31 10:00:00','+00:00','+00:00') | fields"
+ " f",
TEST_INDEX_DATE));
- verifySchema(result, schema("f", null, "datetime"));
+ verifySchema(result, schema("f", null, "timestamp"));
verifySome(result.getJSONArray("datarows"), rows(new Object[] {null}));
}
@@ -184,7 +184,7 @@ public void nullDateTimeInvalidDateValueMonth() throws IOException {
"source=%s | eval f = convert_tz('2021-13-03 10:00:00','+00:00','+00:00') | fields"
+ " f",
TEST_INDEX_DATE));
- verifySchema(result, schema("f", null, "datetime"));
+ verifySchema(result, schema("f", null, "timestamp"));
verifySome(result.getJSONArray("datarows"), rows(new Object[] {null}));
}
}
diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeComparisonIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeComparisonIT.java
index 6f6b5cc297..7cc083cbb6 100644
--- a/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeComparisonIT.java
+++ b/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeComparisonIT.java
@@ -98,32 +98,6 @@ public static Iterable