-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Replace custom sort field with SortedSetSortField and SortedNumericSortField when possible #23827
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
Conversation
jpountz
left a comment
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 looks great. Before pushing, could you leave some inline comments in the sortField impls to explain the rationale of not using the comparatorsource approach all the time?
| throw new UnsupportedOperationException("no global ordinals sorting yet"); | ||
| public SortField sortField(@Nullable Object missingValue, MultiValueMode sortMode, Nested nested, boolean reverse) { | ||
| return null; | ||
| } |
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.
?
| XFieldComparatorSource source = new BytesRefFieldComparatorSource(this, missingValue, sortMode, nested); | ||
| if (nested != null || | ||
| (sortMode != MultiValueMode.MAX && sortMode != MultiValueMode.MIN) || | ||
| (source.sortMissingFirst(missingValue) == false && source.sortMissingLast(missingValue) == false)) { |
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.
can you indent the content of the if statement and the content of the block at different levels, otherwise I find it a bit hard to read
| if (nested != null | ||
| || (sortMode != MultiValueMode.MAX && sortMode != MultiValueMode.MAX) | ||
| || numericType == NumericType.HALF_FLOAT) { | ||
| return new SortField(fieldName, source, reverse); |
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.
indentation
| if (nested != null || | ||
| (sortMode != MultiValueMode.MAX && sortMode != MultiValueMode.MIN) || | ||
| (source.sortMissingLast(missingValue) == false && source.sortMissingFirst(missingValue) == false)) { | ||
| return new SortField(getFieldName(), source, reverse); |
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.
indentation
| public org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource comparatorSource(Object missingValue, MultiValueMode sortMode, Nested nested) { | ||
| return new BytesRefFieldComparatorSource((IndexFieldData<?>) this, missingValue, sortMode, nested); | ||
| public SortField sortField(@Nullable Object missingValue, MultiValueMode sortMode, Nested nested, boolean reverse) { | ||
| XFieldComparatorSource source = new BytesRefFieldComparatorSource((IndexFieldData<?>) this, missingValue, sortMode, nested); |
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 know it was here before already, but I think we can remove this cast?
…rtField when possible
Currently for field sorting we always use a custom sort field and a custom comparator source.
Though for numeric fields this custom sort field could be replaced with a standard SortedNumericSortField unless
the field is nested especially since we removed the FieldData for numerics.
We can also use a SortedSetSortField for string sort based on doc_values when the field is not nested.
This change replaces IndexFieldData#comparatorSource with IndexFieldData#sortField that returns a Sorted{Set,Numeric}SortField when possible or a custom
sort field when the field sort spec is not handled by the SortedSortFields.
813d9fa to
d844e98
Compare
…rtField when possible (#23827) Currently for field sorting we always use a custom sort field and a custom comparator source. Though for numeric fields this custom sort field could be replaced with a standard SortedNumericSortField unless the field is nested especially since we removed the FieldData for numerics. We can also use a SortedSetSortField for string sort based on doc_values when the field is not nested. This change replaces IndexFieldData#comparatorSource with IndexFieldData#sortField that returns a Sorted{Set,Numeric}SortField when possible or a custom sort field when the field sort spec is not handled by the SortedSortFields.
* master: (137 commits) CONSOLEify the "using scripts" documentation Adds tests for cardinality and filter aggregations Add Backoff policy to azure repository Revert "Adds tests for cardinality and filter aggregations (elastic#23826)" Adds tests for cardinality and filter aggregations (elastic#23826) mute testDifferentRolesMaintainPathOnRestart Replace custom sort field with SortedSetSortField and SortedNumericSortField when possible (elastic#23827) Prevent nodes from joining if newer indices exist in the cluster (elastic#23843) Synchronized CollapseTopFieldDocs with lucenes relatives (elastic#23854) CONSOLEify analysis docs Adapted search_shards rest test to work with Perl To examine an exception in rest tests, the exception should be caught, not ignored Fixed bad YAML in rest tests Fix BootstrapForTesting blowup Ban Boolean#getBoolean Fix language in some docs CONSOLEify lang-analyzer docs Stricter parsing of remote node attribute Fix cross-cluster remote node gateway attributes FieldCapabilitiesRequest should implements Replaceable since it accepts index patterns ...
* master: (146 commits) Introduce single-node discovery Await termination after shutting down executors Fix initialization issue in ElasticsearchException Fix bulk queue size in thread pool docs [DOCS] Remove line about eager loading global ordinals GceDiscoverTests - remove intitial_state_timeout SpecificMasterNodesIT shouldn't use autoMinMasterNodes testRestorePersistentSettings doesn't to mess with discovery settings testDifferentRolesMaintainPathOnRestart shouldn't use auto managing of min master nodes CONSOLEify the "using scripts" documentation Adds tests for cardinality and filter aggregations Add Backoff policy to azure repository Revert "Adds tests for cardinality and filter aggregations (elastic#23826)" Adds tests for cardinality and filter aggregations (elastic#23826) mute testDifferentRolesMaintainPathOnRestart Replace custom sort field with SortedSetSortField and SortedNumericSortField when possible (elastic#23827) Prevent nodes from joining if newer indices exist in the cluster (elastic#23843) Synchronized CollapseTopFieldDocs with lucenes relatives (elastic#23854) CONSOLEify analysis docs Adapted search_shards rest test to work with Perl ...
Currently for field sorting we always use a custom sort field and a custom comparator source.
Though for numeric fields this custom sort field could be replaced with a standard SortedNumericSortField (unless the field is nested) especially since we removed the FieldData for numerics.
We can also use a SortedSetSortField for string sort based on doc_values when the field is not nested.
This change replaces IndexFieldData#comparatorSource with IndexFieldData#sortField that returns a Sorted{Set,Numeric}SortField when possible or a custom sort field when the field sort spec is not handled by the SortedSortFields.