Skip to content
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

Support setting properties for CreateCollectionRequest #1128

Merged
merged 1 commit into from
Oct 21, 2024
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 @@ -120,15 +120,18 @@ public Void createCollectionWithSchema(MilvusServiceGrpc.MilvusServiceBlockingSt
}

//create collection
CreateCollectionRequest createCollectionRequest = CreateCollectionRequest.newBuilder()
CreateCollectionRequest.Builder builder = CreateCollectionRequest.newBuilder()
.setCollectionName(request.getCollectionName())
.setSchema(grpcSchema.toByteString())
.setShardsNum(request.getNumShards())
.build();
.setShardsNum(request.getNumShards());
List<KeyValuePair> propertiesList = ParamUtils.AssembleKvPair(request.getProperties());
if (CollectionUtils.isNotEmpty(propertiesList)) {
propertiesList.forEach(builder::addProperties);
}
if (request.getNumPartitions() != null) {
createCollectionRequest = createCollectionRequest.toBuilder().setNumPartitions(request.getNumPartitions()).build();
builder.setNumPartitions(request.getNumPartitions());
}
Status createCollectionResponse = blockingStub.createCollection(createCollectionRequest);
Status createCollectionResponse = blockingStub.createCollection(builder.build());
rpcUtils.handleResponse(title, createCollectionResponse);

//create index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
import lombok.experimental.SuperBuilder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@SuperBuilder
Expand Down Expand Up @@ -74,6 +76,9 @@ public class CreateCollectionReq {
@Builder.Default
private ConsistencyLevel consistencyLevel = ConsistencyLevel.BOUNDED;

@Builder.Default
private final Map<String, String> properties = new HashMap<>();

public static abstract class CreateCollectionReqBuilder<C extends CreateCollectionReq, B extends CreateCollectionReq.CreateCollectionReqBuilder<C, B>> {
public B indexParam(IndexParam indexParam) {
try {
Expand Down Expand Up @@ -106,6 +111,15 @@ public B collectionSchema(CollectionSchema collectionSchema) {
this.enableDynamicField$set = true;
return self();
}

public B property(String key, String value) {
if(null == this.properties$value ){
this.properties$value = new HashMap<>();
}
this.properties$value.put(key, value);
this.properties$set = true;
return self();
}
}

@Data
Expand Down
15 changes: 13 additions & 2 deletions src/test/java/io/milvus/v2/client/MilvusClientV2DockerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1225,8 +1225,19 @@ void testIndex() {
.collectionName(randomCollectionName)
.collectionSchema(collectionSchema)
.indexParams(indexes)
.property(Constant.TTL_SECONDS, "5")
.property(Constant.MMAP_ENABLED, "false")
.build());

DescribeCollectionResp descCollResp = client.describeCollection(DescribeCollectionReq.builder()
.collectionName(randomCollectionName)
.build());
Map<String, String> collProps = descCollResp.getProperties();
Assertions.assertTrue(collProps.containsKey(Constant.TTL_SECONDS));
Assertions.assertTrue(collProps.containsKey(Constant.MMAP_ENABLED));
Assertions.assertEquals("5", collProps.get(Constant.TTL_SECONDS));
Assertions.assertEquals("false", collProps.get(Constant.MMAP_ENABLED));

client.releaseCollection(ReleaseCollectionReq.builder()
.collectionName(randomCollectionName)
.build());
Expand All @@ -1239,10 +1250,10 @@ void testIndex() {
.properties(properties)
.property("prop", "val")
.build());
DescribeCollectionResp descCollResp = client.describeCollection(DescribeCollectionReq.builder()
descCollResp = client.describeCollection(DescribeCollectionReq.builder()
.collectionName(randomCollectionName)
.build());
Map<String, String> collProps = descCollResp.getProperties();
collProps = descCollResp.getProperties();
Assertions.assertTrue(collProps.containsKey(Constant.TTL_SECONDS));
Assertions.assertTrue(collProps.containsKey(Constant.MMAP_ENABLED));
Assertions.assertTrue(collProps.containsKey("prop"));
Expand Down
Loading