Skip to content

Commit d989904

Browse files
nknizeKiran Reddy
authored andcommitted
[Remove] JodaCompatibleZonedDateTime (opensearch-project#9355)
This commit removes the JodaCompatibleZonedDateTime class and tests in favor of Java time. Signed-off-by: Nicholas Walter Knize <nknize@apache.org> Signed-off-by: Kiran Reddy <kkreddy@amazon.com>
1 parent 801ff14 commit d989904

22 files changed

Lines changed: 35 additions & 816 deletions

File tree

libs/core/src/test/java/org/opensearch/core/common/io/stream/BaseStreamTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@
4141
import org.opensearch.core.common.bytes.BytesArray;
4242
import org.opensearch.core.common.bytes.BytesReference;
4343
import org.opensearch.core.common.settings.SecureString;
44-
import org.opensearch.script.JodaCompatibleZonedDateTime;
4544
import org.opensearch.test.OpenSearchTestCase;
4645

4746
import java.io.ByteArrayInputStream;
4847
import java.io.EOFException;
4948
import java.io.IOException;
5049
import java.time.Instant;
5150
import java.time.ZoneOffset;
51+
import java.time.ZonedDateTime;
5252
import java.util.ArrayList;
5353
import java.util.Arrays;
5454
import java.util.Collection;
@@ -400,10 +400,10 @@ public void testOptionalInstantSerialization() throws IOException {
400400
}
401401
}
402402

