-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Option to configure default analysis types in SegmentMetadataQuery #4259
Changes from 2 commits
ddb6565
4103a6c
9891b09
81e7464
6c9cde2
a756d4f
dfacab1
98db5a7
7313175
6612a4a
639661f
cb98ac3
5529f6a
b544694
f68927e
aee4da9
6e1a11c
bd2324f
1871c92
6433796
7096d9a
8aecbde
b7f586c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,7 +89,10 @@ public SegmentMetadataQueryQueryToolChest(SegmentMetadataQueryConfig config) | |
} | ||
|
||
@Inject | ||
public SegmentMetadataQueryQueryToolChest(SegmentMetadataQueryConfig config, GenericQueryMetricsFactory queryMetricsFactory) | ||
public SegmentMetadataQueryQueryToolChest( | ||
SegmentMetadataQueryConfig config, | ||
GenericQueryMetricsFactory queryMetricsFactory | ||
) | ||
{ | ||
this.config = config; | ||
this.queryMetricsFactory = queryMetricsFactory; | ||
|
@@ -233,18 +236,30 @@ public SegmentAnalysis apply(@Nullable SegmentAnalysis input) | |
@Override | ||
public <T extends LogicalSegment> List<T> filterSegments(SegmentMetadataQuery query, List<T> segments) | ||
{ | ||
if (!query.isUsingDefaultInterval()) { | ||
return segments; | ||
} | ||
|
||
if (segments.size() <= 1) { | ||
return segments; | ||
} | ||
|
||
final T max = segments.get(segments.size() - 1); | ||
|
||
DateTime targetEnd = max.getInterval().getEnd(); | ||
final Interval targetInterval = new Interval(config.getDefaultHistory(), targetEnd); | ||
List<Interval> intervals = query.getIntervals(); | ||
|
||
DateTime queryStartTime = JodaUtils.ETERNITY.getEnd(); | ||
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. In other parts of the Druid codebase |
||
DateTime queryEndTIme = JodaUtils.ETERNITY.getStart(); | ||
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. queryEndTime |
||
|
||
for (Interval interval : intervals) { | ||
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. Consider queryStartTime = intervals.stream().map(Interval::getEnd)
.max(Ordering.natural()).orElseThrow(IllegalStateException::new); |
||
queryEndTIme = queryEndTIme.isAfter(interval.getEnd()) ? queryEndTIme : interval.getEnd(); | ||
queryStartTime = queryStartTime.isBefore(interval.getStart()) ? queryStartTime : interval.getStart(); | ||
} | ||
|
||
Interval targetInterval; | ||
if (!query.isUsingDefaultInterval()) { | ||
targetInterval = new Interval(queryStartTime, queryEndTIme); | ||
} else { | ||
DateTime finalEndTime = queryEndTIme.isBefore(targetEnd) ? queryEndTIme : targetEnd; | ||
targetInterval = new Interval(config.getDefaultHistory(), finalEndTime); | ||
} | ||
|
||
return Lists.newArrayList( | ||
Iterables.filter( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,13 +117,8 @@ public SegmentMetadataQuery( | |
if (querySegmentSpec == null) { | ||
this.usingDefaultInterval = true; | ||
} else { | ||
if (querySegmentSpec.getIntervals().size() == 1 && querySegmentSpec.getIntervals() | ||
.get(0) | ||
.equals(DEFAULT_INTERVAL)) { | ||
this.usingDefaultInterval = true; | ||
} else { | ||
this.usingDefaultInterval = false; | ||
} | ||
this.usingDefaultInterval = (querySegmentSpec.getIntervals().size() == 1 && | ||
querySegmentSpec.getIntervals().get(0).equals(DEFAULT_INTERVAL)); | ||
} | ||
this.toInclude = toInclude == null ? new AllColumnIncluderator() : toInclude; | ||
this.merge = merge == null ? false : merge; | ||
|
@@ -262,9 +257,14 @@ public SegmentMetadataQuery withFinalizedAnalysisTypes(SegmentMetadataQueryConfi | |
return this; | ||
} | ||
return Druids.SegmentMetadataQueryBuilder | ||
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. Don't create a new query object if analysisTypes are already non-null, just return |
||
.copy(this) | ||
.analysisTypes(config.getDefaultAnalysisTypes()) | ||
.build(); | ||
.copy(this) | ||
.analysisTypes(config.getDefaultAnalysisTypes()) | ||
.build(); | ||
} | ||
|
||
public List<Interval> getIntervals() | ||
{ | ||
return this.getQuerySegmentSpec().getIntervals(); | ||
} | ||
|
||
@Override | ||
|
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 purpose of the changes in this method? They don't seem related to the rest of the patch.
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, these are unrelated to the changes proposed for this patch, I'll open up another PR for this.
The current implementation does not take into consideration the time range while filtering, I added an improvement to only include segments that are within the intervals mentioned by the query.
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.
filterSegments doesn't need to worry about that, since the list of segments it gets has already been pruned down to whatever matches the intervals filter. In fact many implementations just
return segments;
with no changes -- check out timeseries for an example. filterSegments only has to potentially filter it down even further, if it wants (see timeBoundary for another example of that). I suppose the javadocs for filterSegments could be more clear on this.Please also see #4259 (review) for rationale about the current behavior of defaultInterval.
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 was under the impression that this method was called to prune the segments to include only the required ones from a list of all segments, didn't know it was already pruned. Now that I look at the examples you suggested I understand why it is required even if we already prune it.
Reg:
defaultInterval
- I had some failing tests that were because ofdefaultInterval
, I don't remember the exact test case, but reverting to the old behavior did not break any tests (probably the change of not having null configs helped I guess), so we can keep the implementation on masterI excluded these changes from this PR.