Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
08a62e30
M
milvus
项目概览
milvus
/
milvus
大约 1 年 前同步成功
通知
261
Star
22476
Fork
2472
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
08a62e30
编写于
9月 19, 2020
作者:
Z
zhenshan.cao
提交者:
yefu.chen
9月 19, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor SDK
Signed-off-by:
N
zhenshan.cao
<
zhenshan.cao@zilliz.com
>
上级
ece87075
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
113 addition
and
117 deletion
+113
-117
sdk/CMakeLists.txt
sdk/CMakeLists.txt
+2
-0
sdk/examples/CMakeLists.txt
sdk/examples/CMakeLists.txt
+0
-11
sdk/examples/simple/CMakeLists.txt
sdk/examples/simple/CMakeLists.txt
+23
-21
sdk/examples/simple/CreateCollection.cpp
sdk/examples/simple/CreateCollection.cpp
+9
-3
sdk/examples/simple/delete.cpp
sdk/examples/simple/delete.cpp
+8
-5
sdk/examples/simple/insert.cpp
sdk/examples/simple/insert.cpp
+29
-13
sdk/examples/simple/ip.h
sdk/examples/simple/ip.h
+0
-16
sdk/examples/simple/search.cpp
sdk/examples/simple/search.cpp
+12
-10
sdk/grpc/ClientProxy.cpp
sdk/grpc/ClientProxy.cpp
+14
-22
sdk/grpc/GrpcClient.cpp
sdk/grpc/GrpcClient.cpp
+13
-13
sdk/utils/ThreadPool.h
sdk/utils/ThreadPool.h
+0
-0
sdk/utils/TimeRecorder.cpp
sdk/utils/TimeRecorder.cpp
+1
-1
sdk/utils/TimeRecorder.h
sdk/utils/TimeRecorder.h
+0
-0
sdk/utils/Utils.cpp
sdk/utils/Utils.cpp
+2
-2
sdk/utils/Utils.h
sdk/utils/Utils.h
+0
-0
未找到文件。
sdk/CMakeLists.txt
浏览文件 @
08a62e30
...
...
@@ -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
...
...
sdk/examples/CMakeLists.txt
浏览文件 @
08a62e30
...
...
@@ -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
}
)
sdk/examples/simple/CMakeLists.txt
浏览文件 @
08a62e30
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
}
)
sdk/examples/simple/CreateCollection.cpp
浏览文件 @
08a62e30
...
...
@@ -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
;
...
...
sdk/examples/simple/delete.cpp
浏览文件 @
08a62e30
...
...
@@ -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
;
...
...
sdk/examples/simple/insert.cpp
浏览文件 @
08a62e30
...
...
@@ -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
;
}
sdk/examples/simple/ip.h
已删除
100644 → 0
浏览文件 @
ece87075
// 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
sdk/examples/simple/search.cpp
浏览文件 @
08a62e30
...
...
@@ -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
;
}
sdk/grpc/ClientProxy.cpp
浏览文件 @
08a62e30
...
...
@@ -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
...
...
sdk/grpc/GrpcClient.cpp
浏览文件 @
08a62e30
...
...
@@ -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
();
}
...
...
sdk/
examples/
utils/ThreadPool.h
→
sdk/utils/ThreadPool.h
浏览文件 @
08a62e30
文件已移动
sdk/
examples/
utils/TimeRecorder.cpp
→
sdk/utils/TimeRecorder.cpp
浏览文件 @
08a62e30
...
...
@@ -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>
...
...
sdk/
examples/
utils/TimeRecorder.h
→
sdk/utils/TimeRecorder.h
浏览文件 @
08a62e30
文件已移动
sdk/
examples/
utils/Utils.cpp
→
sdk/utils/Utils.cpp
浏览文件 @
08a62e30
...
...
@@ -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
{
...
...
sdk/
examples/
utils/Utils.h
→
sdk/utils/Utils.h
浏览文件 @
08a62e30
文件已移动
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录