-
Notifications
You must be signed in to change notification settings - Fork 25.6k
MappedFieldType no longer requires equals/hashCode/clone #59212
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
|
Pinging @elastic/es-search (:Search/Mapping) |
| eagerGlobalOrdinals, meta); | ||
| } | ||
|
|
||
| // TODO: we need to override freeze() and add safety checks that all settings are actually set |
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 TODO doesn't make sense now that we don't extend lucene's FieldType
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.
👍
| protected MappedFieldType createDefaultFieldType(String name, Map<String, String> meta) { | ||
| return new BinaryFieldMapper.BinaryFieldType(name, true, meta); | ||
| } | ||
| } |
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.
FieldTypeTestCase extensions that test only equals and hashCode can just be removed entirely. BinaryFieldType doesn't have any search methods on it, and docvalues are tested in BinaryFieldMapperTests
|
|
||
| public class TextFieldTypeTests extends FieldTypeTestCase<TextFieldType> { | ||
|
|
||
| @Before |
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.
We check that these modifications block merging in TextFieldMapperTests, so we can safely remove them here - this is just checking the equals implementation, which is now gone.
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.
👍. That is a better place for them.
jtibshirani
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 is a nice simplification! I left one comment about an accidental change in a test.
I was also curious, do we have a standard practice as to when we implement equals/ hashCode versus omitting them? We certainly implement these on request and response objects, but I think we make a case-by-case choice for internal objects like MappedFieldType ?
|
|
||
| public void testIsAggregatable() { | ||
| MappedFieldType fieldType = createDefaultFieldType("field", Collections.emptyMap()); | ||
| MappedFieldType fieldType = new RankFeatureFieldMapper.RankFeatureFieldType("field", Collections.emptyMap(), true); |
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 don't think this should have changed, now we're creating RankFeatureFieldType (singular not plural)?
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.
Oh, good catch! Autocomplete is not always my friend...
I think we only do this one request and response objects so we can assert round tripping them. |
nik9000
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 is great! @jtibshirani found something worth fixing before merging, but it is wonderful to see so much subtracted code!
| this.positiveScoreImpact = ref.positiveScoreImpact; | ||
| } | ||
|
|
||
| public RankFeatureFieldType clone() { |
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'm so happy to see clone go!
| eagerGlobalOrdinals, meta); | ||
| } | ||
|
|
||
| // TODO: we need to override freeze() and add safety checks that all settings are actually set |
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.
👍
| if (o == null || getClass() != o.getClass()) return false; | ||
| if (!super.equals(o)) return false; | ||
| PrefixFieldType that = (PrefixFieldType) o; | ||
| return minChars == that.minChars && |
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.
Yikes! This was never really equality!
|
|
||
| public class TextFieldTypeTests extends FieldTypeTestCase<TextFieldType> { | ||
|
|
||
| @Before |
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.
👍. That is a better place for them.
|
|
||
| /** Base test case for subclasses of MappedFieldType */ | ||
| public abstract class FieldTypeTestCase<T extends MappedFieldType> extends ESTestCase { | ||
| public abstract class FieldTypeTestCase extends ESTestCase { |
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.
It might be worth dropping this in a followup. It is just about empty now.
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.
The mock shard contexts are still pretty widely used, so I think it's worth keeping for now.
javanna
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.
LGTM
|
@elasticmachine update branch |
With the removal of mapping types and the immutability of FieldTypeLookup in #58162, we no longer have any cause to compare MappedFieldType instances. This means that we can remove all equals and hashCode implementations, and in addition we no longer need the clone implementations which were required for equals/hashcode testing. This greatly simplifies implementing new MappedFieldTypes, which will be particularly useful for the runtime fields project.
The MappedFieldType#updateMeta method was used for testing equality checks, but we no longer need these after #59212 , so we can remove this method and make meta final.
The MappedFieldType#updateMeta method was used for testing equality checks, but we no longer need these after #59212 , so we can remove this method and make meta final.
With the removal of mapping types and the immutability of FieldTypeLookup in #58162, we no longer
have any cause to compare MappedFieldType instances. This means that we can remove all equals
and hashCode implementations, and in addition we no longer need the clone implementations which
were required for equals/hashcode testing. This greatly simplifies implementing new MappedFieldTypes,
which will be particularly useful for the runtime fields project.