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
4 changes: 2 additions & 2 deletions src/it/java/io/weaviate/integration/AggregationITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void testOverAll_groupBy_category() {
Aggregation.integer("price",
calculate -> calculate.min().max().count()))
.includeTotalCount(true),
new GroupBy("category"));
GroupBy.property("category"));

Assertions.assertThat(result)
.extracting(AggregateResponseGrouped::groups)
Expand Down Expand Up @@ -139,7 +139,7 @@ public void testNearVector_groupBy_category() {
calculate -> calculate.min().max().median()))
.objectLimit(9)
.includeTotalCount(true),
new GroupBy("category"));
GroupBy.property("category"));

Assertions.assertThat(result)
.extracting(AggregateResponseGrouped::groups)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,48 @@
package io.weaviate.client6.v1.api.collections.aggregate;

import java.util.function.Function;

import io.weaviate.client6.v1.internal.ObjectBuilder;
import io.weaviate.client6.v1.internal.grpc.protocol.WeaviateProtoAggregate;

public record GroupBy(String property) {
public static final GroupBy of(String property) {
return new GroupBy(property);
public record GroupBy(String property, Integer limit) {
public static final GroupBy property(String property) {
return property(property, ObjectBuilder.identity());
}

public static final GroupBy property(String property, Function<Builder, ObjectBuilder<GroupBy>> fn) {
return fn.apply(new Builder(property)).build();
}

public GroupBy(Builder builder) {
this(builder.property, builder.limit);
}

public static class Builder implements ObjectBuilder<GroupBy> {
private final String property;

public Builder(String property) {
this.property = property;
}

private Integer limit;

public final Builder limit(int limit) {
this.limit = limit;
return this;
}

@Override
public GroupBy build() {
return new GroupBy(this);
}
}

void appendTo(WeaviateProtoAggregate.AggregateRequest.Builder req, String collection) {
if (limit != null) {
req.setLimit(limit);
}

req.setGroupBy(WeaviateProtoAggregate.AggregateRequest.GroupBy.newBuilder()
.setCollection(collection)
.setProperty(property));
Expand Down