Add simple tests to SDK

Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
This commit is contained in:
bigsheeper 2020-09-16 10:39:09 +08:00 committed by yefu.chen
parent 11125bc6eb
commit 9ccf5c1c7d
8 changed files with 198 additions and 140 deletions

View File

@ -11,6 +11,7 @@
# or implied. See the License for the specific language governing permissions and limitations under the License.
#-------------------------------------------------------------------------------
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)

View File

@ -1,81 +0,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.
#include <getopt.h>
#include <libgen.h>
#include <cstring>
#include <string>
#include <iostream>
#include "examples/utils/Utils.h"
#include "grpc/ClientProxy.h"
#include "interface/ConnectionImpl.h"
const milvus::FieldValue GetData() {
milvus::FieldValue value_map;
std::vector<int8_t> char_data;
std::vector<int32_t> int32_data;
for (int i = 0; i < 20; i++) {
char_data.push_back(i);
int32_data.push_back(i);
}
std::vector<milvus::VectorData> vector_data;
for (int i = 0; i < 20; i++) {
std::vector<float> float_data(10, 10.25);
milvus::VectorData vectorData;
vectorData.float_data = float_data;
vector_data.push_back(vectorData);
}
value_map.int8_value["INT8"] = char_data;
value_map.int32_value["INT32"] = int32_data;
value_map.vector_value["VECTOR"] = vector_data;
value_map.row_num = 20;
return value_map;
}
milvus::Mapping
GetMapByInsertParam(milvus::grpc::InsertParam &insert_param) {
milvus::Mapping map;
for (int64_t i = 0; i < insert_param.schema().field_metas().size(); i++) {
auto grpc_field = insert_param.schema().field_metas()[i];
milvus::FieldPtr field_ptr = std::make_shared<milvus::Field>();
field_ptr->field_name = grpc_field.field_name();
field_ptr->field_type = (milvus::DataType) grpc_field.type();
field_ptr->dim = grpc_field.dim();
map.fields.emplace_back(field_ptr);
}
return map;
}
int
main(int argc, char* argv[]) {
printf("Client start...\n");
TestParameters parameters = milvus_sdk::Utils::ParseTestParameters(argc, argv);
std::cout<<parameters.port_<<std::endl;
// printf("%s\n",parameters.port_);
std::cout<<milvus_sdk::Utils::CurrentTime()<<std::endl;
printf("Client exits ...\n");
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() ? "8080":parameters.port_ ;
client.Connect(connect_param);
std::vector<int64_t> ids_array;
auto data = GetData();
for (int64_t i = 0; i < 20; i++) {
ids_array.push_back(i);
}
client.Insert("collection0", "tag01", data, ids_array);
return 0;
}

View File

@ -1,59 +0,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.
#include "interface/ConnectionImpl.h"
#include "include/MilvusApi.h"
#include "grpc/ClientProxy.h"
#include "interface/ConnectionImpl.h"
#include "utils/TimeRecorder.h"
int main(int argc , char**argv) {
auto client = milvus::ConnectionImpl();
milvus::ConnectParam connect_param;
connect_param.ip_address = "192.168.2.28";
connect_param.port = "19530";
client.Connect(connect_param);
std::vector<int64_t> ids_array;
std::vector<std::string> partition_list;
partition_list.emplace_back("partition-1");
partition_list.emplace_back("partition-2");
partition_list.emplace_back("partition-3");
milvus::VectorParam vectorParam;
milvus::VectorData vectorData;
std::vector<float> float_data;
std::vector<uint8_t> binary_data;
for (int i = 0; i < 100; ++i) {
float_data.emplace_back(i);
binary_data.emplace_back(i);
}
vectorData.float_data = float_data;
vectorData.binary_data = binary_data;
std::vector<milvus::VectorData> vector_records;
for (int j = 0; j < 10; ++j) {
vector_records.emplace_back(vectorData);
}
vectorParam.json_param = "json_param";
vectorParam.vector_records = vector_records;
milvus::TopKQueryResult result;
milvus_sdk::TimeRecorder test_search("search");
auto status = client.Search("collection1", partition_list, "dsl", vectorParam, result);
return 0;
}

View File

@ -0,0 +1,17 @@
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)

View File

@ -0,0 +1,36 @@
// 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.
#include <getopt.h>
#include <libgen.h>
#include <cstring>
#include <string>
#include "interface/ConnectionImpl.h"
#include "ip.h"
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> delete_ids;
delete_ids.push_back(1);
delete_ids.push_back(2);
delete_ids.push_back(3);
client.DeleteEntityByID("collection0", delete_ids);
return 0;
}

View File

@ -0,0 +1,60 @@
// 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.
#include <getopt.h>
#include <libgen.h>
#include <cstring>
#include <string>
#include <iostream>
#include "examples/utils/Utils.h"
#include "grpc/ClientProxy.h"
#include "interface/ConnectionImpl.h"
#include "ip.h"
const int N = 100;
const int DIM = 16;
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);
}
std::vector<milvus::VectorData> vector_data;
for (int i = 0; i < N; i++) {
std::vector<float> float_data(DIM, 10.25);
milvus::VectorData vectorData;
vectorData.float_data = float_data;
vector_data.push_back(vectorData);
}
value_map.int32_value["INT32"] = int32_data;
value_map.vector_value["VECTOR"] = vector_data;
value_map.row_num = N;
return value_map;
}
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);
}

16
sdk/examples/simple/ip.h Normal file
View File

@ -0,0 +1,16 @@
// 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";

View File

@ -0,0 +1,68 @@
// 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.
#include <thirdparty/nlohmann/json.hpp>
#include "interface/ConnectionImpl.h"
#include "include/MilvusApi.h"
#include "grpc/ClientProxy.h"
#include "interface/ConnectionImpl.h"
#include "ip.h"
const int TOP_K = 10;
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;
std::vector<std::string> partition_list;
partition_list.emplace_back("partition-1");
partition_list.emplace_back("partition-2");
partition_list.emplace_back("partition-3");
milvus::VectorParam vectorParam;
milvus::VectorData vectorData;
std::vector<float> float_data;
for (int i = 0; i < 100; ++i) {
float_data.emplace_back(i);
}
vectorData.float_data = float_data;
std::vector<milvus::VectorData> vector_records;
for (int j = 0; j < 10; ++j) {
vector_records.emplace_back(vectorData);
}
nlohmann::json vector_param_json;
vector_param_json["num_queries"] = 1;
vector_param_json["topK"] = TOP_K;
vector_param_json["field_name"] = "fakevec";
std::string vector_param_json_string = vector_param_json.dump();
vectorParam.json_param = vector_param_json_string;
vectorParam.vector_records = vector_records;
milvus::TopKQueryResult result;
auto t1 = std::chrono::high_resolution_clock::now();
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;
}