Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ List<Pair<Integer, Long>> page2Departments = entityStream.of(Person.class)
.groupBy(Person$.DEPARTMENT_NUMBER)
.reduce(COUNT)
.sorted(Order.asc("@count"))
.limit(5, 10) // Skip 5, take 10
.limit(5, 10) // offset=5, limit=10 (skip 5, take 10)
.toList(Integer.class, Long.class);
----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,8 @@ public <S extends T> Page<S> findAll(Example<S> example, Pageable pageable) {
SearchStream<S> stream = entityStream.of(example.getProbeType());
var offset = pageable.getPageNumber() * pageable.getPageSize();
var limit = pageable.getPageSize();
Page<S> page = stream.filter(example).dialect(Dialect.TWO.getValue()).loadAll().limit(limit, Math.toIntExact(
offset)).toList(pageable, stream.getEntityClass());
Page<S> page = stream.filter(example).dialect(Dialect.TWO.getValue()).loadAll().limit(Math.toIntExact(offset),
limit).toList(pageable, stream.getEntityClass());

return page;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ public <S extends T> Page<S> findAll(Example<S> example, Pageable pageable) {
SearchStream<S> stream = entityStream.of(example.getProbeType());
var offset = pageable.getPageNumber() * pageable.getPageSize();
var limit = pageable.getPageSize();
Page<S> page = stream.filter(example).loadAll().limit(limit, Math.toIntExact(offset)).toList(pageable, stream
Page<S> page = stream.filter(example).loadAll().limit(Math.toIntExact(offset), limit).toList(pageable, stream
.getEntityClass());

return page;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,23 @@ public interface AggregationStream<T> {

/**
* Limits the number of results and applies an offset for pagination.
* <p>
* This method controls the pagination of aggregation results by specifying
* how many results to skip (offset) and how many to return (limit).
* </p>
* <p>
* Example usage:
* <pre>{@code
* // Skip the first 10 results and return the next 5
* stream.limit(10, 5) // offset=10, limit=5
* }</pre>
*
* @param offset the number of results to skip before starting to return results (0-based)
* @param limit the maximum number of results to return
* @param offset the number of results to skip
* @return a new AggregationStream with the limit and offset applied
* @throws IllegalArgumentException if limit or offset is negative
*/
AggregationStream<T> limit(int limit, int offset);
AggregationStream<T> limit(int offset, int limit);

/**
* Applies filter expressions to the aggregation pipeline.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public AggregationStream<T> limit(int limit) {
}

@Override
public AggregationStream<T> limit(int limit, int offset) {
public AggregationStream<T> limit(int offset, int limit) {
applyCurrentGroupBy();
aggregation.limit(offset, limit);
limitSet = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -985,4 +985,23 @@ void testNotExistPredicate() {
assertThat(releasedFilms.get(0).getFirst()).isEqualTo(1);
}

@Test
void testAggregationLimitWithOffsetParameterOrder() {
// Test the correct parameter order: offset first, then limit
// We want to skip 2 games and get the next 3
List<Pair<String, String>> results = entityStream.of(Game.class)
.groupBy(Game$.TITLE)
.reduce(ReducerFunction.COUNT).as("count")
.sorted(Order.asc("@title"))
.limit(2, 3) // Skip 2, take 3 (offset=2, limit=3)
.toList(String.class, String.class);

// We should get exactly 3 results after skipping the first 2
assertThat(results).hasSize(3);

// Verify we're getting the 3rd, 4th, and 5th games alphabetically
// (skipping the first 2)
assertThat(results).isNotEmpty();
}

}