提交 08a62e30 编写于 作者: Z zhenshan.cao 提交者: yefu.chen

Refactor SDK

Signed-off-by: Nzhenshan.cao <zhenshan.cao@zilliz.com>
上级 ece87075
......@@ -66,6 +66,7 @@ endif ()
aux_source_directory(interface interface_files)
aux_source_directory(grpc grpc_client_files)
aux_source_directory(utils utils_files)
set(grpc_service_files
grpc-gen/message.grpc.pb.cc
......@@ -84,6 +85,7 @@ add_library(milvus_sdk SHARED
${interface_files}
${grpc_client_files}
${grpc_service_files}
${utils_files}
)
target_link_libraries(milvus_sdk
......
......@@ -12,14 +12,3 @@
#-------------------------------------------------------------------------------
add_subdirectory(simple)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/utils UTIL_SRC_FILES)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/common COMMON_SRC_FILES)
file( GLOB APP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp )
foreach( sourcefile ${APP_SOURCES} )
file(RELATIVE_PATH filename ${CMAKE_CURRENT_SOURCE_DIR} ${sourcefile})
string( REPLACE ".cpp" "" program ${filename} )
add_executable( ${program} ${sourcefile} ${COMMON_SRC_FILES} ${UTIL_SRC_FILES})
target_link_libraries( ${program} milvus_sdk pthread )
install(TARGETS ${program} DESTINATION bin)
endforeach( sourcefile ${APP_SOURCES} )
add_executable(search search.cpp)
target_link_libraries(search milvus_sdk pthread)
install(TARGETS search DESTINATION test)
add_executable(insert insert.cpp)
target_link_libraries(insert milvus_sdk pthread)
install(TARGETS insert DESTINATION test)
add_executable(delete delete.cpp)
target_link_libraries(delete milvus_sdk pthread)
install(TARGETS delete DESTINATION test)
add_executable(create CreateCollection.cpp)
target_link_libraries(create milvus_sdk pthread)
install(TARGETS create DESTINATION test)
\ No newline at end of file
#-------------------------------------------------------------------------------
# Copyright (C) 2019-2020 Zilliz. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under the License.
#-------------------------------------------------------------------------------
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../common COMMON_SRC_FILES)
file( GLOB APP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp )
foreach( sourcefile ${APP_SOURCES} )
file(RELATIVE_PATH filename ${CMAKE_CURRENT_SOURCE_DIR} ${sourcefile})
string( REPLACE ".cpp" "" program ${filename} )
add_executable( ${program} ${sourcefile} ${COMMON_SRC_FILES})
target_link_libraries( ${program} milvus_sdk pthread )
install(TARGETS ${program} DESTINATION bin)
endforeach( sourcefile ${APP_SOURCES} )
......@@ -3,12 +3,18 @@
#include <Field.h>
#include <MilvusApi.h>
#include <interface/ConnectionImpl.h>
#include "utils/Utils.h"
int main() {
int main(int argc , char**argv) {
TestParameters parameters = milvus_sdk::Utils::ParseTestParameters(argc, argv);
if (!parameters.is_valid){
return 0;
}
auto client = milvus::ConnectionImpl();
milvus::ConnectParam connect_param;
connect_param.ip_address = "localhost";
connect_param.port = "19530";
connect_param.ip_address = parameters.address_.empty() ? "127.0.0.1":parameters.address_;
connect_param.port = parameters.port_.empty() ? "19530":parameters.port_ ;
client.Connect(connect_param);
milvus::Status stat;
......
......@@ -13,16 +13,19 @@
#include <libgen.h>
#include <cstring>
#include <string>
#include "interface/ConnectionImpl.h"
#include "ip.h"
#include "utils/Utils.h"
int
main(int argc, char *argv[]) {
TestParameters parameters = milvus_sdk::Utils::ParseTestParameters(argc, argv);
if (!parameters.is_valid){
return 0;
}
auto client = milvus::ConnectionImpl();
milvus::ConnectParam connect_param;
connect_param.ip_address = IP;
connect_param.port = "19530";
connect_param.ip_address = parameters.address_.empty() ? "127.0.0.1":parameters.address_;
connect_param.port = parameters.port_.empty() ? "19530":parameters.port_ ;
client.Connect(connect_param);
std::vector<int64_t> delete_ids;
......
......@@ -15,17 +15,19 @@
#include <string>
#include <iostream>
#include "examples/utils/Utils.h"
#include "utils/Utils.h"
#include "grpc/ClientProxy.h"
#include "interface/ConnectionImpl.h"
#include "ip.h"
#include "utils/TimeRecorder.h"
const int N = 100;
const int DIM = 16;
const int LOOP = 10;
const milvus::FieldValue GetData() {
milvus::FieldValue value_map;
std::vector<int32_t> int32_data;
for (int i = 0; i < N; i++) {
int32_data.push_back(i);
......@@ -46,15 +48,29 @@ const milvus::FieldValue GetData() {
int
main(int argc, char* argv[]) {
auto client = milvus::ConnectionImpl();
milvus::ConnectParam connect_param;
connect_param.ip_address = IP;
connect_param.port = "19530";
client.Connect(connect_param);
std::vector <int64_t> ids_array;
auto data = GetData();
for (int64_t i = 0; i < N; i++) {
ids_array.push_back(i);
}
auto status = client.Insert("collection1", "tag01", data, ids_array);
TestParameters parameters = milvus_sdk::Utils::ParseTestParameters(argc, argv);
if (!parameters.is_valid){
return 0;
}
auto client = milvus::ConnectionImpl();
milvus::ConnectParam connect_param;
connect_param.ip_address = parameters.address_.empty() ? "127.0.0.1":parameters.address_;
connect_param.port = parameters.port_.empty() ? "19530":parameters.port_ ;
client.Connect(connect_param);
std::vector<int64_t> ids_array;
auto data = GetData();
for (int64_t i = 0; i < N; i++) {
ids_array.push_back(i);
}
milvus_sdk::TimeRecorder insert("insert");
for (int j = 0; j < LOOP; ++j) {
auto status = client.Insert("collection1", "tag01", data, ids_array);
if (!status.ok()){
return -1;
}
}
return 0;
}
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under the License.
const std::string IP = "localhost";
//const std::string IP = "192.168.2.9";
//const std::string IP = "192.168.2.28";
\ No newline at end of file
......@@ -15,15 +15,21 @@
#include "include/MilvusApi.h"
#include "grpc/ClientProxy.h"
#include "interface/ConnectionImpl.h"
#include "ip.h"
#include "utils/TimeRecorder.h"
#include "utils/Utils.h"
const int TOP_K = 10;
int main(int argc , char**argv) {
TestParameters parameters = milvus_sdk::Utils::ParseTestParameters(argc, argv);
if (!parameters.is_valid){
return 0;
}
auto client = milvus::ConnectionImpl();
milvus::ConnectParam connect_param;
connect_param.ip_address = IP;
connect_param.port = "19530";
connect_param.ip_address = parameters.address_.empty() ? "127.0.0.1":parameters.address_;
connect_param.port = parameters.port_.empty() ? "19530":parameters.port_ ;
client.Connect(connect_param);
std::vector<int64_t> ids_array;
std::vector<std::string> partition_list;
......@@ -56,13 +62,9 @@ int main(int argc , char**argv) {
milvus::TopKQueryResult result;
auto t1 = std::chrono::high_resolution_clock::now();
milvus_sdk::TimeRecorder test_search("search");
auto status = client.Search("collection1", partition_list, "dsl", vectorParam, result);
auto t2 = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
std::cout << "Query run time: " << duration/1000.0 << "ms" << std::endl;
return 0;
return 0;
}
......@@ -407,32 +407,24 @@ ClientProxy::Disconnect() {
Status
ClientProxy::CreateCollection(const Mapping& mapping, const std::string& extra_params) {
try {
// ::milvus::grpc::Mapping grpc_mapping;
// grpc_mapping.set_collection_name(mapping.collection_name);
// for (auto& field : mapping.fields) {
// auto grpc_field = grpc_mapping.add_fields();
// grpc_field->set_name(field->field_name);
// grpc_field->set_type((::milvus::grpc::DataType)field->field_type);
// JSON json_index_param = JSON::parse(field->index_params);
// for (auto& json_param : json_index_param.items()) {
// auto grpc_index_param = grpc_field->add_index_params();
// grpc_index_param->set_key(json_param.key());
// grpc_index_param->set_value(json_param.value());
// }
//
// auto grpc_extra_param = grpc_field->add_extra_params();
// grpc_extra_param->set_key(EXTRA_PARAM_KEY);
// grpc_extra_param->set_value(field->extra_params);
// }
// auto grpc_param = grpc_mapping.add_extra_params();
// grpc_param->set_key(EXTRA_PARAM_KEY);
// grpc_param->set_value(extra_params);
::milvus::grpc::Mapping grpc_mapping;
grpc_mapping.set_collection_name(mapping.collection_name);
for (auto& field : mapping.fields) {
auto grpc_field = grpc_mapping.mutable_schema()->add_field_metas();
grpc_field->set_field_name(field->field_name);
grpc_field->set_type((::milvus::grpc::DataType)field->field_type);
grpc_field->set_dim(field->dim);
// return client_ptr_->CreateCollection(grpc_mapping);
return Status::OK();
}
auto grpc_param = grpc_mapping.add_extra_params();
grpc_param->set_key(EXTRA_PARAM_KEY);
grpc_param->set_value(extra_params);
return client_ptr_->CreateCollection(grpc_mapping);
} catch (std::exception& ex) {
return Status(StatusCode::UnknownError, "Failed to create collection: " + std::string(ex.what()));
}
return Status::OK();
}
Status
......
......@@ -37,19 +37,19 @@ GrpcClient::~GrpcClient() = default;
Status
GrpcClient::CreateCollection(const milvus::grpc::Mapping& mapping) {
// ClientContext context;
// ::milvus::grpc::Status response;
// ::grpc::Status grpc_status = stub_->CreateCollection(&context, mapping, &response);
//
// if (!grpc_status.ok()) {
// std::cerr << "CreateHybridCollection gRPC failed!" << std::endl;
// return Status(StatusCode::RPCFailed, grpc_status.error_message());
// }
//
// if (response.error_code() != grpc::SUCCESS) {
// std::cerr << response.reason() << std::endl;
// return Status(StatusCode::ServerFailed, response.reason());
// }
ClientContext context;
::milvus::grpc::Status response;
::grpc::Status grpc_status = stub_->CreateCollection(&context, mapping, &response);
if (!grpc_status.ok()) {
std::cerr << "CreateHybridCollection gRPC failed!" << std::endl;
return Status(StatusCode::RPCFailed, grpc_status.error_message());
}
if (response.error_code() != grpc::SUCCESS) {
std::cerr << response.reason() << std::endl;
return Status(StatusCode::ServerFailed, response.reason());
}
return Status::OK();
}
......
......@@ -9,7 +9,7 @@
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under the License.
#include "examples/utils/TimeRecorder.h"
#include "TimeRecorder.h"
#include <iostream>
......
......@@ -9,7 +9,7 @@
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under the License.
#include "examples/utils/Utils.h"
#include "Utils.h"
#include <time.h>
#include <unistd.h>
......@@ -25,7 +25,7 @@
#include <cstring>
#include <string>
#include "examples/utils/TimeRecorder.h"
#include "TimeRecorder.h"
namespace {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册