Skip to content

Conversation

@jaymode
Copy link
Member

@jaymode jaymode commented Feb 25, 2020

This commit changes the IndexNameExpressionResolver and the inner
ExpressionResolver objects to use Sets instead of Lists in their APIs,
which addresses a TODO left in this code.

Relates #40263

This commit changes the IndexNameExpressionResolver and the inner
ExpressionResolver objects to use Sets instead of Lists in their APIs,
which addresses a TODO left in this code.
@jaymode jaymode added >non-issue :Core/Infra/Core Core issues without another label v8.0.0 v7.7.0 labels Feb 25, 2020
@jaymode jaymode requested a review from jpountz February 25, 2020 18:23
Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

It looks like this PR uses LinkedHashSet in place of all the previous Lists. Do we rely on the original ordering? If so, why are we converting to Set?

@jaymode
Copy link
Member Author

jaymode commented Feb 26, 2020

Do we rely on the original ordering?

Yes we do because of the negation syntax, -, that we support for index name expressions.

If so, why are we converting to Set?

Internally we convert to a set and then convert back to a List in the WildcardExpressionResolver. I was trying to address this TODO but I'm not sure this is the right change to make. @jpountz you left the original TODO, can you elaborate on the TODO and if you still think we should do this?

@jpountz
Copy link
Contributor

jpountz commented Feb 28, 2020

I had not looked deeply into the consequences of moving to sets, but this code keeps going back and forth between lists and sets, which fels wasteful.

@jpountz
Copy link
Contributor

jpountz commented Feb 28, 2020

I originally wrote this comment because expressions are initially provided as a list, and are then converted to a set in WildcardExpressionResolver#innerResolve, back to a list in WildcardExpressionResolver#resolve and back to a set again in IndexNameExpressionResolver#concreteIndices. This didn't feel like it was necessary.

Do we rely on the original ordering?

Yes we do because of the negation syntax, -, that we support for index name expressions.

This is a good point. It probably means that even the LinkedHashSet approach is not good, as providing a list of expressions that looks like [ "foo", "-foo", "foo" ] would resolve to an empty collection because the LinkedHashSet would remove the second foo?

I'm not sure this is the right change to make

Yes, sorry for the time you spent on it, it looks like this TODO is buggy and we should remove it.

@jaymode
Copy link
Member Author

jaymode commented Feb 28, 2020

It probably means that even the LinkedHashSet approach is not good

Excellent point.

sorry for the time you spent on it

No worries. I just wanted the API to be more stable if we make the wildcard resolver pluggable. I will close this and open a PR removing the TODO

@jaymode jaymode closed this Feb 28, 2020
@jaymode jaymode deleted the index_name_resolver_set branch February 28, 2020 16:57
jaymode added a commit to jaymode/elasticsearch that referenced this pull request Feb 28, 2020
This commit removes a TODO in the IndexNameExpressionResolver that
indicated the API should use a Set instead of a List. However, this
TODO was not completely correct since the ordering of arguments matters
due to negations when evaluating wildcards and since we also allow
a list of patterns like `*,-foo,*`, which would have a different
meaning even when using a Set with insertion ordering.

Relates elastic#52788
jaymode added a commit that referenced this pull request Feb 28, 2020
This commit removes a TODO in the IndexNameExpressionResolver that
indicated the API should use a Set instead of a List. However, this
TODO was not completely correct since the ordering of arguments matters
due to negations when evaluating wildcards and since we also allow
a list of patterns like `*,-foo,*`, which would have a different
meaning even when using a Set with insertion ordering.

Relates #52788
jaymode added a commit to jaymode/elasticsearch that referenced this pull request Feb 28, 2020
This commit removes a TODO in the IndexNameExpressionResolver that
indicated the API should use a Set instead of a List. However, this
TODO was not completely correct since the ordering of arguments matters
due to negations when evaluating wildcards and since we also allow
a list of patterns like `*,-foo,*`, which would have a different
meaning even when using a Set with insertion ordering.

Relates elastic#52788
jaymode added a commit that referenced this pull request Feb 28, 2020
This commit removes a TODO in the IndexNameExpressionResolver that
indicated the API should use a Set instead of a List. However, this
TODO was not completely correct since the ordering of arguments matters
due to negations when evaluating wildcards and since we also allow
a list of patterns like `*,-foo,*`, which would have a different
meaning even when using a Set with insertion ordering.

Relates #52788
Backport of #52963
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Core/Infra/Core Core issues without another label >non-issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants