-
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
Decode max and min optimization more carefully #52336
Merged
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 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 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 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 |
---|---|---|
|
@@ -46,13 +46,17 @@ | |
import org.apache.lucene.search.TermQuery; | ||
import org.apache.lucene.store.Directory; | ||
import org.apache.lucene.util.BytesRef; | ||
import org.elasticsearch.Version; | ||
import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
import org.elasticsearch.common.CheckedConsumer; | ||
import org.elasticsearch.common.collect.Tuple; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.IndexSettings; | ||
import org.elasticsearch.index.mapper.ContentPath; | ||
import org.elasticsearch.index.mapper.DateFieldMapper; | ||
import org.elasticsearch.index.mapper.KeywordFieldMapper; | ||
import org.elasticsearch.index.mapper.MappedFieldType; | ||
import org.elasticsearch.index.mapper.Mapper; | ||
import org.elasticsearch.index.mapper.MapperService; | ||
import org.elasticsearch.index.mapper.NumberFieldMapper; | ||
import org.elasticsearch.index.query.QueryShardContext; | ||
|
@@ -87,17 +91,16 @@ | |
import org.elasticsearch.search.lookup.LeafDocLookup; | ||
|
||
import java.io.IOException; | ||
import java.time.Instant; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.BiFunction; | ||
import java.util.function.Consumer; | ||
import java.util.function.DoubleConsumer; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
|
@@ -740,41 +743,56 @@ public void testShortcutIsApplicable() { | |
) | ||
); | ||
} | ||
assertNotNull( | ||
for (DateFieldMapper.Resolution resolution : DateFieldMapper.Resolution.values()) { | ||
assertNull( | ||
MinAggregator.getPointReaderOrNull( | ||
mockSearchContext(new MatchAllDocsQuery()), | ||
mockAggregator(), | ||
mockDateValuesSourceConfig("number", true, resolution) | ||
) | ||
); | ||
assertNull( | ||
MinAggregator.getPointReaderOrNull( | ||
mockSearchContext(new TermQuery(new Term("foo", "bar"))), | ||
null, | ||
mockDateValuesSourceConfig("number", true, resolution) | ||
) | ||
); | ||
assertNull( | ||
MinAggregator.getPointReaderOrNull( | ||
mockSearchContext(null), | ||
mockAggregator(), | ||
mockDateValuesSourceConfig("number", true, resolution) | ||
) | ||
); | ||
assertNull( | ||
MinAggregator.getPointReaderOrNull( | ||
mockSearchContext(null), | ||
null, | ||
mockDateValuesSourceConfig("number", false, resolution) | ||
) | ||
); | ||
} | ||
// Check that we decode a dates "just like" the doc values instance. | ||
Instant expected = Instant.from(DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.parse("2020-01-01T00:00:00Z")); | ||
byte[] scratch = new byte[8]; | ||
LongPoint.encodeDimension(DateFieldMapper.Resolution.MILLISECONDS.convert(expected), scratch, 0); | ||
assertThat( | ||
MinAggregator.getPointReaderOrNull( | ||
mockSearchContext(new MatchAllDocsQuery()), | ||
null, | ||
mockDateValuesSourceConfig("number", true) | ||
) | ||
mockDateValuesSourceConfig("number", true, DateFieldMapper.Resolution.MILLISECONDS) | ||
).apply(scratch), equalTo(expected.toEpochMilli()) | ||
); | ||
assertNull( | ||
LongPoint.encodeDimension(DateFieldMapper.Resolution.NANOSECONDS.convert(expected), scratch, 0); | ||
assertThat( | ||
MinAggregator.getPointReaderOrNull( | ||
mockSearchContext(new MatchAllDocsQuery()), | ||
mockAggregator(), | ||
mockDateValuesSourceConfig("number", true) | ||
) | ||
); | ||
assertNull( | ||
MinAggregator.getPointReaderOrNull( | ||
mockSearchContext(new TermQuery(new Term("foo", "bar"))), | ||
null, | ||
mockDateValuesSourceConfig("number", true) | ||
) | ||
); | ||
assertNull( | ||
MinAggregator.getPointReaderOrNull( | ||
mockSearchContext(null), | ||
mockAggregator(), | ||
mockDateValuesSourceConfig("number", true) | ||
) | ||
); | ||
assertNull( | ||
MinAggregator.getPointReaderOrNull( | ||
mockSearchContext(null), | ||
null, | ||
mockDateValuesSourceConfig("number", false) | ||
) | ||
mockDateValuesSourceConfig("number", true, DateFieldMapper.Resolution.NANOSECONDS) | ||
).apply(scratch), equalTo(expected.toEpochMilli()) | ||
); | ||
|
||
} | ||
|
||
public void testMinShortcutRandom() throws Exception { | ||
|
@@ -799,21 +817,6 @@ public void testMinShortcutRandom() throws Exception { | |
(v) -> DoublePoint.decodeDimension(v, 0)); | ||
} | ||
|
||
private void testMinCase(IndexSearcher searcher, | ||
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. This isn't used any more. |
||
AggregationBuilder aggregationBuilder, | ||
MappedFieldType ft, | ||
DoubleConsumer testResult) throws IOException { | ||
Collection<Query> queries = Arrays.asList(new MatchAllDocsQuery(), new DocValuesFieldExistsQuery(ft.name())); | ||
for (Query query : queries) { | ||
MinAggregator aggregator = createAggregator(query, aggregationBuilder, searcher, createIndexSettings(), ft); | ||
aggregator.preCollection(); | ||
searcher.search(new MatchAllDocsQuery(), aggregator); | ||
aggregator.postCollection(); | ||
InternalMin result = (InternalMin) aggregator.buildAggregation(0L); | ||
testResult.accept(result.getValue()); | ||
} | ||
} | ||
|
||
private void testMinShortcutCase(Supplier<Number> randomNumber, | ||
Function<Number, Field> pointFieldFunc, | ||
Function<byte[], Number> pointConvertFunc) throws IOException { | ||
|
@@ -889,12 +892,17 @@ private ValuesSourceConfig<ValuesSource.Numeric> mockNumericValuesSourceConfig(S | |
return config; | ||
} | ||
|
||
private ValuesSourceConfig<ValuesSource.Numeric> mockDateValuesSourceConfig(String fieldName, boolean indexed) { | ||
private ValuesSourceConfig<ValuesSource.Numeric> mockDateValuesSourceConfig(String fieldName, boolean indexed, | ||
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. There is a ton more ceremony here because |
||
DateFieldMapper.Resolution resolution) { | ||
ValuesSourceConfig<ValuesSource.Numeric> config = mock(ValuesSourceConfig.class); | ||
MappedFieldType ft = new DateFieldMapper.Builder(fieldName).fieldType(); | ||
ft.setName(fieldName); | ||
ft.setIndexOptions(indexed ? IndexOptions.DOCS : IndexOptions.NONE); | ||
ft.freeze(); | ||
Mapper.BuilderContext builderContext = new Mapper.BuilderContext( | ||
Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(), | ||
new ContentPath()); | ||
MappedFieldType ft = new DateFieldMapper.Builder(fieldName) | ||
.index(indexed) | ||
.withResolution(resolution) | ||
.build(builderContext) | ||
.fieldType(); | ||
when(config.fieldContext()).thenReturn(new FieldContext(fieldName, null, ft)); | ||
return config; | ||
} | ||
|
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.
This was a javadoc comment in an invalid spot for javadoc.