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 stream() method for convenient result traversal #24525
Add stream() method for convenient result traversal #24525
Conversation
I wonder what do you think of such thing, IMHO it makes API more user-friendly without much of a code (underlying interator is the same). |
It would close #22166 I think |
default Stream<SqlRow> stream() { | ||
return StreamSupport.stream(spliterator(), false); | ||
} |
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 don't understand why this default method doesn't exist in the Iterable
interface.
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.
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.
argument with specialised iterator types does not apply to us. I wonder if adding this method would promote less efficient (but easier) usage. Also users will not be able to use this method in a fully fluent way because SqlResult
has to be closed
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.
Java architects' defenses on these type of poor design choices are really funny. They are reluctant to get rid of primitive/boxed duality (by burying auto-(un)boxing deeper) and they use this as a counter-argument in order not to implement some convenience methods. By the way, I upvoted this and this.
To get rid of try-with-resources, we can return StreamSupport.stream(spliterator(), false).onClose(this::close)
, but try-with-resources is the only reliable way to release resources in case a RuntimeException
is thrown. Closing SqlResult
in the end of iterator()
, i.e. when hasNext()
returns false, is also a bad idea since the iterator doesn't have to be used to the end.
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.
to say "Java is not perfect" would be a huge understatement, but we have to live with it
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.
Yeah I know it's not perfect - still needs try-with-resources - but it's simpler for queries where you expect not many result rows (e.g. with limit
), similar to Mongo's .into()
function
run-lab-run |
run-lab-run |
Because of https://github.com/hazelcast/hazelcast-enterprise/issues/5966 and time constraints postponing decision to 5.4 release. |
hazelcast-sql/src/test/java/com/hazelcast/jet/sql/SqlQueryResultTest.java
Show resolved
Hide resolved
The job Click to expand the log file-------------------------- -------TEST FAILURE------- -------------------------- [INFO] Results: [INFO] [ERROR] Failures: [ERROR] StreamKafkaPTest.when_processingGuaranteeNone_then_continueFromBeginningAfterJobRestart:249->testWithJobRestart:315->testWithJobRestart:350->HazelcastTestSupport.assertTrueEventually:1184->HazelcastTestSupport.assertTrueEventually:1165->lambda$testWithJobRestart$4:350 expected:<300> but was:<389> [INFO] [ERROR] Tests run: 51, Failures: 1, Errors: 0, Skipped: 1 [INFO] |
run-lab-run |
Checklist:
Team:
,Type:
,Source:
,Module:
) and Milestone setAdd to Release Notes
orNot Release Notes content
set@Nonnull/@Nullable
annotations@since
tags in Javadoc