Skip to content
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

Add equals/hashcode to fieldtypes #11644

Merged
merged 2 commits into from Jun 15, 2015

Conversation

rjernst
Copy link
Member

@rjernst rjernst commented Jun 12, 2015

In order to restrict a single set of field type settings for a given
field name across an index, we need the ability to compare field types.
This change adds equals and hashcode, as well as tests for every field
type.

In order to restrict a single set of field type settings for a given
field name across an index, we need the ability to compare field types.
This change adds equals and hashcode, as well as tests for every field
type.
@rjernst rjernst added v2.0.0-beta1 :Search/Mapping Index mappings, including merging and defining field types labels Jun 12, 2015
@rjernst
Copy link
Member Author

rjernst commented Jun 12, 2015

Note there were also some bugs found in GeoShapeFieldMapper that are fixed here. Notably the default strategy, tree level, and tree precision were not correctly serialized.

@clintongormley clintongormley changed the title Mappings: Add equals/hashcode to fieldtypes Add equals/hashcode to fieldtypes Jun 13, 2015
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof MappedFieldType)) return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

super.equals already ensures this, since it does: if (getClass() != obj.getClass()) return false;

Copy link
Member Author

Choose a reason for hiding this comment

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

I generated all equals/hashcode methods with intellij. I've removed the checks before super.equals, and filed an issue with intellij [1] to be smarter about this.

I also had noticed always using Objects.equals here, even for primitive types. It looks like this is fixed [2] in an unreleased version of intellij. For now, I've gone through and changed each primitive type to use == instead.

[1] https://youtrack.jetbrains.com/issue/IDEA-141479
[2] https://youtrack.jetbrains.com/issue/IDEA-139622

@jpountz
Copy link
Contributor

jpountz commented Jun 15, 2015

I left some minor comments but I like the PR in general, especially the careful unit tests.

geoShapeFieldType.setStrategies(strategyName, recursiveStrategy, termStrategy);
geoShapeFieldType.setOrientation(orientation);
if (context.indexCreatedVersion().before(Version.V_2_0_0) ||
(geoShapeFieldType.treeLevels() == 0 && geoShapeFieldType.precisionInMeters() < 0)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this was here before, definitely not a blocker as we can clean it up in another PR, but this treeLevels == 0 check has bothered me. Especially since a treeLevel of 0 doesn't make sense and this is only used as an "initial state" condition. It seems cleaner to set the default tree and level at construction and appropriately change if/when the user explicitly defines the tree? That might make these conditionals cleaner and the whole tree parameter code easier to read?

Copy link
Contributor

Choose a reason for hiding this comment

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

Since this isn't a blocker we'll cleanup these defaults in a separate 2.x issue. Opened #11682 to track.

@nknize
Copy link
Contributor

nknize commented Jun 15, 2015

Geo field changes LGTM

@rjernst
Copy link
Member Author

rjernst commented Jun 15, 2015

@jpountz I pushed a new commit.

@jpountz
Copy link
Contributor

jpountz commented Jun 15, 2015

LGTM

rjernst added a commit that referenced this pull request Jun 15, 2015
@rjernst rjernst merged commit 7ab0009 into elastic:master Jun 15, 2015
@rjernst rjernst deleted the refactor/field-type-equality branch June 15, 2015 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Search/Mapping Index mappings, including merging and defining field types v2.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants