-
Notifications
You must be signed in to change notification settings - Fork 21
Correct query to ignore aliases. #1672
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
Merged
+48
−15
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
So I copied this from the getAll handler above, and initially left it at .stream().findFirst(). Now Idea why but in that usage the underlying connection never closed so the fetchOptional was used and that error went away.
Not a huge deal, but figured I'd mention it for others to be aware of.
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 believe Ryan has run into this before and did an audit previously to check for that kind of usage. The jOOQ documentation is misleading: https://www.jooq.org/doc/latest/manual/sql-execution/fetching/lazy-fetching-with-streams/ - in that second example, it makes it look like you don't have to handle the resources unlike the first example.
Lukas has commented on: https://stackoverflow.com/questions/35558364/do-i-risk-a-jdbc-connection-leak-when-streaming-jooq-results-outside-a-try-with which is the reference we had looked at before to determine where the leak was coming from.
Uh oh!
There was an error while loading. Please reload this page.
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.
That would seem to imply the queries I copied are incorrect. And yet they seem to pass the test just fine. Checking that was part of why I set it to a repeated test.
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 have previously double-checked all our usages of stream wrt to jooq. I believe the query you copied from was modified in Dec. It may have been missed in review. Stream() works and its super natural to use and it looks clean but to work correctly with jooq I believe it must be inside a try-with-resources block. My understanding is that jooq's stream() call also pulls the entire result set before streaming it. Since you need to wrap the block in the try-with-resources anyway seems likr you might as well use fetchLazy and get whatever minor performance improvements you can.
I skimmed the jooq implementation of fetch and it looked to me like it was doing try-with-resources around fetchLazy with an internal call to collect so I'd suggest replacing any usages of the pattern of calling stream().map(...).collect(...) with .fetch(Mapper).
I'm not sure why your findFirst wouldn't close the connection but if you wanted to find out I'd set a breakpoint right before that jooq call and then when you are at that break-point I'd add/enable a new generic breakpoint on any thrown exceptions and see what pops up. It sounds like fetchOptional is what you want anyways so if you believe my previous arg against using stream() then fetchOptional is the right thing anyways and its not worth investigating.
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. I'll just leave it for now, as all the tests pass. I'm I'm curious enough that I'll investigate later in the week so we can know for sure.