diff --git a/cpp/CHANGELOG.md b/cpp/CHANGELOG.md index 263f4a787a0cde03db00f4937e8714e232ac217c..489228eca8aae8211890c99b74f08c75d5f38c56 100644 --- a/cpp/CHANGELOG.md +++ b/cpp/CHANGELOG.md @@ -16,3 +16,4 @@ Please mark all change in change log and use the ticket from JIRA. - MS-1 - Add CHANGELOG.md - MS-4 - Refactor the vecwise_engine code structure +- MS-6 - Implement SDK interface part 1 diff --git a/cpp/src/sdk/src/interface/ConnectionImpl.cpp b/cpp/src/sdk/src/interface/ConnectionImpl.cpp index 26fb5ff209928c49facf5384e726fe772ccad53a..69612ad8b4748a9a667df41068fbd132a6efb0d1 100644 --- a/cpp/src/sdk/src/interface/ConnectionImpl.cpp +++ b/cpp/src/sdk/src/interface/ConnectionImpl.cpp @@ -22,59 +22,59 @@ Connection::Destroy(std::shared_ptr connection_ptr) { ////////////////////////////////////////////////////////////////////////////////////////////// ConnectionImpl::ConnectionImpl() { - client_proxy = std::make_shared(); + client_proxy_ = std::make_shared(); } Status ConnectionImpl::Connect(const ConnectParam ¶m) { - return client_proxy->Connect(param); + return client_proxy_->Connect(param); } Status ConnectionImpl::Connect(const std::string &uri) { - return client_proxy->Connect(uri); + return client_proxy_->Connect(uri); } Status ConnectionImpl::Connected() const { - return client_proxy->Connected(); + return client_proxy_->Connected(); } Status ConnectionImpl::Disconnect() { - return client_proxy->Disconnect(); + return client_proxy_->Disconnect(); } std::string ConnectionImpl::ClientVersion() const { - return client_proxy->ClientVersion(); + return client_proxy_->ClientVersion(); } Status ConnectionImpl::CreateTable(const TableSchema ¶m) { - return client_proxy->CreateTable(param); + return client_proxy_->CreateTable(param); } Status ConnectionImpl::CreateTablePartition(const CreateTablePartitionParam ¶m) { - return client_proxy->CreateTablePartition(param); + return client_proxy_->CreateTablePartition(param); } Status ConnectionImpl::DeleteTablePartition(const DeleteTablePartitionParam ¶m) { - return client_proxy->DeleteTablePartition(param); + return client_proxy_->DeleteTablePartition(param); } Status ConnectionImpl::DeleteTable(const std::string &table_name) { - return client_proxy->DeleteTable(table_name); + return client_proxy_->DeleteTable(table_name); } Status ConnectionImpl::AddVector(const std::string &table_name, const std::vector &record_array, std::vector &id_array) { - return client_proxy->AddVector(table_name, record_array, id_array); + return client_proxy_->AddVector(table_name, record_array, id_array); } Status @@ -82,27 +82,27 @@ ConnectionImpl::SearchVector(const std::string &table_name, const std::vector &query_record_array, std::vector &topk_query_result_array, int64_t topk) { - return client_proxy->SearchVector(table_name, query_record_array, topk_query_result_array, topk); + return client_proxy_->SearchVector(table_name, query_record_array, topk_query_result_array, topk); } Status ConnectionImpl::DescribeTable(const std::string &table_name, TableSchema &table_schema) { - return client_proxy->DescribeTable(table_name, table_schema); + return client_proxy_->DescribeTable(table_name, table_schema); } Status ConnectionImpl::ShowTables(std::vector &table_array) { - return client_proxy->ShowTables(table_array); + return client_proxy_->ShowTables(table_array); } std::string ConnectionImpl::ServerVersion() const { - return client_proxy->ServerVersion(); + return client_proxy_->ServerVersion(); } std::string ConnectionImpl::ServerStatus() const { - return client_proxy->ServerStatus(); + return client_proxy_->ServerStatus(); } } diff --git a/cpp/src/sdk/src/interface/ConnectionImpl.h b/cpp/src/sdk/src/interface/ConnectionImpl.h index 624bbebde55032b35ec668b9971dbf2fa58c91c3..0c67ea3f4259c53d99f7fd4a09197c8b53932693 100644 --- a/cpp/src/sdk/src/interface/ConnectionImpl.h +++ b/cpp/src/sdk/src/interface/ConnectionImpl.h @@ -51,7 +51,7 @@ public: virtual std::string ServerStatus() const override; private: - std::shared_ptr client_proxy; + std::shared_ptr client_proxy_; }; } diff --git a/cpp/src/sdk/src/util/ConvertUtil.cpp b/cpp/src/sdk/src/util/ConvertUtil.cpp index 90cab3fdb42cfcae26b640b4702c136a9dc095a3..577f5de446abdb37d1397e71e80dd30c00c48f7a 100644 --- a/cpp/src/sdk/src/util/ConvertUtil.cpp +++ b/cpp/src/sdk/src/util/ConvertUtil.cpp @@ -4,6 +4,7 @@ * Proprietary and confidential. ******************************************************************************/ #include "ConvertUtil.h" +#include "Exception.h" #include @@ -20,7 +21,7 @@ std::string ConvertUtil::IndexType2Str(megasearch::IndexType index) { const auto& iter = s_index2str.find(index); if(iter == s_index2str.end()) { - return INDEX_RAW; + throw Exception(StatusCode::Invalid, "Invalid index type"); } return iter->second; @@ -34,7 +35,7 @@ megasearch::IndexType ConvertUtil::Str2IndexType(const std::string& type) { const auto& iter = s_str2index.find(type); if(iter == s_str2index.end()) { - return megasearch::IndexType::raw; + throw Exception(StatusCode::Invalid, "Invalid index type"); } return iter->second; diff --git a/cpp/src/sdk/src/util/Exception.h b/cpp/src/sdk/src/util/Exception.h new file mode 100644 index 0000000000000000000000000000000000000000..7e31b182a6f7de540884cbfa87dd07669a79828b --- /dev/null +++ b/cpp/src/sdk/src/util/Exception.h @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited. + * Proprietary and confidential. + ******************************************************************************/ +#pragma once + +#include "Status.h" + +#include + +namespace megasearch { +class Exception : public std::exception { +public: + Exception(StatusCode error_code, + const std::string &message = std::string()) + : error_code_(error_code), message_(message) {} + +public: + StatusCode error_code() const { + return error_code_; + } + + virtual const char *what() const noexcept { + return message_.c_str(); + } + +private: + StatusCode error_code_; + std::string message_; +}; +} \ No newline at end of file