From 5243119df10b70278ffb511fb1f721424e377e23 Mon Sep 17 00:00:00 2001 From: groot Date: Thu, 4 Dec 2025 17:39:07 +0800 Subject: [PATCH] Support AddCollectionFunction/AlterCollectionFunction/DropCollectionFunction (#1708) Signed-off-by: yhmo --- .../io/milvus/v2/client/MilvusClientV2.java | 27 ++++++ .../service/collection/CollectionService.java | 64 +++++++++++++ .../request/AddCollectionFunctionReq.java | 93 +++++++++++++++++++ .../request/AlterCollectionFunctionReq.java | 93 +++++++++++++++++++ .../request/DropCollectionFunctionReq.java | 93 +++++++++++++++++++ sdk-core/src/main/milvus-proto | 2 +- 6 files changed, 371 insertions(+), 1 deletion(-) create mode 100644 sdk-core/src/main/java/io/milvus/v2/service/collection/request/AddCollectionFunctionReq.java create mode 100644 sdk-core/src/main/java/io/milvus/v2/service/collection/request/AlterCollectionFunctionReq.java create mode 100644 sdk-core/src/main/java/io/milvus/v2/service/collection/request/DropCollectionFunctionReq.java diff --git a/sdk-core/src/main/java/io/milvus/v2/client/MilvusClientV2.java b/sdk-core/src/main/java/io/milvus/v2/client/MilvusClientV2.java index 8ada2b41e..b87e5ca78 100644 --- a/sdk-core/src/main/java/io/milvus/v2/client/MilvusClientV2.java +++ b/sdk-core/src/main/java/io/milvus/v2/client/MilvusClientV2.java @@ -533,6 +533,33 @@ public DescribeReplicasResp describeReplicas(DescribeReplicasReq request) { return rpcUtils.retry(() -> collectionService.describeReplicas(this.getRpcStub(), request)); } + /** + * Add a function to collection. + * + * @param request add function request + */ + public void addCollectionFunction(AddCollectionFunctionReq request) { + rpcUtils.retry(() -> collectionService.addCollectionFunction(this.getRpcStub(), request)); + } + + /** + * Alter a function of collection. + * + * @param request alter function request + */ + public void alterCollectionFunction(AlterCollectionFunctionReq request) { + rpcUtils.retry(() -> collectionService.alterCollectionFunction(this.getRpcStub(), request)); + } + + /** + * Drop a function of collection. + * + * @param request drop function request + */ + public void dropCollectionFunction(DropCollectionFunctionReq request) { + rpcUtils.retry(() -> collectionService.dropCollectionFunction(this.getRpcStub(), request)); + } + ///////////////////////////////////////////////////////////////////////////////////////////// // Index Operations ///////////////////////////////////////////////////////////////////////////////////////////// diff --git a/sdk-core/src/main/java/io/milvus/v2/service/collection/CollectionService.java b/sdk-core/src/main/java/io/milvus/v2/service/collection/CollectionService.java index 904b631c7..f653ab138 100644 --- a/sdk-core/src/main/java/io/milvus/v2/service/collection/CollectionService.java +++ b/sdk-core/src/main/java/io/milvus/v2/service/collection/CollectionService.java @@ -553,6 +553,70 @@ public DescribeReplicasResp describeReplicas(MilvusServiceGrpc.MilvusServiceBloc .build(); } + public Void addCollectionFunction(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, + AddCollectionFunctionReq request) { + if (request.getFunction() == null) { + throw new MilvusClientException(ErrorCode.INVALID_PARAMS, "Function cannot be null."); + } + + String dbName = request.getDatabaseName(); + String collectionName = request.getCollectionName(); + String title = String.format("Add function to collection: '%s' in database: '%s'", collectionName, dbName); + AddCollectionFunctionRequest.Builder builder = AddCollectionFunctionRequest.newBuilder() + .setCollectionName(collectionName) + .setFunctionSchema(SchemaUtils.convertToGrpcFunction(request.getFunction())); + if (StringUtils.isNotEmpty(dbName)) { + builder.setDbName(dbName); + } + Status status = blockingStub.addCollectionFunction(builder.build()); + rpcUtils.handleResponse(title, status); + + return null; + } + + public Void alterCollectionFunction(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, + AlterCollectionFunctionReq request) { + if (request.getFunction() == null) { + throw new MilvusClientException(ErrorCode.INVALID_PARAMS, "Function cannot be null."); + } + + String dbName = request.getDatabaseName(); + String collectionName = request.getCollectionName(); + String title = String.format("Alter function of collection: '%s' in database: '%s'", collectionName, dbName); + AlterCollectionFunctionRequest.Builder builder = AlterCollectionFunctionRequest.newBuilder() + .setCollectionName(collectionName) + .setFunctionName(request.getFunction().getName()) + .setFunctionSchema(SchemaUtils.convertToGrpcFunction(request.getFunction())); + if (StringUtils.isNotEmpty(dbName)) { + builder.setDbName(dbName); + } + Status status = blockingStub.alterCollectionFunction(builder.build()); + rpcUtils.handleResponse(title, status); + + return null; + } + + public Void dropCollectionFunction(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, + DropCollectionFunctionReq request) { + if (StringUtils.isEmpty(request.getFunctionName())) { + throw new MilvusClientException(ErrorCode.INVALID_PARAMS, "Function name cannot be empty."); + } + + String dbName = request.getDatabaseName(); + String collectionName = request.getCollectionName(); + String title = String.format("Drop function to collection: '%s' in database: '%s'", collectionName, dbName); + DropCollectionFunctionRequest.Builder builder = DropCollectionFunctionRequest.newBuilder() + .setCollectionName(collectionName) + .setFunctionName(request.getFunctionName()); + if (StringUtils.isNotEmpty(dbName)) { + builder.setDbName(dbName); + } + Status status = blockingStub.dropCollectionFunction(builder.build()); + rpcUtils.handleResponse(title, status); + + return null; + } + private void WaitForLoadCollection(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, String databaseName, String collectionName, long timeoutMs) { long startTime = System.currentTimeMillis(); // Capture start time/ Timeout in milliseconds (60 seconds) diff --git a/sdk-core/src/main/java/io/milvus/v2/service/collection/request/AddCollectionFunctionReq.java b/sdk-core/src/main/java/io/milvus/v2/service/collection/request/AddCollectionFunctionReq.java new file mode 100644 index 000000000..282d818f5 --- /dev/null +++ b/sdk-core/src/main/java/io/milvus/v2/service/collection/request/AddCollectionFunctionReq.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.milvus.v2.service.collection.request; + +public class AddCollectionFunctionReq { + private String collectionName; + private String databaseName; + private CreateCollectionReq.Function function; + + private AddCollectionFunctionReq(AddCollectionFunctionReqBuilder builder) { + this.collectionName = builder.collectionName; + this.databaseName = builder.databaseName; + this.function = builder.function; + } + + public String getCollectionName() { + return collectionName; + } + + public void setCollectionName(String collectionName) { + this.collectionName = collectionName; + } + + public String getDatabaseName() { + return databaseName; + } + + public void setDatabaseName(String databaseName) { + this.databaseName = databaseName; + } + + public CreateCollectionReq.Function getFunction() { + return function; + } + + @Override + public String toString() { + return "AddCollectionFunctionReq{" + + "collectionName='" + collectionName + '\'' + + ", databaseName='" + databaseName + '\'' + + ", function= " + function + + '}'; + } + + public static AddCollectionFunctionReqBuilder builder() { + return new AddCollectionFunctionReqBuilder(); + } + + public static class AddCollectionFunctionReqBuilder { + private String collectionName = ""; + private String databaseName = ""; + private CreateCollectionReq.Function function; + + private AddCollectionFunctionReqBuilder() { + } + + public AddCollectionFunctionReqBuilder collectionName(String collectionName) { + this.collectionName = collectionName; + return this; + } + + public AddCollectionFunctionReqBuilder databaseName(String databaseName) { + this.databaseName = databaseName; + return this; + } + + public AddCollectionFunctionReqBuilder function(CreateCollectionReq.Function function) { + this.function = function; + return this; + } + + public AddCollectionFunctionReq build() { + return new AddCollectionFunctionReq(this); + } + } +} diff --git a/sdk-core/src/main/java/io/milvus/v2/service/collection/request/AlterCollectionFunctionReq.java b/sdk-core/src/main/java/io/milvus/v2/service/collection/request/AlterCollectionFunctionReq.java new file mode 100644 index 000000000..7efcb3580 --- /dev/null +++ b/sdk-core/src/main/java/io/milvus/v2/service/collection/request/AlterCollectionFunctionReq.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.milvus.v2.service.collection.request; + +public class AlterCollectionFunctionReq { + private String collectionName; + private String databaseName; + private CreateCollectionReq.Function function; + + private AlterCollectionFunctionReq(AlterCollectionFunctionReqBuilder builder) { + this.collectionName = builder.collectionName; + this.databaseName = builder.databaseName; + this.function = builder.function; + } + + public String getCollectionName() { + return collectionName; + } + + public void setCollectionName(String collectionName) { + this.collectionName = collectionName; + } + + public String getDatabaseName() { + return databaseName; + } + + public void setDatabaseName(String databaseName) { + this.databaseName = databaseName; + } + + public CreateCollectionReq.Function getFunction() { + return function; + } + + @Override + public String toString() { + return "AlterCollectionFunctionReq{" + + "collectionName='" + collectionName + '\'' + + ", databaseName='" + databaseName + '\'' + + ", function= " + function + + '}'; + } + + public static AlterCollectionFunctionReqBuilder builder() { + return new AlterCollectionFunctionReqBuilder(); + } + + public static class AlterCollectionFunctionReqBuilder { + private String collectionName = ""; + private String databaseName = ""; + private CreateCollectionReq.Function function; + + private AlterCollectionFunctionReqBuilder() { + } + + public AlterCollectionFunctionReqBuilder collectionName(String collectionName) { + this.collectionName = collectionName; + return this; + } + + public AlterCollectionFunctionReqBuilder databaseName(String databaseName) { + this.databaseName = databaseName; + return this; + } + + public AlterCollectionFunctionReqBuilder function(CreateCollectionReq.Function function) { + this.function = function; + return this; + } + + public AlterCollectionFunctionReq build() { + return new AlterCollectionFunctionReq(this); + } + } +} diff --git a/sdk-core/src/main/java/io/milvus/v2/service/collection/request/DropCollectionFunctionReq.java b/sdk-core/src/main/java/io/milvus/v2/service/collection/request/DropCollectionFunctionReq.java new file mode 100644 index 000000000..7f806d7ab --- /dev/null +++ b/sdk-core/src/main/java/io/milvus/v2/service/collection/request/DropCollectionFunctionReq.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.milvus.v2.service.collection.request; + +public class DropCollectionFunctionReq { + private String collectionName; + private String databaseName; + private String functionName; + + private DropCollectionFunctionReq(DropCollectionFunctionReqBuilder builder) { + this.collectionName = builder.collectionName; + this.databaseName = builder.databaseName; + this.functionName = builder.functionName; + } + + public String getCollectionName() { + return collectionName; + } + + public void setCollectionName(String collectionName) { + this.collectionName = collectionName; + } + + public String getDatabaseName() { + return databaseName; + } + + public void setDatabaseName(String databaseName) { + this.databaseName = databaseName; + } + + public String getFunctionName() { + return functionName; + } + + @Override + public String toString() { + return "DropCollectionFunctionReq{" + + "collectionName='" + collectionName + '\'' + + ", databaseName='" + databaseName + '\'' + + ", functionName= '" + functionName + '\'' + + '}'; + } + + public static DropCollectionFunctionReqBuilder builder() { + return new DropCollectionFunctionReqBuilder(); + } + + public static class DropCollectionFunctionReqBuilder { + private String collectionName = ""; + private String databaseName = ""; + private String functionName = ""; + + private DropCollectionFunctionReqBuilder() { + } + + public DropCollectionFunctionReqBuilder collectionName(String collectionName) { + this.collectionName = collectionName; + return this; + } + + public DropCollectionFunctionReqBuilder databaseName(String databaseName) { + this.databaseName = databaseName; + return this; + } + + public DropCollectionFunctionReqBuilder functionName(String functionName) { + this.functionName = functionName; + return this; + } + + public DropCollectionFunctionReq build() { + return new DropCollectionFunctionReq(this); + } + } +} diff --git a/sdk-core/src/main/milvus-proto b/sdk-core/src/main/milvus-proto index 99dbd46f1..44bb43c7e 160000 --- a/sdk-core/src/main/milvus-proto +++ b/sdk-core/src/main/milvus-proto @@ -1 +1 @@ -Subproject commit 99dbd46f10b7f11907a2a967185c8178292d3239 +Subproject commit 44bb43c7e07b36fc6dcecba3b902c0612c0463d0