Skip to content

Commit ed8bb40

Browse files
authored
Add AddCollectionFuntion/AlterCollectionFunction/DropCollectionFunction (milvus-io#470)
Signed-off-by: yhmo <yihua.mo@zilliz.com>
1 parent be9f009 commit ed8bb40

13 files changed

Lines changed: 499 additions & 1 deletion

.github/mergify.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,16 @@ pull_request_rules:
5858
add:
5959
- ci-passed
6060

61-
- name: Remove ci-passed when build failed
61+
- name: Remove ci-passed when checks are not green
6262
conditions:
6363
- or: *BRANCHES
6464
- or:
65+
- "check-pending=Detect path changes"
66+
- "check-pending=Build and test AMD64 Ubuntu 20.04"
67+
- "check-pending=Build and test AMD64 Fedora 39"
68+
- "check-pending=Integration test"
69+
- "check-pending=Build and test macOS 15"
70+
- "check-pending=Build and test windows"
6571
- "check-failure=Detect path changes"
6672
- "check-failure=Build and test AMD64 Ubuntu 20.04"
6773
- "check-failure=Build and test AMD64 Fedora 39"

src/impl/MilvusClientV2Impl.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,64 @@ MilvusClientV2Impl::AddCollectionField(const AddCollectionFieldRequest& request)
547547
pre, &MilvusConnection::AddCollectionField);
548548
}
549549

