GrpcClient.h 2.6 KB
Newer Older
J
jinhai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you 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.

K
kun yu 已提交
18 19 20 21 22 23 24 25 26 27 28 29 30
#pragma once
#include <chrono>
#include <iostream>
#include <memory>
#include <random>
#include <string>
#include <thread>

#include <grpc/grpc.h>
#include <grpcpp/channel.h>
#include <grpcpp/client_context.h>
#include <grpcpp/create_channel.h>
#include <grpcpp/security/credentials.h>
K
kun yu 已提交
31
#include "MilvusApi.h"
K
kun yu 已提交
32 33 34 35 36 37 38 39 40

#include "milvus.grpc.pb.h"
//#include "status.grpc.pb.h"

#include <memory>

namespace milvus {
class GrpcClient {
public:
K
kun yu 已提交
41 42
    explicit
    GrpcClient(std::shared_ptr<::grpc::Channel>& channel);
K
kun yu 已提交
43

K
kun yu 已提交
44 45
    virtual
    ~GrpcClient();
K
kun yu 已提交
46

K
kun yu 已提交
47 48
    Status
    CreateTable(const grpc::TableSchema& table_schema);
K
kun yu 已提交
49

K
kun yu 已提交
50 51
    bool
    HasTable(const grpc::TableName& table_name, Status& status);
K
kun yu 已提交
52

K
kun yu 已提交
53 54
    Status
    DropTable(const grpc::TableName& table_name);
K
kun yu 已提交
55

K
kun yu 已提交
56
    Status
Y
Yu Kun 已提交
57
    CreateIndex(const grpc::IndexParam& index_param);
K
kun yu 已提交
58

K
kun yu 已提交
59
    void
Y
Yu Kun 已提交
60 61
    Insert(grpc::VectorIds& vector_ids,
                      const grpc::InsertParam& insert_param,
K
kun yu 已提交
62
                      Status& status);
K
kun yu 已提交
63

K
kun yu 已提交
64
    Status
65 66
    Search(::milvus::grpc::TopKQueryResultList& topk_query_result_list,
           const grpc::SearchParam &search_param);
K
kun yu 已提交
67

K
kun yu 已提交
68 69 70
    Status
    DescribeTable(grpc::TableSchema& grpc_schema,
                        const std::string& table_name);
K
kun yu 已提交
71

K
kun yu 已提交
72
    int64_t
Y
Yu Kun 已提交
73
    CountTable(const std::string& table_name, Status& status);
K
kun yu 已提交
74

K
kun yu 已提交
75
    Status
76
    ShowTables(milvus::grpc::TableNameList &table_name_list);
K
kun yu 已提交
77

K
kun yu 已提交
78
    Status
Y
Yu Kun 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91
    Cmd(std::string &result, const std::string& cmd);

    Status
    DeleteByRange(grpc::DeleteByRangeParam &delete_by_range_param);

    Status
    PreloadTable(grpc::TableName &table_name);

    Status
    DescribeIndex(grpc::TableName &table_name, grpc::IndexParam &index_param);

    Status
    DropIndex(grpc::TableName &table_name);
K
kun yu 已提交
92

K
kun yu 已提交
93 94
    Status
    Disconnect();
K
kun yu 已提交
95 96 97 98 99 100

private:
    std::unique_ptr<grpc::MilvusService::Stub> stub_;
};

}