-
Notifications
You must be signed in to change notification settings - Fork 21
v6: Pagination #399
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
Merged
v6: Pagination #399
Conversation
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
CursorSpliterator powers 2 patterns for iterating over objects: - list() returns an Iterable that can be used in a for-loop - stream() presents the internal Iterator via a familiar Stream API
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.
Orca Security Scan Summary
Status | Check | Issues by priority | |
---|---|---|---|
![]() |
Secrets | ![]() ![]() ![]() ![]() |
View in Orca |
This lets us keep all configurations 'on the left' of the operator and all operations on the right
ObjectBuilder.partial is a new util for composing ObjectBuilder-style functions.
E.g.: Boolean properties cannot be compared using gt(-e) and lt(-e) operators. Also LIKE operator only makes sense to text properties and should accept a single pattern.
Does not support Stream or Spliterator / Iterator APIs, because those are inherently synchronous.
salvatore-campagna-weaviate
requested changes
Jul 2, 2025
src/main/java/io/weaviate/client6/v1/api/collections/pagination/Paginator.java
Show resolved
Hide resolved
src/main/java/io/weaviate/client6/v1/api/collections/pagination/Paginator.java
Outdated
Show resolved
Hide resolved
src/main/java/io/weaviate/client6/v1/api/collections/pagination/Paginator.java
Outdated
Show resolved
Hide resolved
src/main/java/io/weaviate/client6/v1/api/collections/pagination/CursorSpliterator.java
Outdated
Show resolved
Hide resolved
src/main/java/io/weaviate/client6/v1/api/collections/pagination/Paginator.java
Show resolved
Hide resolved
src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncResultSet.java
Show resolved
Hide resolved
src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncResultSet.java
Show resolved
Hide resolved
src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncResultSet.java
Show resolved
Hide resolved
src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncResultSet.java
Outdated
Show resolved
Hide resolved
src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncResultSet.java
Show resolved
Hide resolved
- this.cursor should be a final field since AsyncResult will only ever work with a single page - change currentPage access to package-private to avoid confusion See: #399 (comment)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR adds Pagination API for sync and async clients. Owing to a different asynchronous programming model that we have in Java, the APIs are not identical.
Sync
Synchronous pagination is instantly familiar.
CursorSpliterator
powers 2 patterns for iterating over objects:collection.paginate()
implements Iterable that can be used in a traditional for-loopAsync
We cannot do the exact same thing in asynchronous part of the client; Streams and Iterator APIs are inherently synchronous and resist being bent into asynchronicity.
Our API ends up looking only slightly differently:
In case other components of the application are also doing async-batching type of work, it is possible to process complete pages at once too:
AsyncPaginator supports prefetching, so that work can begin before the main thread starts to process results:
For example, it is possible to write an
async for
loop in Python, where eachawait
cedes control to the event loop. Java's concurrency is built on threads and we end up working at a slightly lower level.E.g.: asynchronously iterating over a loop requires manually scheduling recursive callbacks. Some pseudo-code to illustrate:
The example snippet above demonstrates the helper
forEach
which reduces the boilerplate necessary.Passing query options
I purposefully omitted passing arguments to
.stream()
method, because normally this method does not take any parameters.