-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Begin moving date_histogram to offset rounding #50873
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
Merged
nik9000
merged 4 commits into
elastic:master
from
nik9000:offset_rounding_date_histogram_1
Jan 14, 2020
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,10 +67,9 @@ class DateRangeHistogramAggregator extends BucketsAggregator { | |
private final ExtendedBounds extendedBounds; | ||
|
||
private final LongHash bucketOrds; | ||
private long offset; | ||
|
||
DateRangeHistogramAggregator(String name, AggregatorFactories factories, Rounding rounding, Rounding shardRounding, | ||
long offset, BucketOrder order, boolean keyed, | ||
BucketOrder order, boolean keyed, | ||
long minDocCount, @Nullable ExtendedBounds extendedBounds, @Nullable ValuesSource.Range valuesSource, | ||
DocValueFormat formatter, SearchContext aggregationContext, | ||
Aggregator parent, List<PipelineAggregator> pipelineAggregators, | ||
|
@@ -79,7 +78,6 @@ class DateRangeHistogramAggregator extends BucketsAggregator { | |
super(name, factories, aggregationContext, parent, pipelineAggregators, metaData); | ||
this.rounding = rounding; | ||
this.shardRounding = shardRounding; | ||
this.offset = offset; | ||
this.order = InternalOrder.validate(order, this); | ||
this.keyed = keyed; | ||
this.minDocCount = minDocCount; | ||
|
@@ -126,8 +124,8 @@ public void collect(int doc, long bucket) throws IOException { | |
// The encoding should ensure that this assert is always true. | ||
assert from >= previousFrom : "Start of range not >= previous start"; | ||
final Long to = (Long) range.getTo(); | ||
final long startKey = offsetAwareRounding(shardRounding, from, offset); | ||
final long endKey = offsetAwareRounding(shardRounding, to, offset); | ||
final long startKey = shardRounding.round(from); | ||
final long endKey = shardRounding.round(to); | ||
for (long key = startKey > previousKey ? startKey : previousKey; key <= endKey; | ||
key = shardRounding.nextRoundingValue(key)) { | ||
if (key == previousKey) { | ||
|
@@ -153,10 +151,6 @@ public void collect(int doc, long bucket) throws IOException { | |
}; | ||
} | ||
|
||
private long offsetAwareRounding(Rounding rounding, long value, long offset) { | ||
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. Glad to see this getting moved into the rounding itself. Makes much more sense. |
||
return rounding.round(value - offset) + offset; | ||
} | ||
|
||
@Override | ||
public InternalAggregation buildAggregation(long owningBucketOrdinal) throws IOException { | ||
assert owningBucketOrdinal == 0; | ||
|
@@ -175,7 +169,7 @@ public InternalAggregation buildAggregation(long owningBucketOrdinal) throws IOE | |
InternalDateHistogram.EmptyBucketInfo emptyBucketInfo = minDocCount == 0 | ||
? new InternalDateHistogram.EmptyBucketInfo(rounding, buildEmptySubAggregations(), extendedBounds) | ||
: null; | ||
return new InternalDateHistogram(name, buckets, order, minDocCount, offset, emptyBucketInfo, formatter, keyed, | ||
return new InternalDateHistogram(name, buckets, order, minDocCount, rounding.offset(), emptyBucketInfo, formatter, keyed, | ||
pipelineAggregators(), metaData()); | ||
} | ||
|
||
|
@@ -184,8 +178,8 @@ public InternalAggregation buildEmptyAggregation() { | |
InternalDateHistogram.EmptyBucketInfo emptyBucketInfo = minDocCount == 0 | ||
? new InternalDateHistogram.EmptyBucketInfo(rounding, buildEmptySubAggregations(), extendedBounds) | ||
: null; | ||
return new InternalDateHistogram(name, Collections.emptyList(), order, minDocCount, offset, emptyBucketInfo, formatter, keyed, | ||
pipelineAggregators(), metaData()); | ||
return new InternalDateHistogram(name, Collections.emptyList(), order, minDocCount, rounding.offset(), emptyBucketInfo, formatter, | ||
keyed, pipelineAggregators(), metaData()); | ||
} | ||
|
||
@Override | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,7 +166,11 @@ ExtendedBounds parseAndValidate(String aggName, QueryShardContext queryShardCont | |
} | ||
|
||
ExtendedBounds round(Rounding rounding) { | ||
return new ExtendedBounds(min != null ? rounding.round(min) : null, max != null ? rounding.round(max) : null); | ||
// Extended bounds shouldn't be effected by the offset | ||
Rounding effectiveRounding = rounding.withoutOffset(); | ||
return new ExtendedBounds( | ||
min != null ? effectiveRounding.round(min) : null, | ||
max != null ? effectiveRounding.round(max) : null); | ||
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. Excellent formatting choice, much more readable. |
||
} | ||
|
||
@Override | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What's the plan to migrate away from this? I'm not sure I understand the benefit to adding a deprecated method now that we intend to remove in the next PR, as opposed to just removing the need for it in this PR.
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 added this to cut the PR in half, basically. I'll remove it in a followup. I believe that follow up with have serialization changes so it'll feel pretty different than this PR.
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.
Seems reasonable, thanks for explaining!