Skip to content

Commit d25ba00

Browse files
authored
Merge pull request #416 from weaviate/v6-aggregate-groupby-limit
v6: Add `limit` to GroupBy parameter in Aggregate queries
2 parents e85eebe + af83454 commit d25ba00

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

src/it/java/io/weaviate/integration/AggregationITest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void testOverAll_groupBy_category() {
8080
Aggregation.integer("price",
8181
calculate -> calculate.min().max().count()))
8282
.includeTotalCount(true),
83-
new GroupBy("category"));
83+
GroupBy.property("category"));
8484

8585
Assertions.assertThat(result)
8686
.extracting(AggregateResponseGrouped::groups)
@@ -139,7 +139,7 @@ public void testNearVector_groupBy_category() {
139139
calculate -> calculate.min().max().median()))
140140
.objectLimit(9)
141141
.includeTotalCount(true),
142-
new GroupBy("category"));
142+
GroupBy.property("category"));
143143

144144
Assertions.assertThat(result)
145145
.extracting(AggregateResponseGrouped::groups)

src/main/java/io/weaviate/client6/v1/api/collections/aggregate/GroupBy.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,48 @@
11
package io.weaviate.client6.v1.api.collections.aggregate;
22

3+
import java.util.function.Function;
4+
5+
import io.weaviate.client6.v1.internal.ObjectBuilder;
36
import io.weaviate.client6.v1.internal.grpc.protocol.WeaviateProtoAggregate;
47

5-
public record GroupBy(String property) {
6-
public static final GroupBy of(String property) {
7-
return new GroupBy(property);
8+
public record GroupBy(String property, Integer limit) {
9+
public static final GroupBy property(String property) {
10+
return property(property, ObjectBuilder.identity());
11+
}
12+
13+
public static final GroupBy property(String property, Function<Builder, ObjectBuilder<GroupBy>> fn) {
14+
return fn.apply(new Builder(property)).build();
15+
}
16+
17+
public GroupBy(Builder builder) {
18+
this(builder.property, builder.limit);
19+
}
20+
21+
public static class Builder implements ObjectBuilder<GroupBy> {
22+
private final String property;
23+
24+
public Builder(String property) {
25+
this.property = property;
26+
}
27+
28+
private Integer limit;
29+
30+
public final Builder limit(int limit) {
31+
this.limit = limit;
32+
return this;
33+
}
34+
35+
@Override
36+
public GroupBy build() {
37+
return new GroupBy(this);
38+
}
839
}
940

1041
void appendTo(WeaviateProtoAggregate.AggregateRequest.Builder req, String collection) {
42+
if (limit != null) {
43+
req.setLimit(limit);
44+
}
45+
1146
req.setGroupBy(WeaviateProtoAggregate.AggregateRequest.GroupBy.newBuilder()
1247
.setCollection(collection)
1348
.setProperty(property));

0 commit comments

Comments
 (0)