550+
Status
551+
MilvusClientV2Impl::AddCollectionFunction(const AddCollectionFunctionRequest& request) {
552+
if (request.Function() == nullptr) {
553+
return {StatusCode::INVALID_ARGUMENT, "Function cannot be null."};
554+
}
555+
if (request.Function()->Name().empty()) {
556+
return {StatusCode::INVALID_ARGUMENT, "Function name cannot be empty."};
557+
}
558+
559+
auto pre = [&request](proto::milvus::AddCollectionFunctionRequest& rpc_request) {
560+
rpc_request.set_db_name(request.DatabaseName());
561+
rpc_request.set_collection_name(request.CollectionName());
562+
ConvertFunctionSchema(request.Function(), *rpc_request.mutable_functionschema());
563+
return Status::OK();
564+
};
565+
566+
return connection_.Invoke<proto::milvus::AddCollectionFunctionRequest, proto::common::Status>(
567+
pre, &MilvusConnection::AddCollectionFunction);
568+
}
569+
570+
Status
571+
MilvusClientV2Impl::AlterCollectionFunction(const AlterCollectionFunctionRequest& request) {
572+
if (request.Function() == nullptr) {
573+
return {StatusCode::INVALID_ARGUMENT, "Function cannot be null."};
574+
}
575+
if (request.Function()->Name().empty()) {
576+
return {StatusCode::INVALID_ARGUMENT, "Function name cannot be empty."};
577+
}
578+
579+
auto pre = [&request](proto::milvus::AlterCollectionFunctionRequest& rpc_request) {
580+
rpc_request.set_db_name(request.DatabaseName());
581+
rpc_request.set_collection_name(request.CollectionName());
582+
rpc_request.set_function_name(request.Function()->Name());
583+
ConvertFunctionSchema(request.Function(), *rpc_request.mutable_functionschema());
584+
return Status::OK();
585+
};
586+
587+
return connection_.Invoke<proto::milvus::AlterCollectionFunctionRequest, proto::common::Status>(
588+
pre, &MilvusConnection::AlterCollectionFunction);
589+
}
590+
591+
Status
592+
MilvusClientV2Impl::DropCollectionFunction(const DropCollectionFunctionRequest& request) {
593+
if (request.FunctionName().empty()) {
594+
return {StatusCode::INVALID_ARGUMENT, "Function name cannot be empty."};
595+
}
596+
597+
auto pre = [&request](proto::milvus::DropCollectionFunctionRequest& rpc_request) {
598+
rpc_request.set_db_name(request.DatabaseName());
599+
rpc_request.set_collection_name(request.CollectionName());
600+
rpc_request.set_function_name(request.FunctionName());
601+
return Status::OK();
602+
};
603+
604+
return connection_.Invoke<proto::milvus::DropCollectionFunctionRequest, proto::common::Status>(
605+
pre, &MilvusConnection::DropCollectionFunction);
606+
}
607+
550608
Status
551609
MilvusClientV2Impl::CreatePartition(const CreatePartitionRequest& request) {
552610
auto pre = [&request](proto::milvus::CreatePartitionRequest& rpc_request) {

src/impl/MilvusClientV2Impl.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ class MilvusClientV2Impl : public MilvusClientV2 {
102102
Status
103103
AddCollectionField(const AddCollectionFieldRequest& request) final;
104104

105+
Status
106+
AddCollectionFunction(const AddCollectionFunctionRequest& request) final;
107+
108+
Status
109+
AlterCollectionFunction(const AlterCollectionFunctionRequest& request) final;
110+
111+
Status
112+
DropCollectionFunction(const DropCollectionFunctionRequest& request) final;
113+
105114
Status
106115
CreatePartition(const CreatePartitionRequest& request) final;
107116

src/impl/MilvusConnection.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,24 @@ MilvusConnection::AddCollectionField(const proto::milvus::AddCollectionFieldRequ
327327
return grpcCall("AddCollectionField", &Stub::AddCollectionField, request, response, options);
328328
}
329329

330+
Status
331+
MilvusConnection::AddCollectionFunction(const proto::milvus::AddCollectionFunctionRequest& request,
332+
proto::common::Status& response, const GrpcContextOptions& options) {
333+
return grpcCall("AddCollectionFunction", &Stub::AddCollectionFunction, request, response, options);
334+
}
335+
336+
Status
337+
MilvusConnection::AlterCollectionFunction(const proto::milvus::AlterCollectionFunctionRequest& request,
338+
proto::common::Status& response, const GrpcContextOptions& options) {
339+
return grpcCall("AlterCollectionFunction", &Stub::AlterCollectionFunction, request, response, options);
340+
}
341+
342+
Status
343+
MilvusConnection::DropCollectionFunction(const proto::milvus::DropCollectionFunctionRequest& request,
344+
proto::common::Status& response, const GrpcContextOptions& options) {
345+
return grpcCall("DropCollectionFunction", &Stub::DropCollectionFunction, request, response, options);
346+
}
347+
330348
Status
331349
MilvusConnection::CreatePartition(const proto::milvus::CreatePartitionRequest& request, proto::common::Status& response,
332350
const GrpcContextOptions& options) {

src/impl/MilvusConnection.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,18 @@ class MilvusConnection {
154154
AddCollectionField(const proto::milvus::AddCollectionFieldRequest& request, proto::common::Status& response,
155155
const GrpcContextOptions& options);
156156

157+
Status
158+
AddCollectionFunction(const proto::milvus::AddCollectionFunctionRequest& request, proto::common::Status& response,
159+
const GrpcContextOptions& options);
160+
161+
Status
162+
AlterCollectionFunction(const proto::milvus::AlterCollectionFunctionRequest& request,
163+
proto::common::Status& response, const GrpcContextOptions& options);
164+
165+
Status
166+
DropCollectionFunction(const proto::milvus::DropCollectionFunctionRequest& request, proto::common::Status& response,
167+
const GrpcContextOptions& options);
168+
157169
Status
158170
CreatePartition(const proto::milvus::CreatePartitionRequest& request, proto::common::Status& response,
159171
const GrpcContextOptions& options);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Licensed to the LF AI & Data foundation under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
#include "milvus/request/collection/AddCollectionFunctionRequest.h"
18+
19+
namespace milvus {
20+
21+
const FunctionPtr&
22+
AddCollectionFunctionRequest::Function() const {
23+
return function_;
24+
}
25+
26+
void
27+
AddCollectionFunctionRequest::SetFunction(const FunctionPtr& function) {
28+
function_ = function;
29+
}
30+
31+
AddCollectionFunctionRequest&
32+
AddCollectionFunctionRequest::WithFunction(const FunctionPtr& function) {
33+
SetFunction(function);
34+
return *this;
35+
}
36+
37+
} // namespace milvus
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Licensed to the LF AI & Data foundation under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
#include "milvus/request/collection/AlterCollectionFunctionRequest.h"
18+
19+
namespace milvus {
20+
21+
const FunctionPtr&
22+
AlterCollectionFunctionRequest::Function() const {
23+
return function_;
24+
}
25+
26+
void
27+
AlterCollectionFunctionRequest::SetFunction(const FunctionPtr& function) {
28+
function_ = function;
29+
}
30+
31+
AlterCollectionFunctionRequest&
32+
AlterCollectionFunctionRequest::WithFunction(const FunctionPtr& function) {
33+
SetFunction(function);
34+
return *this;
35+
}
36+
37+
} // namespace milvus
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Licensed to the LF AI & Data foundation under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
#include "milvus/request/collection/DropCollectionFunctionRequest.h"
18+
19+
#include <utility>
20+
21+
namespace milvus {
22+
23+
const std::string&
24+
DropCollectionFunctionRequest::FunctionName() const {
25+
return function_name_;
26+
}
27+
28+
void
29+
DropCollectionFunctionRequest::SetFunctionName(std::string function_name) {
30+
function_name_ = std::move(function_name);
31+
}
32+
33+
DropCollectionFunctionRequest&
34+
DropCollectionFunctionRequest::WithFunctionName(std::string function_name) {
35+
SetFunctionName(std::move(function_name));
36+
return *this;
37+
}
38+
39+
} // namespace milvus

src/include/milvus/MilvusClientV2.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
#include "request/alias/DropAliasRequest.h"
2424
#include "request/alias/ListAliasesRequest.h"
2525
#include "request/collection/AddCollectionFieldRequest.h"
26+
#include "request/collection/AddCollectionFunctionRequest.h"
2627
#include "request/collection/AlterCollectionFieldPropertiesRequest.h"
28+
#include "request/collection/AlterCollectionFunctionRequest.h"
2729
#include "request/collection/AlterCollectionPropertiesRequest.h"
2830
#include "request/collection/CreateCollectionRequest.h"
2931
#include "request/collection/CreateSimpleCollectionRequest.h"
3032
#include "request/collection/DescribeCollectionRequest.h"
3133
#include "request/collection/DropCollectionFieldPropertiesRequest.h"
34+
#include "request/collection/DropCollectionFunctionRequest.h"
3235
#include "request/collection/DropCollectionPropertiesRequest.h"
3336
#include "request/collection/DropCollectionRequest.h"
3437
#include "request/collection/GetCollectionStatsRequest.h"
@@ -371,6 +374,34 @@ class MilvusClientV2 {
371374
virtual Status
372375
AddCollectionField(const AddCollectionFieldRequest& request) = 0;
373376

377+
/**
378+
* @brief Add a function to an existing collection.
379+
*
380+
* @param [in] request input parameters
381+
* @return Status operation successfully or not
382+
*/
383+
virtual Status
384+
AddCollectionFunction(const AddCollectionFunctionRequest& request) = 0;
385+
386+
/**
387+
* @brief Alter a function of an existing collection. The function name
388+
* (taken from the Function object) identifies which function to alter.
389+
*
390+
* @param [in] request input parameters
391+
* @return Status operation successfully or not
392+
*/
393+
virtual Status
394+
AlterCollectionFunction(const AlterCollectionFunctionRequest& request) = 0;
395+
396+
/**
397+
* @brief Drop a function of an existing collection.
398+
*
399+
* @param [in] request input parameters
400+
* @return Status operation successfully or not
401+
*/
402+
virtual Status
403+
DropCollectionFunction(const DropCollectionFunctionRequest& request) = 0;
404+
374405
/**
375406
* @brief Create a partition in a collection.
376407
*
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Licensed to the LF AI & Data foundation under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
#pragma once
18+
19+
#include "../../types/Function.h"
20+
#include "./CollectionRequestBase.h"
21+
22+
namespace milvus {
23+
24+
/**
25+
* @brief Used by MilvusClientV2::AddCollectionFunction()
26+
*/
27+
class AddCollectionFunctionRequest : public CollectionRequestBase<AddCollectionFunctionRequest> {
28+
public:
29+
/**
30+
* @brief Constructor
31+
*/
32+
AddCollectionFunctionRequest() = default;
33+
34+
/**
35+
* @brief Get the function to be added.
36+
*/
37+
const FunctionPtr&
38+
Function() const;
39+
40+
/**
41+
* @brief Set the function to be added.
42+
*/
43+
void
44+
SetFunction(const FunctionPtr& function);
45+
46+
/**
47+
* @brief Set the function to be added.
48+
*/
49+
AddCollectionFunctionRequest&
50+
WithFunction(const FunctionPtr& function);
51+
52+
private:
53+
FunctionPtr function_;
54+
};
55+
56+
} // namespace milvus

0 commit comments

Comments
 (0)