-
Notifications
You must be signed in to change notification settings - Fork 227
Lazy iteration over JDBC ResultSet #1487
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
base: main
Are you sure you want to change the base?
Conversation
ba13ac2
to
d8d4ce2
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.
Thank you so much for this improvement @eric-maynard !
.map(ModelEntity::toEntity) | ||
.filter(entityFilter) | ||
.limit(limit) | ||
.forEach(results::add); |
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.
is there a way to do toList()
?
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.
With the loan pattern, we aren't returning anything so we need to get the list as a side effect. Unfortunately, there is a restriction in Java that variables pulled in to the scope of a lambda must be "effectively final", so we can't do like results = ...toList()
in the lambda
...rc/main/java/org/apache/polaris/extension/persistence/relational/jdbc/ResultSetIterator.java
Outdated
Show resolved
Hide resolved
hasNext = false; | ||
throw new RuntimeException(e); |
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.
interesting, if it's a SQLException shouldn't we throw it as SQLException to inspect the error code ? any other exception other than SQLException is considered as RTE for now in the caller.
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 the real problem here is ResultSetIterator.next()
, which can't throw an exception so long as we're implementing Iterator
.
For now I'll have the constructor throw a SQLException
so we have a chance of finding a SQLException
, but we'd still wrap SQLExceptions
that happen after the first ResultSet.next()
call. If that's an issue, we can move away from implementing Iterator or fix the caller to unwrap the exception.
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 !
In
DatasourceOperations.executeSelect
, we currently return aList
after copying the entireResultSet
into aList
. We provide a few arguments so the caller can supply a limit, a transformer, and a filter.Instead, we can let the caller provide a
Consumer
over an Iterator / Stream of the data, keeping the logic inDatasourceOperations
strictly persistence-related and affording the caller greater flexibility.This will help in #273 so we can push the page token down into the query but still do client filtering without having to make a copy of the entire
ResultSet
.