Skip to content

Commit

Permalink
fix v2 procedure (#412)
Browse files Browse the repository at this point in the history
* v2 procedure

* cpplint

* cpplint

* it

* it

* it

* it

* node_buffer_

* node_buffer_

* add algo in it

* add algo in it

* add algo in it

* add algo in it

* disable it

* upload multiple cpp files

* rpc client

* cpplint

* asan

* comments

* comments

* comments

* procedure

* procedure

* procedure

* procedure

---------

Co-authored-by: Shipeng Qi <[email protected]>
  • Loading branch information
GongChangYan and qishipengqsp authored Apr 2, 2024
1 parent 7fadaad commit 28405ef
Show file tree
Hide file tree
Showing 67 changed files with 2,467 additions and 752 deletions.
2 changes: 1 addition & 1 deletion ci/github_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ else
cp -r ../../learn/examples/* ./
cp -r ../../demo/movie .
if [[ "$WITH_PROCEDURE" == "OFF" ]]; then
rm -rf test_algo.py test_sampling.py test_train.py
rm -rf test_algo.py test_sampling.py test_train.py test_algo_v2.py
fi
pytest ./
# codecov
Expand Down
2 changes: 1 addition & 1 deletion cpplint/check_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
set -e
dir=$(dirname "$(readlink -f "$0")")
cd $dir/../
find src test include toolkits procedures -name "*.cpp" -o -name "*.h" | grep -v "/lmdb/" | xargs python3 ./cpplint/cpplint.py --quiet
find src test include toolkits procedures -name "*.cpp" -o -name "*.h" | grep -v "/lmdb/" | grep -v "test/test_procedures/" | xargs python3 ./cpplint/cpplint.py --quiet
2 changes: 1 addition & 1 deletion deps/tugraph-web
150 changes: 75 additions & 75 deletions docs/en-US/source/5.developer-manual/6.interface/1.query/1.cypher.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -213,26 +213,31 @@ extern "C" LGAPI bool GetSignature(SigSpec &sig_spec) {

extern "C" LGAPI bool ProcessInTxn(Transaction &txn,
const std::string &request,
std::string &response) {
Result &response) {
int64_t limit;
try {
json input = json::parse(request);
limit = input["limit"].get<int64_t>();
} catch (std::exception &e) {
response = std::string("error parsing json: ") + e.what();
response.ResetHeader({
{"errMsg", LGraphType::STRING}
});
response.MutableRecord()->Insert(
"errMsg",
FieldData::String(std::string("error parsing json: ") + e.what()));
return false;
}

Result result({{"node", LGraphType::NODE},
{"salt", LGraphType::FLOAT},
});
response.ResetHeader({
{"node", LGraphType::NODE},
{"salt", LGraphType::FLOAT}
});
for (size_t i = 0; i < limit; i++) {
auto r = result.MutableRecord();
auto r = response.MutableRecord();
auto vit = txn.GetVertexIterator(i);
r->Insert("node", vit);
r->Insert("salt", FieldData::Float(20.23*float(i)));
}
response = result.Dump();
return true;
}
```
Expand Down
160 changes: 80 additions & 80 deletions docs/zh-CN/source/5.developer-manual/6.interface/1.query/1.cypher.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -217,26 +217,31 @@ extern "C" LGAPI bool GetSignature(SigSpec &sig_spec) {

extern "C" LGAPI bool ProcessInTxn(Transaction &txn,
const std::string &request,
std::string &response) {
Result &response) {
int64_t limit;
try {
json input = json::parse(request);
limit = input["limit"].get<int64_t>();
} catch (std::exception &e) {
response = std::string("error parsing json: ") + e.what();
response.ResetHeader({
{"errMsg", LGraphType::STRING}
});
response.MutableRecord()->Insert(
"errMsg",
FieldData::String(std::string("error parsing json: ") + e.what()));
return false;
}

Result result({{"node", LGraphType::NODE},
{"salt", LGraphType::FLOAT},
});
response.ResetHeader({
{"node", LGraphType::NODE},
{"salt", LGraphType::FLOAT}
});
for (size_t i = 0; i < limit; i++) {
auto r = result.MutableRecord();
auto r = response.MutableRecord();
auto vit = txn.GetVertexIterator(i);
r->Insert("node", vit);
r->Insert("salt", FieldData::Float(20.23*float(i)));
}
response = result.Dump();
return true;
}
```
Expand Down
6 changes: 5 additions & 1 deletion include/lgraph/lgraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@
#undef BOOL
#endif

namespace lgraph_api {
class Result;
}

namespace lgraph_api {
typedef bool GetSignature(SigSpec &sig_spec);
typedef bool Process(lgraph_api::GraphDB &db, const std::string &input, std::string &output);
typedef bool ProcessInTxn(lgraph_api::Transaction& txn,
const std::string &input,
std::string &output);
lgraph_api::Result &output);
}

/*
Expand Down
19 changes: 19 additions & 0 deletions include/lgraph/lgraph_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,25 @@ class Result {
*/
Record *MutableRecord();

/**
* @brief This function attempts to reserve enough memory for the result vector to hold
* the specified number of elements.
*
*/
void Reserve(size_t n);

/**
* @brief This function will resize the vector to the specified number of elements
*
*/
void Resize(size_t n);

/**
* @brief Provides access to the data contained in the vector.
*
*/
Record* At(size_t n);

/**
* @brief return header of the table.
*
Expand Down
26 changes: 24 additions & 2 deletions include/lgraph/lgraph_rpc_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class RpcClient {
* @brief Load a user-defined procedure
*
* @param [out] result The result.
* @param [in] source_file the source_file contain procedure code.
* @param [in] source_files the source_file list contain procedure code(only
* for code_type cpp)
* @param [in] procedure_type the procedure type, currently supported CPP and PY.
* @param [in] procedure_name procedure name.
* @param [in] code_type code type, currently supported PY, SO, CPP, ZIP.
Expand All @@ -84,7 +85,7 @@ class RpcClient {
*
* @returns True if it succeeds, false if it fails.
*/
bool LoadProcedure(std::string& result, const std::string& source_file,
bool LoadProcedure(std::string& result, const std::vector<std::string>& source_files,
const std::string& procedure_type, const std::string& procedure_name,
const std::string& code_type, const std::string& procedure_description,
bool read_only, const std::string& version = "v1",
Expand Down Expand Up @@ -441,6 +442,27 @@ class RpcClient {
bool read_only, const std::string& version = "v1",
const std::string& graph = "default");

/**
* @brief Load a built-in procedure
*
* @param [out] result The result.
* @param [in] source_files the source_file list contain procedure code(only
* for code_type cpp)
* @param [in] procedure_type the procedure type, currently supported CPP and PY.
* @param [in] procedure_name procedure name.
* @param [in] code_type code type, currently supported PY, SO, CPP, ZIP.
* @param [in] procedure_description procedure description.
* @param [in] read_only procedure is read only or not.
* @param [in] version (Optional) the version of procedure.
* @param [in] graph (Optional) the graph to query.
* @returns True if it succeeds, false if it fails.
*/
bool LoadProcedure(std::string& result, const std::vector<std::string>& source_files,
const std::string& procedure_type, const std::string& procedure_name,
const std::string& code_type, const std::string& procedure_description,
bool read_only, const std::string& version = "v1",
const std::string& graph = "default");

/**
* @brief List user-defined procedures
*
Expand Down
8 changes: 8 additions & 0 deletions include/lgraph/lgraph_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,12 @@ void parse_from_json(std::vector<DataType>& value, const char* key, json& input)
}
}

/**
* \brief Parse vid from the node passed in by cypher. For V2 procedure.
*
* \param[in] node_string node
* \return vid
*/
size_t GetVidFromNodeString(const std::string& node_string);

} // namespace lgraph_api
3 changes: 2 additions & 1 deletion include/lgraph/olap_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,6 @@ class OlapBase {
* @param vertices The vertex id (in the Graph) to lock/unlock.
*
*/

void set_num_vertices(size_t vertices) {
if (this->num_vertices_ == 0) {
this->num_vertices_ = vertices;
Expand Down Expand Up @@ -1041,6 +1040,7 @@ class OlapBase {
num_threads = omp_get_num_threads();
}
};
// TODO(niyan.zy): move ThreadState to Construct
ThreadState **thread_state;
thread_state = new ThreadState *[num_threads];
for (int t_i = 0; t_i < num_threads; t_i++) {
Expand Down Expand Up @@ -1166,6 +1166,7 @@ class OlapBase {
num_threads = omp_get_num_threads();
}
};
// TODO(niyan.zy): move ThreadState to Construct
ThreadState **thread_state;
thread_state = new ThreadState *[num_threads];
for (int t_i = 0; t_i < num_threads; t_i++) {
Expand Down
Loading

0 comments on commit 28405ef

Please sign in to comment.