This document is the usage instruction of TuGraph C++ SDK
Instructions
C++ Client can use RPC to connect to lgraph_server to import data, execute stored procedures, call Cypher and other operations.
Demo
Instantiate the client object
Introduce dependencies and instantiate
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
Call 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
Call stored procedure
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
Load stored procedure
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
Import from a byte stream 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
Import node and edge data from a byte stream
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
**Import schema from a file **
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
Import edge data from a file
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