-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scripting: Rework joda time backcompat #33486
Changes from 11 commits
f815009
8260827
56f1f1e
9035788
d876b3d
f3ec719
19019e7
92a227c
8cc0a3a
3930cf6
bd83968
11e03c7
eab341a
f105096
03a28dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,9 +76,93 @@ class org.elasticsearch.index.fielddata.ScriptDocValues$Longs { | |
List getValues() | ||
} | ||
|
||
class org.elasticsearch.script.JodaCompatibleZonedDateTime { | ||
##### ZonedDateTime methods | ||
int getDayOfMonth() | ||
int getDayOfYear() | ||
int getHour() | ||
LocalDate toLocalDate() | ||
LocalDateTime toLocalDateTime() | ||
int getMinute() | ||
Month getMonth() | ||
int getMonthValue() | ||
int getNano() | ||
int getSecond() | ||
int getYear() | ||
ZonedDateTime minus(TemporalAmount) | ||
ZonedDateTime minus(long,TemporalUnit) | ||
ZonedDateTime minusYears(long) | ||
ZonedDateTime minusMonths(long) | ||
ZonedDateTime minusWeeks(long) | ||
ZonedDateTime minusDays(long) | ||
ZonedDateTime minusHours(long) | ||
ZonedDateTime minusMinutes(long) | ||
ZonedDateTime minusSeconds(long) | ||
ZonedDateTime minusNanos(long) | ||
ZonedDateTime plus(TemporalAmount) | ||
ZonedDateTime plus(long,TemporalUnit) | ||
ZonedDateTime plusDays(long) | ||
ZonedDateTime plusHours(long) | ||
ZonedDateTime plusMinutes(long) | ||
ZonedDateTime plusMonths(long) | ||
ZonedDateTime plusNanos(long) | ||
ZonedDateTime plusSeconds(long) | ||
ZonedDateTime plusWeeks(long) | ||
ZonedDateTime plusYears(long) | ||
Instant toInstant() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where is this one coming from? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ignore this, misread it as being something for BWC, but it's a new method |
||
OffsetDateTime toOffsetDateTime() | ||
ZonedDateTime truncatedTo(TemporalUnit) | ||
ZonedDateTime with(TemporalAdjuster) | ||
ZonedDateTime with(TemporalField,long) | ||
ZonedDateTime withDayOfMonth(int) | ||
ZonedDateTime withDayOfYear(int) | ||
ZonedDateTime withEarlierOffsetAtOverlap() | ||
ZonedDateTime withFixedOffsetZone() | ||
ZonedDateTime withHour(int) | ||
ZonedDateTime withLaterOffsetAtOverlap() | ||
ZonedDateTime withMinute(int) | ||
ZonedDateTime withMonth(int) | ||
ZonedDateTime withNano(int) | ||
ZonedDateTime withSecond(int) | ||
ZonedDateTime withYear(int) | ||
ZonedDateTime withZoneSameLocal(ZoneId) | ||
ZonedDateTime withZoneSameInstant(ZoneId) | ||
|
||
#### Joda methods that exist in java time | ||
boolean equals(Object) | ||
int hashCode() | ||
boolean isAfter(ZonedDateTime) | ||
boolean isBefore(ZonedDateTime) | ||
boolean isEqual(ZonedDateTime) | ||
String toString() | ||
|
||
#### Joda time methods | ||
long getMillis() | ||
int getCenturyOfEra() | ||
int getEra() | ||
int getHourOfDay() | ||
int getMillisOfDay() | ||
int getMillisOfSecond() | ||
int getMinuteOfDay() | ||
int getMinuteOfHour() | ||
int getMonthOfYear() | ||
int getSecondOfDay() | ||
int getSecondOfMinute() | ||
int getWeekOfWeekyear() | ||
int getWeekyear() | ||
int getYearOfCentury() | ||
int getYearOfEra() | ||
String toString(String) | ||
String toString(String,Locale) | ||
|
||
# conflicting methods | ||
DayOfWeek getDayOfWeekEnum() | ||
int getDayOfWeek() | ||
} | ||
|
||
class org.elasticsearch.index.fielddata.ScriptDocValues$Dates { | ||
Object get(int) | ||
Object getValue() | ||
JodaCompatibleZonedDateTime get(int) | ||
JodaCompatibleZonedDateTime getValue() | ||
List getValues() | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
import org.elasticsearch.common.text.Text; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; | ||
import org.elasticsearch.script.JodaCompatibleZonedDateTime; | ||
import org.joda.time.DateTimeZone; | ||
import org.joda.time.ReadableInstant; | ||
|
||
|
@@ -680,6 +681,14 @@ public final <K, V> void writeMap(final Map<K, V> map, final Writer<K> keyWriter | |
o.writeString(zonedDateTime.getZone().getId()); | ||
o.writeLong(zonedDateTime.toInstant().toEpochMilli()); | ||
}); | ||
writers.put(JodaCompatibleZonedDateTime.class, (o, v) -> { | ||
// write the joda compatibility datetime as joda datetime | ||
o.writeByte((byte) 13); | ||
final JodaCompatibleZonedDateTime zonedDateTime = (JodaCompatibleZonedDateTime) v; | ||
String zoneId = zonedDateTime.getZonedDateTime().getZone().getId(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops. This was because the zoneId used by joda doesn't appear to always be the same as java time. Joda does not know how to parse "Z". I'll add special casing for that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I pushed f105096 |
||
o.writeString(DateTimeZone.UTC.getID()); | ||
o.writeLong(zonedDateTime.toInstant().toEpochMilli()); | ||
}); | ||
WRITERS = Collections.unmodifiableMap(writers); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,7 @@ public Map<Class<?>, XContentBuilder.Writer> getXContentWriters() { | |
writers.put(Year.class, (b, v) -> b.value(v.toString())); | ||
writers.put(Duration.class, (b, v) -> b.value(v.toString())); | ||
writers.put(Period.class, (b, v) -> b.value(v.toString())); | ||
//writers.put(JodaCompatibleZonedDateTime.class, XContentBuilder::timeValue); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean to uncomment this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will be removing it. I added it originally because I thought it was needed due to the api leakage I mentioned in my other comment, but I found a way around that and don't want to expose this compatibility class at all. |
||
|
||
writers.put(BytesReference.class, (b, v) -> { | ||
if (v == null) { | ||
|
@@ -141,6 +142,8 @@ public Map<Class<?>, Function<Object, Object>> getDateTransformers() { | |
d -> DEFAULT_FORMATTER.format(ZonedDateTime.ofInstant((java.time.Instant) d, ZoneOffset.UTC))); | ||
transformers.put(LocalDate.class, d -> ((LocalDate) d).toString()); | ||
transformers.put(LocalTime.class, d -> LOCAL_TIME_FORMATTER.format((LocalTime) d)); | ||
/*transformers.put(JodaCompatibleZonedDateTime.class, | ||
d -> DEFAULT_FORMATTER.format(((JodaCompatibleZonedDateTime) d).getZonedDateTime()));*/ | ||
return transformers; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should update this to the ES 7 compatible call.