olap_on_db
TuGraph OLAP interface. To implement a plugin that perform graph analytics on TuGraph, user can load a Snapshot from the database, and then use the Gather-Apply-Scatter style interface to do the computation.
-
namespace lgraph_api
-
namespace olap
Variables
-
static constexpr size_t SNAPSHOT_PARALLEL = 1ul << 0
The available options for (graph construction) flags.
-
static constexpr size_t SNAPSHOT_UNDIRECTED = 1ul << 1
-
static constexpr size_t SNAPSHOT_IDMAPPING = 1ul << 2
-
static constexpr size_t SNAPSHOT_OUT_DEGREE = 1ul << 3
The following options are not implemented yet.
-
static constexpr size_t SNAPSHOT_IN_DEGREE = 1ul << 4
-
static constexpr size_t SNAPSHOT_OUT_EDGES = 1ul << 5
-
static constexpr size_t SNAPSHOT_IN_EDGES = 1ul << 6
-
template<typename EdgeData>
std::function<bool(OutEdgeIterator&, EdgeData&)> edge_convert_default =[] (OutEdgeIterator &eit, EdgeData &edge_data) -> bool { edge_data= 1;return true;} Default Parser for weighted edges for graph.
- Return
Edge is converted into graph or not.
-
template<typename EdgeData>
std::function<bool(OutEdgeIterator&, EdgeData&)> edge_convert_weight =[](OutEdgeIterator &eit, EdgeData &edge_data) -> bool { edge_data= eit.GetField("weight").real();return true;} Example parser for extract from edge property “weight”.
- Return
Edge is converted into graph or not.
-
template<typename EdgeData>
class OlapOnDB : public lgraph_api::olap::OlapBase<EdgeData> - #include <olap_on_db.h>
Snapshot is a derived class of Graph. Snapshot instances represent static (sub)graphs exported from LightningGraph. The internal organization uses compressed sparse matrix formats which are optimized for read-only accesses.
EdgeData is used for representing edge weights (the default type is Empty which is used for unweighted graphs).
- Template Parameters
EdgeData – Type of the edge data.
Public Functions
-
inline OlapOnDB(GraphDB &db, Transaction &txn, size_t flags = 0, std::function<bool(VertexIterator&)> vertex_filter = nullptr, std::function<bool(OutEdgeIterator&, EdgeData&)> out_edge_filter = nullptr)
Generate a graph with LightningGraph.
Note that the transaction must be read- only if SNAPSHOT_PARALLEL is specified (actually read-write transactions are not recommended here for safety, e.g. some vertices might be removed causing inconsistencies of the analysis, and vertex data extraction may not work for deleted vertices). The constructed graph should contain all vertices whose vertex_filter calls return true and all edges sourced from these vertices whose out_edge_filter calls return true. If SNAPSHOT_UNDIRECTED is specified, the graph will be made symmetric (i.e. reversed edges are also added to the graph).
- Throws
std::runtime_error – Raised when a runtime error condition occurs.
- Parameters
db – [inout] The GraphDB instance.
txn – [inout] The transaction.
flags – (Optional) The generation flags.
vertex_filter – [inout] (Optional) A function filtering vertices.
out_edge_filter – [inout] (Optional) A function filtering out edges.
-
OlapOnDB() = delete
-
inline virtual ~OlapOnDB()
-
template<typename VertexData>
inline ParallelVector<VertexData> ExtractVertexData(std::function<void(VertexIterator&, VertexData&)> extract) Extract a vertex array from the graph.
- Parameters
extract – The function describing the extraction logic.
- Returns
A ParallelVector containing each vertex’s extracted data.
-
inline size_t OriginalVid(size_t vid)
Get the original vertex id (in LightningGraph) of some vertex.
- Parameters
vid – The vertex id (in the graph) to access.
- Returns
The original id of the specified vertex in the graph.
-
inline size_t MappedVid(size_t original_vid)
Get the mapped vertex id (in the graph) of some vertex.
- Parameters
original_vid – The original vertex id (in LightningGraph) to access.
- Returns
The mapped id of the specified vertex (in LightningGraph).
-
inline Transaction &GetTransaction()
Private Functions
-
inline void Init(size_t num_vertices)
-
inline virtual bool CheckKillThisTask()
This decision formula is used to determine whether to stop the algorithm running in OlapOnDB.
-
inline virtual void Construct()
-
inline void ConstructWithVid()
-
inline void ConstructWithDegree()
Private Members
-
Transaction &txn_
-
ParallelVector<size_t> original_vids_
-
cuckoohash_map<size_t, size_t> vid_map_
-
size_t flags_
-
std::function<bool(VertexIterator&)> vertex_filter_
-
std::function<bool(OutEdgeIterator&, EdgeData&)> out_edge_filter_
-
static constexpr size_t SNAPSHOT_PARALLEL = 1ul << 0
-
namespace olap