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

Enhancements to ResultIterable #2056

Merged
merged 3 commits into from Jul 7, 2022

Conversation

spannm
Copy link
Contributor

@spannm spannm commented Jun 11, 2022

  • Add method ResultIterable#filter to apply a filter (predicate) to a result iterable without use of streams.
    Similarities with ResultIterable#map extracted into class ResultIteratorDelegate
  • Add enhanced ResultIterable#forEachWithCount, an enhanced forEach method that returns the iteration/record count
  • Add unit tests

@stevenschlansker
Copy link
Member

Hi @sman-81 , could you share a bit about what use case you expect for these new features? In particular, we avoid doing filter in Java code, since the predicate cannot be lifted up to the database.
And, if you want to do more in-Java processing, we would encourage you to .stream() the results, and then you get much more powerful / flexible processing "for free" without Jdbi modifications.

@spannm spannm force-pushed the sman-81-jdbi-resultiterable branch from c231d6e to 2aa2768 Compare June 14, 2022 05:23
@spannm
Copy link
Contributor Author

spannm commented Jun 14, 2022

Hi @stevenschlansker,

thanks for your feedback!

We avoid switching to Stream for 'intermediate' operations and stay within the ResultIterable type to perform custom, value-added 'terminal' operations such as forEachWithCount.
Frequently working with resultsets and Jdbi one will do forEach to iterate over the resultset (doing this does not use Stream API).
Along the same lines, the map, findOne, first, findFirst methods, which all have existed for a long time, do not use Stream API. My new filter method works along those lines.

In particular, we avoid doing filter in Java code, since the predicate cannot be lifted up to the database.

What do you mean?
filter could be done in most if not all dbms using WHERE.
Similarly map could be done inside db using built-in functions.

Yet, having both in JDBI serves a very good purpose, as it allows you to keep a db simple and shift more complex processing to Java.

@spannm
Copy link
Contributor Author

spannm commented Jun 20, 2022

Hi @stevenschlansker,

Hope this finds you well :)
I am rather excited about the positive impact of this PR.
Could you kindly get back to me on my above comments?

Cheers, Markus

Copy link
Member

@stevenschlansker stevenschlansker left a comment

Choose a reason for hiding this comment

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

Ok. I am still slightly concerned that newbie users would mistake that filter somehow operates efficiently, when it actually precludes letting the database do the heavy lifting.
Perhaps we could add a note to the Javadoc to make it clear that results must be loaded into Java and then thrown away, which means e.g. that indexes cannot be used.
Otherwise people might incorrectly assume that we have LINQ-like features which actually can magically do this.

I left some comments on the implementation. Let me know what you think.

@stevenschlansker
Copy link
Member

And sorry for the delay @sman-81 , I have been on vacation 🌴

Add method ResultIterable#filter to apply a filter (predicate) to a result iterable without use of streams.
Similarities with ResultIterable#map extracted into class ResultIteratorDelegate

Add enhanced ResultIterable#forEachWithCount, an enhanced forEach method that returns the iteration/record count

Add unit tests

Incorporate feedback from Steven
@spannm spannm force-pushed the sman-81-jdbi-resultiterable branch from 17bbc56 to 1e7275e Compare June 29, 2022 06:26
@spannm
Copy link
Contributor Author

spannm commented Jun 29, 2022

Your feedback incorporated and pr updated.

@sonarcloud
Copy link

sonarcloud bot commented Jun 29, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

stevenschlansker added a commit that referenced this pull request Jul 7, 2022
@stevenschlansker stevenschlansker merged commit 4b4894b into jdbi:master Jul 7, 2022
@spannm spannm deleted the sman-81-jdbi-resultiterable branch July 7, 2022 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants