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

Internal: make sure ParseField is always used in combination with parse flags #11859

Closed
wants to merge 1 commit into from

Conversation

javanna
Copy link
Member

@javanna javanna commented Jun 24, 2015

Removed ParseField#match variant that accepts the field name only, without parse flags. Such a method is harmful as it defaults to empty parse flags, meaning that no deprecation exceptions will be thrown in strict mode, which defeats the purpose of using ParseField. Unfortunately such a method was used in a lot of places were the parse flags weren't accessible (outside of query parsing), and in a lot of other places just by mistake.

Parse flags have been introduced now as part of SearchContext and mappers where needed. There are a few places (e.g. java api requests) where it is not possible to retrieve them as they depend on settings, in that case we explicitly pass in EMPTY_FLAGS, but it has to be seen as an exception.

@@ -59,7 +53,7 @@ public ScriptParameterParser(Set<String> parameterNames) {
fileParameters = new HashSet<>();
indexedParameters = new HashSet<>();
for (String parameterName : parameterNames) {
if (ScriptService.SCRIPT_LANG.match(parameterName)) {
if (ScriptService.SCRIPT_LANG.match(parameterName, ParseField.EMPTY_FLAGS)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we should be able to get correct flags? Maybe not always, but at least in the context of aggs, I think the search context is available

Copy link
Member Author

Choose a reason for hiding this comment

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

yes we could but it is not needed given what we are doing we did, in this specific case we are only interested in the return value of the call, cause if it's true we throw exception ourselves. Makes sense?

@jpountz
Copy link
Contributor

jpountz commented Jun 24, 2015

LGTM

Just thinking out loud, but for future usage of this API, I'm wondering how we could make it easier to use in order to discourage lazy users to pass empty flags. Could be something like SearchContext.match(ParseField) that would automatically pass in the right flags.

@javanna
Copy link
Member Author

javanna commented Jun 25, 2015

I agree @jpountz we could make it even better , I will look into your suggestion

@javanna
Copy link
Member Author

javanna commented Jun 25, 2015

@jpountz I pushed another commit that should make it harder to forget parse flags, naming might need some adjustments, but I think this looks much better, thanks for your suggestion!

@jpountz
Copy link
Contributor

jpountz commented Jun 26, 2015

One concern I have is that it introduces yet another API: in addition to SearchContext and ParseField, we now have ParseFieldMatcher. Should we just have this class hidden and just a SearchContext.match(ParseField) method?

@javanna
Copy link
Member Author

javanna commented Jun 26, 2015

I see your point @jpountz , that said we have different places where we need the parseFlags and we would need the match method, it is not just about the SearchContext. We could have a common interface (e.g. ParseFieldMatcher itself) and have different implementors for it (SearchContext, QueryParseContext and anywhere we use ParseField) but that would still introduce a new api which is what doesn't make you happy. Anyways we do use ParseField to define fields but the match method there is now package private which means that you have to go through ParseFieldMatcher all the time. I still think it is a good improvement cause we make sure that we don't miss parse flags anywhere. @s1monw what do you think? Maybe you have even better ideas?

@javanna
Copy link
Member Author

javanna commented Jun 30, 2015

ping @s1monw this is quite a big PR I would love to get to some agreement and merge it in soon otherwise it gets outdated pretty quickly. Opinions?

@s1monw
Copy link
Contributor

s1monw commented Jul 1, 2015

I like this but I also like @jpountz suggestion. Yet, this is a good improvement and we should not let it get old. I am +1 on moving forward here @javanna

@s1monw
Copy link
Contributor

s1monw commented Jul 2, 2015

@javanna I think we should push as is. The Matcher looks ok to me for now?

@javanna
Copy link
Member Author

javanna commented Jul 2, 2015

cool will push as is then, thanks!

@javanna javanna removed the review label Jul 2, 2015
…se flags

Removed ParseField#match variant that accepts the field name only, without parse flags. Such a method is harmful as it defaults to empty parse flags, meaning that no deprecation exceptions will be thrown in strict mode, which defeats the purpose of using ParseField. Unfortunately such a method was used in a lot of places were the parse flags weren't easily accessible (outside of query parsing), and in a lot of other places just by mistake.

Parse flags have been introduced now as part of SearchContext and mappers where needed. There are a few places (e.g. java api requests) where it is not possible to retrieve them as they depend on the index settings, in that case we explicitly pass in EMPTY_FLAGS for now, but this has to be seen as an exception.

Closes elastic#11859
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants