-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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 to java.time. ML package #35493
Core: Migrating from joda to java.time. ML package #35493
Conversation
This commit moves the aggregation and mapping code from joda time to java time. This includes field mappers, root object mappers, aggregations with date histograms, query builders and a lot of changes within tests.
…m property configured
Pinging @elastic/es-core-infra |
055ec8d
to
d3a6e85
Compare
@@ -112,6 +112,7 @@ public static ExtractedField newField(String alias, String name, ExtractionMetho | |||
} | |||
if (value[0] instanceof String) { // doc_value field with the epoch_millis format | |||
value[0] = Long.parseLong((String) value[0]); | |||
//TODO confirm if can remove the script time field |
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.
OK, I had a discussion with @jpountz and got to the bottom of this. BaseDateTime
was the type returned for date fields in doc values prior to allowing configuring the doc value format. Thus, we still need this for mixed 6.x clusters. The comment below // script field
is actually misleading. ML never supported scripted date fields.
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.
OK, I think the only thing left is to remove this TODO and correct the comment below (// script field
). A more accurate comment would be // for handling doc value type prior to 6.4
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 need to investigate what will be the behaviour for a mix cluster like that.
Is there a test in any of the old branches that I can modify and see that place being hit? We could possibly then think of creating a similar one on the master branch with a mixed cluster?
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.
Actually we should be able to remove this from master
. 7.x
nodes should only talk to 6.latest
which already have the doc value format specified. It's only in 6.x
we need to keep this code for. Any datafeed test should be hitting this prior to 6.4
.
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.
Note that prior to 6.4
there was no if
block in this method. It was directly casting to the joda time.
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.
See #31463
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.
as we discussed, that sounds really good. Will remove that line in master
@@ -179,7 +179,7 @@ private void processDateHistogram(Histogram agg) throws IOException { | |||
* Histograms have either a Double or Long. | |||
*/ | |||
private long toHistogramKeyToEpoch(Object key) { | |||
if (key instanceof DateTime) { | |||
if (key instanceof DateTime) {//TODO what do we use as key in aggregations |
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.
Is this a question for the ML folk?
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.
@dimitris-athanasiou I thought initially to ask ML team, but from what I see now we are missing that migration in elasticsearch. This seems to be a planned work but not started yet.
Will have to switch to datetime histograms first before finishing ML package
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.
That is on the java-time branch at the moment and the ZonedDateTime will be returned
|
||
import java.time.Instant; |
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.
Is this import used?
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.
unused indeed - will remove
@@ -180,10 +180,10 @@ private void processDateHistogram(Histogram agg) throws IOException { | |||
*/ | |||
private long toHistogramKeyToEpoch(Object key) { | |||
if (key instanceof ZonedDateTime) { | |||
return ((ZonedDateTime)key).toInstant().toEpochMilli(); | |||
return ((ZonedDateTime)keEy).toInstant().toEpochMilli(); |
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 believe this introduced a typo: keEy
instead of key
3d5696f
to
bb0d60b
Compare
bb0d60b
to
d737fe5
Compare
41950c9
to
166be62
Compare
166be62
to
cef95b2
Compare
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.
left a few minor comments on how to get the current time in milliseconds, but it seems this has to wait for the java-time branch first
@@ -66,7 +68,13 @@ | |||
public ExpiredForecastsRemover(Client client, ThreadPool threadPool) { | |||
this.client = Objects.requireNonNull(client); | |||
this.threadPool = Objects.requireNonNull(threadPool); | |||
this.cutoffEpochMs = DateTime.now(ISOChronology.getInstance()).getMillis(); | |||
this.cutoffEpochMs = getNowEpochMs(); |
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.
how about Instant.now().toEpochMilli()
?
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 are right, there is no point using ISOChronology when all we need here are milliseconds since epoch
long nowEpochMs = DateTime.now(ISOChronology.getInstance()).getMillis(); | ||
Instant instant = ZonedDateTime.now().toInstant(); | ||
long nowEpochMs = IsoChronology.INSTANCE.zonedDateTime(instant, ZoneId.systemDefault()) | ||
.toInstant().toEpochMilli(); |
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.
how about Instant.now().toEpochMilli()?
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.
good idea
return TimeValue.timeValueMillis(next.getMillis() - now.getMillis()); | ||
|
||
Instant instant = ZonedDateTime.now().toInstant(); | ||
ZonedDateTime now = IsoChronology.INSTANCE.zonedDateTime(instant, ZoneId.systemDefault()); |
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.
how about Instant.now().toEpochMilli()?
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.
good idea
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.
actually I ZonedDatetime, might better here - more on a new review https://github.com/elastic/elasticsearch/pull/35949/files#r236714576
@spinscale I will rebase this branch on top of java-time branch. It will help me to integrate when java-time is merged into master |
cef95b2
to
06b44dc
Compare
part of the migrating joda time work. The goal is to find usages of joda time and refactor to use java.time. closes: elastic#35490 confirmed histograms are returning zoneddatedate remove unused imports missing space typos removing the DateTime usage as it won't be hit removing tests no longer valid as code has been removed
06b44dc
to
3b90c7b
Compare
closing, as the change was merged into java-time |
part of the migrating joda time work. The goal is to find usages of joda
time and refactor to use java.time.
refers #27330