├── .clang-format ├── .clang-tidy ├── .github ├── mergify.yml └── workflows │ ├── main.yaml │ └── release.yaml ├── .gitignore ├── CMakeLists.txt ├── DEVELOPMENT.md ├── LICENSE ├── Makefile ├── OWNERS ├── README.md ├── cmake ├── DefineOptions.cmake ├── FindClangTools.cmake ├── MilvusProtoGen.cmake ├── MilvusSdkPackages.cmake └── ThirdPartyPackages.cmake ├── codecov.yml ├── doc └── Doxyfile ├── examples ├── CMakeLists.txt ├── example.md └── simple │ ├── CMakeLists.txt │ └── main.cpp ├── libmilvus.spec.rpkg ├── scripts ├── build.sh ├── coverage.sh ├── cpplint.py ├── format_exclusions.txt ├── install_deps.sh ├── lint_exclusions.txt ├── lintutils.py ├── run_clang_format.py ├── run_clang_tidy.py ├── run_cpplint.py └── scripts.md ├── src ├── CHANGELOG.md ├── CMakeLists.txt ├── impl │ ├── BulkImport.cpp │ ├── MilvusClientImpl.cpp │ ├── MilvusClientImpl.h │ ├── MilvusClientImplV2.cpp │ ├── MilvusClientImplV2.h │ ├── MilvusConnection.cpp │ ├── MilvusConnection.h │ ├── MilvusInterceptor.cpp │ ├── MilvusInterceptor.h │ ├── Status.cpp │ ├── TypeUtils.cpp │ ├── TypeUtils.h │ └── types │ │ ├── AliasDesc.cpp │ │ ├── AnnSearchRequest.cpp │ │ ├── CollectionDesc.cpp │ │ ├── CollectionInfo.cpp │ │ ├── CollectionSchema.cpp │ │ ├── CollectionStat.cpp │ │ ├── CompactionPlan.cpp │ │ ├── CompactionState.cpp │ │ ├── ConnectParam.cpp │ │ ├── DatabaseDesc.cpp │ │ ├── DistanceArray.cpp │ │ ├── DmlResults.cpp │ │ ├── FieldData.cpp │ │ ├── FieldSchema.cpp │ │ ├── GetArguments.cpp │ │ ├── HybridTimestamp.cpp │ │ ├── IDArray.cpp │ │ ├── IndexDesc.cpp │ │ ├── IndexState.cpp │ │ ├── ListAliasesResult.cpp │ │ ├── LoadState.cpp │ │ ├── NodeInfo.cpp │ │ ├── PartitionInfo.cpp │ │ ├── PartitionStat.cpp │ │ ├── PrivilegeGroupInfo.cpp │ │ ├── ProgressMonitor.cpp │ │ ├── QueryArguments.cpp │ │ ├── QueryResults.cpp │ │ ├── Ranker.cpp │ │ ├── ResourceGroupConfig.cpp │ │ ├── ResourceGroupDesc.cpp │ │ ├── RoleDesc.cpp │ │ ├── SearchArguments.cpp │ │ ├── SearchResults.cpp │ │ ├── SegmentInfo.cpp │ │ └── UserResult.cpp └── include │ └── milvus │ ├── BulkImport.h │ ├── MilvusClient.h │ ├── MilvusClientV2.h │ ├── Status.h │ ├── param │ └── BaseParam.h │ └── types │ ├── AliasDesc.h │ ├── AnnSearchRequest.h │ ├── CollectionDesc.h │ ├── CollectionInfo.h │ ├── CollectionSchema.h │ ├── CollectionStat.h │ ├── CompactionPlan.h │ ├── CompactionState.h │ ├── ConnectParam.h │ ├── Constant.h │ ├── DataType.h │ ├── DatabaseDesc.h │ ├── DistanceArray.h │ ├── DmlResults.h │ ├── FieldData.h │ ├── FieldSchema.h │ ├── GetArguments.h │ ├── HybridTimestamp.h │ ├── IDArray.h │ ├── IndexDesc.h │ ├── IndexState.h │ ├── IndexType.h │ ├── ListAliasesResult.h │ ├── LoadState.h │ ├── MetricType.h │ ├── NodeInfo.h │ ├── PartitionInfo.h │ ├── PartitionStat.h │ ├── PrivilegeGroupInfo.h │ ├── ProgressMonitor.h │ ├── QueryArguments.h │ ├── QueryResults.h │ ├── Ranker.h │ ├── ResourceGroupConfig.h │ ├── ResourceGroupDesc.h │ ├── RoleDesc.h │ ├── SearchArguments.h │ ├── SearchResults.h │ ├── SegmentInfo.h │ └── UserResult.h ├── test ├── CHANGELOG.md ├── CMakeLists.txt ├── it │ ├── TestAlias.cpp │ ├── TestCompact.cpp │ ├── TestConnection.cpp │ ├── TestCreateCollection.cpp │ ├── TestCreateIndex.cpp │ ├── TestCreatePartition.cpp │ ├── TestCredential.cpp │ ├── TestDelete.cpp │ ├── TestDescribeCollection.cpp │ ├── TestDescribeIndex.cpp │ ├── TestDropCollection.cpp │ ├── TestDropIndex.cpp │ ├── TestDropPartition.cpp │ ├── TestFlush.cpp │ ├── TestGetCollectionsStatistics.cpp │ ├── TestGetIndexBuildProgress.cpp │ ├── TestGetIndexState.cpp │ ├── TestGetMetrics.cpp │ ├── TestGetPartitionStatistics.cpp │ ├── TestGetPersistentSegmentInfo.cpp │ ├── TestGetQuerySegmentInfo.cpp │ ├── TestGetVersion.cpp │ ├── TestHasCollection.cpp │ ├── TestHasPartition.cpp │ ├── TestInsert.cpp │ ├── TestLoadBalance.cpp │ ├── TestLoadCollection.cpp │ ├── TestLoadPartitions.cpp │ ├── TestQuery.cpp │ ├── TestReleasePartitions.cpp │ ├── TestRelseaseCollection.cpp │ ├── TestSearch.cpp │ ├── TestShowPartitions.cpp │ └── mocks │ │ ├── MilvusMockedServer.cpp │ │ ├── MilvusMockedServer.h │ │ ├── MilvusMockedService.h │ │ ├── MilvusMockedTest.cpp │ │ └── MilvusMockedTest.h ├── st │ ├── Main.cpp │ ├── MilvusServerTest.cpp │ ├── MilvusServerTest.h │ ├── TestCollection.cpp │ ├── TestConnectWithTls.cpp │ ├── TestConnectWithUser.cpp │ ├── TestGeneric.cpp │ ├── TestSearch.cpp │ └── TestSearchWithBinaryVectors.cpp └── ut │ ├── TestCollectionDesc.cpp │ ├── TestCollectionInfo.cpp │ ├── TestCollectionSchema.cpp │ ├── TestCollectionStat.cpp │ ├── TestCompactionPlan.cpp │ ├── TestCompactionState.cpp │ ├── TestConnectParam.cpp │ ├── TestDistanceArray.cpp │ ├── TestDmlResults.cpp │ ├── TestDummy.cpp │ ├── TestFieldData.cpp │ ├── TestFieldSchema.cpp │ ├── TestHybirdTimestamp.cpp │ ├── TestIDArray.cpp │ ├── TestIndexDesc.cpp │ ├── TestPartitionStat.cpp │ ├── TestProgressMonitor.cpp │ ├── TestQueryArguments.cpp │ ├── TestQueryResults.cpp │ ├── TestSearchArguments.cpp │ ├── TestSearchResults.cpp │ ├── TestSegmentInfo.cpp │ ├── TestStatus.cpp │ └── TestTypeUtils.cpp └── thirdparty └── thirdparty.md /.clang-format: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) 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, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | --- 18 | BasedOnStyle: Google 19 | DerivePointerAlignment: false 20 | ColumnLimit: 120 21 | IndentWidth: 4 22 | AccessModifierOffset: -3 23 | AlwaysBreakAfterReturnType: All 24 | AllowShortBlocksOnASingleLine: Never 25 | AllowShortFunctionsOnASingleLine: None 26 | AllowShortIfStatementsOnASingleLine: false 27 | AlignTrailingComments: true 28 | -------------------------------------------------------------------------------- /.github/mergify.yml: -------------------------------------------------------------------------------- 1 | misc: 2 | - branch: &BRANCHES 3 | # In this pull request, the changes are based on the master branch 4 | - &MASTER_BRANCH base=master 5 | # In this pull request, the changes are based on the 2.x(or 2.x.x) branch 6 | - &2X_BRANCH base~=^2(\.\d+){1,2}$ 7 | 8 | pull_request_rules: 9 | - name: Add needs-dco label when DCO check failed 10 | conditions: 11 | # branch condition: in this pull request, the changes are based on any branch referenced by BRANCHES 12 | - or: *BRANCHES 13 | - -status-success=DCO 14 | actions: 15 | label: 16 | remove: 17 | - dco-passed 18 | add: 19 | - needs-dco 20 | comment: 21 | message: | 22 | @{{author}} Thanks for your contribution. Please submit with DCO, see the contributing guide https://github.com/milvus-io/milvus/blob/master/CONTRIBUTING.md#developer-certificate-of-origin-dco. 23 | 24 | - name: Add dco-passed label when DCO check passed 25 | conditions: 26 | # branch condition: in this pull request, the changes are based on any branch referenced by BRANCHES 27 | - or: *BRANCHES 28 | - status-success=DCO 29 | actions: 30 | label: 31 | remove: 32 | - needs-dco 33 | add: 34 | - dco-passed 35 | 36 | - name: Test passed for code changed 37 | conditions: 38 | - or: *BRANCHES 39 | - "status-success=Build and test AMD64 Ubuntu 20.04" 40 | - "status-success=Build and test AMD64 Ubuntu 22.04" 41 | - "status-success=Build and test AMD64 Fedora 38" 42 | - "status-success=Build and test AMD64 Fedora 39" 43 | - "status-success=Build and test macOS 13" 44 | - "status-success=Build and test windows" 45 | actions: 46 | label: 47 | add: 48 | - ci-passed 49 | 50 | - name: Remove ci-passed when build failed 51 | conditions: 52 | - or: *BRANCHES 53 | - or: 54 | - "check-failure=Build and test AMD64 Ubuntu 20.04" 55 | - "check-failure=Build and test AMD64 Ubuntu 22.04" 56 | - "check-failure=Build and test AMD64 Fedora 38" 57 | - "check-failure=Build and test AMD64 Fedora 39" 58 | - "check-failure=Build and test macOS 13" 59 | - "check-failure=Build and test windows" 60 | actions: 61 | label: 62 | remove: 63 | - ci-passed 64 | 65 | - name: Add ci-passed when no code changes 66 | conditions: 67 | - or: *BRANCHES 68 | - or: 69 | # all path not in source pattern 70 | # try keep same as in .github/workflows/main.yaml 71 | - and: 72 | - -files~=^(cmake|examples|doc/thirdparty)\/.*$ 73 | # only .md files changed 74 | - -files~=^.*(?>& headers) 20 | : headers_(headers) { 21 | } 22 | 23 | void 24 | HeaderAdderInterceptor::Intercept(grpc::experimental::InterceptorBatchMethods* methods) { 25 | if (methods->QueryInterceptionHookPoint(grpc::experimental::InterceptionHookPoints::PRE_SEND_INITIAL_METADATA)) { 26 | for (const auto& header : headers_) { 27 | methods->GetSendInitialMetadata()->insert({header.first, header.second}); 28 | } 29 | } 30 | methods->Proceed(); 31 | } 32 | 33 | HeaderAdderInterceptorFactory::HeaderAdderInterceptorFactory( 34 | const std::vector>& headers) 35 | : headers_(headers) { 36 | } 37 | 38 | grpc::experimental::Interceptor* 39 | HeaderAdderInterceptorFactory::CreateClientInterceptor(grpc::experimental::ClientRpcInfo* info) { 40 | return new HeaderAdderInterceptor(headers_); 41 | } 42 | 43 | std::shared_ptr 44 | CreateChannelWithHeaderInterceptor(const std::string& target, const std::shared_ptr& creds, 45 | const grpc::ChannelArguments& args, 46 | const std::vector>& headers) { 47 | std::vector> interceptor_creators; 48 | interceptor_creators.push_back(std::make_unique(headers)); 49 | 50 | return grpc::experimental::CreateCustomChannelWithInterceptors(target, creds, args, 51 | std::move(interceptor_creators)); 52 | } 53 | -------------------------------------------------------------------------------- /src/impl/MilvusInterceptor.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | class HeaderAdderInterceptor : public grpc::experimental::Interceptor { 26 | public: 27 | explicit HeaderAdderInterceptor(const std::vector>& headers); 28 | 29 | void 30 | Intercept(grpc::experimental::InterceptorBatchMethods* methods) override; 31 | 32 | private: 33 | std::vector> headers_; 34 | }; 35 | 36 | class HeaderAdderInterceptorFactory : public grpc::experimental::ClientInterceptorFactoryInterface { 37 | public: 38 | explicit HeaderAdderInterceptorFactory(const std::vector>& headers); 39 | 40 | grpc::experimental::Interceptor* 41 | CreateClientInterceptor(grpc::experimental::ClientRpcInfo* info) override; 42 | 43 | private: 44 | std::vector> headers_; 45 | }; 46 | 47 | std::shared_ptr 48 | CreateChannelWithHeaderInterceptor(const std::string& target, const std::shared_ptr& creds, 49 | const grpc::ChannelArguments& args, 50 | const std::vector>& headers); 51 | -------------------------------------------------------------------------------- /src/impl/Status.cpp: -------------------------------------------------------------------------------- 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/Status.h" 18 | 19 | namespace milvus { 20 | 21 | Status::Status(StatusCode code, std::string msg) : code_(code), msg_(std::move(msg)) { 22 | } 23 | 24 | Status::Status() = default; 25 | 26 | Status 27 | Status::OK() { 28 | return {}; 29 | } 30 | 31 | bool 32 | Status::IsOk() const { 33 | return code_ == StatusCode::OK; 34 | } 35 | 36 | StatusCode 37 | Status::Code() const { 38 | return code_; 39 | } 40 | 41 | const std::string& 42 | Status::Message() const { 43 | return msg_; 44 | } 45 | 46 | } // namespace milvus 47 | -------------------------------------------------------------------------------- /src/impl/types/AliasDesc.cpp: -------------------------------------------------------------------------------- 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/types/AliasDesc.h" 18 | 19 | namespace milvus { 20 | 21 | AliasDesc::AliasDesc() = default; 22 | 23 | AliasDesc::AliasDesc(const std::string& db_name, const std::string& alias, const std::string& collection_name) 24 | : db_name_(db_name), alias_(alias), collection_name_(collection_name) { 25 | } 26 | 27 | const std::string& 28 | AliasDesc::GetDbName() const { 29 | return db_name_; 30 | } 31 | 32 | const std::string& 33 | AliasDesc::GetAlias() const { 34 | return alias_; 35 | } 36 | 37 | const std::string& 38 | AliasDesc::GetCollectionName() const { 39 | return collection_name_; 40 | } 41 | 42 | void 43 | AliasDesc::SetDbName(const std::string& db_name) { 44 | db_name_ = db_name; 45 | } 46 | 47 | void 48 | AliasDesc::SetAlias(const std::string& alias) { 49 | alias_ = alias; 50 | } 51 | 52 | void 53 | AliasDesc::SetCollectionName(const std::string& collection_name) { 54 | collection_name_ = collection_name; 55 | } 56 | 57 | } // namespace milvus 58 | -------------------------------------------------------------------------------- /src/impl/types/CollectionDesc.cpp: -------------------------------------------------------------------------------- 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/types/CollectionDesc.h" 18 | 19 | namespace milvus { 20 | 21 | const CollectionSchema& 22 | CollectionDesc::Schema() const { 23 | return schema_; 24 | } 25 | 26 | void 27 | CollectionDesc::SetSchema(const CollectionSchema& schema) { 28 | schema_ = schema; 29 | } 30 | 31 | void 32 | CollectionDesc::SetSchema(CollectionSchema&& schema) { 33 | schema_ = std::move(schema); 34 | } 35 | 36 | int64_t 37 | CollectionDesc::ID() const { 38 | return collection_id_; 39 | } 40 | 41 | void 42 | CollectionDesc::SetID(int64_t id) { 43 | collection_id_ = id; 44 | } 45 | 46 | const std::vector& 47 | CollectionDesc::Alias() const { 48 | return alias_; 49 | } 50 | 51 | void 52 | CollectionDesc::SetAlias(const std::vector& alias) { 53 | alias_ = alias; 54 | } 55 | 56 | void 57 | CollectionDesc::SetAlias(std::vector&& alias) { 58 | alias_ = std::move(alias); 59 | } 60 | 61 | uint64_t 62 | CollectionDesc::CreatedTime() const { 63 | return created_utc_timestamp_; 64 | } 65 | 66 | void 67 | CollectionDesc::SetCreatedTime(uint64_t ts) { 68 | created_utc_timestamp_ = ts; 69 | } 70 | 71 | } // namespace milvus 72 | -------------------------------------------------------------------------------- /src/impl/types/CollectionInfo.cpp: -------------------------------------------------------------------------------- 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/types/CollectionInfo.h" 18 | 19 | namespace milvus { 20 | 21 | CollectionInfo::CollectionInfo() = default; 22 | 23 | CollectionInfo::CollectionInfo(std::string collection_name, int64_t collection_id, uint64_t create_time, 24 | uint64_t load_percentage) 25 | : name_(std::move(collection_name)), 26 | collection_id_(collection_id), 27 | created_utc_timestamp_(create_time), 28 | in_memory_percentage_(load_percentage) { 29 | } 30 | 31 | const std::string& 32 | CollectionInfo::Name() const { 33 | return name_; 34 | } 35 | 36 | int64_t 37 | CollectionInfo::ID() const { 38 | return collection_id_; 39 | } 40 | 41 | uint64_t 42 | CollectionInfo::CreatedTime() const { 43 | return created_utc_timestamp_; 44 | } 45 | 46 | uint64_t 47 | CollectionInfo::MemoryPercentage() const { 48 | return in_memory_percentage_; 49 | } 50 | 51 | } // namespace milvus 52 | -------------------------------------------------------------------------------- /src/impl/types/CollectionStat.cpp: -------------------------------------------------------------------------------- 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/types/CollectionStat.h" 18 | 19 | #include "milvus/types/Constant.h" 20 | 21 | namespace milvus { 22 | 23 | CollectionStat::CollectionStat() = default; 24 | 25 | uint64_t 26 | CollectionStat::RowCount() const { 27 | const auto iter = statistics_.find(KeyRowCount()); 28 | if (iter == statistics_.end()) { 29 | // TODO: throw exception or log 30 | return 0; 31 | } 32 | return std::strtoll(iter->second.c_str(), nullptr, 10); 33 | } 34 | 35 | void 36 | CollectionStat::SetName(std::string name) { 37 | name_ = std::move(name); 38 | } 39 | 40 | const std::string& 41 | CollectionStat::Name() const { 42 | return name_; 43 | } 44 | 45 | void 46 | CollectionStat::Emplace(std::string key, std::string value) { 47 | statistics_.emplace(std::move(key), std::move(value)); 48 | } 49 | 50 | } // namespace milvus 51 | -------------------------------------------------------------------------------- /src/impl/types/CompactionPlan.cpp: -------------------------------------------------------------------------------- 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/types/CompactionPlan.h" 18 | 19 | namespace milvus { 20 | 21 | CompactionPlan::CompactionPlan() = default; 22 | 23 | CompactionPlan::CompactionPlan(const std::vector& segments, int64_t dst_segment) 24 | : src_segments_(segments), dst_segment_(dst_segment) { 25 | } 26 | 27 | CompactionPlan::CompactionPlan(std::vector&& segments, int64_t dst_segment) 28 | : src_segments_(std::move(segments)), dst_segment_(dst_segment) { 29 | } 30 | 31 | const std::vector& 32 | CompactionPlan::SourceSegments() const { 33 | return src_segments_; 34 | } 35 | 36 | void 37 | CompactionPlan::SetSourceSegments(const std::vector& segments) { 38 | src_segments_ = segments; 39 | } 40 | 41 | void 42 | CompactionPlan::SetSourceSegments(std::vector&& segments) { 43 | src_segments_ = std::move(segments); 44 | } 45 | 46 | int64_t 47 | CompactionPlan::DestinySegemnt() const { 48 | return dst_segment_; 49 | } 50 | 51 | void 52 | CompactionPlan::SetDestinySegemnt(int64_t id) { 53 | dst_segment_ = id; 54 | } 55 | 56 | } // namespace milvus 57 | -------------------------------------------------------------------------------- /src/impl/types/CompactionState.cpp: -------------------------------------------------------------------------------- 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/types/CompactionState.h" 18 | 19 | namespace milvus { 20 | 21 | CompactionState::CompactionState() = default; 22 | 23 | CompactionStateCode 24 | CompactionState::State() const { 25 | return state_code_; 26 | } 27 | 28 | void 29 | CompactionState::SetState(CompactionStateCode state) { 30 | state_code_ = state; 31 | } 32 | 33 | int64_t 34 | CompactionState::ExecutingPlan() const { 35 | return executing_plan_; 36 | } 37 | 38 | void 39 | CompactionState::SetExecutingPlan(int64_t id) { 40 | executing_plan_ = id; 41 | } 42 | 43 | int64_t 44 | CompactionState::TimeoutPlan() const { 45 | return timeout_plan_; 46 | } 47 | 48 | void 49 | CompactionState::SetTimeoutPlan(int64_t id) { 50 | timeout_plan_ = id; 51 | } 52 | 53 | int64_t 54 | CompactionState::CompletedPlan() const { 55 | return completed_plan_; 56 | } 57 | 58 | void 59 | CompactionState::SetCompletedPlan(int64_t id) { 60 | completed_plan_ = id; 61 | } 62 | 63 | } // namespace milvus 64 | -------------------------------------------------------------------------------- /src/impl/types/DatabaseDesc.cpp: -------------------------------------------------------------------------------- 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/types/DatabaseDesc.h" 18 | 19 | namespace milvus { 20 | 21 | DatabaseDesc::DatabaseDesc() = default; 22 | 23 | DatabaseDesc::DatabaseDesc(const std::string& db_name, int64_t db_id, uint64_t created_timestamp, 24 | const std::vector>& properties) 25 | : db_name_(db_name), db_id_(db_id), created_timestamp_(created_timestamp), properties_(properties) { 26 | } 27 | 28 | const std::string& 29 | DatabaseDesc::GetDbName() const { 30 | return db_name_; 31 | } 32 | 33 | int64_t 34 | DatabaseDesc::GetDbID() const { 35 | return db_id_; 36 | } 37 | 38 | uint64_t 39 | DatabaseDesc::GetCreatedTimestamp() const { 40 | return created_timestamp_; 41 | } 42 | 43 | const std::vector>& 44 | DatabaseDesc::GetProperties() const { 45 | return properties_; 46 | } 47 | 48 | void 49 | DatabaseDesc::SetDbName(const std::string& db_name) { 50 | db_name_ = db_name; 51 | } 52 | 53 | void 54 | DatabaseDesc::SetDbID(int64_t db_id) { 55 | db_id_ = db_id; 56 | } 57 | 58 | void 59 | DatabaseDesc::SetCreatedTimestamp(uint64_t created_timestamp) { 60 | created_timestamp_ = created_timestamp; 61 | } 62 | 63 | void 64 | DatabaseDesc::SetProperties(const std::vector>& properties) { 65 | properties_ = properties; 66 | } 67 | 68 | void 69 | DatabaseDesc::AddProperty(const std::string& key, const std::string& value) { 70 | properties_.emplace_back(key, value); 71 | } 72 | 73 | } // namespace milvus 74 | -------------------------------------------------------------------------------- /src/impl/types/DmlResults.cpp: -------------------------------------------------------------------------------- 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/types/DmlResults.h" 18 | 19 | namespace milvus { 20 | 21 | const IDArray& 22 | DmlResults::IdArray() const { 23 | return id_array_; 24 | } 25 | 26 | void 27 | DmlResults::SetIdArray(const IDArray& id_array) { 28 | id_array_ = id_array; 29 | } 30 | 31 | void 32 | DmlResults::SetIdArray(IDArray&& id_array) { 33 | id_array_ = std::move(id_array); 34 | } 35 | 36 | uint64_t 37 | DmlResults::Timestamp() const { 38 | return timestamp_; 39 | } 40 | 41 | void 42 | DmlResults::SetTimestamp(uint64_t timestamp) { 43 | timestamp_ = timestamp; 44 | } 45 | 46 | } // namespace milvus 47 | -------------------------------------------------------------------------------- /src/impl/types/GetArguments.cpp: -------------------------------------------------------------------------------- 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/types/GetArguments.h" 18 | 19 | namespace milvus { 20 | 21 | const std::string& 22 | GetArguments::CollectionName() const { 23 | return collection_name_; 24 | } 25 | 26 | Status 27 | GetArguments::SetCollectionName(std::string collection_name) { 28 | if (collection_name.empty()) { 29 | return {StatusCode::INVALID_AGUMENT, "Collection name cannot be empty!"}; 30 | } 31 | collection_name_ = std::move(collection_name); 32 | return Status::OK(); 33 | } 34 | 35 | const std::set& 36 | GetArguments::PartitionNames() const { 37 | return partition_names_; 38 | } 39 | 40 | Status 41 | GetArguments::AddPartitionName(std::string partition_name) { 42 | if (partition_name.empty()) { 43 | return {StatusCode::INVALID_AGUMENT, "Partition name cannot be empty!"}; 44 | } 45 | 46 | partition_names_.emplace(std::move(partition_name)); 47 | return Status::OK(); 48 | } 49 | 50 | const std::set& 51 | GetArguments::OutputFields() const { 52 | return output_field_names_; 53 | } 54 | 55 | Status 56 | GetArguments::AddOutputField(std::string field_name) { 57 | if (field_name.empty()) { 58 | return {StatusCode::INVALID_AGUMENT, "Field name cannot be empty!"}; 59 | } 60 | 61 | output_field_names_.emplace(std::move(field_name)); 62 | return Status::OK(); 63 | } 64 | 65 | const std::vector& 66 | GetArguments::Ids() const { 67 | return ids_; 68 | } 69 | 70 | Status 71 | GetArguments::SetIds(std::vector ids) { 72 | if (ids.empty()) { 73 | return {StatusCode::INVALID_AGUMENT, "Ids cannot be empty!"}; 74 | } 75 | ids_ = std::move(ids); 76 | return Status::OK(); 77 | } 78 | 79 | } // namespace milvus 80 | -------------------------------------------------------------------------------- /src/impl/types/HybridTimestamp.cpp: -------------------------------------------------------------------------------- 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/types/HybridTimestamp.h" 18 | 19 | namespace milvus { 20 | 21 | HybridTimestamp::HybridTimestamp() = default; 22 | 23 | HybridTimestamp::HybridTimestamp(uint64_t ts) : ts_(ts) { 24 | } 25 | 26 | HybridTimestamp::HybridTimestamp(uint64_t physical, uint64_t logical) 27 | : ts_((physical << milvus::HybridTsLogicalBits()) + logical) { 28 | } 29 | 30 | uint64_t 31 | HybridTimestamp::Timestamp() const { 32 | return ts_; 33 | } 34 | 35 | uint64_t 36 | HybridTimestamp::Logical() const { 37 | return ts_ & milvus::HybridTsLogicalBitsMask(); 38 | } 39 | 40 | uint64_t 41 | HybridTimestamp::Physical() const { 42 | return ts_ >> milvus::HybridTsLogicalBits(); 43 | } 44 | 45 | HybridTimestamp& 46 | HybridTimestamp::operator+=(uint64_t milliseconds) { 47 | ts_ += (milliseconds << milvus::HybridTsLogicalBits()); 48 | return *this; 49 | } 50 | 51 | HybridTimestamp 52 | HybridTimestamp::operator+(uint64_t milliseconds) const { 53 | return {Physical() + milliseconds, Logical()}; 54 | } 55 | 56 | HybridTimestamp 57 | HybridTimestamp::CreateFromUnixTime(uint64_t epoch_in_milliseconds) { 58 | return {epoch_in_milliseconds, 0}; 59 | } 60 | } // namespace milvus 61 | -------------------------------------------------------------------------------- /src/impl/types/IDArray.cpp: -------------------------------------------------------------------------------- 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/types/IDArray.h" 18 | 19 | namespace milvus { 20 | 21 | IDArray::IDArray(const std::vector& id_array) : int_id_array_(id_array) { 22 | } 23 | 24 | IDArray::IDArray(std::vector&& id_array) : int_id_array_(std::move(id_array)) { 25 | } 26 | 27 | IDArray::IDArray(const std::vector& id_array) : str_id_array_(id_array), is_int_array_{false} { 28 | } 29 | 30 | IDArray::IDArray(std::vector&& id_array) : str_id_array_(std::move(id_array)), is_int_array_{false} { 31 | } 32 | 33 | bool 34 | IDArray::IsIntegerID() const { 35 | return is_int_array_; 36 | } 37 | 38 | const std::vector& 39 | IDArray::IntIDArray() const { 40 | return int_id_array_; 41 | } 42 | 43 | const std::vector& 44 | IDArray::StrIDArray() const { 45 | return str_id_array_; 46 | } 47 | 48 | } // namespace milvus 49 | -------------------------------------------------------------------------------- /src/impl/types/IndexState.cpp: -------------------------------------------------------------------------------- 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/types/IndexState.h" 18 | 19 | namespace milvus { 20 | 21 | IndexStateCode 22 | IndexState::StateCode() const { 23 | return state_code_; 24 | } 25 | 26 | void 27 | IndexState::SetStateCode(IndexStateCode state_code) { 28 | state_code_ = state_code; 29 | } 30 | 31 | std::string 32 | IndexState::FailedReason() const { 33 | return failed_reason_; 34 | } 35 | void 36 | IndexState::SetFailedReason(std::string failed_reason) { 37 | failed_reason_ = std::move(failed_reason); 38 | } 39 | 40 | int64_t 41 | IndexProgress::IndexedRows() const { 42 | return indexed_rows_; 43 | } 44 | 45 | void 46 | IndexProgress::SetIndexedRows(int64_t indexed_rows) { 47 | indexed_rows_ = indexed_rows; 48 | } 49 | 50 | int64_t 51 | IndexProgress::TotalRows() const { 52 | return total_rows_; 53 | } 54 | 55 | void 56 | IndexProgress::SetTotalRows(int64_t total_rows) { 57 | total_rows_ = total_rows; 58 | } 59 | 60 | } // namespace milvus 61 | -------------------------------------------------------------------------------- /src/impl/types/ListAliasesResult.cpp: -------------------------------------------------------------------------------- 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/types/ListAliasesResult.h" 18 | 19 | namespace milvus { 20 | 21 | ListAliasesResult::ListAliasesResult() = default; 22 | 23 | ListAliasesResult::ListAliasesResult(const std::string& db_name, const std::string& collection_name, 24 | const std::vector& aliases) 25 | : db_name_(db_name), collection_name_(collection_name), aliases_(aliases) { 26 | } 27 | 28 | const std::string& 29 | ListAliasesResult::GetDbName() const { 30 | return db_name_; 31 | } 32 | 33 | const std::string& 34 | ListAliasesResult::GetCollectionName() const { 35 | return collection_name_; 36 | } 37 | 38 | const std::vector& 39 | ListAliasesResult::GetAliases() const { 40 | return aliases_; 41 | } 42 | 43 | void 44 | ListAliasesResult::SetDbName(const std::string& db_name) { 45 | db_name_ = db_name; 46 | } 47 | 48 | void 49 | ListAliasesResult::SetCollectionName(const std::string& collection_name) { 50 | collection_name_ = collection_name; 51 | } 52 | 53 | void 54 | ListAliasesResult::SetAliases(const std::vector& aliases) { 55 | aliases_ = aliases; 56 | } 57 | 58 | } // namespace milvus 59 | -------------------------------------------------------------------------------- /src/impl/types/LoadState.cpp: -------------------------------------------------------------------------------- 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/types/LoadState.h" 18 | 19 | namespace milvus { 20 | 21 | LoadState::LoadState() : code_(LoadStateCode::NOT_EXIST) { 22 | updateStateDesc(); 23 | } 24 | 25 | LoadState::LoadState(LoadStateCode code) : code_(code) { 26 | updateStateDesc(); 27 | } 28 | 29 | LoadStateCode 30 | LoadState::GetCode() const { 31 | return code_; 32 | } 33 | 34 | const std::string& 35 | LoadState::GetDesc() const { 36 | return state_desc_; 37 | } 38 | 39 | void 40 | LoadState::SetCode(LoadStateCode code) { 41 | code_ = code; 42 | updateStateDesc(); 43 | } 44 | 45 | void 46 | LoadState::updateStateDesc() { 47 | switch (code_) { 48 | case LoadStateCode::NOT_EXIST: 49 | state_desc_ = "NotExist"; 50 | break; 51 | case LoadStateCode::NOT_LOAD: 52 | state_desc_ = "NotLoad"; 53 | break; 54 | case LoadStateCode::LOADING: 55 | state_desc_ = "Loading"; 56 | break; 57 | case LoadStateCode::LOADED: 58 | state_desc_ = "Loaded"; 59 | break; 60 | default: 61 | state_desc_ = "Unknown"; 62 | } 63 | } 64 | 65 | } // namespace milvus 66 | -------------------------------------------------------------------------------- /src/impl/types/NodeInfo.cpp: -------------------------------------------------------------------------------- 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/types/NodeInfo.h" 18 | 19 | NodeInfo::NodeInfo(int64_t id, const std::string& addr, const std::string& host) 20 | : node_id_(id), address_(addr), hostname_(host) { 21 | } 22 | 23 | int64_t 24 | NodeInfo::GetNodeId() const { 25 | return node_id_; 26 | } 27 | 28 | const std::string& 29 | NodeInfo::GetAddress() const { 30 | return address_; 31 | } 32 | 33 | const std::string& 34 | NodeInfo::GetHostname() const { 35 | return hostname_; 36 | } 37 | -------------------------------------------------------------------------------- /src/impl/types/PartitionInfo.cpp: -------------------------------------------------------------------------------- 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/types/PartitionInfo.h" 18 | 19 | namespace milvus { 20 | PartitionInfo::PartitionInfo(std::string name, int64_t id, uint64_t created_utc_timestamp, int64_t in_memory_percentage) 21 | : name_(std::move(name)), 22 | id_(id), 23 | created_utc_timestamp_(created_utc_timestamp), 24 | in_memory_percentage_(in_memory_percentage) { 25 | } 26 | 27 | std::string 28 | PartitionInfo::Name() const { 29 | return name_; 30 | } 31 | 32 | int64_t 33 | PartitionInfo::Id() const { 34 | return id_; 35 | } 36 | 37 | uint64_t 38 | PartitionInfo::CreatedUtcTimestamp() const { 39 | return created_utc_timestamp_; 40 | } 41 | 42 | int64_t 43 | PartitionInfo::InMemoryPercentage() const { 44 | return in_memory_percentage_; 45 | } 46 | 47 | bool 48 | PartitionInfo::Loaded() const { 49 | return in_memory_percentage_ >= 100; 50 | } 51 | 52 | bool 53 | operator==(const PartitionInfo& a, const PartitionInfo& b) { 54 | return a.Name() == b.Name() && a.Id() && b.Id() && a.CreatedUtcTimestamp() == b.CreatedUtcTimestamp() && 55 | a.InMemoryPercentage() == b.InMemoryPercentage(); 56 | } 57 | 58 | } // namespace milvus 59 | -------------------------------------------------------------------------------- /src/impl/types/PartitionStat.cpp: -------------------------------------------------------------------------------- 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/types/PartitionStat.h" 18 | 19 | namespace milvus { 20 | uint64_t 21 | PartitionStat::RowCount() const { 22 | const auto iter = statistics_.find(KeyRowCount()); 23 | if (iter == statistics_.end()) { 24 | // TODO: throw exception or log 25 | return 0; 26 | } 27 | return std::strtoll(iter->second.c_str(), nullptr, 10); 28 | } 29 | 30 | void 31 | PartitionStat::SetName(std::string name) { 32 | name_ = std::move(name); 33 | } 34 | 35 | const std::string& 36 | PartitionStat::Name() const { 37 | return name_; 38 | } 39 | 40 | void 41 | PartitionStat::Emplace(std::string key, std::string value) { 42 | statistics_.emplace(std::move(key), std::move(value)); 43 | } 44 | 45 | } // namespace milvus 46 | -------------------------------------------------------------------------------- /src/impl/types/PrivilegeGroupInfo.cpp: -------------------------------------------------------------------------------- 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/types/PrivilegeGroupInfo.h" 18 | 19 | namespace milvus { 20 | 21 | PrivilegeGroupInfo::PrivilegeGroupInfo(const std::string& group_name) : group_name_(group_name) { 22 | } 23 | 24 | void 25 | PrivilegeGroupInfo::AddPrivilege(const std::string& privilege) { 26 | privileges_.push_back(privilege); 27 | } 28 | 29 | const std::string& 30 | PrivilegeGroupInfo::GroupName() const { 31 | return group_name_; 32 | } 33 | 34 | void 35 | PrivilegeGroupInfo::SetGroupName(const std::string& group_name) { 36 | this->group_name_ = group_name; 37 | } 38 | 39 | const std::vector& 40 | PrivilegeGroupInfo::Privileges() const { 41 | return privileges_; 42 | } 43 | 44 | void 45 | PrivilegeGroupInfo::SetPrivileges(const std::vector& privileges) { 46 | this->privileges_ = privileges; 47 | } 48 | 49 | } // namespace milvus 50 | -------------------------------------------------------------------------------- /src/impl/types/ProgressMonitor.cpp: -------------------------------------------------------------------------------- 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/types/ProgressMonitor.h" 18 | 19 | namespace milvus { 20 | 21 | Progress::Progress() = default; 22 | 23 | Progress::Progress(uint32_t finished, uint32_t total) : finished_(finished), total_(total) { 24 | } 25 | 26 | bool 27 | Progress::Done() const { 28 | return finished_ >= total_; 29 | } 30 | 31 | bool 32 | operator==(const Progress& a, const Progress& b) { 33 | return a.finished_ == b.finished_ && a.total_ == b.total_; 34 | } 35 | 36 | ProgressMonitor::ProgressMonitor(uint32_t check_timeout) : check_timeout_(check_timeout) { 37 | } 38 | 39 | ProgressMonitor::ProgressMonitor() = default; 40 | 41 | uint32_t 42 | ProgressMonitor::CheckTimeout() const { 43 | return check_timeout_; 44 | } 45 | 46 | uint32_t 47 | ProgressMonitor::CheckInterval() const { 48 | return check_interval_; 49 | } 50 | 51 | void 52 | ProgressMonitor::SetCheckInterval(uint32_t check_interval) { 53 | check_interval_ = check_interval; 54 | } 55 | 56 | void 57 | ProgressMonitor::DoProgress(Progress& p) const { 58 | if (callback_func_ != nullptr) { 59 | callback_func_(p); 60 | } 61 | } 62 | 63 | void 64 | ProgressMonitor::SetCallbackFunc(CallbackFunc func) { 65 | callback_func_ = std::move(func); 66 | } 67 | 68 | ProgressMonitor 69 | ProgressMonitor::NoWait() { 70 | return ProgressMonitor{0}; 71 | } 72 | 73 | ProgressMonitor 74 | ProgressMonitor::Forever() { 75 | return ProgressMonitor{std::numeric_limits::max()}; 76 | } 77 | 78 | } // namespace milvus 79 | -------------------------------------------------------------------------------- /src/impl/types/QueryResults.cpp: -------------------------------------------------------------------------------- 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/types/QueryResults.h" 18 | 19 | namespace milvus { 20 | 21 | QueryResults::QueryResults() = default; 22 | 23 | QueryResults::QueryResults(const std::vector& output_fields) { 24 | output_fields_ = output_fields; 25 | } 26 | 27 | QueryResults::QueryResults(std::vector&& output_fields) { 28 | output_fields_ = std::move(output_fields); 29 | } 30 | 31 | FieldDataPtr 32 | QueryResults::GetFieldByName(const std::string& name) { 33 | for (FieldDataPtr& field : output_fields_) { 34 | if (nullptr == field) { 35 | continue; 36 | } 37 | 38 | if (field->Name() == name) { 39 | return field; 40 | } 41 | } 42 | 43 | return nullptr; 44 | } 45 | 46 | const std::vector& 47 | QueryResults::OutputFields() const { 48 | return output_fields_; 49 | } 50 | 51 | } // namespace milvus 52 | -------------------------------------------------------------------------------- /src/impl/types/Ranker.cpp: -------------------------------------------------------------------------------- 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/types/Ranker.h" 18 | 19 | namespace milvus { 20 | 21 | nlohmann::json 22 | BaseRanker::Dict() const { 23 | nlohmann::json json; 24 | json["strategy"] = GetStrategy(); 25 | json["params"] = GetParams(); 26 | return json; 27 | } 28 | 29 | RRFRanker::RRFRanker(float k) : k_(k) { 30 | } 31 | 32 | std::map 33 | RRFRanker::GetParams() const { 34 | return {{"k", std::to_string(k_)}}; 35 | } 36 | 37 | std::string 38 | RRFRanker::GetStrategy() const { 39 | return "rrf"; 40 | } 41 | 42 | WeightedRanker::WeightedRanker(std::vector weights) : weights_(weights) { 43 | } 44 | 45 | std::map 46 | WeightedRanker::GetParams() const { 47 | std::string weights_str = "["; 48 | for (size_t i = 0; i < weights_.size(); ++i) { 49 | weights_str += std::to_string(weights_[i]); 50 | if (i < weights_.size() - 1) { 51 | weights_str += ", "; 52 | } 53 | } 54 | weights_str += "]"; 55 | 56 | return {{"weights", weights_str}}; 57 | } 58 | 59 | std::string 60 | WeightedRanker::GetStrategy() const { 61 | return "weighted"; 62 | } 63 | 64 | } // namespace milvus 65 | -------------------------------------------------------------------------------- /src/impl/types/ResourceGroupConfig.cpp: -------------------------------------------------------------------------------- 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/types/ResourceGroupConfig.h" 18 | 19 | namespace milvus { 20 | 21 | ResourceGroupConfig::ResourceGroupConfig(int req_node_num, int lim_node_num, const std::vector& from, 22 | const std::vector& to, 23 | const std::vector>& labels) 24 | : requests_node_num_(req_node_num), 25 | limits_node_num_(lim_node_num), 26 | transfer_from_(from), 27 | transfer_to_(to), 28 | node_labels_(labels) { 29 | } 30 | 31 | int 32 | ResourceGroupConfig::GetRequestsNodeNum() const { 33 | return requests_node_num_; 34 | } 35 | 36 | void 37 | ResourceGroupConfig::SetRequestsNodeNum(int num) { 38 | requests_node_num_ = num; 39 | } 40 | 41 | int 42 | ResourceGroupConfig::GetLimitsNodeNum() const { 43 | return limits_node_num_; 44 | } 45 | 46 | void 47 | ResourceGroupConfig::SetLimitsNodeNum(int num) { 48 | limits_node_num_ = num; 49 | } 50 | 51 | const std::vector& 52 | ResourceGroupConfig::GetTransferFrom() const { 53 | return transfer_from_; 54 | } 55 | 56 | void 57 | ResourceGroupConfig::SetTransferFrom(const std::vector& from) { 58 | transfer_from_ = from; 59 | } 60 | 61 | const std::vector& 62 | ResourceGroupConfig::GetTransferTo() const { 63 | return transfer_to_; 64 | } 65 | 66 | void 67 | ResourceGroupConfig::SetTransferTo(const std::vector& to) { 68 | transfer_to_ = to; 69 | } 70 | 71 | const std::vector>& 72 | ResourceGroupConfig::GetNodeLabels() const { 73 | return node_labels_; 74 | } 75 | 76 | void 77 | ResourceGroupConfig::SetNodeLabels(const std::vector>& labels) { 78 | node_labels_ = labels; 79 | } 80 | 81 | } // namespace milvus 82 | -------------------------------------------------------------------------------- /src/impl/types/ResourceGroupDesc.cpp: -------------------------------------------------------------------------------- 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/types/ResourceGroupDesc.h" 18 | 19 | namespace milvus { 20 | 21 | ResourceGroupDesc::ResourceGroupDesc(const std::string& name, int32_t capacity, int32_t available_nodes, 22 | const std::map& loaded_replicas, 23 | const std::map& outgoing_nodes, 24 | const std::map& incoming_nodes, 25 | const ResourceGroupConfig& config, const std::vector& nodes) 26 | : name_(name), 27 | capacity_(capacity), 28 | num_available_node_(available_nodes), 29 | num_loaded_replica_(loaded_replicas), 30 | num_outgoing_node_(outgoing_nodes), 31 | num_incoming_node_(incoming_nodes), 32 | config_(config), 33 | nodes_(nodes) { 34 | } 35 | 36 | const std::string& 37 | ResourceGroupDesc::GetName() const { 38 | return name_; 39 | } 40 | 41 | int32_t 42 | ResourceGroupDesc::GetCapacity() const { 43 | return capacity_; 44 | } 45 | 46 | int32_t 47 | ResourceGroupDesc::GetNumAvailableNode() const { 48 | return num_available_node_; 49 | } 50 | 51 | const std::map& 52 | ResourceGroupDesc::GetNumLoadedReplica() const { 53 | return num_loaded_replica_; 54 | } 55 | 56 | const std::map& 57 | ResourceGroupDesc::GetNumOutgoingNode() const { 58 | return num_outgoing_node_; 59 | } 60 | 61 | const std::map& 62 | ResourceGroupDesc::GetNumIncomingNode() const { 63 | return num_incoming_node_; 64 | } 65 | 66 | const ResourceGroupConfig& 67 | ResourceGroupDesc::GetConfig() const { 68 | return config_; 69 | } 70 | 71 | const std::vector& 72 | ResourceGroupDesc::GetNodes() const { 73 | return nodes_; 74 | } 75 | 76 | } // namespace milvus 77 | -------------------------------------------------------------------------------- /src/impl/types/RoleDesc.cpp: -------------------------------------------------------------------------------- 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/types/RoleDesc.h" 18 | 19 | namespace milvus { 20 | 21 | RoleDesc::RoleDesc() { 22 | } 23 | 24 | RoleDesc::RoleDesc(const std::string& role, const std::vector& privileges) 25 | : role_(role), privileges_(privileges) { 26 | } 27 | 28 | const std::string& 29 | RoleDesc::GetRole() const { 30 | return role_; 31 | } 32 | 33 | const std::vector& 34 | RoleDesc::GetPrivileges() const { 35 | return privileges_; 36 | } 37 | 38 | } // namespace milvus 39 | -------------------------------------------------------------------------------- /src/impl/types/SearchResults.cpp: -------------------------------------------------------------------------------- 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/types/SearchResults.h" 18 | 19 | namespace milvus { 20 | 21 | SingleResult::SingleResult(IDArray&& ids, std::vector&& scores, std::vector&& output_fields) 22 | : ids_{std::move(ids)}, scores_{std::move(scores)}, output_fields_{std::move(output_fields)} { 23 | } 24 | 25 | const std::vector& 26 | SingleResult::Scores() const { 27 | return scores_; 28 | } 29 | 30 | const IDArray& 31 | SingleResult::Ids() const { 32 | return ids_; 33 | } 34 | 35 | const std::vector& 36 | SingleResult::OutputFields() const { 37 | return output_fields_; 38 | } 39 | 40 | FieldDataPtr 41 | SingleResult::OutputField(const std::string& name) const { 42 | for (const auto& output_field : output_fields_) { 43 | if (output_field->Name() == name) { 44 | return output_field; 45 | } 46 | } 47 | return nullptr; 48 | } 49 | 50 | SearchResults::SearchResults() = default; 51 | 52 | SearchResults::SearchResults(std::vector&& results) { 53 | nq_results_.swap(results); 54 | } 55 | 56 | std::vector& 57 | SearchResults::Results() { 58 | return nq_results_; 59 | } 60 | 61 | } // namespace milvus 62 | -------------------------------------------------------------------------------- /src/impl/types/SegmentInfo.cpp: -------------------------------------------------------------------------------- 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/types/SegmentInfo.h" 18 | 19 | namespace milvus { 20 | 21 | SegmentInfo::SegmentInfo(int64_t collection_id, int64_t partition_id, int64_t segment_id, int64_t row_count, 22 | SegmentState state) 23 | : collection_id_{collection_id}, 24 | partition_id_{partition_id}, 25 | segment_id_{segment_id}, 26 | row_count_{row_count}, 27 | state_(state) { 28 | } 29 | 30 | int64_t 31 | SegmentInfo::CollectionID() const { 32 | return collection_id_; 33 | } 34 | 35 | int64_t 36 | SegmentInfo::PartitionID() const { 37 | return partition_id_; 38 | } 39 | 40 | int64_t 41 | SegmentInfo::SegmentID() const { 42 | return segment_id_; 43 | } 44 | 45 | int64_t 46 | SegmentInfo::RowCount() const { 47 | return row_count_; 48 | } 49 | 50 | SegmentState 51 | SegmentInfo::State() const { 52 | return state_; 53 | } 54 | 55 | QuerySegmentInfo::QuerySegmentInfo(int64_t collection_id, int64_t partition_id, int64_t segment_id, int64_t row_count, 56 | SegmentState state, std::string index_name, int64_t index_id, int64_t node_id) 57 | : SegmentInfo(collection_id, partition_id, segment_id, row_count, state), 58 | index_name_{std::move(index_name)}, 59 | index_id_{index_id}, 60 | node_id_{node_id} { 61 | } 62 | 63 | std::string 64 | QuerySegmentInfo::IndexName() const { 65 | return index_name_; 66 | } 67 | 68 | int64_t 69 | QuerySegmentInfo::IndexID() const { 70 | return index_id_; 71 | } 72 | 73 | int64_t 74 | QuerySegmentInfo::NodeID() const { 75 | return node_id_; 76 | } 77 | 78 | } // namespace milvus 79 | -------------------------------------------------------------------------------- /src/impl/types/UserResult.cpp: -------------------------------------------------------------------------------- 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/types/UserResult.h" 18 | 19 | namespace milvus { 20 | 21 | UserResult::UserResult() = default; 22 | 23 | void 24 | UserResult::SetUserName(const std::string& user_name) { 25 | user_name_ = user_name; 26 | } 27 | 28 | const std::string& 29 | UserResult::UserName() const { 30 | return user_name_; 31 | } 32 | 33 | void 34 | UserResult::AddRole(const std::string& role) { 35 | roles_.emplace_back(role); 36 | } 37 | 38 | const std::vector& 39 | UserResult::Roles() const { 40 | return roles_; 41 | } 42 | 43 | } // namespace milvus 44 | -------------------------------------------------------------------------------- /src/include/milvus/BulkImport.h: -------------------------------------------------------------------------------- 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 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | namespace milvus { 26 | 27 | class BulkImport { 28 | public: 29 | static nlohmann::json 30 | CreateImportJobs(const std::string& url, const std::string& collection_name, const std::vector& files, 31 | const std::string& db_name = "default", const std::string& api_key = "", 32 | const std::string& partition_name = "", const nlohmann::json& options = nlohmann::json{}); 33 | 34 | static nlohmann::json 35 | ListImportJobs(const std::string& url, const std::string& collection_name, const std::string& db_name = "default", 36 | const std::string& api_key = ""); 37 | 38 | static nlohmann::json 39 | GetImportJobProgress(const std::string& url, const std::string& job_id, const std::string& db_name = "default", 40 | const std::string& api_key = ""); 41 | }; 42 | 43 | } // namespace milvus 44 | -------------------------------------------------------------------------------- /src/include/milvus/Status.h: -------------------------------------------------------------------------------- 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 20 | 21 | /** 22 | * @brief Milvus SDK namespace 23 | */ 24 | namespace milvus { 25 | 26 | /** 27 | * @brief Status code for SDK interface return 28 | */ 29 | enum class StatusCode { 30 | OK = 0, 31 | 32 | // system error section 33 | UNKNOWN_ERROR = 1, 34 | NOT_SUPPORTED, 35 | NOT_CONNECTED, 36 | 37 | // function error section 38 | INVALID_AGUMENT = 1000, 39 | RPC_FAILED, 40 | SERVER_FAILED, 41 | TIMEOUT, 42 | 43 | // validation error 44 | DIMENSION_NOT_EQUAL = 2000, 45 | VECTOR_IS_EMPTY, 46 | JSON_PARSE_ERROR, 47 | }; 48 | 49 | /** 50 | * @brief Status code and message returned by SDK interface. 51 | */ 52 | class Status { 53 | public: 54 | /** 55 | * @brief Constructor of Status 56 | */ 57 | Status(StatusCode code, std::string msg); 58 | Status(); 59 | 60 | /** 61 | * @brief A success status 62 | */ 63 | static Status 64 | OK(); 65 | 66 | /** 67 | * @brief Indicate the status is ok 68 | */ 69 | bool 70 | IsOk() const; 71 | 72 | /** 73 | * @brief Return the status code 74 | */ 75 | StatusCode 76 | Code() const; 77 | 78 | /** 79 | * @brief Return the error message 80 | */ 81 | const std::string& 82 | Message() const; 83 | 84 | private: 85 | StatusCode code_{StatusCode::OK}; 86 | std::string msg_{"OK"}; 87 | }; // Status 88 | 89 | } // namespace milvus 90 | -------------------------------------------------------------------------------- /src/include/milvus/param/BaseParam.h: -------------------------------------------------------------------------------- 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 "../Status.h" 20 | 21 | namespace milvus { 22 | 23 | class BaseParam { 24 | public: 25 | virtual Status 26 | Verify() = 0; 27 | }; 28 | 29 | } // namespace milvus 30 | -------------------------------------------------------------------------------- /src/include/milvus/types/AliasDesc.h: -------------------------------------------------------------------------------- 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 20 | 21 | namespace milvus { 22 | 23 | class AliasDesc { 24 | public: 25 | AliasDesc(); 26 | AliasDesc(const std::string& db_name, const std::string& alias, const std::string& collection_name); 27 | 28 | const std::string& 29 | GetDbName() const; 30 | const std::string& 31 | GetAlias() const; 32 | const std::string& 33 | GetCollectionName() const; 34 | 35 | void 36 | SetDbName(const std::string& db_name); 37 | void 38 | SetAlias(const std::string& alias); 39 | void 40 | SetCollectionName(const std::string& collection_name); 41 | 42 | private: 43 | std::string db_name_{"default"}; 44 | std::string alias_; 45 | std::string collection_name_; 46 | }; 47 | 48 | } // namespace milvus 49 | -------------------------------------------------------------------------------- /src/include/milvus/types/AnnSearchRequest.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | #include 22 | #include 23 | 24 | #include "FieldData.h" 25 | 26 | namespace milvus { 27 | 28 | class AnnSearchRequest { 29 | public: 30 | AnnSearchRequest(const std::string& anns_field, const std::map& param, int limit, 31 | const std::string& expr = "") 32 | : anns_field_(anns_field), param_(param), limit_(limit), expr_(expr) { 33 | } 34 | 35 | const std::string& 36 | AnnsField() const; 37 | const std::map& 38 | Param() const; 39 | int 40 | Limit() const; 41 | const std::string& 42 | Expr() const; 43 | 44 | FieldDataPtr 45 | TargetVectors() const; 46 | 47 | Status 48 | AddTargetVector(std::string field_name, const std::string& vector); 49 | 50 | Status 51 | AddTargetVector(std::string field_name, const std::vector& vector); 52 | 53 | Status 54 | AddTargetVector(std::string field_name, std::string&& vector); 55 | 56 | Status 57 | AddTargetVector(std::string field_name, const FloatVecFieldData::ElementT& vector); 58 | 59 | Status 60 | AddTargetVector(std::string field_name, FloatVecFieldData::ElementT&& vector); 61 | 62 | private: 63 | std::string anns_field_; 64 | std::map param_; 65 | int limit_; 66 | std::string expr_; 67 | 68 | BinaryVecFieldDataPtr binary_vectors_; 69 | FloatVecFieldDataPtr float_vectors_; 70 | }; 71 | 72 | } // namespace milvus 73 | -------------------------------------------------------------------------------- /src/include/milvus/types/CollectionDesc.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | #include 22 | 23 | #include "CollectionSchema.h" 24 | 25 | namespace milvus { 26 | 27 | /** 28 | * @brief Collection schema and runtime information returned by MilvusClient::DescribeCollection(). 29 | */ 30 | class CollectionDesc { 31 | public: 32 | /** 33 | * @brief Collection schema. 34 | */ 35 | const CollectionSchema& 36 | Schema() const; 37 | 38 | /** 39 | * @brief Set collection schema. 40 | */ 41 | void 42 | SetSchema(const CollectionSchema& schema); 43 | 44 | /** 45 | * @brief Set collection schema. 46 | */ 47 | void 48 | SetSchema(CollectionSchema&& schema); 49 | 50 | /** 51 | * @brief Collection id. 52 | */ 53 | int64_t 54 | ID() const; 55 | 56 | /** 57 | * @brief Set collection id. 58 | */ 59 | void 60 | SetID(int64_t id); 61 | 62 | /** 63 | * @brief Collection alias. 64 | */ 65 | const std::vector& 66 | Alias() const; 67 | 68 | /** 69 | * @brief Set collection alias. 70 | */ 71 | void 72 | SetAlias(const std::vector& alias); 73 | 74 | /** 75 | * @brief Set collection alias. 76 | */ 77 | void 78 | SetAlias(std::vector&& alias); 79 | 80 | /** 81 | * @brief Timestamp when the collection created. 82 | */ 83 | uint64_t 84 | CreatedTime() const; 85 | 86 | /** 87 | * @brief Set timestamp when the collection created. 88 | */ 89 | void 90 | SetCreatedTime(uint64_t ts); 91 | 92 | private: 93 | CollectionSchema schema_; 94 | int64_t collection_id_; 95 | std::vector alias_; 96 | uint64_t created_utc_timestamp_ = 0; 97 | }; 98 | 99 | } // namespace milvus 100 | -------------------------------------------------------------------------------- /src/include/milvus/types/CollectionInfo.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | #include 22 | 23 | namespace milvus { 24 | 25 | /** 26 | * @brief Collection runtime information including create timestamp and loading percentage, returned by 27 | * MilvusClient::ShowCollections(). 28 | */ 29 | class CollectionInfo { 30 | public: 31 | /** 32 | * @brief Constructor 33 | */ 34 | CollectionInfo(); 35 | 36 | /** 37 | * @brief Constructor 38 | */ 39 | CollectionInfo(std::string collection_name, int64_t collection_id, uint64_t create_time, uint64_t load_percentage); 40 | 41 | /** 42 | * @brief Name of the collection. 43 | */ 44 | const std::string& 45 | Name() const; 46 | 47 | /** 48 | * @brief Internal ID of the collection. 49 | */ 50 | int64_t 51 | ID() const; 52 | 53 | /** 54 | * @brief The utc time when the collection is created. 55 | */ 56 | uint64_t 57 | CreatedTime() const; 58 | 59 | /** 60 | * @brief Loading percentage of the collection. 61 | */ 62 | uint64_t 63 | MemoryPercentage() const; 64 | 65 | private: 66 | std::string name_; 67 | int64_t collection_id_ = 0; 68 | uint64_t created_utc_timestamp_ = 0; 69 | uint64_t in_memory_percentage_ = 0; 70 | }; 71 | 72 | /** 73 | * @brief CollectionsInfo objects array 74 | */ 75 | using CollectionsInfo = std::vector; 76 | 77 | } // namespace milvus 78 | -------------------------------------------------------------------------------- /src/include/milvus/types/CollectionStat.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | #include 22 | 23 | namespace milvus { 24 | 25 | /** 26 | * @brief Collection statistics returned by MilvusClient::GetCollectionStats(). 27 | */ 28 | class CollectionStat { 29 | public: 30 | /** 31 | * @brief Construct a new Collection Stat object 32 | */ 33 | CollectionStat(); 34 | 35 | /** 36 | * @brief Return row count of this collection. 37 | * 38 | */ 39 | uint64_t 40 | RowCount() const; 41 | 42 | /** 43 | * @brief Set collection name 44 | * 45 | */ 46 | void 47 | SetName(std::string name); 48 | 49 | /** 50 | * @brief Get collection name 51 | * 52 | */ 53 | const std::string& 54 | Name() const; 55 | 56 | /** 57 | * @brief add key/value pair for collection statistics 58 | */ 59 | void 60 | Emplace(std::string key, std::string value); 61 | 62 | private: 63 | std::string name_; 64 | std::unordered_map statistics_; 65 | }; 66 | 67 | } // namespace milvus 68 | -------------------------------------------------------------------------------- /src/include/milvus/types/CompactionPlan.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | 22 | namespace milvus { 23 | 24 | /** 25 | * @brief Compaction plan information. Used by MilvusClient::GetCompactionPlans(). 26 | */ 27 | class CompactionPlan { 28 | public: 29 | /** 30 | * @brief Construct a new Compaction Plan object 31 | * 32 | */ 33 | CompactionPlan(); 34 | 35 | /** 36 | * @brief Constructor 37 | */ 38 | CompactionPlan(const std::vector& segments, int64_t dst_segment); 39 | 40 | /** 41 | * @brief Constructor 42 | */ 43 | CompactionPlan(std::vector&& segments, int64_t dst_segment); 44 | 45 | /** 46 | * @brief Segment id array to be merged. 47 | */ 48 | const std::vector& 49 | SourceSegments() const; 50 | 51 | /** 52 | * @brief Set segment id array to be merged. 53 | */ 54 | void 55 | SetSourceSegments(const std::vector& segments); 56 | 57 | /** 58 | * @brief Set segment id array to be merged. 59 | */ 60 | void 61 | SetSourceSegments(std::vector&& segments); 62 | 63 | /** 64 | * @brief New generated segment id after merging. 65 | */ 66 | int64_t 67 | DestinySegemnt() const; 68 | 69 | /** 70 | * @brief Set segment id. 71 | */ 72 | void 73 | SetDestinySegemnt(int64_t id); 74 | 75 | private: 76 | std::vector src_segments_; 77 | int64_t dst_segment_ = 0; 78 | }; 79 | 80 | /** 81 | * @brief CompactionPlans objects array 82 | */ 83 | using CompactionPlans = std::vector; 84 | 85 | } // namespace milvus 86 | -------------------------------------------------------------------------------- /src/include/milvus/types/CompactionState.h: -------------------------------------------------------------------------------- 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 20 | 21 | namespace milvus { 22 | 23 | /** 24 | * @brief State Code for compaction 25 | */ 26 | enum class CompactionStateCode { 27 | UNKNOWN = 0, 28 | EXECUTING = 1, 29 | COMPLETED = 2, 30 | }; 31 | 32 | /** 33 | * @brief Compaction state. Used by MilvusClient::GetCompactionState(). 34 | */ 35 | class CompactionState { 36 | public: 37 | CompactionState(); 38 | 39 | /** 40 | * @brief Compaction state code. 41 | */ 42 | CompactionStateCode 43 | State() const; 44 | 45 | /** 46 | * @brief Set compaction state code. 47 | */ 48 | void 49 | SetState(CompactionStateCode state); 50 | 51 | /** 52 | * @brief The executing plan id. 53 | */ 54 | int64_t 55 | ExecutingPlan() const; 56 | 57 | /** 58 | * @brief Set the executing plan id. 59 | */ 60 | void 61 | SetExecutingPlan(int64_t id); 62 | 63 | /** 64 | * @brief The timeout plan id. 65 | */ 66 | int64_t 67 | TimeoutPlan() const; 68 | 69 | /** 70 | * @brief Set the timeout plan id. 71 | */ 72 | void 73 | SetTimeoutPlan(int64_t id); 74 | 75 | /** 76 | * @brief The completed plan id. 77 | */ 78 | int64_t 79 | CompletedPlan() const; 80 | 81 | /** 82 | * @brief Set the completed plan id. 83 | */ 84 | void 85 | SetCompletedPlan(int64_t id); 86 | 87 | private: 88 | CompactionStateCode state_code_{CompactionStateCode::UNKNOWN}; 89 | 90 | int64_t executing_plan_ = 0; 91 | int64_t timeout_plan_ = 0; 92 | int64_t completed_plan_ = 0; 93 | }; 94 | 95 | } // namespace milvus 96 | -------------------------------------------------------------------------------- /src/include/milvus/types/Constant.h: -------------------------------------------------------------------------------- 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 | #include 19 | #include 20 | 21 | namespace milvus { 22 | 23 | /** 24 | * @brief Global definition for row count label 25 | */ 26 | inline std::string 27 | KeyRowCount() { 28 | return "row_count"; 29 | } 30 | 31 | /** 32 | * @brief Global definition for index type label 33 | */ 34 | inline std::string 35 | KeyIndexType() { 36 | return "index_type"; 37 | } 38 | 39 | /** 40 | * @brief Global definition for metric type label 41 | */ 42 | inline std::string 43 | KeyMetricType() { 44 | return "metric_type"; 45 | } 46 | 47 | /** 48 | * @brief Global definition for metric type label 49 | */ 50 | inline std::string 51 | KeyParams() { 52 | return "params"; 53 | } 54 | 55 | /** 56 | * @brief Global definition for vector dimension label 57 | */ 58 | inline std::string 59 | FieldDim() { 60 | return "dim"; 61 | } 62 | 63 | /** 64 | * @brief Max length field name for varchar field 65 | */ 66 | inline std::string 67 | FieldMaxLength() { 68 | return "max_length"; 69 | } 70 | 71 | /** 72 | * @brief Global definition for strong guarantee timestamp 73 | */ 74 | inline uint64_t 75 | GuaranteeStrongTs() { 76 | return 0; 77 | } 78 | 79 | /** 80 | * @brief Global definition for eventually guarantee timestamp 81 | */ 82 | inline uint64_t 83 | GuaranteeEventuallyTs() { 84 | return 1; 85 | } 86 | 87 | /** 88 | * @brief The logical bits in hybrid timestamp 89 | */ 90 | constexpr size_t inline HybridTsLogicalBits() { 91 | return 18; 92 | } 93 | 94 | /** 95 | * @brief The logical bits mask for hybrid timestamp 96 | */ 97 | constexpr uint64_t inline HybridTsLogicalBitsMask() { 98 | return (1 << HybridTsLogicalBits()) - 1; 99 | } 100 | 101 | } // namespace milvus 102 | -------------------------------------------------------------------------------- /src/include/milvus/types/DataType.h: -------------------------------------------------------------------------------- 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 | namespace milvus { 20 | 21 | /** 22 | * @brief Data type of field 23 | */ 24 | enum class DataType { 25 | UNKNOWN = 0, 26 | 27 | BOOL = 1, 28 | INT8 = 2, 29 | INT16 = 3, 30 | INT32 = 4, 31 | INT64 = 5, 32 | 33 | FLOAT = 10, 34 | DOUBLE = 11, 35 | 36 | // STRING not available 37 | // STRING = 20, 38 | VARCHAR = 21, 39 | 40 | BINARY_VECTOR = 100, 41 | FLOAT_VECTOR = 101, 42 | }; 43 | 44 | } // namespace milvus 45 | -------------------------------------------------------------------------------- /src/include/milvus/types/DatabaseDesc.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | #include 22 | #include 23 | 24 | namespace milvus { 25 | 26 | class DatabaseDesc { 27 | public: 28 | DatabaseDesc(); 29 | DatabaseDesc(const std::string& db_name, int64_t db_id, uint64_t created_timestamp, 30 | const std::vector>& properties); 31 | 32 | const std::string& 33 | GetDbName() const; 34 | int64_t 35 | GetDbID() const; 36 | uint64_t 37 | GetCreatedTimestamp() const; 38 | const std::vector>& 39 | GetProperties() const; 40 | 41 | void 42 | SetDbName(const std::string& db_name); 43 | void 44 | SetDbID(int64_t db_id); 45 | void 46 | SetCreatedTimestamp(uint64_t created_timestamp); 47 | void 48 | SetProperties(const std::vector>& properties); 49 | void 50 | AddProperty(const std::string& key, const std::string& value); 51 | 52 | private: 53 | std::string db_name_; 54 | int64_t db_id_{0}; 55 | uint64_t created_timestamp_{0}; 56 | std::vector> properties_; 57 | }; 58 | 59 | } // namespace milvus 60 | -------------------------------------------------------------------------------- /src/include/milvus/types/DmlResults.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | 22 | #include "IDArray.h" 23 | 24 | namespace milvus { 25 | 26 | /** 27 | * @brief Result returned by MilvusClientV2::Insert(), MilvusClientV2::Upsert() and MilvusClientV2::Delete() 28 | */ 29 | class DmlResults { 30 | public: 31 | /** 32 | * @brief The id array for entities which are inserted or deleted. 33 | */ 34 | const IDArray& 35 | IdArray() const; 36 | 37 | /** 38 | * @brief Set the id array. 39 | */ 40 | void 41 | SetIdArray(const IDArray& id_array); 42 | 43 | /** 44 | * @brief Set the id array. 45 | */ 46 | void 47 | SetIdArray(IDArray&& id_array); 48 | 49 | /** 50 | * @brief The operation timestamp marked by server side. 51 | */ 52 | uint64_t 53 | Timestamp() const; 54 | 55 | /** 56 | * @brief Set operation timestamp. 57 | */ 58 | void 59 | SetTimestamp(uint64_t timestamp); 60 | 61 | private: 62 | IDArray id_array_{std::vector{}}; 63 | uint64_t timestamp_{0}; 64 | }; 65 | 66 | } // namespace milvus 67 | -------------------------------------------------------------------------------- /src/include/milvus/types/GetArguments.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | #include 22 | #include 23 | 24 | #include "../Status.h" 25 | 26 | namespace milvus { 27 | 28 | /** 29 | * @brief Arguments for MilvusClientV2::Get(). 30 | */ 31 | class GetArguments { 32 | public: 33 | /** 34 | * @brief Get name of the target collection 35 | */ 36 | const std::string& 37 | CollectionName() const; 38 | 39 | /** 40 | * @brief Set name of this collection, cannot be empty 41 | */ 42 | Status 43 | SetCollectionName(std::string collection_name); 44 | 45 | /** 46 | * @brief Get partition names 47 | */ 48 | const std::set& 49 | PartitionNames() const; 50 | 51 | /** 52 | * @brief Specify partition name to control get scope, the name cannot be empty 53 | */ 54 | Status 55 | AddPartitionName(std::string partition_name); 56 | 57 | /** 58 | * @brief Get output field names 59 | */ 60 | const std::set& 61 | OutputFields() const; 62 | 63 | /** 64 | * @brief Specify output field names to return field data, the name cannot be empty 65 | */ 66 | Status 67 | AddOutputField(std::string field_name); 68 | 69 | /** 70 | * @brief Get primary key ids 71 | */ 72 | const std::vector& 73 | Ids() const; 74 | 75 | /** 76 | * @brief Set primary key ids to get 77 | */ 78 | Status 79 | SetIds(std::vector ids); 80 | 81 | private: 82 | std::string collection_name_; 83 | std::set partition_names_; 84 | std::set output_field_names_; 85 | std::vector ids_; 86 | }; 87 | 88 | } // namespace milvus 89 | -------------------------------------------------------------------------------- /src/include/milvus/types/IDArray.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | #include 22 | 23 | namespace milvus { 24 | 25 | /** 26 | * @brief ID array, each ID could be int64 type or string type. \n 27 | * Note: v2.0 only support int64 type id. 28 | */ 29 | class IDArray { 30 | public: 31 | /** 32 | * @brief Constructor 33 | */ 34 | explicit IDArray(const std::vector& id_array); 35 | 36 | /** 37 | * @brief Constructor 38 | */ 39 | explicit IDArray(std::vector&& id_array); 40 | 41 | /** 42 | * @brief Constructor 43 | */ 44 | explicit IDArray(const std::vector& id_array); 45 | 46 | /** 47 | * @brief Constructor 48 | */ 49 | explicit IDArray(std::vector&& id_array); 50 | 51 | /** 52 | * @brief Indicate this is an integer id array 53 | */ 54 | bool 55 | IsIntegerID() const; 56 | 57 | /** 58 | * @brief Return integer id array 59 | */ 60 | const std::vector& 61 | IntIDArray() const; 62 | 63 | /** 64 | * @brief Return string id array 65 | */ 66 | const std::vector& 67 | StrIDArray() const; 68 | 69 | private: 70 | bool is_int_array_{true}; 71 | std::vector int_id_array_; 72 | std::vector str_id_array_; 73 | }; 74 | 75 | } // namespace milvus 76 | -------------------------------------------------------------------------------- /src/include/milvus/types/IndexType.h: -------------------------------------------------------------------------------- 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 | namespace milvus { 20 | 21 | /** 22 | * @brief Supported index types. 23 | */ 24 | enum class IndexType { 25 | INVALID = 0, 26 | 27 | // CPU indexes only for float vectors 28 | // the value of each index type doesn't matter, the sdk converts IndexType to string name and 29 | // passes the name to the server 30 | // Note: in milvus 2.4+, IVF_HNSW/RHNSW_FLAT/RHNSW_SQ/RHNSW_PQ/ANNOY have been deprecated 31 | FLAT, 32 | IVF_FLAT, 33 | IVF_SQ8, 34 | IVF_PQ, 35 | HNSW, 36 | DISKANN, 37 | AUTOINDEX, 38 | SCANN, 39 | 40 | // GPU indexes only for float vectors 41 | GPU_IVF_FLAT = 201, 42 | GPU_IVF_PQ, 43 | GPU_BRUTE_FORCE, 44 | GPU_CAGRA, 45 | 46 | // Indexes for binary vectors 47 | BIN_FLAT = 1001, 48 | BIN_IVF_FLAT, 49 | 50 | // Only for varchar type field 51 | TRIE = 1101, 52 | // Only for scalar type field 53 | STL_SORT, // only for numeric type field 54 | INVERTED, // works for all scalar fields except JSON type field 55 | 56 | // Only for sparse vectors 57 | SPARSE_INVERTED_INDEX = 1201, 58 | SPARSE_WAND 59 | }; 60 | } // namespace milvus 61 | -------------------------------------------------------------------------------- /src/include/milvus/types/ListAliasesResult.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | 22 | namespace milvus { 23 | 24 | class ListAliasesResult { 25 | public: 26 | ListAliasesResult(); 27 | ListAliasesResult(const std::string& db_name, const std::string& collection_name, 28 | const std::vector& aliases); 29 | 30 | const std::string& 31 | GetDbName() const; 32 | const std::string& 33 | GetCollectionName() const; 34 | const std::vector& 35 | GetAliases() const; 36 | 37 | void 38 | SetDbName(const std::string& db_name); 39 | void 40 | SetCollectionName(const std::string& collection_name); 41 | void 42 | SetAliases(const std::vector& aliases); 43 | 44 | private: 45 | std::string db_name_{"default"}; 46 | std::string collection_name_; 47 | std::vector aliases_; 48 | }; 49 | 50 | } // namespace milvus 51 | -------------------------------------------------------------------------------- /src/include/milvus/types/LoadState.h: -------------------------------------------------------------------------------- 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 20 | 21 | namespace milvus { 22 | 23 | enum class LoadStateCode { NOT_EXIST = 0, NOT_LOAD = 1, LOADING = 2, LOADED = 3 }; 24 | 25 | class LoadState { 26 | public: 27 | LoadState(); 28 | explicit LoadState(LoadStateCode code); 29 | 30 | LoadStateCode 31 | GetCode() const; 32 | const std::string& 33 | GetDesc() const; 34 | void 35 | SetCode(LoadStateCode code); 36 | 37 | private: 38 | LoadStateCode code_; 39 | std::string state_desc_; 40 | void 41 | updateStateDesc(); 42 | }; 43 | 44 | } // namespace milvus 45 | -------------------------------------------------------------------------------- /src/include/milvus/types/MetricType.h: -------------------------------------------------------------------------------- 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 | namespace milvus { 20 | 21 | /** 22 | * @brief Supported metric types. 23 | */ 24 | enum class MetricType { 25 | INVALID, 26 | L2, 27 | IP, 28 | COSINE, 29 | // The following values are for binary vectors 30 | HAMMING, 31 | JACCARD, 32 | 33 | // Note: in milvus 2.4+, TANIMOTO/SUBSTRUCTURE/SUPERSTRUCTURE have been deprecated 34 | }; 35 | } // namespace milvus 36 | -------------------------------------------------------------------------------- /src/include/milvus/types/NodeInfo.h: -------------------------------------------------------------------------------- 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 20 | 21 | class NodeInfo { 22 | public: 23 | NodeInfo(int64_t id, const std::string& addr, const std::string& host); 24 | 25 | int64_t 26 | GetNodeId() const; 27 | const std::string& 28 | GetAddress() const; 29 | const std::string& 30 | GetHostname() const; 31 | 32 | private: 33 | int64_t node_id_; 34 | std::string address_; 35 | std::string hostname_; 36 | }; 37 | -------------------------------------------------------------------------------- /src/include/milvus/types/PartitionInfo.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | #include 22 | 23 | namespace milvus { 24 | 25 | /** 26 | * @brief Partition runtime information including create timestamp and loading percentage, returned by 27 | * MilvusClient::ShowPartitions(). 28 | */ 29 | class PartitionInfo { 30 | public: 31 | /** 32 | * @brief Constructor 33 | */ 34 | PartitionInfo(std::string name, int64_t id, uint64_t created_utc_timestamp = 0, int64_t in_memory_percentage = 0); 35 | 36 | /** 37 | * @brief Get name of this partition. 38 | */ 39 | std::string 40 | Name() const; 41 | 42 | /** 43 | * @brief Get internal id of this partition. 44 | */ 45 | int64_t 46 | Id() const; 47 | 48 | /** 49 | * @brief Get the utc timestamp calculated by created_timestamp. 50 | */ 51 | uint64_t 52 | CreatedUtcTimestamp() const; 53 | 54 | /** 55 | * @brief Get partition loading percentage. 56 | */ 57 | int64_t 58 | InMemoryPercentage() const; 59 | 60 | /** 61 | * @brief Indicated whether the partition has been loaded completed. 62 | */ 63 | bool 64 | Loaded() const; 65 | 66 | private: 67 | std::string name_; 68 | int64_t id_{0}; 69 | uint64_t created_utc_timestamp_{0}; 70 | int64_t in_memory_percentage_ = {0}; 71 | }; 72 | 73 | /** 74 | * @brief To test two PartitionInfo are equal 75 | */ 76 | bool 77 | operator==(const PartitionInfo& a, const PartitionInfo& b); 78 | 79 | /** 80 | * @brief PartitionsInfo objects array 81 | */ 82 | using PartitionsInfo = std::vector; 83 | 84 | } // namespace milvus 85 | -------------------------------------------------------------------------------- /src/include/milvus/types/PartitionStat.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | 22 | #include "Constant.h" 23 | 24 | namespace milvus { 25 | 26 | /** 27 | * @brief Partition statistics returned by MilvusClient::GetPartitionStats(). 28 | */ 29 | class PartitionStat { 30 | public: 31 | /** 32 | * @brief Return row count of this partition. 33 | * 34 | * @return uint64_t row count of this partition 35 | */ 36 | uint64_t 37 | RowCount() const; 38 | 39 | /** 40 | * @brief Set partition name 41 | */ 42 | void 43 | SetName(std::string name); 44 | 45 | /** 46 | * @brief Get partition name 47 | */ 48 | const std::string& 49 | Name() const; 50 | 51 | /** 52 | * @brief add key/value pair for partition statistics 53 | */ 54 | void 55 | Emplace(std::string key, std::string value); 56 | 57 | private: 58 | std::string name_; 59 | std::unordered_map statistics_; 60 | }; 61 | 62 | } // namespace milvus 63 | -------------------------------------------------------------------------------- /src/include/milvus/types/PrivilegeGroupInfo.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | 22 | namespace milvus { 23 | 24 | class PrivilegeGroupInfo { 25 | public: 26 | PrivilegeGroupInfo() = default; 27 | explicit PrivilegeGroupInfo(const std::string& group_name); 28 | 29 | void 30 | AddPrivilege(const std::string& privilege); 31 | const std::string& 32 | GroupName() const; 33 | void 34 | SetGroupName(const std::string& group_name); 35 | const std::vector& 36 | Privileges() const; 37 | void 38 | SetPrivileges(const std::vector& privileges); 39 | 40 | private: 41 | std::string group_name_; 42 | std::vector privileges_; 43 | }; 44 | 45 | } // namespace milvus 46 | -------------------------------------------------------------------------------- /src/include/milvus/types/QueryResults.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | 22 | #include "FieldData.h" 23 | 24 | namespace milvus { 25 | 26 | /** 27 | * @brief Results returned by MilvusClient::Query(). 28 | */ 29 | class QueryResults { 30 | public: 31 | QueryResults(); 32 | 33 | /** 34 | * @brief Constructor 35 | */ 36 | explicit QueryResults(const std::vector& output_fields); 37 | 38 | /** 39 | * @brief Constructor 40 | */ 41 | explicit QueryResults(std::vector&& output_fields); 42 | 43 | /** 44 | * @brief Get output field data by name. 45 | */ 46 | FieldDataPtr 47 | GetFieldByName(const std::string& name); 48 | 49 | /** 50 | * @brief Get all output fields data. 51 | */ 52 | const std::vector& 53 | OutputFields() const; 54 | 55 | private: 56 | std::vector output_fields_; 57 | }; 58 | 59 | } // namespace milvus 60 | -------------------------------------------------------------------------------- /src/include/milvus/types/Ranker.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | #include 22 | #include 23 | 24 | namespace milvus { 25 | 26 | class BaseRanker { 27 | public: 28 | virtual ~BaseRanker() = default; 29 | virtual std::map 30 | GetParams() const = 0; 31 | virtual std::string 32 | GetStrategy() const = 0; 33 | virtual nlohmann::json 34 | Dict() const; 35 | }; 36 | 37 | class RRFRanker : public BaseRanker { 38 | public: 39 | explicit RRFRanker(float k = 60.0); 40 | std::map 41 | GetParams() const override; 42 | std::string 43 | GetStrategy() const override; 44 | 45 | private: 46 | float k_; 47 | }; 48 | 49 | class WeightedRanker : public BaseRanker { 50 | public: 51 | explicit WeightedRanker(std::vector weights); 52 | std::map 53 | GetParams() const override; 54 | std::string 55 | GetStrategy() const override; 56 | 57 | private: 58 | std::vector weights_; 59 | }; 60 | 61 | } // namespace milvus 62 | -------------------------------------------------------------------------------- /src/include/milvus/types/ResourceGroupConfig.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | #include 22 | 23 | namespace milvus { 24 | 25 | class ResourceGroupConfig { 26 | public: 27 | ResourceGroupConfig() = default; 28 | ResourceGroupConfig(int req_node_num, int lim_node_num, const std::vector& from, 29 | const std::vector& to, 30 | const std::vector>& labels); 31 | 32 | int 33 | GetRequestsNodeNum() const; 34 | void 35 | SetRequestsNodeNum(int num); 36 | 37 | int 38 | GetLimitsNodeNum() const; 39 | void 40 | SetLimitsNodeNum(int num); 41 | 42 | const std::vector& 43 | GetTransferFrom() const; 44 | void 45 | SetTransferFrom(const std::vector& from); 46 | 47 | const std::vector& 48 | GetTransferTo() const; 49 | void 50 | SetTransferTo(const std::vector& to); 51 | 52 | const std::vector>& 53 | GetNodeLabels() const; 54 | void 55 | SetNodeLabels(const std::vector>& labels); 56 | 57 | private: 58 | int requests_node_num_; 59 | int limits_node_num_; 60 | std::vector transfer_from_; 61 | std::vector transfer_to_; 62 | std::vector> node_labels_; 63 | }; 64 | 65 | } // namespace milvus 66 | -------------------------------------------------------------------------------- /src/include/milvus/types/ResourceGroupDesc.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | #include 22 | 23 | #include "NodeInfo.h" 24 | #include "ResourceGroupConfig.h" 25 | 26 | namespace milvus { 27 | 28 | class ResourceGroupDesc { 29 | public: 30 | ResourceGroupDesc() = default; 31 | ResourceGroupDesc(const std::string& name, int32_t capacity, int32_t available_nodes, 32 | const std::map& loaded_replicas, 33 | const std::map& outgoing_nodes, 34 | const std::map& incoming_nodes, const ResourceGroupConfig& config, 35 | const std::vector& nodes); 36 | 37 | const std::string& 38 | GetName() const; 39 | int32_t 40 | GetCapacity() const; 41 | int32_t 42 | GetNumAvailableNode() const; 43 | const std::map& 44 | GetNumLoadedReplica() const; 45 | const std::map& 46 | GetNumOutgoingNode() const; 47 | const std::map& 48 | GetNumIncomingNode() const; 49 | const ResourceGroupConfig& 50 | GetConfig() const; 51 | const std::vector& 52 | GetNodes() const; 53 | 54 | private: 55 | std::string name_; 56 | int32_t capacity_; 57 | int32_t num_available_node_; 58 | std::map num_loaded_replica_; 59 | std::map num_outgoing_node_; 60 | std::map num_incoming_node_; 61 | ResourceGroupConfig config_; 62 | std::vector nodes_; 63 | }; 64 | 65 | } // namespace milvus 66 | -------------------------------------------------------------------------------- /src/include/milvus/types/RoleDesc.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | 22 | namespace milvus { 23 | 24 | struct Privilege { 25 | std::string object_type; 26 | std::string object_name; 27 | std::string db_name; 28 | std::string role_name; 29 | std::string privilege; 30 | std::string grantor_name; 31 | }; 32 | 33 | class RoleDesc { 34 | public: 35 | RoleDesc(); 36 | RoleDesc(const std::string& role, const std::vector& privileges); 37 | 38 | const std::string& 39 | GetRole() const; 40 | const std::vector& 41 | GetPrivileges() const; 42 | 43 | private: 44 | std::string role_; 45 | std::vector privileges_; 46 | }; 47 | 48 | } // namespace milvus 49 | -------------------------------------------------------------------------------- /src/include/milvus/types/SearchResults.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | 22 | #include "FieldData.h" 23 | #include "IDArray.h" 24 | 25 | namespace milvus { 26 | 27 | /** 28 | * @brief Topk results for one target vector of MilvusClient::Search() 29 | */ 30 | struct SingleResult { 31 | /** 32 | * @brief Constructor 33 | */ 34 | SingleResult(IDArray&& ids, std::vector&& scores, std::vector&& output_fields); 35 | 36 | /** 37 | * @brief Distances/scores array of one target vector 38 | */ 39 | const std::vector& 40 | Scores() const; 41 | 42 | /** 43 | * @brief Topk id array of one target vector 44 | */ 45 | const IDArray& 46 | Ids() const; 47 | 48 | /** 49 | * @brief Output fields data 50 | */ 51 | const std::vector& 52 | OutputFields() const; 53 | 54 | /** 55 | * @brief Get an output field by name 56 | */ 57 | FieldDataPtr 58 | OutputField(const std::string& name) const; 59 | 60 | private: 61 | IDArray ids_; 62 | std::vector scores_; 63 | std::vector output_fields_; 64 | }; 65 | 66 | /** 67 | * @brief Results returned by MilvusClient::Search(). 68 | */ 69 | class SearchResults { 70 | public: 71 | SearchResults(); 72 | 73 | /** 74 | * @brief Constructor 75 | */ 76 | explicit SearchResults(std::vector&& results); 77 | 78 | /** 79 | * @brief Get search results. 80 | */ 81 | std::vector& 82 | Results(); 83 | 84 | private: 85 | std::vector nq_results_{}; 86 | }; 87 | 88 | } // namespace milvus 89 | -------------------------------------------------------------------------------- /src/include/milvus/types/UserResult.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | 22 | namespace milvus { 23 | 24 | class UserResult { 25 | public: 26 | UserResult(); 27 | 28 | void 29 | SetUserName(const std::string& user_name); 30 | const std::string& 31 | UserName() const; 32 | 33 | void 34 | AddRole(const std::string& role); 35 | const std::vector& 36 | Roles() const; 37 | 38 | private: 39 | std::string user_name_; 40 | std::vector roles_; 41 | }; 42 | 43 | } // namespace milvus 44 | -------------------------------------------------------------------------------- /test/CHANGELOG.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milvus-io/milvus-sdk-cpp/a0592aaa5d7191e35246d9aaf372eabab414de4f/test/CHANGELOG.md -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 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_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src/include) 18 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src/impl) 19 | include_directories(${milvus_proto_BINARY_DIR}) 20 | 21 | # resolve gtest 22 | if ("${MILVUS_WITH_GTEST}" STREQUAL "package") 23 | find_package(GTest REQUIRED) 24 | else () 25 | if (NOT googletest_POPULATED) 26 | FetchContent_Populate(googletest) 27 | set(gtest_force_shared_crt ON CACHE INTERNAL "") 28 | set(INSTALL_GTEST OFF CACHE INTERNAL "") 29 | add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL) 30 | endif () 31 | endif () 32 | 33 | set(GTEST_LIBRARIES gtest) 34 | set(GMOCK_LIBRARIES gmock) 35 | set(GTEST_MAIN_LIBRARIES gtest_main) 36 | 37 | aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/ut ut_files) 38 | add_executable(testing-ut ${ut_files}) 39 | target_compile_options(testing-ut PRIVATE $<$:/bigobj>) 40 | target_link_libraries(testing-ut PRIVATE milvus_sdk ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES} ${GTEST_MAIN_LIBRARIES}) 41 | 42 | aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/it it_files) 43 | aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/it/mocks it_mocks_files) 44 | add_executable(testing-it ${it_files} ${it_mocks_files}) 45 | target_compile_options(testing-it PRIVATE $<$:/bigobj>) 46 | target_link_libraries(testing-it PRIVATE milvus_sdk ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES} ${GTEST_MAIN_LIBRARIES}) 47 | 48 | # st only available under linux/macos 49 | if (CMAKE_SYSTEM_NAME MATCHES "(Linux|Darwin)") 50 | aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/st st_files) 51 | add_executable(testing-st ${st_files}) 52 | target_link_libraries(testing-st PRIVATE milvus_sdk ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES}) 53 | endif() 54 | -------------------------------------------------------------------------------- /test/it/TestConnection.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "mocks/MilvusMockedTest.h" 20 | 21 | using ::milvus::StatusCode; 22 | using ::milvus::proto::milvus::HasCollectionRequest; 23 | using ::testing::_; 24 | using ::testing::Property; 25 | 26 | TEST_F(MilvusMockedTest, ConnectSuccessful) { 27 | milvus::ConnectParam connect_param{"127.0.0.1", server_.ListenPort()}; 28 | auto status = client_->Connect(connect_param); 29 | EXPECT_TRUE(status.IsOk()); 30 | } 31 | 32 | TEST_F(MilvusMockedTest, ConnectFailed) { 33 | auto port = server_.ListenPort(); 34 | milvus::ConnectParam connect_param{"127.0.0.1", ++port}; 35 | connect_param.SetConnectTimeout(200); 36 | auto status = client_->Connect(connect_param); 37 | EXPECT_FALSE(status.IsOk()); 38 | } 39 | 40 | TEST_F(MilvusMockedTest, ConnectWithUsername) { 41 | milvus::ConnectParam connect_param{"127.0.0.1", server_.ListenPort(), "username", "password"}; 42 | auto status = client_->Connect(connect_param); 43 | 44 | EXPECT_EQ(connect_param.Authorizations(), "dXNlcm5hbWU6cGFzc3dvcmQ="); 45 | 46 | std::string collection_name = "Foo"; 47 | 48 | EXPECT_CALL(service_, HasCollection(_, Property(&HasCollectionRequest::collection_name, collection_name), _)) 49 | .WillOnce([](::grpc::ServerContext* context, const HasCollectionRequest*, 50 | ::milvus::proto::milvus::BoolResponse* response) { 51 | // check context 52 | auto& meta = context->client_metadata(); 53 | auto it = meta.find("authorization"); 54 | EXPECT_NE(it, meta.end()); 55 | EXPECT_EQ(it->second, "dXNlcm5hbWU6cGFzc3dvcmQ="); 56 | 57 | response->set_value(false); 58 | return ::grpc::Status{}; 59 | }); 60 | bool has_collection{false}; 61 | status = client_->HasCollection(collection_name, has_collection); 62 | 63 | EXPECT_TRUE(status.IsOk()); 64 | EXPECT_FALSE(has_collection); 65 | } -------------------------------------------------------------------------------- /test/it/TestGetCollectionsStatistics.cpp: -------------------------------------------------------------------------------- 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 18 | #include 19 | 20 | #include "mocks/MilvusMockedTest.h" 21 | 22 | using ::milvus::StatusCode; 23 | using ::milvus::proto::milvus::FlushRequest; 24 | using ::milvus::proto::milvus::FlushResponse; 25 | using ::milvus::proto::milvus::GetCollectionStatisticsRequest; 26 | using ::milvus::proto::milvus::GetCollectionStatisticsResponse; 27 | using ::testing::_; 28 | using ::testing::AllOf; 29 | using ::testing::ElementsAre; 30 | using ::testing::Property; 31 | 32 | TEST_F(MilvusMockedTest, GetCollectionStatisticsInstantly) { 33 | milvus::ConnectParam connect_param{"127.0.0.1", server_.ListenPort()}; 34 | client_->Connect(connect_param); 35 | 36 | std::string collection = "Foo"; 37 | milvus::CollectionStat collection_stat; 38 | 39 | EXPECT_CALL(service_, GetCollectionStatistics( 40 | _, AllOf(Property(&GetCollectionStatisticsRequest::collection_name, collection)), _)) 41 | .WillOnce([](::grpc::ServerContext*, const GetCollectionStatisticsRequest*, 42 | GetCollectionStatisticsResponse* response) { 43 | auto* stats = response->add_stats(); 44 | stats->set_key("row_count"); 45 | stats->set_value("1000"); 46 | return grpc::Status{}; 47 | }); 48 | 49 | auto status = client_->GetCollectionStatistics(collection, collection_stat, milvus::ProgressMonitor::NoWait()); 50 | EXPECT_TRUE(status.IsOk()); 51 | EXPECT_EQ(collection_stat.RowCount(), 1000); 52 | } 53 | -------------------------------------------------------------------------------- /test/it/TestGetIndexBuildProgress.cpp: -------------------------------------------------------------------------------- 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 18 | #include 19 | 20 | #include "mocks/MilvusMockedTest.h" 21 | 22 | using ::milvus::StatusCode; 23 | using ::milvus::proto::milvus::GetIndexBuildProgressRequest; 24 | using ::milvus::proto::milvus::GetIndexBuildProgressResponse; 25 | using ::testing::_; 26 | using ::testing::AllOf; 27 | using ::testing::Property; 28 | 29 | TEST_F(MilvusMockedTest, GetIndexBuildProgressFoo) { 30 | milvus::ConnectParam connect_param{"127.0.0.1", server_.ListenPort()}; 31 | client_->Connect(connect_param); 32 | 33 | std::string collection_name = "Foo"; 34 | std::string field_name = "Bar"; 35 | milvus::IndexProgress index_progress; 36 | 37 | EXPECT_CALL(service_, 38 | GetIndexBuildProgress(_, 39 | AllOf(Property(&GetIndexBuildProgressRequest::collection_name, collection_name), 40 | Property(&GetIndexBuildProgressRequest::field_name, field_name)), 41 | _)) 42 | .WillOnce( 43 | [](::grpc::ServerContext*, const GetIndexBuildProgressRequest*, GetIndexBuildProgressResponse* response) { 44 | response->set_total_rows(1000); 45 | response->set_indexed_rows(100); 46 | return grpc::Status{}; 47 | }); 48 | 49 | auto status = client_->GetIndexBuildProgress(collection_name, field_name, index_progress); 50 | EXPECT_TRUE(status.IsOk()); 51 | EXPECT_EQ(index_progress.TotalRows(), 1000); 52 | EXPECT_EQ(index_progress.IndexedRows(), 100); 53 | } -------------------------------------------------------------------------------- /test/it/TestGetIndexState.cpp: -------------------------------------------------------------------------------- 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 18 | #include 19 | 20 | #include "mocks/MilvusMockedTest.h" 21 | 22 | using ::milvus::StatusCode; 23 | using ::milvus::proto::common::IndexState; 24 | using ::milvus::proto::milvus::GetIndexStateRequest; 25 | using ::milvus::proto::milvus::GetIndexStateResponse; 26 | using ::testing::_; 27 | using ::testing::AllOf; 28 | using ::testing::ElementsAre; 29 | using ::testing::Property; 30 | 31 | TEST_F(MilvusMockedTest, GetIndexStateFoo) { 32 | milvus::ConnectParam connect_param{"127.0.0.1", server_.ListenPort()}; 33 | client_->Connect(connect_param); 34 | 35 | std::string collection_name = "Foo"; 36 | std::string field_name = "Bar"; 37 | milvus::IndexState index_state; 38 | 39 | EXPECT_CALL(service_, GetIndexState(_, 40 | AllOf(Property(&GetIndexStateRequest::collection_name, collection_name), 41 | Property(&GetIndexStateRequest::field_name, field_name)), 42 | _)) 43 | .WillOnce([](::grpc::ServerContext*, const GetIndexStateRequest*, GetIndexStateResponse* response) { 44 | response->set_state(IndexState::Finished); 45 | return grpc::Status{}; 46 | }); 47 | 48 | auto status = client_->GetIndexState(collection_name, field_name, index_state); 49 | EXPECT_TRUE(status.IsOk()); 50 | EXPECT_EQ(index_state.StateCode(), milvus::IndexStateCode::FINISHED); 51 | } -------------------------------------------------------------------------------- /test/it/TestGetVersion.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "milvus.pb.h" 20 | #include "mocks/MilvusMockedTest.h" 21 | 22 | using ::milvus::StatusCode; 23 | using ::milvus::proto::milvus::GetVersionRequest; 24 | using ::testing::_; 25 | using ::testing::Property; 26 | 27 | TEST_F(MilvusMockedTest, GetVersionFoo) { 28 | milvus::ConnectParam connect_param{"127.0.0.1", server_.ListenPort()}; 29 | client_->Connect(connect_param); 30 | 31 | EXPECT_CALL(service_, GetVersion(_, _, _)) 32 | .WillOnce([](::grpc::ServerContext*, const GetVersionRequest*, 33 | ::milvus::proto::milvus::GetVersionResponse* response) { 34 | response->set_version("2.0.0"); 35 | return ::grpc::Status{}; 36 | }); 37 | std::string version; 38 | auto status = client_->GetVersion(version); 39 | 40 | EXPECT_TRUE(status.IsOk()); 41 | EXPECT_EQ(version, "2.0.0"); 42 | } 43 | -------------------------------------------------------------------------------- /test/it/TestHasCollection.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "mocks/MilvusMockedTest.h" 20 | 21 | using ::milvus::StatusCode; 22 | using ::milvus::proto::milvus::HasCollectionRequest; 23 | using ::testing::_; 24 | using ::testing::Property; 25 | 26 | TEST_F(MilvusMockedTest, HasCollectionFoo) { 27 | milvus::ConnectParam connect_param{"127.0.0.1", server_.ListenPort()}; 28 | client_->Connect(connect_param); 29 | 30 | std::string collection_schema = "Foo"; 31 | 32 | for (auto value : {true, false}) { 33 | EXPECT_CALL(service_, HasCollection(_, Property(&HasCollectionRequest::collection_name, collection_schema), _)) 34 | .WillOnce([value](::grpc::ServerContext*, const HasCollectionRequest*, 35 | ::milvus::proto::milvus::BoolResponse* response) { 36 | response->set_value(value); 37 | return ::grpc::Status{}; 38 | }); 39 | bool has_collection{false}; 40 | auto status = client_->HasCollection(collection_schema, has_collection); 41 | 42 | EXPECT_TRUE(status.IsOk()); 43 | EXPECT_EQ(has_collection, value); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /test/it/TestHasPartition.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "mocks/MilvusMockedTest.h" 20 | 21 | using ::milvus::StatusCode; 22 | using ::milvus::proto::milvus::HasPartitionRequest; 23 | using ::testing::_; 24 | using ::testing::Property; 25 | 26 | TEST_F(MilvusMockedTest, HasPartitionFoo) { 27 | milvus::ConnectParam connect_param{"127.0.0.1", server_.ListenPort()}; 28 | client_->Connect(connect_param); 29 | 30 | const std::string collection{"Foo"}; 31 | const std::string partition{"Bar"}; 32 | 33 | for (auto value : {true, false}) { 34 | EXPECT_CALL(service_, HasPartition(_, 35 | AllOf(Property(&HasPartitionRequest::collection_name, collection), 36 | 37 | Property(&HasPartitionRequest::partition_name, partition)), 38 | _)) 39 | .WillOnce([value](::grpc::ServerContext*, const HasPartitionRequest*, 40 | ::milvus::proto::milvus::BoolResponse* response) { 41 | response->set_value(value); 42 | return ::grpc::Status{}; 43 | }); 44 | bool has{false}; 45 | auto status = client_->HasPartition(collection, partition, has); 46 | 47 | EXPECT_TRUE(status.IsOk()); 48 | EXPECT_EQ(has, value); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /test/it/TestLoadBalance.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "mocks/MilvusMockedTest.h" 20 | 21 | using ::milvus::StatusCode; 22 | using ::milvus::proto::milvus::LoadBalanceRequest; 23 | using ::testing::_; 24 | using ::testing::AllOf; 25 | using ::testing::ElementsAreArray; 26 | using ::testing::Property; 27 | 28 | TEST_F(MilvusMockedTest, LoadBalanceFoo) { 29 | milvus::ConnectParam connect_param{"127.0.0.1", server_.ListenPort()}; 30 | client_->Connect(connect_param); 31 | 32 | int64_t src_node = 1000; 33 | std::vector dst_nodes = {2000, 2001, 2002}; 34 | std::vector segments = {3000, 3001, 3002}; 35 | 36 | EXPECT_CALL(service_, 37 | LoadBalance(_, 38 | AllOf(Property(&LoadBalanceRequest::src_nodeid, src_node), 39 | Property(&LoadBalanceRequest::dst_nodeids, ElementsAreArray(dst_nodes)), 40 | Property(&LoadBalanceRequest::sealed_segmentids, ElementsAreArray(segments))), 41 | _)) 42 | .WillOnce([](::grpc::ServerContext*, const LoadBalanceRequest*, milvus::proto::common::Status*) { 43 | return ::grpc::Status{}; 44 | }); 45 | 46 | auto status = client_->LoadBalance(src_node, dst_nodes, segments); 47 | EXPECT_TRUE(status.IsOk()); 48 | } 49 | 50 | TEST_F(MilvusMockedTest, LoadBalanceWithoutConnect) { 51 | milvus::ConnectParam connect_param{"127.0.0.1", server_.ListenPort()}; 52 | 53 | int64_t src_node = 1000; 54 | std::vector dst_nodes = {2000, 2001, 2002}; 55 | std::vector segments = {3000, 3001, 3002}; 56 | 57 | auto status = client_->LoadBalance(src_node, dst_nodes, segments); 58 | EXPECT_FALSE(status.IsOk()); 59 | EXPECT_EQ(status.Code(), milvus::StatusCode::NOT_CONNECTED); 60 | } -------------------------------------------------------------------------------- /test/it/TestRelseaseCollection.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "mocks/MilvusMockedTest.h" 20 | 21 | using ::milvus::StatusCode; 22 | using ::milvus::proto::milvus::ReleaseCollectionRequest; 23 | using ::testing::_; 24 | using ::testing::Property; 25 | 26 | TEST_F(MilvusMockedTest, ReleaseCollectionFoo) { 27 | milvus::ConnectParam connect_param{"127.0.0.1", server_.ListenPort()}; 28 | client_->Connect(connect_param); 29 | 30 | const std::string collection = "Foo"; 31 | milvus::proto::milvus::ReleaseCollectionRequest request; 32 | request.set_collection_name(collection); 33 | 34 | EXPECT_CALL(service_, ReleaseCollection(_, Property(&ReleaseCollectionRequest::collection_name, collection), _)) 35 | .WillOnce([](::grpc::ServerContext*, const ReleaseCollectionRequest* request, 36 | ::milvus::proto::common::Status*) { return ::grpc::Status{}; }); 37 | auto status = client_->ReleaseCollection(collection); 38 | EXPECT_TRUE(status.IsOk()); 39 | } -------------------------------------------------------------------------------- /test/it/mocks/MilvusMockedServer.cpp: -------------------------------------------------------------------------------- 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 "MilvusMockedServer.h" 18 | 19 | #include 20 | #include 21 | 22 | milvus::MilvusMockedServer::MilvusMockedServer(milvus::MilvusMockedService& service) : service_(service) { 23 | } 24 | 25 | uint16_t 26 | milvus::MilvusMockedServer::ListenPort() const { 27 | return static_cast(listen_port_); 28 | } 29 | 30 | void 31 | milvus::MilvusMockedServer::Start() { 32 | ::grpc::ServerBuilder builder; 33 | builder.AddListeningPort("[::]:0", ::grpc::InsecureServerCredentials(), &listen_port_); 34 | builder.RegisterService(&service_); 35 | server_ = builder.BuildAndStart(); 36 | } 37 | 38 | void 39 | milvus::MilvusMockedServer::Stop() { 40 | if (server_) { 41 | server_->Shutdown(); 42 | } 43 | } -------------------------------------------------------------------------------- /test/it/mocks/MilvusMockedServer.h: -------------------------------------------------------------------------------- 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 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include "MilvusMockedService.h" 27 | 28 | namespace milvus { 29 | 30 | class MilvusMockedServer { 31 | public: 32 | explicit MilvusMockedServer(MilvusMockedService& service); 33 | 34 | void 35 | Start(); 36 | 37 | void 38 | Stop(); 39 | 40 | uint16_t 41 | ListenPort() const; 42 | 43 | private: 44 | milvus::MilvusMockedService& service_; 45 | int32_t listen_port_{0}; 46 | std::unique_ptr<::grpc::Server> server_{nullptr}; 47 | }; 48 | 49 | } // namespace milvus 50 | -------------------------------------------------------------------------------- /test/it/mocks/MilvusMockedTest.cpp: -------------------------------------------------------------------------------- 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 "MilvusMockedTest.h" 18 | 19 | void 20 | milvus::MilvusMockedTest::SetUp() { 21 | server_.Start(); 22 | client_ = milvus::MilvusClient::Create(); 23 | } 24 | 25 | void 26 | milvus::MilvusMockedTest::TearDown() { 27 | } -------------------------------------------------------------------------------- /test/it/mocks/MilvusMockedTest.h: -------------------------------------------------------------------------------- 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 | #pragma once 17 | 18 | #include 19 | 20 | #include "MilvusMockedServer.h" 21 | #include "MilvusMockedService.h" 22 | #include "milvus/MilvusClient.h" 23 | 24 | namespace milvus { 25 | class MilvusMockedTest : public ::testing::Test { 26 | protected: 27 | testing::StrictMock<::milvus::MilvusMockedService> service_{}; 28 | ::milvus::MilvusMockedServer server_{service_}; 29 | std::shared_ptr<::milvus::MilvusClient> client_; 30 | 31 | void 32 | SetUp() override; 33 | 34 | void 35 | TearDown() override; 36 | }; 37 | } // namespace milvus 38 | 39 | using milvus::MilvusMockedTest; 40 | -------------------------------------------------------------------------------- /test/st/Main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include "milvus/MilvusClient.h" 6 | #include "milvus/Status.h" 7 | 8 | int 9 | main(int argc, char** argv) { 10 | ::testing::InitGoogleTest(&argc, argv); 11 | 12 | std::cout << "======== Test with milvus server ========" << std::endl; 13 | ::testing::GTEST_FLAG(filter) = "-MilvusServerTestWithAuth.*"; 14 | int result = RUN_ALL_TESTS(); 15 | if (result > 0) { 16 | return result; 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /test/st/MilvusServerTest.cpp: -------------------------------------------------------------------------------- 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 "MilvusServerTest.h" 18 | 19 | #include 20 | 21 | namespace milvus { 22 | namespace test { 23 | 24 | std::string 25 | RanName(const std::string& prefix) { 26 | std::default_random_engine ran(time(nullptr)); 27 | std::uniform_int_distribution int_gen(1000, 10000); 28 | return prefix + std::to_string(int_gen(ran)); 29 | } 30 | 31 | } // namespace test 32 | } // namespace milvus -------------------------------------------------------------------------------- /test/st/MilvusServerTest.h: -------------------------------------------------------------------------------- 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 | #pragma once 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "milvus/MilvusClient.h" 26 | 27 | namespace milvus { 28 | namespace test { 29 | 30 | class MilvusServerTest : public ::testing::Test { 31 | protected: 32 | std::shared_ptr client_{nullptr}; 33 | 34 | void 35 | SetUp() override { 36 | milvus::ConnectParam connect_param{"localhost", 19530}; 37 | client_ = milvus::MilvusClient::Create(); 38 | client_->Connect(connect_param); 39 | } 40 | 41 | void 42 | TearDown() override { 43 | client_->Disconnect(); 44 | } 45 | }; 46 | 47 | template 48 | class MilvusServerTestWithParam : public ::testing::TestWithParam { 49 | protected: 50 | std::shared_ptr client_{nullptr}; 51 | 52 | void 53 | SetUp() override { 54 | milvus::ConnectParam connect_param{"localhost", 19530}; 55 | client_ = milvus::MilvusClient::Create(); 56 | client_->Connect(connect_param); 57 | } 58 | 59 | void 60 | TearDown() override { 61 | client_->Disconnect(); 62 | } 63 | }; 64 | 65 | std::string 66 | RanName(const std::string& prefix); 67 | 68 | } // namespace test 69 | } // namespace milvus 70 | -------------------------------------------------------------------------------- /test/st/TestConnectWithTls.cpp: -------------------------------------------------------------------------------- 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 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #include "MilvusServerTest.h" 24 | 25 | using testing::UnorderedElementsAre; 26 | using testing::UnorderedElementsAreArray; 27 | 28 | using milvus::test::MilvusServerTest; 29 | 30 | class MilvusServerTestWithTlsMode : public MilvusServerTest {}; 31 | 32 | TEST_F(MilvusServerTestWithTlsMode, GenericTest) { 33 | bool has; 34 | auto status = client_->HasCollection("nosuchcollection", has); 35 | EXPECT_TRUE(status.IsOk()); 36 | EXPECT_FALSE(has); 37 | 38 | // client without certifications 39 | milvus::ConnectParam param{"127.0.0.1", 19530}; 40 | param.EnableTls(); 41 | std::shared_ptr tempClient = milvus::MilvusClient::Create(); 42 | status = tempClient->Connect(param); 43 | EXPECT_FALSE(status.IsOk()); 44 | status = tempClient->HasCollection("nosuchcollection", has); 45 | EXPECT_FALSE(status.IsOk()); 46 | EXPECT_EQ(status.Code(), milvus::StatusCode::NOT_CONNECTED); 47 | } 48 | -------------------------------------------------------------------------------- /test/st/TestConnectWithUser.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include 20 | 21 | #include "MilvusServerTest.h" 22 | 23 | using milvus::test::MilvusServerTest; 24 | using testing::UnorderedElementsAre; 25 | using testing::UnorderedElementsAreArray; 26 | 27 | class MilvusServerTestWithAuth : public MilvusServerTest {}; 28 | 29 | TEST_F(MilvusServerTestWithAuth, GenericTest) { 30 | bool has; 31 | auto status = client_->HasCollection("nosuchcollection", has); 32 | EXPECT_TRUE(status.IsOk()); 33 | EXPECT_FALSE(has); 34 | 35 | // client without user/pass 36 | milvus::ConnectParam param{"127.0.0.1", 19530}; 37 | std::shared_ptr tempClient = milvus::MilvusClient::Create(); 38 | status = tempClient->Connect(param); 39 | status = tempClient->HasCollection("nosuchcollection", has); 40 | EXPECT_FALSE(status.IsOk()); 41 | EXPECT_NE(status.Code(), milvus::StatusCode::OK); 42 | } 43 | -------------------------------------------------------------------------------- /test/st/TestGeneric.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "MilvusServerTest.h" 20 | #include "gmock/gmock.h" 21 | 22 | using milvus::test::MilvusServerTest; 23 | 24 | class MilvusServerTestGeneric : public MilvusServerTest {}; 25 | 26 | TEST_F(MilvusServerTestGeneric, GetVersion) { 27 | std::string version; 28 | auto status = client_->GetVersion(version); 29 | EXPECT_TRUE(status.IsOk()); 30 | EXPECT_THAT(version, testing::StartsWith("v2.")); 31 | } 32 | -------------------------------------------------------------------------------- /test/ut/TestCollectionDesc.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "milvus/types/CollectionDesc.h" 20 | 21 | class CollectionDescTest : public ::testing::Test {}; 22 | 23 | TEST_F(CollectionDescTest, GeneralTesting) { 24 | milvus::CollectionDesc desc; 25 | milvus::CollectionSchema schema; 26 | 27 | desc.SetSchema(schema); 28 | desc.SetSchema(milvus::CollectionSchema{"foo"}); 29 | EXPECT_EQ(desc.Schema().Name(), "foo"); 30 | 31 | std::vector alias{"bar", "foobar"}; 32 | desc.SetAlias(alias); 33 | EXPECT_EQ(desc.Alias().size(), 2); 34 | 35 | desc.SetCreatedTime(10000); 36 | EXPECT_EQ(desc.CreatedTime(), 10000); 37 | } 38 | -------------------------------------------------------------------------------- /test/ut/TestCollectionInfo.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "milvus/types/CollectionInfo.h" 20 | 21 | class CollectionInfoTest : public ::testing::Test {}; 22 | 23 | TEST_F(CollectionInfoTest, GeneralTesting) { 24 | std::string name = "test"; 25 | int64_t id = 1; 26 | uint64_t created_ts = 100; 27 | uint64_t in_memory_percent = 50; 28 | 29 | milvus::CollectionInfo info(name, id, created_ts, in_memory_percent); 30 | EXPECT_EQ(name, info.Name()); 31 | EXPECT_EQ(id, info.ID()); 32 | EXPECT_EQ(created_ts, info.CreatedTime()); 33 | EXPECT_EQ(in_memory_percent, info.MemoryPercentage()); 34 | 35 | milvus::CollectionInfo info_bar; 36 | EXPECT_EQ("", info_bar.Name()); 37 | EXPECT_EQ(0, info_bar.ID()); 38 | EXPECT_EQ(0, info_bar.CreatedTime()); 39 | EXPECT_EQ(0, info_bar.MemoryPercentage()); 40 | } 41 | -------------------------------------------------------------------------------- /test/ut/TestCollectionSchema.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "milvus/types/CollectionSchema.h" 20 | 21 | class CollectionSchemaTest : public ::testing::Test {}; 22 | 23 | TEST_F(CollectionSchemaTest, GeneralTesting) { 24 | milvus::CollectionSchema schema; 25 | schema.SetName("test"); 26 | schema.SetDescription("test"); 27 | 28 | milvus::FieldSchema id_field{"foo", milvus::DataType::INT64, "foo"}; 29 | EXPECT_TRUE(schema.AddField(id_field)); 30 | EXPECT_FALSE(schema.AddField(id_field)); 31 | 32 | EXPECT_TRUE(schema.AddField(milvus::FieldSchema("bar", milvus::DataType::FLOAT_VECTOR, "bar"))); 33 | EXPECT_FALSE(schema.AddField(milvus::FieldSchema("bar", milvus::DataType::FLOAT_VECTOR, "bar"))); 34 | 35 | EXPECT_EQ(schema.ShardsNum(), 2); 36 | EXPECT_EQ(schema.Fields().size(), 2); 37 | EXPECT_EQ(schema.AnnsFieldNames().size(), 1); 38 | EXPECT_EQ(*schema.AnnsFieldNames().begin(), "bar"); 39 | } 40 | -------------------------------------------------------------------------------- /test/ut/TestCollectionStat.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "milvus/types/CollectionStat.h" 20 | #include "milvus/types/Constant.h" 21 | 22 | class CollectionStatTest : public ::testing::Test {}; 23 | 24 | TEST_F(CollectionStatTest, GeneralTesting) { 25 | milvus::CollectionStat stat; 26 | stat.SetName("test"); 27 | EXPECT_EQ(stat.Name(), "test"); 28 | EXPECT_EQ(stat.RowCount(), 0); 29 | stat.Emplace(milvus::KeyRowCount(), "1000"); 30 | EXPECT_EQ(stat.RowCount(), 1000); 31 | } 32 | -------------------------------------------------------------------------------- /test/ut/TestCompactionPlan.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "milvus/types/CompactionPlan.h" 20 | 21 | class CompactionPlanTest : public ::testing::Test {}; 22 | 23 | TEST_F(CompactionPlanTest, GeneralTesting) { 24 | int64_t dst_segment = 4; 25 | 26 | milvus::CompactionPlan plan; 27 | plan.SetSourceSegments({1, 2, 3}); 28 | plan.SetDestinySegemnt(dst_segment); 29 | EXPECT_EQ(3, plan.SourceSegments().size()); 30 | EXPECT_EQ(dst_segment, plan.DestinySegemnt()); 31 | 32 | milvus::CompactionPlan plan_foo{std::vector{1, 2, 3}, dst_segment}; 33 | auto segments = plan_foo.SourceSegments(); 34 | plan_foo.SetSourceSegments(segments); 35 | EXPECT_EQ(plan_foo.SourceSegments(), segments); 36 | } 37 | -------------------------------------------------------------------------------- /test/ut/TestCompactionState.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "milvus/types/CompactionState.h" 20 | 21 | class CompactionStateTest : public ::testing::Test {}; 22 | 23 | TEST_F(CompactionStateTest, GeneralTesting) { 24 | int64_t executing = 1; 25 | int64_t timeout = 2; 26 | int64_t completed = 3; 27 | 28 | milvus::CompactionStateCode state_code = milvus::CompactionStateCode::EXECUTING; 29 | 30 | milvus::CompactionState state; 31 | state.SetState(state_code); 32 | state.SetExecutingPlan(executing); 33 | state.SetTimeoutPlan(timeout); 34 | state.SetCompletedPlan(completed); 35 | EXPECT_EQ(state_code, state.State()); 36 | EXPECT_EQ(executing, state.ExecutingPlan()); 37 | EXPECT_EQ(timeout, state.TimeoutPlan()); 38 | EXPECT_EQ(completed, state.CompletedPlan()); 39 | } 40 | -------------------------------------------------------------------------------- /test/ut/TestConnectParam.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "milvus/types/ConnectParam.h" 20 | 21 | class ConnectParamTest : public ::testing::Test {}; 22 | 23 | TEST_F(ConnectParamTest, GeneralTesting) { 24 | milvus::ConnectParam param{"localhost", 10000}; 25 | EXPECT_EQ(param.Host(), "localhost"); 26 | EXPECT_EQ(param.Port(), 10000); 27 | EXPECT_EQ(param.Uri(), "localhost:10000"); 28 | EXPECT_EQ(param.ConnectTimeout(), 5000); 29 | 30 | param.SetConnectTimeout(1000); 31 | EXPECT_EQ(param.ConnectTimeout(), 1000); 32 | 33 | param.EnableTls(); 34 | EXPECT_TRUE(param.TlsEnabled()); 35 | 36 | param.EnableTls("local", "ca"); 37 | EXPECT_TRUE(param.TlsEnabled()); 38 | EXPECT_EQ(param.ServerName(), "local"); 39 | EXPECT_EQ(param.CaCert(), "ca"); 40 | EXPECT_EQ(param.Cert(), ""); 41 | EXPECT_EQ(param.Key(), ""); 42 | 43 | param.EnableTls("local", "a", "b", "c"); 44 | EXPECT_EQ(param.Cert(), "a"); 45 | EXPECT_EQ(param.Key(), "b"); 46 | 47 | param.DisableTls(); 48 | EXPECT_FALSE(param.TlsEnabled()); 49 | } 50 | -------------------------------------------------------------------------------- /test/ut/TestDistanceArray.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "milvus/types/DistanceArray.h" 20 | 21 | class DistanceArrayTest : public ::testing::Test {}; 22 | 23 | TEST_F(DistanceArrayTest, GeneralTesting) { 24 | std::vector> array_foo = {{1, 2, 3}, {2, 3, 4}}; 25 | std::vector> array_bar = {{1.f, 2.f, 3.f}, {2.f, 3.f, 4.f}}; 26 | 27 | milvus::DistanceArray distance_array; 28 | EXPECT_FALSE(distance_array.IsIntegerDistance()); 29 | 30 | distance_array = milvus::DistanceArray(array_foo); 31 | EXPECT_TRUE(distance_array.IsIntegerDistance()); 32 | EXPECT_EQ(distance_array.IntDistanceArray(), array_foo); 33 | 34 | distance_array = milvus::DistanceArray(array_bar); 35 | EXPECT_FALSE(distance_array.IsIntegerDistance()); 36 | EXPECT_EQ(distance_array.FloatDistanceArray(), array_bar); 37 | 38 | distance_array.SetIntDistance(array_foo); 39 | EXPECT_TRUE(distance_array.IsIntegerDistance()); 40 | EXPECT_EQ(distance_array.IntDistanceArray(), array_foo); 41 | 42 | distance_array.SetFloatDistance(array_bar); 43 | EXPECT_FALSE(distance_array.IsIntegerDistance()); 44 | EXPECT_EQ(distance_array.FloatDistanceArray(), array_bar); 45 | 46 | distance_array = milvus::DistanceArray(std::move(array_foo)); 47 | EXPECT_TRUE(distance_array.IsIntegerDistance()); 48 | array_foo = distance_array.IntDistanceArray(); 49 | 50 | distance_array = milvus::DistanceArray(std::move(array_bar)); 51 | EXPECT_FALSE(distance_array.IsIntegerDistance()); 52 | array_bar = distance_array.FloatDistanceArray(); 53 | 54 | distance_array.SetIntDistance(std::move(array_foo)); 55 | EXPECT_TRUE(distance_array.IsIntegerDistance()); 56 | 57 | distance_array.SetFloatDistance(std::move(array_bar)); 58 | EXPECT_FALSE(distance_array.IsIntegerDistance()); 59 | } 60 | -------------------------------------------------------------------------------- /test/ut/TestDmlResults.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Licensed to the LF AI & Data foundation 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, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | #include 19 | 20 | #include "milvus/types/DmlResults.h" 21 | 22 | class DmlResultsTest : public ::testing::Test {}; 23 | 24 | TEST_F(DmlResultsTest, GeneralTesting) { 25 | milvus::DmlResults dml_results; 26 | milvus::IDArray id_array{std::vector{10000, 20000}}; 27 | dml_results.SetIdArray(id_array); 28 | dml_results.SetTimestamp(10000); 29 | EXPECT_EQ(dml_results.IdArray().IntIDArray(), id_array.IntIDArray()); 30 | EXPECT_EQ(dml_results.Timestamp(), 10000); 31 | } 32 | -------------------------------------------------------------------------------- /test/ut/TestDummy.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | class DummyTest : public ::testing::Test {}; 20 | 21 | TEST_F(DummyTest, Foo) { 22 | EXPECT_EQ(0, 0); 23 | } -------------------------------------------------------------------------------- /test/ut/TestHybirdTimestamp.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "milvus/types/HybridTimestamp.h" 20 | 21 | class HybridTimestampTest : public ::testing::Test {}; 22 | 23 | TEST_F(HybridTimestampTest, GeneralTesting) { 24 | milvus::HybridTimestamp foo{}; 25 | EXPECT_EQ(foo.Timestamp(), 0); 26 | EXPECT_EQ(foo.Logical(), 0); 27 | EXPECT_EQ(foo.Physical(), 0); 28 | 29 | milvus::HybridTimestamp bar{1, 1}; 30 | EXPECT_EQ(bar.Timestamp(), (1 << 18) + 1); 31 | EXPECT_EQ(bar.Logical(), 1); 32 | EXPECT_EQ(bar.Physical(), 1); 33 | 34 | foo += 1ULL; 35 | EXPECT_EQ(foo.Logical(), 0); 36 | EXPECT_EQ(foo.Physical(), 1); 37 | 38 | foo += std::chrono::seconds{1}; 39 | EXPECT_EQ(foo.Logical(), 0); 40 | EXPECT_EQ(foo.Physical(), 1001); 41 | 42 | bar = foo + std::chrono::seconds{1}; 43 | EXPECT_EQ(bar.Logical(), 0); 44 | EXPECT_EQ(bar.Physical(), 2001); 45 | 46 | bar = milvus::HybridTimestamp::CreateFromUnixTime(1000); 47 | EXPECT_EQ(bar.Logical(), 0); 48 | EXPECT_EQ(bar.Physical(), 1000); 49 | 50 | milvus::HybridTimestamp ts_a = milvus::HybridTimestamp::CreateFromUnixTime(3); 51 | milvus::HybridTimestamp ts_b{ts_a.Timestamp()}; 52 | EXPECT_EQ(ts_a.Logical(), ts_b.Logical()); 53 | EXPECT_EQ(ts_a.Physical(), ts_b.Physical()); 54 | } 55 | -------------------------------------------------------------------------------- /test/ut/TestIDArray.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "milvus/types/IDArray.h" 20 | 21 | class IDArrayTest : public ::testing::Test {}; 22 | 23 | TEST_F(IDArrayTest, GeneralTesting) { 24 | { 25 | std::vector ids = {1, 2, 3}; 26 | milvus::IDArray id_array_foo(ids); 27 | EXPECT_TRUE(id_array_foo.IsIntegerID()); 28 | EXPECT_EQ(id_array_foo.IntIDArray().size(), 3); 29 | EXPECT_TRUE(id_array_foo.StrIDArray().empty()); 30 | 31 | milvus::IDArray id_array_bar(std::move(ids)); 32 | EXPECT_TRUE(id_array_bar.IsIntegerID()); 33 | EXPECT_EQ(id_array_bar.IntIDArray().size(), 3); 34 | EXPECT_TRUE(id_array_bar.StrIDArray().empty()); 35 | } 36 | 37 | { 38 | std::vector ids = {"a", "b", "c"}; 39 | milvus::IDArray id_array_foo(ids); 40 | EXPECT_FALSE(id_array_foo.IsIntegerID()); 41 | EXPECT_EQ(id_array_foo.StrIDArray().size(), 3); 42 | EXPECT_TRUE(id_array_foo.IntIDArray().empty()); 43 | 44 | milvus::IDArray id_array_bar(std::move(ids)); 45 | EXPECT_FALSE(id_array_bar.IsIntegerID()); 46 | EXPECT_EQ(id_array_bar.StrIDArray().size(), 3); 47 | EXPECT_TRUE(id_array_bar.IntIDArray().empty()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /test/ut/TestIndexDesc.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "milvus/types/IndexDesc.h" 20 | 21 | class IndexDescTest : public ::testing::Test {}; 22 | 23 | TEST_F(IndexDescTest, GeneralTesting) { 24 | milvus::IndexDesc index_desc; 25 | 26 | index_desc.SetFieldName("field_name"); 27 | EXPECT_EQ(index_desc.FieldName(), "field_name"); 28 | 29 | index_desc.SetIndexName("index_name"); 30 | EXPECT_EQ(index_desc.IndexName(), "index_name"); 31 | 32 | index_desc.SetIndexId(1); 33 | EXPECT_EQ(index_desc.IndexId(), 1); 34 | 35 | index_desc.SetIndexType(milvus::IndexType::IVF_FLAT); 36 | EXPECT_EQ(index_desc.IndexType(), milvus::IndexType::IVF_FLAT); 37 | 38 | index_desc.SetMetricType(milvus::MetricType::L2); 39 | EXPECT_EQ(index_desc.MetricType(), milvus::MetricType::L2); 40 | } 41 | -------------------------------------------------------------------------------- /test/ut/TestPartitionStat.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "milvus/types/PartitionStat.h" 20 | 21 | class PartitionStatTest : public ::testing::Test {}; 22 | 23 | TEST_F(PartitionStatTest, GeneralTesting) { 24 | milvus::PartitionStat stat; 25 | stat.SetName("foo"); 26 | EXPECT_EQ(stat.Name(), "foo"); 27 | EXPECT_EQ(stat.RowCount(), 0); 28 | 29 | stat.Emplace("row_count", "1000"); 30 | EXPECT_EQ(stat.RowCount(), 1000); 31 | } 32 | -------------------------------------------------------------------------------- /test/ut/TestProgressMonitor.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include 20 | 21 | #include "milvus/types/ProgressMonitor.h" 22 | 23 | class ProgressMonitorTest : public ::testing::Test {}; 24 | 25 | TEST_F(ProgressMonitorTest, DefaultSetting) { 26 | milvus::ProgressMonitor pm; 27 | EXPECT_EQ(pm.CheckTimeout(), 60); 28 | EXPECT_EQ(pm.CheckInterval(), 500); 29 | 30 | auto no_wait = milvus::ProgressMonitor::NoWait(); 31 | EXPECT_EQ(no_wait.CheckTimeout(), 0); 32 | 33 | auto forever = milvus::ProgressMonitor::Forever(); 34 | EXPECT_EQ(forever.CheckTimeout(), std::numeric_limits::max()); 35 | } 36 | 37 | TEST_F(ProgressMonitorTest, Setting) { 38 | milvus::ProgressMonitor pm{100}; 39 | EXPECT_EQ(pm.CheckTimeout(), 100); 40 | 41 | pm.SetCheckInterval(100); 42 | EXPECT_EQ(pm.CheckInterval(), 100); 43 | } 44 | 45 | TEST_F(ProgressMonitorTest, Callback) { 46 | milvus::Progress progress(50, 100); 47 | auto func = [&](milvus::Progress& p) -> void { 48 | EXPECT_EQ(p.finished_, progress.finished_); 49 | EXPECT_EQ(p.total_, progress.total_); 50 | }; 51 | 52 | milvus::ProgressMonitor pm; 53 | pm.SetCallbackFunc(func); 54 | pm.DoProgress(progress); 55 | } 56 | -------------------------------------------------------------------------------- /test/ut/TestQueryArguments.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "milvus/types/QueryArguments.h" 20 | 21 | class QueryArgumentsTest : public ::testing::Test {}; 22 | 23 | TEST_F(QueryArgumentsTest, GeneralTesting) { 24 | milvus::QueryArguments arguments; 25 | 26 | std::string empty_name; 27 | std::string collection_name = "test"; 28 | arguments.SetCollectionName(collection_name); 29 | EXPECT_FALSE(arguments.SetCollectionName(empty_name).IsOk()); 30 | EXPECT_EQ(collection_name, arguments.CollectionName()); 31 | 32 | std::string partition_name = "p1"; 33 | arguments.AddPartitionName(partition_name); 34 | EXPECT_FALSE(arguments.AddPartitionName(empty_name).IsOk()); 35 | EXPECT_EQ(1, arguments.PartitionNames().size()); 36 | auto names = arguments.PartitionNames(); 37 | EXPECT_TRUE(names.find(partition_name) != names.end()); 38 | 39 | std::string field_name = "f1"; 40 | arguments.AddOutputField(field_name); 41 | EXPECT_FALSE(arguments.AddOutputField(empty_name).IsOk()); 42 | EXPECT_EQ(1, arguments.OutputFields().size()); 43 | auto field_names = arguments.OutputFields(); 44 | EXPECT_TRUE(field_names.find(field_name) != field_names.end()); 45 | 46 | std::string expression = "expr"; 47 | arguments.SetExpression(expression); 48 | EXPECT_FALSE(arguments.SetExpression(empty_name).IsOk()); 49 | EXPECT_EQ(expression, arguments.Expression()); 50 | 51 | uint64_t ts = 1000; 52 | arguments.SetTravelTimestamp(ts); 53 | EXPECT_EQ(ts, arguments.TravelTimestamp()); 54 | arguments.SetGuaranteeTimestamp(ts); 55 | EXPECT_EQ(ts, arguments.GuaranteeTimestamp()); 56 | } 57 | -------------------------------------------------------------------------------- /test/ut/TestQueryResults.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "milvus/types/QueryResults.h" 20 | 21 | class QueryResultsTest : public ::testing::Test {}; 22 | 23 | TEST_F(QueryResultsTest, GeneralTesting) { 24 | std::vector fields{ 25 | nullptr, 26 | std::make_shared("bool_data"), 27 | std::make_shared("int16_data"), 28 | }; 29 | 30 | milvus::QueryResults results(fields); 31 | EXPECT_EQ(results.GetFieldByName("foo"), nullptr); 32 | EXPECT_EQ(results.GetFieldByName("int16_data")->Name(), "int16_data"); 33 | 34 | EXPECT_EQ(results.OutputFields().front(), nullptr); 35 | } 36 | -------------------------------------------------------------------------------- /test/ut/TestSearchResults.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "milvus/types/SearchResults.h" 20 | 21 | class SearchResultsTest : public ::testing::Test {}; 22 | 23 | TEST_F(SearchResultsTest, TestSingleResult) { 24 | milvus::SingleResult result{ 25 | milvus::IDArray{std::vector{10000}}, std::vector{0.1f}, 26 | std::vector{std::make_shared("bool", std::vector{true}), 27 | std::make_shared("int16", std::vector{1})}}; 28 | EXPECT_EQ(result.Ids().IntIDArray(), std::vector{10000}); 29 | EXPECT_EQ(result.Scores(), std::vector{0.1f}); 30 | EXPECT_EQ(result.OutputField("bool")->Name(), "bool"); 31 | EXPECT_EQ(result.OutputField("int16")->Name(), "int16"); 32 | EXPECT_EQ(result.OutputField("invalid"), nullptr); 33 | EXPECT_EQ(result.OutputFields().size(), 2); 34 | } 35 | 36 | TEST_F(SearchResultsTest, GeneralTesting) { 37 | milvus::IDArray ids{std::vector{}}; 38 | std::vector scores{}; 39 | std::vector fields{}; 40 | 41 | std::vector result_array = { 42 | milvus::SingleResult(std::move(ids), std::move(scores), std::move(fields))}; 43 | 44 | milvus::SearchResults results(std::move(result_array)); 45 | EXPECT_EQ(1, results.Results().size()); 46 | } 47 | -------------------------------------------------------------------------------- /test/ut/TestSegmentInfo.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "milvus/types/SegmentInfo.h" 20 | 21 | class SegmentInfoTest : public ::testing::Test {}; 22 | 23 | TEST_F(SegmentInfoTest, GeneralTesting) { 24 | int64_t collection_id = 1; 25 | int64_t partition_id = 2; 26 | int64_t segment_id = 3; 27 | int64_t row_count = 4; 28 | 29 | milvus::SegmentState state = milvus::SegmentState::GROWING; 30 | 31 | milvus::SegmentInfo info(collection_id, partition_id, segment_id, row_count, state); 32 | EXPECT_EQ(collection_id, info.CollectionID()); 33 | EXPECT_EQ(partition_id, info.PartitionID()); 34 | EXPECT_EQ(segment_id, info.SegmentID()); 35 | EXPECT_EQ(row_count, info.RowCount()); 36 | EXPECT_EQ(state, info.State()); 37 | 38 | std::string index_name = "IVF_FLAT"; 39 | int64_t index_id = 5; 40 | int64_t node_id = 6; 41 | milvus::QuerySegmentInfo query_info(collection_id, partition_id, segment_id, row_count, state, index_name, index_id, 42 | node_id); 43 | EXPECT_EQ(index_name, query_info.IndexName()); 44 | EXPECT_EQ(index_id, query_info.IndexID()); 45 | EXPECT_EQ(node_id, query_info.NodeID()); 46 | } 47 | -------------------------------------------------------------------------------- /test/ut/TestStatus.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | #include "milvus/Status.h" 20 | 21 | class StatusTest : public ::testing::Test {}; 22 | 23 | TEST_F(StatusTest, DefaultStatus) { 24 | milvus::Status status; 25 | EXPECT_TRUE(status.IsOk()); 26 | EXPECT_EQ(status.Message(), "OK"); 27 | EXPECT_EQ(status.Code(), milvus::StatusCode::OK); 28 | } 29 | 30 | TEST_F(StatusTest, StatusOK) { 31 | milvus::Status status = milvus::Status::OK(); 32 | EXPECT_TRUE(status.IsOk()); 33 | EXPECT_EQ(status.Message(), "OK"); 34 | EXPECT_EQ(status.Code(), milvus::StatusCode::OK); 35 | } 36 | 37 | TEST_F(StatusTest, ConstructorWithFailed) { 38 | milvus::Status status{milvus::StatusCode::SERVER_FAILED, "server failed"}; 39 | EXPECT_FALSE(status.IsOk()); 40 | EXPECT_EQ(status.Message(), "server failed"); 41 | EXPECT_EQ(status.Code(), milvus::StatusCode::SERVER_FAILED); 42 | } 43 | 44 | TEST_F(StatusTest, CopyConstructor) { 45 | milvus::Status statusFoo{milvus::StatusCode::SERVER_FAILED, "server failed"}; 46 | auto status = milvus::Status(statusFoo); 47 | EXPECT_FALSE(status.IsOk()); 48 | EXPECT_EQ(status.Message(), "server failed"); 49 | EXPECT_EQ(status.Code(), milvus::StatusCode::SERVER_FAILED); 50 | } 51 | 52 | TEST_F(StatusTest, MoveConstructor) { 53 | milvus::Status statusFoo{milvus::StatusCode::SERVER_FAILED, "server failed"}; 54 | auto status = milvus::Status(std::move(statusFoo)); 55 | EXPECT_FALSE(status.IsOk()); 56 | EXPECT_EQ(status.Message(), "server failed"); 57 | EXPECT_EQ(status.Code(), milvus::StatusCode::SERVER_FAILED); 58 | } -------------------------------------------------------------------------------- /thirdparty/thirdparty.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milvus-io/milvus-sdk-cpp/a0592aaa5d7191e35246d9aaf372eabab414de4f/thirdparty/thirdparty.md --------------------------------------------------------------------------------