-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Core: Migrating from joda time to java.time #27330
Comments
++ We can deprecate their use in 6.x and say ("please replace with YYYY..."), then on upgrade to 7.0, we can auto-upgrade the mappings to use the equivalent date pattern format. |
StreamInput/Streamoutput now use java.time when a timezone is serialized over the wire. There is one special case that needs to be taken care of and that is when java.time is sending 'Z' instead of 'UTC', which joda time does not understand. Relates elastic#27330
some more discussion about BWC. PainlessRight now calling A possible work around for this would be to have a Client side runtime casting of bucket keys
We need to check if the high level REST client is affected by this as well. Different symbols used in date formattingThere are a couple of differences when date time formatters are used, according to the java docs. joda time has a One idea was to have a setting which allows to set which date implementation would be used, but this would mean to not have support rolling upgrades as having to have a hard move from one implementation to the other, so we need to support both time libraries at least in scripting. |
There are some differences in TZ handling we have to cater for. Jodatime has 593 tz ids, java time 600. java time adds a few new ones (starting with The general recommendation seems to be to use either offsets, like We might need to add deprecation warnings for the above timezones. |
- StreamInput/StreamOutput now use java.time to interpret date times. - XContentBuilder uses java.time for its formatters. - Cutover to using java time zones in MappedFieldType.rangeQuery (and thus RangeFieldMapper, DateFieldMapper, SimpleMappedFieldType) - QueryStringQueryBuilder and RangeQueryBuilder uses java.time time zone - A few tests were moved to java.time where simply any time was needed Relates elastic#27330
Relates #10005 |
I've been investigating how we might add support for a bwc layer within 6.x so that using existing joda format strings is backed by java time. This looks completely possible to do with a sysprop that controls whether a mapping layer on parsing formats is enabled, except for the lack of century-of-era support @spinscale mentioned in an earlier comment. This raises the question of whether this extremely esoteric option could be broken in a minor (since there is no migration path anyways, and IMO the likelihood of any user out there using it is almost non-existent). The alternative to this is to build an abstraction layer internally for all datetime uses, so that java/joda use can be swapped by the same sysprop, determine which underlying implementation of the abstraction to use (this would rely on replacing all uses of parsing/formatting on the abstraction). I'd like others opinions on the tradeoffs between these two approaches. |
Note: A third alternative that I do not see as viable is implementing the century-of-era in java time. While it is possible, it would require quite a bit of code for something that I don't think anyone is actually using. |
to add some more background: here is a link what century of era refers to in an ISO chronology, i.e. 19th century for all the years from 1900 till 1999: http://joda-time.sourceforge.net/field.html#CenturyOfEra_and_YearOfCentury - which basically leaves you with a super broad/inexact timestamp My unscientific feeling also says, there are not a lot of users of this. |
Support for JodaTime and NodaTime time formats is really important for me. For all business applications I have worked on, it is way more important to have validateable data types and algorithmic correctness, than issues like having very „high precision“, „better performance“, or „no dependency on external libraries“. Having additional datatypes that support higher precision is ok with me. But I would not invest the work in reinventing the wheel in cases where the JodaTime library works fine. It might make more sense to implement the high-precision time datatypes in the JodaTime library instead. |
@MovGP0 The joda time project encourages users to migrate to the the java time api. From a maintainability perspective, we are moving to java time to both eliminate an external dependency and ensure bugs are fixed. From a format support perspective, joda time and java time are very similar. There are a only a handful of format specifiers that changed, and the year of century mentioned above is the only one that does not exist in java time. Do you have a use for it specifically, or are you generally concerned with needing to update your formats? |
@rjernst I'm mostly concert about reinventing the wheel (aka. 'not invented here syndrome'). Usually it's better to just use and contribute to a library where possible, rather than developing something as complex as handling international time calculations yourself. Not sure how far the Java Time API has evolved to handle Joda Time's use cases. |
@MovGP0 As @rjernst mentioned, Joda is deprecated, no longer developed, and users are encouraged to move to
|
We have been looking carefully at how to provide a migration path and deprecation warnings for those using joda time specific behavior. There are 2 types of places within Elasticsearch APIs the can be found: scripting and anywhere date formats are used. For scripting, we previously attempted to provide migration through #31441. However, that turned out to be problematic with rolling upgrades. The new approach agreed on is to change the scripting api for date fields to return a ZonedDateTime compatible object, but with augmentation methods for the missing joda time methods, which will trigger deprecation warnings when used. This is implemented in #31441. For date formats, the problem is a few characters for which the identifier has changed, or no longer exists in java time. For these the plan is to provide a special prefix that may be used for date formats that want to force the use of java time format specifiers (probably |
Two more BWC things Dave mentioned to me:
public static void main(String[] argv) {
DateTimeFormatter formatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd'T'HH:mm:ss,SSSXX").toFormatter(Locale.ROOT);
String date = "2018-05-15T16:14:56,374Z";
System.out.println(formatter.withZone(ZoneId.of("Europe/Berlin")).parse(date));
System.out.println(formatter.withZone(ZoneOffset.UTC).parse(date));
System.out.println(formatter.parse(date));
System.out.println(Instant.from(formatter.withZone(ZoneId.of("Europe/Berlin")).parse(date)));
System.out.println(Instant.from(formatter.withZone(ZoneOffset.UTC).parse(date)));
System.out.println(Instant.from(formatter.parse(date)));
} Under java 10 this returns
Under java 8 this returns
The third last line is the important one. One time it is
|
What's the plan for solving this issue in terms of releases timeline? |
monitoring plugin migration from joda to java.time refers #27330
part of the migrating joda time work. Migrating watcher plugin to use JDK's java-time refers #27330
part of the migrating joda time work. refactoring x-pack plugins usages of joda to java-time refers #27330
When the millisecond part of a timestamp is 0 the toString representation in java-time is omitting the millisecond part (joda was not). The Search response is returning timestamps formatted with WatcherDateTimeUtils, therefore comparisons of strings should be done with the same formatter relates #27330
When the millisecond part of a timestamp is 0 the toString representation in java-time is omitting the millisecond part (joda was not). The Search response is returning timestamps formatted with WatcherDateTimeUtils, therefore comparisons of strings should be done with the same formatter relates elastic#27330
When the millisecond part of a timestamp is 0 the toString representation in java-time is omitting the millisecond part (joda was not). The Search response is returning timestamps formatted with WatcherDateTimeUtils, therefore comparisons of strings should be done with the same formatter relates elastic#27330
…8505) When the millisecond part of a timestamp is 0 the toString representation in java-time is omitting the millisecond part (joda was not). The Search response is returning timestamps formatted with WatcherDateTimeUtils, therefore comparisons of strings should be done with the same formatter relates #27330 backport#38505
When the millisecond part of a timestamp is 0 the toString representation in java-time is omitting the millisecond part (joda was not). The Search response is returning timestamps formatted with WatcherDateTimeUtils, therefore comparisons of strings should be done with the same formatter relates #27330 BackPort #38505
@jasontedor I think we can close this as we are fully migrated. We only have bugfixes now. |
Objective: In order to support nanosecond resolution and to remove the joda time dependency from Elasticsearch, we need to migrate a lot of code over to java.time.
This is a meta issue detailing the steps that need to be taken to migrate away from joda time and to java.time.
There are a few things to keep in mind and discuss before outlining the single steps
Retaining our gazillion date formats
Do we want to retain the tons of our named date formats, named very well like
strictOrdinalDateTimeNoMillis
orstrictWeekDateTimeNoMillis
(also we support snake and camel case for each of those!)? I think we could built a layer that is still able to read those, but then maybe convert it to formatted dates likexxxx-'W'ww-e'T'HH:mm:ssZZ
(just an example). This way we could get rid of this mapping entirely or at least just maintain it for a few examples likeepoch_millis
,epoch_second
anddateOptionalTime
as the text representation are nowhere near as readable as the date time formats, once internalized.You can find the full list in the Joda class
BWC breaking
Some classes used by builders to create queries are using joda time classes. As we move towards the REST client and away from the Transport Client this will be less of an BWC issue.
Steps
DateMathParser
usejava.time
IndexNameExpressionResolver.DateMathExpressionResolver
use java.time, also remove the check for thedate_math_expression_resolver.default_time_zone
anddate_math_expression_resolver.default_date_format
settings here (they are not registered anyway). Core: Move IndexNameExpressionResolver to java time #34507IndexNameExpressionResolver
is BWC compatible when formatters are usedZonedDateTime
Core: Switch mapping/aggregations over to java time #36363DateTimeUnit
,Rounding
,TimeValue
classesXContentBuilder
,StreamInput
,StreamOutput
classes (the serialized version of this is just a long and a timezone in our streams, so those are easy to convert. Same applies for the XContentBuilder)SortingNumericDocValues
and classes extending from it in the fielddata package need to be converted (or removed?) Core: Switch mapping/aggregations over to java time #36363DocValueFormat
andDateFieldMapper
Core: Switch mapping/aggregations over to java time #36363The text was updated successfully, but these errors were encountered: