-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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 support of getting a Java stream on ImmutableOpenMap #76921
Add support of getting a Java stream on ImmutableOpenMap #76921
Conversation
Pinging @elastic/es-core-infra (Team:Core/Infra) |
23b11fc
to
10a8154
Compare
@elasticmachine |
@elasticmachine |
`ImmutableOpenMap` doesn't support Java streams directly, so consumer have to invoke `StreamSupport.spliterator` on it if they want to run a Java stream over it. We can simplify consumer code by providing a direct `stream` method in `ImmutableOpenMap`
10a8154
to
a68f350
Compare
@elasticmachine update branch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Artem, this is a bit of an annoying corner. I left a suggestion.
server/src/main/java/org/elasticsearch/common/collect/ImmutableOpenMap.java
Outdated
Show resolved
Hide resolved
71d7b98
to
490a13c
Compare
Build a stream from an immutable copy of the cursor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the approach taken has some unnecessary costs, I would like to see if that can be addressed?
server/src/main/java/org/elasticsearch/common/collect/ImmutableOpenMap.java
Outdated
Show resolved
Hide resolved
376fb0c
to
195d207
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
server/src/test/java/org/elasticsearch/common/collect/ImmutableOpenMapTests.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/common/collect/ImmutableOpenMapTests.java
Outdated
Show resolved
Hide resolved
…eOpenMapTests.java Co-authored-by: Henning Andersen <[email protected]>
@elasticmachine update branch |
💔 Backport failed
To backport manually run |
…ic#76921) `ImmutableOpenMap` doesn't support Java streams directly, so consumer have to invoke `StreamSupport.spliterator` on it if they want to run a Java stream over it. We can simplify consumer code by providing a direct `stream` method in `ImmutableOpenMap`
…ic#76921) Backports elastic#76921 to 7.x `ImmutableOpenMap` doesn't support Java streams directly, so consumer have to invoke `StreamSupport.spliterator` on it if they want to run a Java stream over it. We can simplify consumer code by providing a direct `stream` method in `ImmutableOpenMap`
…ic#76921) `ImmutableOpenMap` doesn't support Java streams directly, so consumer have to invoke `StreamSupport.spliterator` on it if they want to run a Java stream over it. We can simplify consumer code by providing a direct `stream` method in `ImmutableOpenMap`
… (#77455) * [7.x] Add support of getting a Java stream on ImmutableOpenMap (#76921) Backports #76921 to 7.x `ImmutableOpenMap` doesn't support Java streams directly, so consumer have to invoke `StreamSupport.spliterator` on it if they want to run a Java stream over it. We can simplify consumer code by providing a direct `stream` method in `ImmutableOpenMap` * [7.x] Add support of getting a Java stream on ImmutableOpenMap (#76921) `ImmutableOpenMap` doesn't support Java streams directly, so consumer have to invoke `StreamSupport.spliterator` on it if they want to run a Java stream over it. We can simplify consumer code by providing a direct `stream` method in `ImmutableOpenMap`
elastic#76921 added support for getting entries as a Java stream, elastic#77897 added the ability to get keys as a Set. This PR adds the values method which returns a Collection to bring the ImmutableOpenMap API closer to java.util.Map (cherry picked from commit cb73e3f)
ImmutableOpenMap
doesn't support Java streams directly, so consumers have to invokeStreamSupport.spliterator
if they want to get a Java stream on it. The stream is actually not safe becauseObjectObjectCursor
is mutable. E.g.This works:
This doesn't work
We can simplify consumer code by providing a direct safe
stream
method inImmutableOpenMap
which would iterate over immutable map entries. We can achieve that by creating own spliterator over the nativeObjectObjectHashMap
iterator which copies the mutable cursor to an immutableMap.Entry
, which in turn should makes the stream safe.