403-
public void testJodaDateTimeSerialization() throws IOException {
403+
public void testJavaDateTimeSerialization() throws IOException {
404404
final BytesStreamOutput output = new BytesStreamOutput();
405405
long millis = randomIntBetween(0, Integer.MAX_VALUE);
406-
JodaCompatibleZonedDateTime time = new JodaCompatibleZonedDateTime(Instant.ofEpochMilli(millis), ZoneOffset.ofHours(-7));
406+
ZonedDateTime time = ZonedDateTime.ofInstant(Instant.ofEpochMilli(millis), ZoneOffset.ofHours(-7));
407407
output.writeGenericValue(time);
408408

409409
final BytesReference bytesReference = output.bytes();

modules/lang-painless/src/main/java/org/opensearch/painless/AnalyzerCaster.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@
3535
import org.opensearch.painless.lookup.PainlessCast;
3636
import org.opensearch.painless.lookup.PainlessLookupUtility;
3737
import org.opensearch.painless.lookup.def;
38-
import org.opensearch.script.JodaCompatibleZonedDateTime;
3938

40-
import java.time.ZonedDateTime;
4139
import java.util.Objects;
4240

4341
/**
@@ -87,19 +85,11 @@ public static PainlessCast getLegalCast(Location location, Class<?> actual, Clas
8785
return PainlessCast.originalTypetoTargetType(def.class, Float.class, explicit);
8886
} else if (expected == Double.class) {
8987
return PainlessCast.originalTypetoTargetType(def.class, Double.class, explicit);
90-
// TODO: remove this when the transition from Joda to Java datetimes is completed
91-
} else if (expected == ZonedDateTime.class) {
92-
return PainlessCast.originalTypetoTargetType(def.class, ZonedDateTime.class, explicit);
9388
}
9489
} else if (actual == String.class) {
9590
if (expected == char.class && explicit) {
9691
return PainlessCast.originalTypetoTargetType(String.class, char.class, true);
9792
}
98-
// TODO: remove this when the transition from Joda to Java datetimes is completed
99-
} else if (actual == JodaCompatibleZonedDateTime.class) {
100-
if (expected == ZonedDateTime.class) {
101-
return PainlessCast.originalTypetoTargetType(JodaCompatibleZonedDateTime.class, ZonedDateTime.class, explicit);
102-
}
10393
} else if (actual == boolean.class) {
10494
if (expected == def.class) {
10595
return PainlessCast.boxOriginalType(Boolean.class, def.class, explicit, boolean.class);

modules/lang-painless/src/main/java/org/opensearch/painless/Def.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@
3636
import org.opensearch.painless.lookup.PainlessLookupUtility;
3737
import org.opensearch.painless.lookup.PainlessMethod;
3838
import org.opensearch.painless.symbol.FunctionTable;
39-
import org.opensearch.script.JodaCompatibleZonedDateTime;
4039

4140
import java.lang.invoke.CallSite;
4241
import java.lang.invoke.MethodHandle;
4342
import java.lang.invoke.MethodHandles;
4443
import java.lang.invoke.MethodType;
45-
import java.time.ZonedDateTime;
4644
import java.util.BitSet;
4745
import java.util.Collections;
4846
import java.util.Iterator;
@@ -1506,15 +1504,6 @@ public static String defToStringExplicit(final Object value) {
15061504
}
15071505
}
15081506

1509-
// TODO: remove this when the transition from Joda to Java datetimes is completed
1510-
public static ZonedDateTime defToZonedDateTime(final Object value) {
1511-
if (value instanceof JodaCompatibleZonedDateTime) {
1512-
return ((JodaCompatibleZonedDateTime) value).getZonedDateTime();
1513-
}
1514-
1515-
return (ZonedDateTime) value;
1516-
}
1517-
15181507
/**
15191508
* "Normalizes" the index into a {@code Map} by making no change to the index.
15201509
*/

modules/lang-painless/src/main/java/org/opensearch/painless/MethodWriter.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.opensearch.painless.lookup.PainlessCast;
3636
import org.opensearch.painless.lookup.PainlessMethod;
3737
import org.opensearch.painless.lookup.def;
38-
import org.opensearch.script.JodaCompatibleZonedDateTime;
3938
import org.objectweb.asm.ClassVisitor;
4039
import org.objectweb.asm.Label;
4140
import org.objectweb.asm.Opcodes;
@@ -44,7 +43,6 @@
4443
import org.objectweb.asm.commons.Method;
4544

4645
import java.lang.reflect.Modifier;
47-
import java.time.ZonedDateTime;
4846
import java.util.ArrayDeque;
4947
import java.util.ArrayList;
5048
import java.util.Arrays;
@@ -86,10 +84,8 @@
8684
import static org.opensearch.painless.WriterConstants.DEF_TO_P_SHORT_IMPLICIT;
8785
import static org.opensearch.painless.WriterConstants.DEF_TO_STRING_EXPLICIT;
8886
import static org.opensearch.painless.WriterConstants.DEF_TO_STRING_IMPLICIT;
89-
import static org.opensearch.painless.WriterConstants.DEF_TO_ZONEDDATETIME;
9087
import static org.opensearch.painless.WriterConstants.DEF_UTIL_TYPE;
9188
import static org.opensearch.painless.WriterConstants.INDY_STRING_CONCAT_BOOTSTRAP_HANDLE;
92-
import static org.opensearch.painless.WriterConstants.JCZDT_TO_ZONEDDATETIME;
9389
import static org.opensearch.painless.WriterConstants.LAMBDA_BOOTSTRAP_HANDLE;
9490
import static org.opensearch.painless.WriterConstants.MAX_INDY_STRING_CONCAT_ARGS;
9591
import static org.opensearch.painless.WriterConstants.PAINLESS_ERROR_TYPE;
@@ -181,9 +177,6 @@ public void writeCast(PainlessCast cast) {
181177
invokeStatic(UTILITY_TYPE, CHAR_TO_STRING);
182178
} else if (cast.originalType == String.class && cast.targetType == char.class) {
183179
invokeStatic(UTILITY_TYPE, STRING_TO_CHAR);
184-
// TODO: remove this when the transition from Joda to Java datetimes is completed
185-
} else if (cast.originalType == JodaCompatibleZonedDateTime.class && cast.targetType == ZonedDateTime.class) {
186-
invokeStatic(UTILITY_TYPE, JCZDT_TO_ZONEDDATETIME);
187180
} else if (cast.unboxOriginalType != null && cast.boxTargetType != null) {
188181
unbox(getType(cast.unboxOriginalType));
189182
writeCast(cast.unboxOriginalType, cast.boxTargetType);
@@ -219,8 +212,6 @@ public void writeCast(PainlessCast cast) {
219212
else if (cast.targetType == Float.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_B_FLOAT_EXPLICIT);
220213
else if (cast.targetType == Double.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_B_DOUBLE_EXPLICIT);
221214
else if (cast.targetType == String.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_STRING_EXPLICIT);
222-
// TODO: remove this when the transition from Joda to Java datetimes is completed
223-
else if (cast.targetType == ZonedDateTime.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_ZONEDDATETIME);
224215
else {
225216
writeCast(cast.originalType, cast.targetType);
226217
}
@@ -242,8 +233,6 @@ public void writeCast(PainlessCast cast) {
242233
else if (cast.targetType == Float.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_B_FLOAT_IMPLICIT);
243234
else if (cast.targetType == Double.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_B_DOUBLE_IMPLICIT);
244235
else if (cast.targetType == String.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_STRING_IMPLICIT);
245-
// TODO: remove this when the transition from Joda to Java datetimes is completed
246-
else if (cast.targetType == ZonedDateTime.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_ZONEDDATETIME);
247236
else {
248237
writeCast(cast.originalType, cast.targetType);
249238
}

modules/lang-painless/src/main/java/org/opensearch/painless/Utility.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@
3232

3333
package org.opensearch.painless;
3434

35-
import org.opensearch.script.JodaCompatibleZonedDateTime;
36-
37-
import java.time.ZonedDateTime;
38-
3935
/**
4036
* A set of methods for non-native boxing and non-native
4137
* exact math operations used at both compile-time and runtime.
@@ -62,10 +58,5 @@ public static char StringTochar(final String value) {
6258
return value.charAt(0);
6359
}
6460

65-
// TODO: remove this when the transition from Joda to Java datetimes is completed
66-
public static ZonedDateTime JCZDTToZonedDateTime(final JodaCompatibleZonedDateTime jczdt) {
67-
return jczdt.getZonedDateTime();
68-
}
69-
7061
private Utility() {}
7162
}

modules/lang-painless/src/main/java/org/opensearch/painless/WriterConstants.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
package org.opensearch.painless;
3434

35-
import org.opensearch.script.JodaCompatibleZonedDateTime;
3635
import org.objectweb.asm.Handle;
3736
import org.objectweb.asm.Opcodes;
3837
import org.objectweb.asm.Type;
@@ -42,7 +41,6 @@
4241
import java.lang.invoke.MethodHandle;
4342
import java.lang.invoke.MethodHandles;
4443
import java.lang.invoke.MethodType;
45-
import java.time.ZonedDateTime;
4644
import java.util.ArrayList;
4745
import java.util.Collection;
4846
import java.util.Iterator;
@@ -82,13 +80,6 @@ public final class WriterConstants {
8280
public static final Method STRING_TO_CHAR = getAsmMethod(char.class, "StringTochar", String.class);
8381
public static final Method CHAR_TO_STRING = getAsmMethod(String.class, "charToString", char.class);
8482

85-
// TODO: remove this when the transition from Joda to Java datetimes is completed
86-
public static final Method JCZDT_TO_ZONEDDATETIME = getAsmMethod(
87-
ZonedDateTime.class,
88-
"JCZDTToZonedDateTime",
89-
JodaCompatibleZonedDateTime.class
90-
);
91-
9283
/**
9384
* A Method instance for {@linkplain Pattern}. This isn't available from PainlessLookup because we intentionally don't add it
9485
* there so that the script can't create regexes without this syntax. Essentially, our static regex syntax has a monopoly on building
@@ -157,9 +148,6 @@ public final class WriterConstants {
157148
public static final Method DEF_TO_STRING_IMPLICIT = getAsmMethod(String.class, "defToStringImplicit", Object.class);
158149
public static final Method DEF_TO_STRING_EXPLICIT = getAsmMethod(String.class, "defToStringExplicit", Object.class);
159150

160-
// TODO: remove this when the transition from Joda to Java datetimes is completed
161-
public static final Method DEF_TO_ZONEDDATETIME = getAsmMethod(ZonedDateTime.class, "defToZonedDateTime", Object.class);
162-
163151
/** invokedynamic bootstrap for lambda expression/method references */
164152
public static final MethodType LAMBDA_BOOTSTRAP_TYPE = MethodType.methodType(
165153
CallSite.class,

modules/lang-painless/src/main/java/org/opensearch/painless/api/Augmentation.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import org.opensearch.common.hash.MessageDigests;
3636

3737
import java.nio.charset.StandardCharsets;
38+
import java.time.DayOfWeek;
39+
import java.time.ZonedDateTime;
3840
import java.util.ArrayList;
3941
import java.util.Base64;
4042
import java.util.Collection;
@@ -721,4 +723,8 @@ public static Matcher matcher(Pattern receiver, int limitFactor, CharSequence in
721723
}
722724
return receiver.matcher(new LimitedCharSequence(input, receiver, limitFactor));
723725
}
726+
727+
public static DayOfWeek getDayOfWeekEnum(ZonedDateTime receiver) {
728+
return receiver.getDayOfWeek();
729+
}
724730
}

modules/lang-painless/src/main/resources/org/opensearch/painless/spi/java.time.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ class java.time.YearMonth {
485485
class java.time.ZonedDateTime {
486486
int getDayOfMonth()
487487
DayOfWeek getDayOfWeek()
488+
DayOfWeek org.opensearch.painless.api.Augmentation getDayOfWeekEnum()
488489
int getDayOfYear()
489490
int getHour()
490491
LocalDate toLocalDate()

modules/lang-painless/src/main/resources/org/opensearch/painless/spi/org.opensearch.score.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ static_import {
3333
double decayNumericLinear(double, double, double, double, double)bound_to org.opensearch.script.ScoreScriptUtils$DecayNumericLinear
3434
double decayNumericExp(double, double, double, double, double) bound_to org.opensearch.script.ScoreScriptUtils$DecayNumericExp
3535
double decayNumericGauss(double, double, double, double, double) bound_to org.opensearch.script.ScoreScriptUtils$DecayNumericGauss
36-
double decayDateLinear(String, String, String, double, JodaCompatibleZonedDateTime) bound_to org.opensearch.script.ScoreScriptUtils$DecayDateLinear
37-
double decayDateExp(String, String, String, double, JodaCompatibleZonedDateTime) bound_to org.opensearch.script.ScoreScriptUtils$DecayDateExp
38-
double decayDateGauss(String, String, String, double, JodaCompatibleZonedDateTime) bound_to org.opensearch.script.ScoreScriptUtils$DecayDateGauss
36+
double decayDateLinear(String, String, String, double, ZonedDateTime) bound_to org.opensearch.script.ScoreScriptUtils$DecayDateLinear
37+
double decayDateExp(String, String, String, double, ZonedDateTime) bound_to org.opensearch.script.ScoreScriptUtils$DecayDateExp
38+
double decayDateGauss(String, String, String, double, ZonedDateTime) bound_to org.opensearch.script.ScoreScriptUtils$DecayDateGauss
3939
}
4040

modules/lang-painless/src/main/resources/org/opensearch/painless/spi/org.opensearch.txt

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -79,62 +79,9 @@ class org.opensearch.index.fielddata.ScriptDocValues$UnsignedLongs {
7979
BigInteger getValue()
8080
}
8181

82-
class org.opensearch.script.JodaCompatibleZonedDateTime {
83-
##### ZonedDateTime methods
84-
int getDayOfMonth()
85-
int getDayOfYear()
86-
int getHour()
87-
LocalDate toLocalDate()
88-
LocalDateTime toLocalDateTime()
89-
int getMinute()
90-
Month getMonth()
91-
int getMonthValue()
92-
int getNano()
93-
int getSecond()
94-
int getYear()
95-
ZonedDateTime minus(TemporalAmount)
96-
ZonedDateTime minus(long,TemporalUnit)
97-
ZonedDateTime minusYears(long)
98-
ZonedDateTime minusMonths(long)
99-
ZonedDateTime minusWeeks(long)
100-
ZonedDateTime minusDays(long)
101-
ZonedDateTime minusHours(long)
102-
ZonedDateTime minusMinutes(long)
103-
ZonedDateTime minusSeconds(long)
104-
ZonedDateTime minusNanos(long)
105-
ZonedDateTime plus(TemporalAmount)
106-
ZonedDateTime plus(long,TemporalUnit)
107-
ZonedDateTime plusDays(long)
108-
ZonedDateTime plusHours(long)
109-
ZonedDateTime plusMinutes(long)
110-
ZonedDateTime plusMonths(long)
111-
ZonedDateTime plusNanos(long)
112-
ZonedDateTime plusSeconds(long)
113-
ZonedDateTime plusWeeks(long)
114-
ZonedDateTime plusYears(long)
115-
OffsetDateTime toOffsetDateTime()
116-
ZonedDateTime truncatedTo(TemporalUnit)
117-
ZonedDateTime with(TemporalAdjuster)
118-
ZonedDateTime with(TemporalField,long)
119-
ZonedDateTime withDayOfMonth(int)
120-
ZonedDateTime withDayOfYear(int)
121-
ZonedDateTime withEarlierOffsetAtOverlap()
122-
ZonedDateTime withFixedOffsetZone()
123-
ZonedDateTime withHour(int)
124-
ZonedDateTime withLaterOffsetAtOverlap()
125-
ZonedDateTime withMinute(int)
126-
ZonedDateTime withMonth(int)
127-
ZonedDateTime withNano(int)
128-
ZonedDateTime withSecond(int)
129-
ZonedDateTime withYear(int)
130-
ZonedDateTime withZoneSameLocal(ZoneId)
131-
ZonedDateTime withZoneSameInstant(ZoneId)
132-
DayOfWeek getDayOfWeekEnum()
133-
}
134-
13582
class org.opensearch.index.fielddata.ScriptDocValues$Dates {
136-
JodaCompatibleZonedDateTime get(int)
137-
JodaCompatibleZonedDateTime getValue()
83+
ZonedDateTime get(int)
84+
ZonedDateTime getValue()
13885
}
13986

14087
class org.opensearch.index.fielddata.ScriptDocValues$Doubles {

0 commit comments

Comments
 (0)