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

Remove the 'array value parser' marker interface. #57571

Merged
merged 1 commit into from
Jun 3, 2020

Conversation

jtibshirani
Copy link
Contributor

This PR replaces the marker interface with the method
FieldMapper#parsesArrayValue. I find this cleaner and it will help cut down
on instanceof checks in the fields retrieval work (#55363).

The refactor also ensures that only field mappers can declare they parse array
values. Previously other types like ObjectMapper could implement the marker
interface and be passed array values, which doesn't make sense.

@jtibshirani jtibshirani added :Search Foundations/Mapping Index mappings, including merging and defining field types >refactoring v8.0.0 v7.8.1 v7.9.0 labels Jun 2, 2020
@elasticmachine
Copy link
Collaborator

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

@elasticmachine elasticmachine added the Team:Search Meta label for search team label Jun 2, 2020
@jtibshirani jtibshirani requested a review from nik9000 June 2, 2020 23:47
This PR replaces the marker interface with the method
FieldMapper#parsesArrayValue. I find this cleaner and it will help with the
fields retrieval work (elastic#55363).

The refactor also ensures that only field mappers can declare they parse array
values. Previously other types like ObjectMapper could implement the marker
interface and be passed array values, which doesn't make sense.
@jtibshirani jtibshirani force-pushed the parse-array-values branch from 4b2dfdb to 2932918 Compare June 2, 2020 23:51
@@ -562,6 +562,10 @@ private static void parseArray(ParseContext context, ObjectMapper parentMapper,
}
}

private static boolean parsesArrayValue(Mapper mapper) {
return mapper instanceof FieldMapper && ((FieldMapper) mapper).parsesArrayValue();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately this refactor didn't actually cut down on the number of instanceof checks. But I feel better about this one, because it's very common for us to check instanceof against FieldMapper or ObjectMapper -- it's just part of how mappings + document parsing currently work.

@nik9000
Copy link
Member

nik9000 commented Jun 3, 2020 via email

@nik9000
Copy link
Member

nik9000 commented Jun 3, 2020 via email

@jtibshirani
Copy link
Contributor Author

jtibshirani commented Jun 3, 2020

We could put the method on Mapper, but that didn't seem conceptually right to me (see my comment above about preventing object mappers from declaring they want array values).

Is there anything we can do to cut down on the instanceof ObjectMapper vs
FieldMapper? Like, in a follow up?

I will give this some thought -- I'll likely file an issue about it so we don't forget. I see it as a worthwhile but bigger and separate refactor from this one.

@jtibshirani
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/1

@nik9000
Copy link
Member

nik9000 commented Jun 3, 2020

I will give this some thought -- I'll likely file an issue about it so we don't forget. I see it as a worthwhile but bigger and separate refactor from this one.

👍

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.

Given that we have this instanceof all the time, I'm ok with it. Its better than a marker interface!

Sometimes I have to take deep breaths and remind myself not to let the perfect be the enemy of the good.

Copy link
Contributor

@markharwood markharwood left a comment

Choose a reason for hiding this comment

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

Small comment but otherwise LGTM

@@ -173,6 +172,11 @@ public DenseVectorFieldType fieldType() {
return (DenseVectorFieldType) super.fieldType();
}

@Override
public boolean parsesArrayValue() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be final, like AbstractGeometryFieldMapper does?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To me this could be a bit confusing, because no other methods on DenseVectorFieldType are final and it wasn't designed for extension.

@jtibshirani
Copy link
Contributor Author

Sometimes I have to take deep breaths and remind myself not to let the perfect be the enemy of the good.

I also found this refactor to be disappointing on its own. But I think we're slowly pushing the document parsing + field mapper code in a good direction.

@jtibshirani
Copy link
Contributor Author

Thank you both for the review !

@jtibshirani jtibshirani merged commit 88a2aeb into elastic:master Jun 3, 2020
@jtibshirani jtibshirani deleted the parse-array-values branch June 3, 2020 17:36
jtibshirani added a commit to jtibshirani/elasticsearch that referenced this pull request Jun 3, 2020
This PR replaces the marker interface with the method
FieldMapper#parsesArrayValue. I find this cleaner and it will help with the
fields retrieval work (elastic#55363).

The refactor also ensures that only field mappers can declare they parse array
values. Previously other types like ObjectMapper could implement the marker
interface and be passed array values, which doesn't make sense.
jtibshirani added a commit to jtibshirani/elasticsearch that referenced this pull request Jun 3, 2020
This PR replaces the marker interface with the method
FieldMapper#parsesArrayValue. I find this cleaner and it will help with the
fields retrieval work (elastic#55363).

The refactor also ensures that only field mappers can declare they parse array
values. Previously other types like ObjectMapper could implement the marker
interface and be passed array values, which doesn't make sense.
jtibshirani added a commit that referenced this pull request Jun 3, 2020
This PR replaces the marker interface with the method
FieldMapper#parsesArrayValue. I find this cleaner and it will help with the
fields retrieval work (#55363).

The refactor also ensures that only field mappers can declare they parse array
values. Previously other types like ObjectMapper could implement the marker
interface and be passed array values, which doesn't make sense.
jtibshirani added a commit that referenced this pull request Jun 3, 2020
This PR replaces the marker interface with the method
FieldMapper#parsesArrayValue. I find this cleaner and it will help with the
fields retrieval work (#55363).

The refactor also ensures that only field mappers can declare they parse array
values. Previously other types like ObjectMapper could implement the marker
interface and be passed array values, which doesn't make sense.
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.8.1 v7.9.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants