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

Support Stream as mapper method return type #3419

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

quaff
Copy link

@quaff quaff commented Feb 24, 2025

No description provided.

@harawata
Copy link
Member

harawata commented Feb 27, 2025

Hello @quaff ,

Thank you for the PR, but I don't think this is a good idea.

  1. Users can easily create Stream in their own code after retrieving List or Cursor from MyBatis.
  2. Users should be able to close Cursor at any point, but it's not possible if we return Stream wrapping Cursor.

I will close this as "won't fix".

@quaff
Copy link
Author

quaff commented Feb 27, 2025

Users can easily create Stream in their own code after retrieving List or Cursor from MyBatis.

Users would expect returning standard Stream instead of proprietary Cursor from declarative mapper interface, especially for beginner, they may don't even know Cursor, see GH-3213.

It's not so easily to create Stream from Cursor, Sure it's easily for List, but List is not suitable for large result, It may cause OOM issue.

It's more easily to create Optional in their own code, but MyBatis provide built-in supports, so I think Stream supports is reasonable, WDYT @harawata

@harawata
Copy link
Member

Thanks for the comment, @quaff !

I'll reopen for other devs to comment.

Comparison with Optional is a fair point.
It's not obvious, however, that the returned Stream wraps Cursor which requires extra care (i.e. resultOrdered="true"), so I still prefer not to merge this personally.
And, in case other devs like this, I would request some additional documentation (please do not work on it yet. I don't want you to waste any time).

@harawata harawata reopened this Feb 27, 2025
@quaff
Copy link
Author

quaff commented Feb 27, 2025

I'll reopen for other devs to comment.

Thanks for reconsideration. @harawata

It's not obvious, however, that the returned Stream wraps Cursor which requires extra care (i.e. resultOrdered="true").

I researched #2812 (comment), I don't think extra care required for resultOrdered="true", Stream inherit all features and limitations from Cursor, It doesn't introduce new things, correct me if I'm wrong.

@harawata
Copy link
Member

harawata commented Feb 27, 2025

What I meant was it is not clear to users that "Stream inherits all features and limitations from Cursor" and it requires additional documentation IF we merge this (again, please do not work on the doc update yet).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants