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
Deprecate using "interval" configuration for date histograms aggregations #1874
Deprecate using "interval" configuration for date histograms aggregations #1874
Conversation
d433024
to
05805f5
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.
👍
05805f5
to
dfb07a3
Compare
Thanks @romainneutron |
f8e4111
to
5b97e70
Compare
@@ -7,10 +7,67 @@ | |||
* | |||
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html | |||
*/ | |||
class DateHistogram extends Histogram | |||
class DateHistogram extends AbstractSimpleAggregation |
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 would be a BC break.
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 thought BC breaks were allowed
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.
Sometimes but should not ;)
I think in this case, we can avoid it or I'm missing something?
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.
so, what should we do?
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.
Wouldn't this be helpful (#1874 (comment)) to avoid changing the inheritance?
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 I got the point.
DateHistogram interval
parameter is deprecated but still useful for Histogram
.
Can you confirm it's what you're addressing by changing the inheritance chain?
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.
yes. We could move methods if we want to keep those implementation.
Maintaining BC on interfaces and userland API yes, but should we maintain BC on abstract internal classes?
$this->_checkVersion('7.2'); | ||
|
||
$agg = new DateHistogram('hist', 'created'); | ||
$agg->setFixedInterval('1h'); |
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.
$this->_checkVersion('7.2'); | |
$agg = new DateHistogram('hist', 'created'); | |
$agg->setFixedInterval('1h'); | |
$version = $this->_getVersion(); | |
if (\version_compare($version, '7.2') < 0) { | |
$this->expectDeprecation('Since ruflin/elastica 7.1.0: The "Elastica\Aggregation\DateHistogram::setInterval()" method is deprecated, use "setDateInterval()" or "setCalendarInterval()" instead. It will be removed in 8.0.'); | |
$agg = (new DateHistogram('hist', 'created')) | |
->setInterval('1h') | |
; | |
} else { | |
$agg = (new DateHistogram('hist', 'created')) | |
->setFixedInterval('1h') | |
; | |
} |
Cannot we use a code like this to test on version lower than 7.2?
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.
$this->_checkVersion('7.2'); | |
$agg = new DateHistogram('hist', 'created'); | |
$agg->setFixedInterval('1h'); | |
$version = $this->_getVersion(); | |
if (\version_compare($version, '7.2') < 0) { | |
$agg = (new DateHistogram('hist', 'created')) | |
->setParam('interval', '1h') | |
; | |
} else { | |
$agg = (new DateHistogram('hist', 'created')) | |
->setFixedInterval('1h') | |
; | |
} |
Or like this?
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.
Maybe the deprecation is a little too violent, as this can't be fixed for versions lower than 7.2 unless using setParam()
directly? WDYT @ruflin @thePanz ? Is there any advices/hints for this kind of deprecations?
Not sure if it's a blocker as the deprecation is also very helpful for upper compatibility.
2747dac
to
4fcbfe1
Compare
PR udpated. |
785d5bc
to
2831bd5
Compare
If understand it there are 2 things here:
We need the first one to only deprecate interval for DateHistogram? It seems the current code change is backward compatible expect in the case someone checked for specifically inherited classes? Is there more the could break users code? |
2831bd5
to
b0f0deb
Compare
PR rebased |
b0f0deb
to
af82aae
Compare
Seems like one of the tests fail because of the deprecation :-) Can you fix it and also rebased the changelog? |
af82aae
to
32e09c2
Compare
32e09c2
to
663cf58
Compare
PR rebased, tests are green :) |
I'll refer to @deguif on the final 👍 as he had the most interactions here. |
any news? |
@deguif Any chance to have a quick look? |
$this->setField($field); | ||
|
||
if (null !== $interval) { | ||
trigger_deprecation('ruflin/elastica', '7.1.0', 'Argument 3 passed to "%s()" is deprecated, use "setDateInterval()" or "setCalendarInterval()" instead. It will be removed in 8.0.', __METHOD__); |
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.
trigger_deprecation('ruflin/elastica', '7.1.0', 'Argument 3 passed to "%s()" is deprecated, use "setDateInterval()" or "setCalendarInterval()" instead. It will be removed in 8.0.', __METHOD__); | |
trigger_deprecation('ruflin/elastica', '7.1.0', 'Argument 3 passed to "%s()" is deprecated, use "setFixedInterval()" or "setCalendarInterval()" instead. It will be removed in 8.0.', __METHOD__); |
@@ -46,9 +46,12 @@ public function testToArray(): void | |||
*/ | |||
public function testMaxAggregation(): void | |||
{ | |||
$this->_checkVersion('7.2'); |
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.
Cannot we do the same you've done later for DateHistogramTest::testDateHistogramAggregation()
, I mean checking the version of elasticsearch and using setInterval()
or setFixedInterval()
depending the version?
@@ -45,9 +45,12 @@ public function testToArray(): void | |||
*/ | |||
public function testMaxAggregation(): void | |||
{ | |||
$this->_checkVersion('7.2'); |
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.
Same here:
Cannot we do the same you've done later for DateHistogramTest::testDateHistogramAggregation(), I mean checking the version of elasticsearch and using setInterval() or setFixedInterval() depending the version?
@@ -20,7 +20,10 @@ class SerialDiffTest extends BaseAggregationTest | |||
*/ | |||
public function testSerialDiffAggregation(): void | |||
{ | |||
$dateHistogramAggregation = new DateHistogram('measurements', 'measured_at', 'hour'); | |||
$this->_checkVersion('7.2'); |
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.
Same here:
Cannot we do the same you've done later for DateHistogramTest::testDateHistogramAggregation(), I mean checking the version of elasticsearch and using setInterval() or setFixedInterval() depending the version?
* | ||
* @return $this | ||
*/ | ||
public function setOrder(string $order, string $direction): self |
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.
It seems it can also be a multi-dimensional array?
Like this:
"order": [ { "rock>playback_stats.avg": "desc" }, { "_count": "desc" } ]
*/ | ||
public function setInterval($interval): self | ||
{ | ||
trigger_deprecation('ruflin/elastica', '7.1.0', 'The "%s()" method is deprecated, use "setDateInterval()" or "setCalendarInterval()" instead. It will be removed in 8.0.', __METHOD__); |
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'm dubious about this deprecation, as interval
parameter is still legit for ES version lower than 7.2
. It was only deprecated in 7.2 version but is still supported (until at least 8.0).
I think we should remove the deprecation here. But I would let the deprecation in the constructor so that users would be required to update their code to explicitly call setInterval()
, setFixedInterval()
or setCalendarInterval()
.
Later when bumping minimum version of ES to a version later than 7.2 (probably when bumping to 8.0) we should be able to drop this method and only let the two others.
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.
There are two different deprecations:
- Deprecation in Elasticsearch
- Deprecation in Elastica
In the best case, they are aligned. As Elastica lags behind in releases, we kind of have the option to deprecate things already in older releases, assuming there is already an option available which is not deprecated.
To remove a method in 8.0, we should have it deprecated already in 7.x. I would say the earlier we can tell devs to adjust their code the better.
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.
Yes but that means in this case, that users of version older than 7.2 will get this deprecation but won't be able to remove the deprecation as the parameters (setFixedInterval
, setCalendarInterval
) can't work with their ES version. But maybe that's not an issue.
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 see. Maybe we can leave in a note in the docs for this. In general it would be great if we can push users to use the newest version of Elastica and the related version of Elasticsearch and would optimise for this. Maybe we could even adjust the README that this version of Elastica is supported for Elasticsearch >= 7.3 or similar. It does not mean, it will not work anymore with the older versions.
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 would add the PHP Doc to the methods, stating that those are not supported by ES >= 8.x
When the library will support ES v8.x only, we can remove those methods.
WDYT?
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.
No strong preference on my end. SGTM
This #2099 could be a simpler way to do it, isn't it ? |
Fixed in #2099 |
The combined
interval
field has been deprecated in favor of fixed_interval or calendar_interval. See https://www.elastic.co/guide/en/elasticsearch/reference/7.2/search-aggregations-bucket-datehistogram-aggregation.html