Skip to content

Commit

Permalink
Support setting properties for CreateCollectionRequest (#1128)
Browse files Browse the repository at this point in the history
Signed-off-by: yhmo <[email protected]>
  • Loading branch information
yhmo authored Oct 21, 2024
1 parent 23be2a6 commit f5f26aa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
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

0 comments on commit f5f26aa

Please sign in to comment.