Skip to content

Conversation

@romseygeek
Copy link
Contributor

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.

@romseygeek romseygeek added :Search Foundations/Mapping Index mappings, including merging and defining field types >refactoring v8.0.0 v7.9.0 labels Jul 8, 2020
@romseygeek romseygeek self-assigned this Jul 8, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Mapping)

@elasticmachine elasticmachine added the Team:Search Meta label for search team label Jul 8, 2020
eagerGlobalOrdinals, meta);
}

// TODO: we need to override freeze() and add safety checks that all settings are actually set
Copy link
Contributor Author

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

Copy link
Member

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);
}
}
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor

@jtibshirani jtibshirani left a 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);
Copy link
Contributor

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)?

Copy link
Contributor Author

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...

@nik9000
Copy link
Member

nik9000 commented Jul 8, 2020

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 ?

I think we only do this one request and response objects so we can assert round tripping them.

Copy link
Member

@nik9000 nik9000 left a 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() {
Copy link
Member

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
Copy link
Member

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 &&
Copy link
Member

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
Copy link
Member

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 {
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@romseygeek
Copy link
Contributor Author

@elasticmachine update branch

@romseygeek romseygeek merged commit 62f51eb into elastic:master Jul 9, 2020
@romseygeek romseygeek deleted the mapper/fieldtype-equals branch July 9, 2020 20:01
romseygeek added a commit that referenced this pull request Jul 9, 2020
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.
romseygeek added a commit that referenced this pull request Jul 14, 2020
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.
romseygeek added a commit that referenced this pull request Jul 16, 2020
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>refactoring :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Meta label for search team v7.9.0 v8.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants