Apache TinkerPop 提供了圖數據庫的抽象接口,方便第三方實現自己的圖數據庫以接入TinkerPop 技術棧,享受TinkerPop 的Gremlin、算法等福利。TinkerPop將這些第三方稱為“Provider ”,知名的Provider包含janusGraph、neo4j、hugegraph等。
Provider包含:
-
Graph System Provider
-
Graph Database Provider
-
Graph Processor Provider
-
-
Graph Driver Provider
-
Graph Language Provider
-
Graph Plugin Provider
Graph Structure API(圖譜數據結構)
Graph最高層的抽象數據結構包含 Graph(圖), Vertex(頂點), Edge(邊), VertexProperty(屬性) and Property.
基於這些基礎數據結構,就可以對進行基本的圖譜操作。
Graph graph = TinkerGraph.open(); //1
Vertex marko = graph.addVertex(T.label, "person", T.id, 1, "name", "marko", "age", 29); //2
Vertex vadas = graph.addVertex(T.label, "person", T.id, 2, "name", "vadas", "age", 27);
Vertex lop = graph.addVertex(T.label, "software", T.id, 3, "name", "lop", "lang", "java");
Vertex josh = graph.addVertex(T.label, "person", T.id, 4, "name", "josh", "age", 32);
Vertex ripple = graph.addVertex(T.label, "software", T.id, 5, "name", "ripple", "lang", "java");
Vertex peter = graph.addVertex(T.label, "person", T.id, 6, "name", "peter", "age", 35);
marko.addEdge("knows", vadas, T.id, 7, "weight", 0.5f); //3
marko.addEdge("knows", josh, T.id, 8, "weight", 1.0f);
marko.addEdge("created", lop, T.id, 9, "weight", 0.4f);
josh.addEdge("created", ripple, T.id, 10, "weight", 1.0f);
josh.addEdge("created", lop, T.id, 11, "weight", 0.4f);
peter.addEdge("created", lop, T.id, 12, "weight", 0.2f);
- 創建一個基於內存存儲的TinkerGraph 實例(TinkerGraph是官方實現的,基於內存的Graph)
2 .創建一個頂點
- 創建邊
上面的代碼構建了一個基本的圖,下面的代碼演示如何進行圖譜的操作。

實現 Gremlin-Core
一個標准的Graph Provider需要實現OLTP 和OLAP兩類接口,官方推薦學習TinkerGraph(in-memory OLTP and OLAP in tinkergraph-gremlin),以及 Neo4jGraph (OLTP w/ transactions in neo4j-gremlin) ,還有
Neo4jGraph (OLTP w/ transactions in neo4j-gremlin) ,還有 HadoopGraph (OLAP in hadoop-gremlin) 。
- 在線事務處理 Graph Systems (OLTP)
1. 數據結構 API: `Graph`, `Element`, `Vertex`, `Edge`, `Property` and `Transaction` (if transactions are supported).
2. 處理API : `TraversalStrategy` instances for optimizing Gremlin traversals to the provider’s graph system (i.e. `TinkerGraphStepStrategy`).
-
在線分析 圖系統 (OLAP)
-
Everything required of OLTP is required of OLAP (but not vice versa).
-
GraphComputer API:
GraphComputer,Messenger,Memory.
-
OLTP 實現
需要實現structure包下的interface,包含Graph, Vertex, Edge, Property, Transaction等等。
Graph實現時,需要命名為XXXGraph(舉例: TinkerGraph, Neo4jGraph, HadoopGraph, etc.).- 需要兼容
GraphFactory,也就是提供一個靜態的Graph open(Configuration)方法。
- 需要兼容
OLAP 實現
需要實現:
-
GraphComputer: 圖計算器,提供隔離環境,執行VertexProgram,和MapReduce任務. -
Memory: A global blackboard for ANDing, ORing, INCRing, and SETing values for specified keys. -
Messenger: The system that collects and distributes messages being propagated by vertices executing the VertexProgram application. -
MapReduce.MapEmitter: The system that collects key/value pairs being emitted by the MapReduce applications map-phase. -
MapReduce.ReduceEmitter: The system that collects key/value pairs being emitted by the MapReduce applications combine- and reduce-phases.
作者:Jadepeng
出處:jqpeng的技術記事本--http://www.cnblogs.com/xiaoqi
您的支持是對博主最大的鼓勵,感謝您的認真閱讀。
本文版權歸作者所有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。
