Skip to content

Commit ad2a5af

Browse files
authored
Support AddCollectionFunction/AlterCollectionFunction/DropCollectionFunction (milvus-io#1708) (milvus-io#1711)
Signed-off-by: yhmo <yihua.mo@zilliz.com>
1 parent a4a1f5c commit ad2a5af

File tree

6 files changed

+371
-1
lines changed

6 files changed

+371
-1
lines changed

sdk-core/src/main/java/io/milvus/v2/client/MilvusClientV2.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,33 @@ public DescribeReplicasResp describeReplicas(DescribeReplicasReq request) {
533533
return rpcUtils.retry(() -> collectionService.describeReplicas(this.getRpcStub(), request));
534534
}
535535

536+
/**
537+
* Add a function to collection.
538+
*
539+
* @param request add function request
540+
*/
541+
public void addCollectionFunction(AddCollectionFunctionReq request) {
542+
rpcUtils.retry(() -> collectionService.addCollectionFunction(this.getRpcStub(), request));
543+
}
544+
545+
/**
546+
* Alter a function of collection.
547+
*
548+
* @param request alter function request
549+
*/
550+
public void alterCollectionFunction(AlterCollectionFunctionReq request) {
551+
rpcUtils.retry(() -> collectionService.alterCollectionFunction(this.getRpcStub(), request));
552+
}
553+
554+
/**
555+
* Drop a function of collection.
556+
*
557+
* @param request drop function request
558+
*/
559+
public void dropCollectionFunction(DropCollectionFunctionReq request) {
560+
rpcUtils.retry(() -> collectionService.dropCollectionFunction(this.getRpcStub(), request));
561+
}
562+
536563
/////////////////////////////////////////////////////////////////////////////////////////////
537564
// Index Operations
538565
/////////////////////////////////////////////////////////////////////////////////////////////

sdk-core/src/main/java/io/milvus/v2/service/collection/CollectionService.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,70 @@ public DescribeReplicasResp describeReplicas(MilvusServiceGrpc.MilvusServiceBloc
553553
.build();
554554
}
555555

556+
public Void addCollectionFunction(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub,
557+
AddCollectionFunctionReq request) {
558+
if (request.getFunction() == null) {
559+
throw new MilvusClientException(ErrorCode.INVALID_PARAMS, "Function cannot be null.");
560+
}
561+
562+
String dbName = request.getDatabaseName();
563+
String collectionName = request.getCollectionName();
564+
String title = String.format("Add function to collection: '%s' in database: '%s'", collectionName, dbName);
565+
AddCollectionFunctionRequest.Builder builder = AddCollectionFunctionRequest.newBuilder()
566+
.setCollectionName(collectionName)
567+
.setFunctionSchema(SchemaUtils.convertToGrpcFunction(request.getFunction()));
568+
if (StringUtils.isNotEmpty(dbName)) {
569+
builder.setDbName(dbName);
570+
}
571+
Status status = blockingStub.addCollectionFunction(builder.build());
572+
rpcUtils.handleResponse(title, status);
573+
574+
return null;
575+
}
576+
577+
public Void alterCollectionFunction(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub,
578+
AlterCollectionFunctionReq request) {
579+
if (request.getFunction() == null) {
580+
throw new MilvusClientException(ErrorCode.INVALID_PARAMS, "Function cannot be null.");
581+
}
582+
583+
String dbName = request.getDatabaseName();
584+
String collectionName = request.getCollectionName();
585+
String title = String.format("Alter function of collection: '%s' in database: '%s'", collectionName, dbName);
586+
AlterCollectionFunctionRequest.Builder builder = AlterCollectionFunctionRequest.newBuilder()
587+
.setCollectionName(collectionName)
588+
.setFunctionName(request.getFunction().getName())
589+
.setFunctionSchema(SchemaUtils.convertToGrpcFunction(request.getFunction()));
590+
if (StringUtils.isNotEmpty(dbName)) {
591+
builder.setDbName(dbName);
592+
}
593+
Status status = blockingStub.alterCollectionFunction(builder.build());
594+
rpcUtils.handleResponse(title, status);
595+
596+
return null;
597+
}
598+
599+
public Void dropCollectionFunction(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub,
600+
DropCollectionFunctionReq request) {
601+
if (StringUtils.isEmpty(request.getFunctionName())) {
602+
throw new MilvusClientException(ErrorCode.INVALID_PARAMS, "Function name cannot be empty.");
603+
}
604+
605+
String dbName = request.getDatabaseName();
606+
String collectionName = request.getCollectionName();
607+
String title = String.format("Drop function to collection: '%s' in database: '%s'", collectionName, dbName);
608+
DropCollectionFunctionRequest.Builder builder = DropCollectionFunctionRequest.newBuilder()
609+
.setCollectionName(collectionName)
610+
.setFunctionName(request.getFunctionName());
611+
if (StringUtils.isNotEmpty(dbName)) {
612+
builder.setDbName(dbName);
613+
}
614+
Status status = blockingStub.dropCollectionFunction(builder.build());
615+
rpcUtils.handleResponse(title, status);
616+
617+
return null;
618+
}
619+
556620
private void WaitForLoadCollection(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, String databaseName,
557621
String collectionName, long timeoutMs) {
558622
long startTime = System.currentTimeMillis(); // Capture start time/ Timeout in milliseconds (60 seconds)
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package io.milvus.v2.service.collection.request;
21+
22+
public class AddCollectionFunctionReq {
23+
private String collectionName;
24+
private String databaseName;
25+
private CreateCollectionReq.Function function;
26+
27+
private AddCollectionFunctionReq(AddCollectionFunctionReqBuilder builder) {
28+
this.collectionName = builder.collectionName;
29+
this.databaseName = builder.databaseName;
30+
this.function = builder.function;
31+
}
32+
33+
public String getCollectionName() {
34+
return collectionName;
35+
}
36+
37+
public void setCollectionName(String collectionName) {
38+
this.collectionName = collectionName;
39+
}
40+
41+
public String getDatabaseName() {
42+
return databaseName;
43+
}
44+
45+
public void setDatabaseName(String databaseName) {
46+
this.databaseName = databaseName;
47+
}
48+
49+
public CreateCollectionReq.Function getFunction() {
50+
return function;
51+
}
52+
53+
@Override
54+
public String toString() {
55+
return "AddCollectionFunctionReq{" +
56+
"collectionName='" + collectionName + '\'' +
57+
", databaseName='" + databaseName + '\'' +
58+
", function= " + function +
59+
'}';
60+
}
61+
62+
public static AddCollectionFunctionReqBuilder builder() {
63+
return new AddCollectionFunctionReqBuilder();
64+
}
65+
66+
public static class AddCollectionFunctionReqBuilder {
67+
private String collectionName = "";
68+
private String databaseName = "";
69+
private CreateCollectionReq.Function function;
70+
71+
private AddCollectionFunctionReqBuilder() {
72+
}
73+
74+
public AddCollectionFunctionReqBuilder collectionName(String collectionName) {
75+
this.collectionName = collectionName;
76+
return this;
77+
}
78+
79+
public AddCollectionFunctionReqBuilder databaseName(String databaseName) {
80+
this.databaseName = databaseName;
81+
return this;
82+
}
83+
84+
public AddCollectionFunctionReqBuilder function(CreateCollectionReq.Function function) {
85+
this.function = function;
86+
return this;
87+
}
88+
89+
public AddCollectionFunctionReq build() {
90+
return new AddCollectionFunctionReq(this);
91+
}
92+
}
93+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package io.milvus.v2.service.collection.request;
21+
22+
public class AlterCollectionFunctionReq {
23+
private String collectionName;
24+
private String databaseName;
25+
private CreateCollectionReq.Function function;
26+
27+
private AlterCollectionFunctionReq(AlterCollectionFunctionReqBuilder builder) {
28+
this.collectionName = builder.collectionName;
29+
this.databaseName = builder.databaseName;
30+
this.function = builder.function;
31+
}
32+
33+
public String getCollectionName() {
34+
return collectionName;
35+
}
36+
37+
public void setCollectionName(String collectionName) {
38+
this.collectionName = collectionName;
39+
}
40+
41+
public String getDatabaseName() {
42+
return databaseName;
43+
}
44+
45+
public void setDatabaseName(String databaseName) {
46+
this.databaseName = databaseName;
47+
}
48+
49+
public CreateCollectionReq.Function getFunction() {
50+
return function;
51+
}
52+
53+
@Override
54+
public String toString() {
55+
return "AlterCollectionFunctionReq{" +
56+
"collectionName='" + collectionName + '\'' +
57+
", databaseName='" + databaseName + '\'' +
58+
", function= " + function +
59+
'}';
60+
}
61+
62+
public static AlterCollectionFunctionReqBuilder builder() {
63+
return new AlterCollectionFunctionReqBuilder();
64+
}
65+
66+
public static class AlterCollectionFunctionReqBuilder {
67+
private String collectionName = "";
68+
private String databaseName = "";
69+
private CreateCollectionReq.Function function;
70+
71+
private AlterCollectionFunctionReqBuilder() {
72+
}
73+
74+
public AlterCollectionFunctionReqBuilder collectionName(String collectionName) {
75+
this.collectionName = collectionName;
76+
return this;
77+
}
78+
79+
public AlterCollectionFunctionReqBuilder databaseName(String databaseName) {
80+
this.databaseName = databaseName;
81+
return this;
82+
}
83+
84+
public AlterCollectionFunctionReqBuilder function(CreateCollectionReq.Function function) {
85+
this.function = function;
86+
return this;
87+
}
88+
89+
public AlterCollectionFunctionReq build() {
90+
return new AlterCollectionFunctionReq(this);
91+
}
92+
}
93+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package io.milvus.v2.service.collection.request;
21+
22+
public class DropCollectionFunctionReq {
23+
private String collectionName;
24+
private String databaseName;
25+
private String functionName;
26+
27+
private DropCollectionFunctionReq(DropCollectionFunctionReqBuilder builder) {
28+
this.collectionName = builder.collectionName;
29+
this.databaseName = builder.databaseName;
30+
this.functionName = builder.functionName;
31+
}
32+
33+
public String getCollectionName() {
34+
return collectionName;
35+
}
36+
37+
public void setCollectionName(String collectionName) {
38+
this.collectionName = collectionName;
39+
}
40+
41+
public String getDatabaseName() {
42+
return databaseName;
43+
}
44+
45+
public void setDatabaseName(String databaseName) {
46+
this.databaseName = databaseName;
47+
}
48+
49+
public String getFunctionName() {
50+
return functionName;
51+
}
52+
53+
@Override
54+
public String toString() {
55+
return "DropCollectionFunctionReq{" +
56+
"collectionName='" + collectionName + '\'' +
57+
", databaseName='" + databaseName + '\'' +
58+
", functionName= '" + functionName + '\'' +
59+
'}';
60+
}
61+
62+
public static DropCollectionFunctionReqBuilder builder() {
63+
return new DropCollectionFunctionReqBuilder();
64+
}
65+
66+
public static class DropCollectionFunctionReqBuilder {
67+
private String collectionName = "";
68+
private String databaseName = "";
69+
private String functionName = "";
70+
71+
private DropCollectionFunctionReqBuilder() {
72+
}
73+
74+
public DropCollectionFunctionReqBuilder collectionName(String collectionName) {
75+
this.collectionName = collectionName;
76+
return this;
77+
}
78+
79+
public DropCollectionFunctionReqBuilder databaseName(String databaseName) {
80+
this.databaseName = databaseName;
81+
return this;
82+
}
83+
84+
public DropCollectionFunctionReqBuilder functionName(String functionName) {
85+
this.functionName = functionName;
86+
return this;
87+
}
88+
89+
public DropCollectionFunctionReq build() {
90+
return new DropCollectionFunctionReq(this);
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)