C++客户端

此文档主要是TuGraph C++ SDK的使用说明。

1.概述

C++ Client 能够使用 RPC 连接lgraph_server,进行数据导入、执行存储过程、调用Cypher等操作。

2.使用示例

2.1.实例化client对象

引入依赖并实例化

RpcClient client3("0.0.0.0:19099", "admin", "73@TuGraph");
RpcClient(const std::string& url, const std::string& user, const std::string& password);
@param url: tugraph host looks like ip:port
@param user: login user name 
@param password: login password

2.2.调用cypher

    std::string str;
    bool ret = client.CallCypher(str,
        "CALL db.createVertexLabel('actor', 'name', 'name', string, false, 'age', int8, true)");
    bool CallCypher(std::string& result, const std::string& cypher,
        const std::string& graph = "default",
        bool json_format = true,
        double timeout = 0);
    @param result: the result returned by the service.
    @param cypher: inquire statement.
    @param graph: the graph to query.
    @param json_format: The result is returned in JSON format
    @param timeout: Maximum execution time, overruns will be interrupted
    @return: whether the command is executed successfully

2.3.调用存储过程

    std::string str;
    bool ret = client.CallPlugin(str, "CPP", "test_plugin1", "bcefg");
    bool CallPlugin(std::string& result, const std::string& plugin_type,
        const std::string& plugin_name, const std::string& param,
        double plugin_time_out = 0.0, bool in_process = false,
        const std::string& graph = "default", bool json_format = true,
        double timeout = 0);
    @param result: the result returned by the service.
    @param plugin_type: the plugin type, currently supported CPP and PY
    @param plugin_name: plugin name
    @param param: the execution parameters
    @param plugin_timeout: Maximum execution time, overruns will be interrupted
    @param graph: the graph to query.
    @param json_format: The result is returned in JSON format
    @param timeout: Maximum execution time, overruns will be interrupted
    @return: whether the command is executed successfully

2.4.加载存储过程

    std::string str;
    bool ret = client.LoadPlugin(str, code_sleep, "PY", "python_plugin1", "PY", "this is a test plugin",
    bool LoadPlugin(std::string& result, const std::string& source_file,
        const std::string& plugin_type, const std::string& plugin_name,
        const std::string& code_type, const std::string& plugin_description,
        bool read_only, const std::string& graph = "default", bool json_format = true,
        double timeout = 0);
    @param result: the result returned by the service.
    @param source_file: the source_file contain plugin code
    @param plugin_type: the plugin type, currently supported CPP and PY
    @param plugin_name: plugin name
    @param code_type: code type, currently supported PY, SO, CPP, ZIP
    @param plugin_description: plugin description
    @param read_only: plugin is read only or not
    @param graph: the graph to query.
    @param json_format: The result is returned in JSON format
    @param timeout: Maximum execution time, overruns will be interrupted
    @return: whether the command is executed successfully

2.5.从字节流中导入schema

    std::string str;
    bool ret = client.ImportSchemaFromContent(str, sImportContent["schema"]);
    bool ImportSchemaFromContent(std::string& result, const std::string& schema,
        const std::string& graph = "default", bool json_format = true,
        double timeout = 0);
    @param result: the result returned by the service.
    @param schema: the schema to be imported
    @param graph: the graph to query.
    @param json_format: The result is returned in JSON format
    @param timeout: Maximum execution time, overruns will be interrupted
    @return: whether the command is executed successfully

2.6.从字节流中导入点边数据

    std::string str;
    ret = client.ImportDataFromContent(str, sImportContent["person_desc"], sImportContent["person"],",");
    bool ImportDataFromContent(std::string& result, const std::string& desc,
        const std::string& data, const std::string& delimiter,
        bool continue_on_error = false, int thread_nums = 8,
        const std::string& graph = "default", bool json_format = true,
        double timeout = 0);
    @param result: the result returned by the service.
    @param desc: data format description
    @param data: the data to be imported
    @param delimiter: data separator
    @param continueOnError: whether to continue when importing data fails
    @param threadNums: maximum number of threads
    @param graph: the graph to query.
    @param json_format: The result is returned in JSON format
    @param timeout: Maximum execution time, overruns will be interrupted
    @return: whether the command is executed successfully

2.7.从文件中导入schema

    std::string conf_file("./yago.conf");
    std::string str;
    ret = client.ImportSchemaFromFile(str, conf_file);
    bool ImportSchemaFromFile(std::string& result, const std::string& schema_file,
        const std::string& graph = "default", bool json_format = true,
        double timeout = 0);
    @param result: the result returned by the service.
    @param schemaFile: the schema_file contain schema
    @param graph: the graph to query.
    @param json_format: The result is returned in JSON format
    @param timeout: Maximum execution time, overruns will be interrupted
    @return: whether the command is executed successfully

2.8.从文件中导入点边数据

    std::string conf_file("./yago.conf");
    std::string str;
    ret = client.ImportDataFromFile(str, conf_file, ",");
    bool ImportDataFromFile(std::string& result, const std::string& conf_file,
        const std::string& delimiter, bool continue_on_error = false,
        int thread_nums = 8, int skip_packages = 0,
        const std::string& graph = "default", bool json_format = true,
        double timeout = 0);
    @param result: the result returned by the service.
    @param conf_file: data file contain format description and data
    @param delimiter: data separator
    @param continue_on_error: whether to continue when importing data fails
    @param thread_nums: maximum number of threads
    @param skip_packages: skip packages number
    @param graph: the graph to query.
    @param json_format: The result is returned in JSON format
    @param timeout: Maximum execution time, overruns will be interrupted
    @return: whether the command is executed successfully