lgraph_result

Result interface for plugins and built-in procedures. The result of a plugin should be provided in this format in order for the Cypher engine and the graph visualizer to understand.

namespace lgraph
namespace cypher
namespace lgraph_api
class Record
#include <lgraph_result.h>

You only initialize the class by Result instance. Record provide some insert method to insert data to the record. eg. Insert, InsertVertexByID, InsertEdgeByID.

Public Functions

Record(const Record&)
Record(Record&&)
Record &operator=(const Record&)
Record &operator=(Record&&)
void Insert(const std::string &fname, const FieldData &fv)

insert a value to result table. You can insert a value by insert function, and value type must be same as you defined earlier.

Parameters
  • fname – Field name you defined earlier.

  • fv – Field value.

void Insert(const std::string &fname, const int64_t vid, lgraph_api::Transaction *txn)

insert a value to result table. You can insert a value by insert function, and value type must be same as you defined earlier. You can get properties and label from the interface, this is different from InsertVertexByID.

Parameters
  • fname – title name you defined earlier.

  • vid – VertextId

  • txnTransaction

void Insert(const std::string &fname, EdgeUid &euid, lgraph_api::Transaction *txn)

insert a value to result table. You can insert a value by insert function, and value type must be same as you defined earlier. You can get properties and label from the interface, this is different from InsertEdgeByID.

Parameters
void InsertVertexByID(const std::string &fname, int64_t vid)

insert a value to result table. You can insert a value by insert function, and value type must be same as you defined earlier.

Parameters
  • fname – Field name you defined earlier.

  • vid – VertextId.

void InsertEdgeByID(const std::string &fname, const EdgeUid &uid)

insert a value to result table. You can insert a value by insert function, and value type must be same as you defined earlier.

Parameters
  • fname – title name you defined earlier.

  • uidEdgeUid.

void Insert(const std::string &fname, const lgraph_api::VertexIterator &vit)

insert a value to result table. You can insert a value by insert function, and value type must be same as you defined earlier.

Parameters
  • fname – one of title name you defined earlier.

  • vitVertexIterator.

void Insert(const std::string &fname, const lgraph_api::InEdgeIterator &ieit)

insert a value to result table. You can insert a value by insert function, and value type must be same as you defined earlier.

Parameters
  • fname – one of title name you defined earlier.

  • ieitInEdgeIterator.

void Insert(const std::string &fname, const lgraph_api::OutEdgeIterator &oeit)

insert a value to result table. You can insert a value by insert function, and value type must be same as you defined earlier.

Parameters
  • fname – one of title name you defined earlier.

  • oeitOutEdgeIterator.

void Insert(const std::string &fname, const std::vector<FieldData> &list)

Insert a value to result table. You can insert a value by insert function, and value type must be same as you defined earlier.

Parameters
  • fname – one of title name you defined earlier.

  • list – LIST OF FieldData.

void Insert(const std::string &fname, const std::map<std::string, FieldData> &map)

insert a value to result table. You can insert a value by insert function, and value type must be same as you defined earlier.

Parameters
  • fname – one of title name you defined earlier.

  • map – MAP OF <string, FieldData>

void Insert(const std::string &fname, const traversal::Path &path, lgraph_api::Transaction *txn)

insert value into result table. You can insert a value by the function, and value must be same as you defined earlier.

Parameters
  • fname – one of title name you defined earlier.

  • path – Path of traverse api.

  • txn – Trasaction

inline int64_t Size() const

Get the size of record. If record is empty, return 0, max size is not beyond the length of your defined param list.

Returns

Size of record.

inline bool HasKey(const std::string &key)

Check a key is exist or not. The key is the one of titile your defined earlier.

Parameters

key – The key.

Returns

True if exsit, otherwise fasle.

Private Functions

explicit Record(const std::vector<std::pair<std::string, LGraphType>>&)

Private Members

std::unordered_map<std::string, std::shared_ptr<ResultElement>> record
std::unordered_map<std::string, LGraphType> header
int64_t length_

Friends

friend class Result
class Result
#include <lgraph_result.h>

Result table, result instance provide [MutableRecord], [ResetHeader], [Dump] and [Load] method. Table also provide some method to view content of table. For example, [Header] and [Recordview].

It’s worth noting that you are best to define your header before using result table. eg. auto result = Result({title, LGraphType}…) If you do not define header and initialize by Result(), you will get a empty table without header, you just use the table after using [ResetHeader] method to set your header.

Public Functions

Result()
Result(const std::initializer_list<std::pair<std::string, LGraphType>>&)
explicit Result(const std::vector<std::pair<std::string, LGraphType>>&)
LGraphType GetType(std::string title)

Get type of title.

Parameters

title – One of titles in table.

Returns

LGraphType.

void ResetHeader(const std::vector<std::pair<std::string, LGraphType>> &header)

Reset your header, the operation will clear the original data and header, please use the function carefully.

Parameters

header – List of <title, LGraphType>

void ResetHeader(const std::initializer_list<std::pair<std::string, LGraphType>> &header)

Reset your header, the operation will clear the original data and header, please use the function carefully.

Parameters

header – List of <title, LGraphType>

Record *MutableRecord()

Create a new record in the table and return the record. The record is the reference of record in the table, if you want to modify the record, you must assign return value to a reference variable.

Returns

The reference of record.

const std::vector<std::pair<std::string, LGraphType>> &Header()

return header of the table.

Returns

header.

int64_t Size() const

return size of the table.

Returns

table size.

std::string Dump(bool is_standard = true)

Serialize the table.

Parameters

is_standard – (Optional) If true, the result will serialize to a standard result, the standard result can be Visualized in web. If false, result will serialize a json object &#8212; SDK result.

Returns

Serialize result.

void Load(const std::string &json)

Deserialize data to result table. This will be clear original data and header, please use this function carefully.

Parameters

json – Json string to be deserialized.

Private Functions

const std::unordered_map<std::string, std::shared_ptr<ResultElement>> &RecordView(int64_t row_num)

Get record of the table, if row number is more bigger than max length of table, throw a exception.

Parameters

row_num – row number of the table.

Returns

One Record.

Private Members

std::vector<Record> result
std::vector<std::pair<std::string, LGraphType>> header
int64_t row_count_

Friends

friend class lgraph::StateMachine
friend class cypher::PluginAdapter