-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Solving wildcard sorting issue for doc_values #18568
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
Merged
Changes from 41 commits
Commits
Show all changes
90 commits
Select commit
Hold shift + click to select a range
164a85e
temorary solve
ajleong623 1825559
spotless
ajleong623 f16b39f
Merge branch 'opensearch-project:main' into wildcard-bug
ajleong623 1741b80
still have to change derived field generator
ajleong623 90f73e2
spotless apply
ajleong623 ffda262
added binary doc values fetcher
ajleong623 723ab8f
supported field types
ajleong623 b54c85e
spotlessapply
ajleong623 447c45d
small change
ajleong623 a8a9e84
disable skipping optimization by changing doc values to binary docs
ajleong623 3b5a2fe
skip sorting wildcard tests for before 3.2.0
ajleong623 2ef4902
Merge branch 'opensearch-project:main' into wildcard-bug
ajleong623 b7313cc
skip running wildcard searches with older versions
ajleong623 5e416a9
skip running wildcard searches with older versions
ajleong623 8b5181f
skip running wildcard searches with older versions
ajleong623 9084f00
original wildcard taml test
ajleong623 9de80c3
parse field for correct version
ajleong623 2a411a5
check correct version
ajleong623 69fad28
test skipping
ajleong623 2c876bf
update wildcard mapper
ajleong623 4b22303
update wildcard mapper
ajleong623 9ddc6e4
update wildcard mapper
ajleong623 19ae6c2
adjust version final
ajleong623 cf505a3
try to disable pruning
ajleong623 a9d940f
spotless and add license
ajleong623 9b8ed7f
java docs and test revert
ajleong623 9f40b3e
Merge branch 'opensearch-project:main' into wildcard-bug
ajleong623 56a94a7
update lucene serialization
ajleong623 d5761a1
Merge branch 'wildcard-bug' of https://github.com/ajleong623/OpenSear…
ajleong623 59ddd2e
delete binary doc values fetcher
ajleong623 7f1df80
fix casting
ajleong623 908593d
non pruning test coverage
ajleong623 dea8109
non pruning test coverage
ajleong623 d8cd0bf
Added more code coverage
ajleong623 1f5b18f
code coverage
ajleong623 a5f474d
Merge branch 'main' into wildcard-bug
ajleong623 101810e
retry
ajleong623 3135fa5
Merge branch 'wildcard-bug' of https://github.com/ajleong623/OpenSear…
ajleong623 751e6fb
retry
ajleong623 ff70c05
the test that failed last time is flaky as I have tried it out on the…
ajleong623 8023bef
cast parsing
ajleong623 ea82489
apply suggestions
ajleong623 fddd862
Merge branch 'main' into wildcard-bug
ajleong623 0d27c7a
reduce the number of methods in NonPruningSortField
ajleong623 c66b323
Merge branch 'wildcard-bug' of https://github.com/ajleong623/OpenSear…
ajleong623 e89f5bf
spotless
ajleong623 39aee3e
Merge branch 'opensearch-project:main' into wildcard-bug
ajleong623 9eeae28
Make sure wildcard search is only checked after 3.3.0
ajleong623 388d2f1
rerun for nondeterministic tests
ajleong623 f9be6f4
Merge branch 'wildcard-bug' of https://github.com/ajleong623/OpenSear…
ajleong623 73fb673
block casting error
ajleong623 d76264f
block casting error
ajleong623 1ef8c34
add check for casting type
ajleong623 ee2c0d9
smoke tests did not run
ajleong623 4330d51
rerun for smoke tests
ajleong623 57ea1ce
rerun for smoke tests
ajleong623 26fca74
Merge branch 'opensearch-project:main' into wildcard-bug
ajleong623 1412294
rerun for flaky detection
ajleong623 4b76d57
rerun for flaky detection
ajleong623 0535677
made changes based on suggestions
ajleong623 4b617fa
fix changelog order
ajleong623 eb61165
Merge branch 'main' into wildcard-bug
ajleong623 9a5d09a
fixed conditional
ajleong623 8fb2860
refactored testing for NonPruningSortedSetOrdinalsIndexFieldDataTests
ajleong623 b0205c5
timed out last time
ajleong623 a67685f
timed out last time
ajleong623 9779af4
Merge branch 'main' into wildcard-bug
ajleong623 e683b30
the negation actually did not go through
ajleong623 94ff235
Merge branch 'wildcard-bug' of https://github.com/ajleong623/OpenSear…
ajleong623 1f03ed0
fix casting error
ajleong623 7e11909
spotless
ajleong623 87f0c93
put serializer in the right place
ajleong623 931b896
Merge branch 'main' into wildcard-bug
ajleong623 aad91ce
rerun spotless
ajleong623 d75b6a9
retry spotless
ajleong623 73d13a2
retry spotless
ajleong623 329a9e6
retry spotless
ajleong623 f6112ac
updated serialization of NonPruningSortField
ajleong623 31f34af
Merge branch 'opensearch-project:main' into wildcard-bug
ajleong623 cdf3779
retry for flaky
ajleong623 505ae6e
retry for flaky
ajleong623 3dec070
updated serialization
ajleong623 5c80ab3
test coverage
ajleong623 04b2a72
retry for flaky
ajleong623 c1f59b6
retry for flaky
ajleong623 91ca440
retry for flaky
ajleong623 f033417
retry for flaky
ajleong623 e55207c
retry for flaky
ajleong623 07eeca3
retry for flaky
ajleong623 c205ff4
retry for flaky
ajleong623 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
228 changes: 228 additions & 0 deletions
228
.../java/org/opensearch/index/fielddata/plain/NonPruningSortedSetOrdinalsIndexFieldData.java
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 |
|---|---|---|
| @@ -0,0 +1,228 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.index.fielddata.plain; | ||
|
|
||
| import org.apache.lucene.index.IndexSorter; | ||
| import org.apache.lucene.index.SortedSetDocValues; | ||
| import org.apache.lucene.search.FieldComparator; | ||
| import org.apache.lucene.search.FieldComparatorSource; | ||
| import org.apache.lucene.search.IndexSearcher; | ||
| import org.apache.lucene.search.Pruning; | ||
| import org.apache.lucene.search.SortField; | ||
| import org.apache.lucene.search.SortedSetSelector; | ||
| import org.apache.lucene.search.SortedSetSortField; | ||
| import org.apache.lucene.store.DataInput; | ||
| import org.apache.lucene.util.BytesRef; | ||
| import org.opensearch.common.Nullable; | ||
| import org.opensearch.core.indices.breaker.CircuitBreakerService; | ||
| import org.opensearch.index.fielddata.IndexFieldData; | ||
| import org.opensearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested; | ||
| import org.opensearch.index.fielddata.IndexFieldDataCache; | ||
| import org.opensearch.index.fielddata.ScriptDocValues; | ||
| import org.opensearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource; | ||
| import org.opensearch.index.mapper.WildcardFieldMapper; | ||
| import org.opensearch.search.MultiValueMode; | ||
| import org.opensearch.search.aggregations.support.ValuesSourceType; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Comparator; | ||
| import java.util.function.Function; | ||
|
|
||
| /** | ||
| * Wrapper for {@link SortedSetOrdinalsIndexFieldData} which disables pruning optimization for | ||
| * sorting. Used in {@link WildcardFieldMapper}. | ||
| * | ||
| * @opensearch.internal | ||
| */ | ||
| public class NonPruningSortedSetOrdinalsIndexFieldData extends SortedSetOrdinalsIndexFieldData { | ||
|
|
||
| /** | ||
| * Builder for non-pruning sorted set ordinals | ||
| * | ||
| * @opensearch.internal | ||
| */ | ||
| public static class Builder implements IndexFieldData.Builder { | ||
| private final String name; | ||
| private final Function<SortedSetDocValues, ScriptDocValues<?>> scriptFunction; | ||
| private final ValuesSourceType valuesSourceType; | ||
|
|
||
| public Builder(String name, ValuesSourceType valuesSourceType) { | ||
| this(name, AbstractLeafOrdinalsFieldData.DEFAULT_SCRIPT_FUNCTION, valuesSourceType); | ||
| } | ||
|
|
||
| public Builder(String name, Function<SortedSetDocValues, ScriptDocValues<?>> scriptFunction, ValuesSourceType valuesSourceType) { | ||
| this.name = name; | ||
| this.scriptFunction = scriptFunction; | ||
| this.valuesSourceType = valuesSourceType; | ||
| } | ||
|
|
||
| @Override | ||
| public NonPruningSortedSetOrdinalsIndexFieldData build(IndexFieldDataCache cache, CircuitBreakerService breakerService) { | ||
| return new NonPruningSortedSetOrdinalsIndexFieldData(cache, name, valuesSourceType, breakerService, scriptFunction); | ||
| } | ||
| } | ||
|
|
||
| public NonPruningSortedSetOrdinalsIndexFieldData( | ||
| IndexFieldDataCache cache, | ||
| String fieldName, | ||
| ValuesSourceType valuesSourceType, | ||
| CircuitBreakerService breakerService, | ||
| Function<SortedSetDocValues, ScriptDocValues<?>> scriptFunction | ||
| ) { | ||
| super(cache, fieldName, valuesSourceType, breakerService, scriptFunction); | ||
| } | ||
|
|
||
| @Override | ||
| public SortField sortField(@Nullable Object missingValue, MultiValueMode sortMode, Nested nested, boolean reverse) { | ||
| XFieldComparatorSource source = new BytesRefFieldComparatorSource(this, missingValue, sortMode, nested); | ||
| /* | ||
| Check if we can use a simple {@link SortedSetSortField} compatible with index sorting and | ||
| returns a custom sort field otherwise. | ||
| */ | ||
| if (nested != null | ||
| || (sortMode != MultiValueMode.MAX && sortMode != MultiValueMode.MIN) | ||
| || (source.sortMissingLast(missingValue) == false && source.sortMissingFirst(missingValue) == false)) { | ||
| return new NonPruningSortField(new SortField(getFieldName(), source, reverse)); | ||
| } | ||
| SortField sortField = new NonPruningSortField( | ||
| new SortedSetSortField( | ||
| getFieldName(), | ||
| reverse, | ||
| sortMode == MultiValueMode.MAX ? SortedSetSelector.Type.MAX : SortedSetSelector.Type.MIN | ||
| ) | ||
| ); | ||
| sortField.setMissingValue( | ||
| source.sortMissingLast(missingValue) ^ reverse ? SortedSetSortField.STRING_LAST : SortedSetSortField.STRING_FIRST | ||
| ); | ||
| return sortField; | ||
| } | ||
|
|
||
| /** | ||
| * {@link SortField} extension which disables pruning in the comparator. | ||
| * | ||
| * @opensearch.internal | ||
| */ | ||
| public static class NonPruningSortField extends SortField { | ||
ajleong623 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private final SortField delegate; | ||
|
|
||
| private NonPruningSortField(SortField sortField) { | ||
| super(sortField.getField(), sortField.getType()); | ||
| this.delegate = sortField; | ||
| } | ||
|
|
||
| public static Type readType(DataInput in) throws IOException { | ||
| return SortField.readType(in); | ||
| } | ||
|
|
||
| @Override | ||
| public Object getMissingValue() { | ||
| return delegate.getMissingValue(); | ||
| } | ||
|
|
||
| @Override | ||
| public void setMissingValue(Object missingValue) { | ||
| delegate.setMissingValue(missingValue); | ||
| } | ||
|
|
||
| @Override | ||
| public String getField() { | ||
| return delegate.getField(); | ||
| } | ||
|
|
||
| @Override | ||
| public Type getType() { | ||
| return delegate.getType(); | ||
| } | ||
ajleong623 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public boolean getReverse() { | ||
| return delegate.getReverse(); | ||
| } | ||
|
|
||
| @Override | ||
| public FieldComparatorSource getComparatorSource() { | ||
| FieldComparatorSource source = delegate.getComparatorSource(); | ||
| return new FieldComparatorSource() { | ||
| @Override | ||
| public FieldComparator<?> newComparator(String fieldname, int numHits, Pruning pruning, boolean reversed) { | ||
| return source.newComparator(fieldname, numHits, Pruning.NONE, reversed); // < ----------- ALWAYS DISABLE PRUNING | ||
ajleong623 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return delegate.toString(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| return delegate.equals(o); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return delegate.hashCode(); | ||
| } | ||
|
|
||
| @Override | ||
| public void setBytesComparator(Comparator<BytesRef> b) { | ||
| delegate.setBytesComparator(b); | ||
| } | ||
|
|
||
| @Override | ||
| public Comparator<BytesRef> getBytesComparator() { | ||
| return delegate.getBytesComparator(); | ||
| } | ||
|
|
||
| @Override | ||
| public FieldComparator<?> getComparator(int numHits, Pruning pruning) { | ||
| return delegate.getComparator(numHits, Pruning.NONE); // < ----------- ALWAYS DISABLE PRUNING | ||
| } | ||
|
|
||
| @Override | ||
| public SortField rewrite(IndexSearcher searcher) throws IOException { | ||
| return delegate.rewrite(searcher); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean needsScores() { | ||
| return delegate.needsScores(); | ||
| } | ||
|
|
||
| @Override | ||
| public IndexSorter getIndexSorter() { | ||
| return delegate.getIndexSorter(); | ||
| } | ||
|
|
||
| @Deprecated | ||
| @Override | ||
| public void setOptimizeSortWithIndexedData(boolean optimizeSortWithIndexedData) { | ||
| delegate.setOptimizeSortWithIndexedData(optimizeSortWithIndexedData); | ||
| } | ||
|
|
||
| @Deprecated | ||
| @Override | ||
| public boolean getOptimizeSortWithIndexedData() { | ||
| return delegate.getOptimizeSortWithIndexedData(); | ||
| } | ||
|
|
||
| @Deprecated | ||
| @Override | ||
| public void setOptimizeSortWithPoints(boolean optimizeSortWithPoints) { | ||
| delegate.setOptimizeSortWithPoints(optimizeSortWithPoints); | ||
| } | ||
|
|
||
| @Deprecated | ||
| @Override | ||
| public boolean getOptimizeSortWithPoints() { | ||
| return delegate.getOptimizeSortWithPoints(); | ||
| } | ||
| } | ||
| } | ||
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
67 changes: 67 additions & 0 deletions
67
.../org/opensearch/index/fielddata/plain/NonPruningSortedSetOrdinalsIndexFieldDataTests.java
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 |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.index.fielddata.plain; | ||
|
|
||
| import org.apache.lucene.search.Pruning; | ||
| import org.apache.lucene.search.SortField; | ||
| import org.apache.lucene.search.SortedSetSortField; | ||
| import org.opensearch.index.IndexService; | ||
| import org.opensearch.index.fielddata.IndexFieldData; | ||
| import org.opensearch.index.fielddata.IndexFieldDataService; | ||
| import org.opensearch.index.fielddata.plain.NonPruningSortedSetOrdinalsIndexFieldData.NonPruningSortField; | ||
| import org.opensearch.index.mapper.ContentPath; | ||
| import org.opensearch.index.mapper.MappedFieldType; | ||
| import org.opensearch.index.mapper.Mapper.BuilderContext; | ||
| import org.opensearch.index.mapper.WildcardFieldMapper; | ||
| import org.opensearch.indices.IndicesService; | ||
| import org.opensearch.search.MultiValueMode; | ||
| import org.opensearch.test.OpenSearchSingleNodeTestCase; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class NonPruningSortedSetOrdinalsIndexFieldDataTests extends OpenSearchSingleNodeTestCase { | ||
| public void testNonPruningSortedSetOrdinalsIndexFieldData() throws IOException { | ||
| final IndexService indexService = createIndex("test"); | ||
| final IndicesService indicesService = getInstanceFromNode(IndicesService.class); | ||
| final IndexFieldDataService ifdService = new IndexFieldDataService( | ||
| indexService.getIndexSettings(), | ||
| indicesService.getIndicesFieldDataCache(), | ||
| indicesService.getCircuitBreakerService(), | ||
| indexService.mapperService(), | ||
| indexService.getThreadPool() | ||
| ); | ||
| final BuilderContext ctx = new BuilderContext(indexService.getIndexSettings().getSettings(), new ContentPath(1)); | ||
| final MappedFieldType stringMapper = new WildcardFieldMapper.Builder("string").docValues(true).build(ctx).fieldType(); | ||
| ifdService.clear(); | ||
| IndexFieldData<?> fd = ifdService.getForField(stringMapper, "test", () -> { throw new UnsupportedOperationException(); }); | ||
| assertTrue(fd instanceof NonPruningSortedSetOrdinalsIndexFieldData); | ||
| SortField field = ((NonPruningSortedSetOrdinalsIndexFieldData) fd).sortField(null, MultiValueMode.MAX, null, false); | ||
| assertTrue(field instanceof NonPruningSortField); | ||
|
|
||
| // Test all the methods of NonPruningSortField for code coverage | ||
|
|
||
| field.setMissingValue(SortedSetSortField.STRING_FIRST); | ||
| field.getMissingValue(); | ||
| field.getField(); | ||
| field.getType(); | ||
| assertFalse(field.getReverse()); | ||
| field.getComparatorSource(); | ||
| field.toString(); | ||
| field.hashCode(); | ||
| field.equals(field); | ||
| field.getBytesComparator(); | ||
| field.getComparator(0, Pruning.NONE); | ||
| field.needsScores(); | ||
| field.getIndexSorter(); | ||
| field.setOptimizeSortWithIndexedData(false); | ||
| field.getOptimizeSortWithIndexedData(); | ||
| field.setOptimizeSortWithPoints(false); | ||
| field.getOptimizeSortWithPoints(); | ||
msfroh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.