Skip to content

Commit 25beda0

Browse files
Remove Datetime data type (opensearch-project#1980)
* Remove Datetime data type (opensearch-project#336) * removed datetime type, updated tests and documentation Signed-off-by: Matthew Wells <[email protected]> * removed duplicate test code, replaced calls of ZoneOffset.UTC with a constant Signed-off-by: Matthew Wells <[email protected]> * readded test and edited it to return timestamp, fixed minor checkstyle difference Signed-off-by: Matthew Wells <[email protected]> * converted all utc timezone/zone id to be ZoneOffset.UTC Signed-off-by: Matthew Wells <[email protected]> * Spotless Apply Signed-off-by: Matthew Wells <[email protected]> * Added tests back in and updated to work with timestamp Signed-off-by: Matthew Wells <[email protected]> * Spotless Apply Signed-off-by: Matthew Wells <[email protected]> * removed duplicate tests, renamed test Signed-off-by: Matthew Wells <[email protected]> --------- Signed-off-by: Matthew Wells <[email protected]>
1 parent 752da21 commit 25beda0

File tree

82 files changed

+1063
-2611
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1063
-2611
lines changed

core/src/main/java/org/opensearch/sql/data/model/ExprDateValue.java

+2-8
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
package org.opensearch.sql.data.model;
77

88
import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL;
9-
import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID;
109

1110
import com.google.common.base.Objects;
1211
import java.time.Instant;
1312
import java.time.LocalDate;
14-
import java.time.LocalDateTime;
1513
import java.time.LocalTime;
14+
import java.time.ZoneOffset;
1615
import java.time.ZonedDateTime;
1716
import java.time.format.DateTimeFormatter;
1817
import java.time.format.DateTimeParseException;
@@ -57,14 +56,9 @@ public LocalTime timeValue() {
5756
return LocalTime.of(0, 0, 0);
5857
}
5958

60-
@Override
61-
public LocalDateTime datetimeValue() {
62-
return LocalDateTime.of(date, timeValue());
63-
}
64-
6559
@Override
6660
public Instant timestampValue() {
67-
return ZonedDateTime.of(date, timeValue(), UTC_ZONE_ID).toInstant();
61+
return ZonedDateTime.of(date, timeValue(), ZoneOffset.UTC).toInstant();
6862
}
6963

7064
@Override

core/src/main/java/org/opensearch/sql/data/model/ExprDatetimeValue.java

-99
This file was deleted.

core/src/main/java/org/opensearch/sql/data/model/ExprStringValue.java

+8-14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package org.opensearch.sql.data.model;
77

8+
import java.time.Instant;
89
import java.time.LocalDate;
910
import java.time.LocalDateTime;
1011
import java.time.LocalTime;
@@ -35,27 +36,20 @@ public String stringValue() {
3536
}
3637

3738
@Override
38-
public LocalDateTime datetimeValue() {
39+
public Instant timestampValue() {
3940
try {
40-
return new ExprDatetimeValue(value).datetimeValue();
41+
return new ExprTimestampValue(value).timestampValue();
4142
} catch (SemanticCheckException e) {
42-
try {
43-
return new ExprDatetimeValue(
44-
LocalDateTime.of(new ExprDateValue(value).dateValue(), LocalTime.of(0, 0, 0)))
45-
.datetimeValue();
46-
} catch (SemanticCheckException exception) {
47-
throw new SemanticCheckException(
48-
String.format(
49-
"datetime:%s in unsupported format, please use 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'",
50-
value));
51-
}
43+
return new ExprTimestampValue(
44+
LocalDateTime.of(new ExprDateValue(value).dateValue(), LocalTime.of(0, 0, 0)))
45+
.timestampValue();
5246
}
5347
}
5448

5549
@Override
5650
public LocalDate dateValue() {
5751
try {
58-
return new ExprDatetimeValue(value).dateValue();
52+
return new ExprTimestampValue(value).dateValue();
5953
} catch (SemanticCheckException e) {
6054
return new ExprDateValue(value).dateValue();
6155
}
@@ -64,7 +58,7 @@ public LocalDate dateValue() {
6458
@Override
6559
public LocalTime timeValue() {
6660
try {
67-
return new ExprDatetimeValue(value).timeValue();
61+
return new ExprTimestampValue(value).timeValue();
6862
} catch (SemanticCheckException e) {
6963
return new ExprTimeValue(value).timeValue();
7064
}

core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77

88
import static java.time.format.DateTimeFormatter.ISO_LOCAL_TIME;
99
import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL;
10-
import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID;
1110

1211
import java.time.Instant;
1312
import java.time.LocalDate;
14-
import java.time.LocalDateTime;
1513
import java.time.LocalTime;
14+
import java.time.ZoneOffset;
1615
import java.time.ZonedDateTime;
1716
import java.time.format.DateTimeParseException;
1817
import java.util.Objects;
@@ -57,12 +56,8 @@ public LocalDate dateValue(FunctionProperties functionProperties) {
5756
return LocalDate.now(functionProperties.getQueryStartClock());
5857
}
5958

60-
public LocalDateTime datetimeValue(FunctionProperties functionProperties) {
61-
return LocalDateTime.of(dateValue(functionProperties), timeValue());
62-
}
63-
6459
public Instant timestampValue(FunctionProperties functionProperties) {
65-
return ZonedDateTime.of(dateValue(functionProperties), timeValue(), UTC_ZONE_ID).toInstant();
60+
return ZonedDateTime.of(dateValue(functionProperties), timeValue(), ZoneOffset.UTC).toInstant();
6661
}
6762

6863
@Override

core/src/main/java/org/opensearch/sql/data/model/ExprTimestampValue.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_VARIABLE_NANOS;
99
import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_WITHOUT_NANO;
10-
import static org.opensearch.sql.utils.DateTimeUtils.UTC_ZONE_ID;
1110

1211
import java.time.Instant;
1312
import java.time.LocalDate;
1413
import java.time.LocalDateTime;
1514
import java.time.LocalTime;
15+
import java.time.ZoneOffset;
1616
import java.time.format.DateTimeParseException;
1717
import java.time.temporal.ChronoUnit;
1818
import java.util.Objects;
@@ -32,7 +32,7 @@ public ExprTimestampValue(String timestamp) {
3232
try {
3333
this.timestamp =
3434
LocalDateTime.parse(timestamp, DATE_TIME_FORMATTER_VARIABLE_NANOS)
35-
.atZone(UTC_ZONE_ID)
35+
.atZone(ZoneOffset.UTC)
3636
.toInstant();
3737
} catch (DateTimeParseException e) {
3838
throw new SemanticCheckException(
@@ -42,13 +42,18 @@ public ExprTimestampValue(String timestamp) {
4242
}
4343
}
4444

45+
/** localDateTime Constructor. */
46+
public ExprTimestampValue(LocalDateTime localDateTime) {
47+
this.timestamp = localDateTime.atZone(ZoneOffset.UTC).toInstant();
48+
}
49+
4550
@Override
4651
public String value() {
4752
return timestamp.getNano() == 0
4853
? DATE_TIME_FORMATTER_WITHOUT_NANO
49-
.withZone(UTC_ZONE_ID)
54+
.withZone(ZoneOffset.UTC)
5055
.format(timestamp.truncatedTo(ChronoUnit.SECONDS))
51-
: DATE_TIME_FORMATTER_VARIABLE_NANOS.withZone(UTC_ZONE_ID).format(timestamp);
56+
: DATE_TIME_FORMATTER_VARIABLE_NANOS.withZone(ZoneOffset.UTC).format(timestamp);
5257
}
5358

5459
@Override
@@ -63,17 +68,12 @@ public Instant timestampValue() {
6368

6469
@Override
6570
public LocalDate dateValue() {
66-
return timestamp.atZone(UTC_ZONE_ID).toLocalDate();
71+
return timestamp.atZone(ZoneOffset.UTC).toLocalDate();
6772
}
6873

6974
@Override
7075
public LocalTime timeValue() {
71-
return timestamp.atZone(UTC_ZONE_ID).toLocalTime();
72-
}
73-
74-
@Override
75-
public LocalDateTime datetimeValue() {
76-
return timestamp.atZone(UTC_ZONE_ID).toLocalDateTime();
76+
return timestamp.atZone(ZoneOffset.UTC).toLocalTime();
7777
}
7878

7979
@Override
@@ -88,12 +88,12 @@ public String toString() {
8888

8989
@Override
9090
public int compare(ExprValue other) {
91-
return timestamp.compareTo(other.timestampValue().atZone(UTC_ZONE_ID).toInstant());
91+
return timestamp.compareTo(other.timestampValue().atZone(ZoneOffset.UTC).toInstant());
9292
}
9393

9494
@Override
9595
public boolean equal(ExprValue other) {
96-
return timestamp.equals(other.timestampValue().atZone(UTC_ZONE_ID).toInstant());
96+
return timestamp.equals(other.timestampValue().atZone(ZoneOffset.UTC).toInstant());
9797
}
9898

9999
@Override

core/src/main/java/org/opensearch/sql/data/model/ExprValue.java

-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.io.Serializable;
99
import java.time.Instant;
1010
import java.time.LocalDate;
11-
import java.time.LocalDateTime;
1211
import java.time.LocalTime;
1312
import java.time.temporal.TemporalAmount;
1413
import java.util.List;
@@ -133,12 +132,6 @@ default LocalDate dateValue() {
133132
"invalid to get dateValue from value of type " + type());
134133
}
135134

136-
/** Get datetime value. */
137-
default LocalDateTime datetimeValue() {
138-
throw new ExpressionEvaluationException(
139-
"invalid to get datetimeValue from value of type " + type());
140-
}
141-
142135
/** Get interval value. */
143136
default TemporalAmount intervalValue() {
144137
throw new ExpressionEvaluationException(

core/src/main/java/org/opensearch/sql/data/model/ExprValueUtils.java

+3-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.time.LocalDate;
1010
import java.time.LocalDateTime;
1111
import java.time.LocalTime;
12+
import java.time.ZoneOffset;
1213
import java.time.temporal.TemporalAmount;
1314
import java.util.ArrayList;
1415
import java.util.LinkedHashMap;
@@ -66,10 +67,6 @@ public static ExprValue dateValue(LocalDate value) {
6667
return new ExprDateValue(value);
6768
}
6869

69-
public static ExprValue datetimeValue(LocalDateTime value) {
70-
return new ExprDatetimeValue(value);
71-
}
72-
7370
public static ExprValue timeValue(LocalTime value) {
7471
return new ExprTimeValue(value);
7572
}
@@ -128,14 +125,14 @@ public static ExprValue fromObjectValue(Object o) {
128125
return floatValue((Float) o);
129126
} else if (o instanceof LocalDate) {
130127
return dateValue((LocalDate) o);
131-
} else if (o instanceof LocalDateTime) {
132-
return datetimeValue((LocalDateTime) o);
133128
} else if (o instanceof LocalTime) {
134129
return timeValue((LocalTime) o);
135130
} else if (o instanceof Instant) {
136131
return timestampValue((Instant) o);
137132
} else if (o instanceof TemporalAmount) {
138133
return intervalValue((TemporalAmount) o);
134+
} else if (o instanceof LocalDateTime) {
135+
return timestampValue(((LocalDateTime) o).toInstant(ZoneOffset.UTC));
139136
} else {
140137
throw new ExpressionEvaluationException("unsupported object " + o.getClass());
141138
}
@@ -150,8 +147,6 @@ public static ExprValue fromObjectValue(Object o, ExprCoreType type) {
150147
return new ExprDateValue((String) o);
151148
case TIME:
152149
return new ExprTimeValue((String) o);
153-
case DATETIME:
154-
return new ExprDatetimeValue((String) o);
155150
default:
156151
return fromObjectValue(o);
157152
}

core/src/main/java/org/opensearch/sql/data/type/ExprCoreType.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ public enum ExprCoreType implements ExprType {
4242
/** Date. */
4343
DATE(STRING),
4444
TIME(STRING),
45-
DATETIME(STRING, DATE, TIME),
46-
TIMESTAMP(STRING, DATETIME),
45+
TIMESTAMP(STRING, DATE, TIME),
4746
INTERVAL(UNDEFINED),
4847

4948
/** Struct. */

core/src/main/java/org/opensearch/sql/expression/DSL.java

-4
Original file line numberDiff line numberDiff line change
@@ -819,10 +819,6 @@ public static FunctionExpression castTimestamp(Expression value) {
819819
return compile(FunctionProperties.None, BuiltinFunctionName.CAST_TO_TIMESTAMP, value);
820820
}
821821

822-
public static FunctionExpression castDatetime(Expression value) {
823-
return compile(FunctionProperties.None, BuiltinFunctionName.CAST_TO_DATETIME, value);
824-
}
825-
826822
public static FunctionExpression typeof(Expression value) {
827823
return compile(FunctionProperties.None, BuiltinFunctionName.TYPEOF, value);
828824
}

0 commit comments

Comments
 (0)