titan
- 簡介
(1)titan:存儲,查詢圖形結(jié)構(gòu)的數(shù)據(jù)庫。分布式集群環(huán)境下,可支持?jǐn)?shù)以千億級別的點和邊,同時支持上千個并發(fā)的實時的復(fù)雜圖形遍歷,支持ACID事務(wù)。
(2)架構(gòu):支持以下3方面的自由組合- 節(jié)點和邊的存儲:
- Apache Cassandra
- Apache HBase
- Oracle BerkeleyDB(測試使用)
- 圖形分析組件:
- Spark
- Giraph
- Hadoop
- 地理,數(shù)值,全文檢索支持
- ElasticSearch
- Solr
- Lucene
- 節(jié)點和邊的存儲:
- titan-hbase-es部署范例
(1)版本對應(yīng)
titan:0.54-hadoop2,hbase:1.1.5 (版本相對寬松),elasticsearch:1.4,rexster-server:2.6
(2)titan server部署- rexster-server解壓
-
修改config/rexster.xml文件,添加如下內(nèi)容
<graph><graph-enabled>true</graph-enabled><graph-name>titanexample</graph-name><graph-type>com.thinkaurelius.titan.tinkerpop.rexster.TitanGraphConfiguration</graph-type><graph-location></graph-location><graph-read-only>false</graph-read-only><properties> <storage.backend>hbase</storage.backend> <storage.hostname>localhost:2181,localhost:2182,localhost:2183</storage.hostname> <storage.hbase.table>facebook</storage.hbase.table> <index.search.backend>elasticsearch</index.search.backend> <index.search.elasticsearch.client-only>true</index.search.elasticsearch.client-only> <index.search.hostname>127.0.0.1</index.search.hostname> <index.search.index-name>facebook</index.search.index-name></properties><extensions><allows><allow>tp:gremlin</allow></allows></extensions> </graph> - 復(fù)制titan jar包到rexster lib
cp TITAN_HOME/lib/* REXSTER_HOME/ext/titan/- 刪除rexster/lib下的lucene相關(guān)jar包,會與titan的引起沖突
- 開啟rexster
./bin/rexster.sh -s -c ./config/rexster.xml- 訪問http://ip:8182/graphs/titanexample,REST
-
titan server接口
(1)RexPro二進制協(xié)議java public class TestClient { public static void main(String[] args) throws Exception { RexsterClient client = RexsterClientFactory.open("localhost", "titanexample"); List<Map<String,Object>> result; result = client.execute("aa=g.V.has('name','saturn');aa.next()"); //result = client.execute("g.getManagementSystem().get(‘cache.db-cache’)"); // result.toString(): [{name="jupiter"}] System.out.println(result); client.close(); } }xml <dependency> <groupId>com.tinkerpop.rexster</groupId> <artifactId>rexster-protocol</artifactId> <version>2.6.0</version> </dependency>
(2)thinkerpop - REST協(xié)議 -
“紅樓夢宗譜”示例
(1)編寫blueprint腳本,設(shè)置schema,索引,添加將節(jié)點數(shù)據(jù)
```java
com.thinkaurelius.titan.core.schema.TitanManagement mgmt = g.getManagementSystem();
//點的屬性名
com.thinkaurelius.titan.core.PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
com.thinkaurelius.titan.core.PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make();
// 點的標(biāo)簽名
mgmt.makeVertexLabel("people").make(); //該點表示人
mgmt.makeVertexLabel("hobby").make(); //該點是一個運動
// 給點的姓名年齡建索引
mgmt.buildIndex("name",Vertex.class).addKey(name).unique().buildCompositeIndex(); // "search"是配置文件中的標(biāo)識符
mgmt.buildIndex("vertices",Vertex.class).addKey(age).buildMixedIndex("search"); // mixedIndex是外部索引,用es存儲索引// 邊的屬性
mgmt.makeEdgeLabel("father").multiplicity(com.thinkaurelius.titan.core.Multiplicity.MANY2ONE).make();
mgmt.makeEdgeLabel("mother").multiplicity(com.thinkaurelius.titan.core.Multiplicity.MANY2ONE).make();
mgmt.makeEdgeLabel("hobby").multiplicity(com.thinkaurelius.titan.core.Multiplicity.MULTI).make();
com.thinkaurelius.titan.core.PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).make();
com.thinkaurelius.titan.core.EdgeLabel love = mgmt.makeEdgeLabel("love").signature(time).make();//什么時候確立愛情掛席
mgmt.buildEdgeIndex(love,"lovetime", Direction.BOTH, com.thinkaurelius.titan.core.Order.DESC,time);
mgmt.commit();//插入點
com.thinkaurelius.titan.core.TitanTransaction tx = g.newTransaction();
Vertex jiazheng = tx.addVertexWithLabel("people"); // 賈政
jiazheng.setProperty("name","賈政");
jiazheng.setProperty("age",48);
Vertex jiabaoyu = tx.addVertexWithLabel("people"); // 賈寶玉
jiabaoyu.setProperty("name","賈寶玉");
jiabaoyu.setProperty("age",18);
Vertex wangfuren = tx.addVertexWithLabel("people"); // 王夫人
wangfuren.setProperty("name","王夫人");
wangfuren.setProperty("age",47);
Vertex xuebaochai = tx.addVertexWithLabel("people"); // 薛寶釵
xuebaochai.setProperty("name","薛寶釵");
xuebaochai.setProperty("age",17);Vertex cixiu = tx.addVertexWithLabel("hobby");
cixiu.setProperty("name","刺繡");
Vertex zuoshi = tx.addVertexWithLabel("hobby");
zuoshi.setProperty("name","作詩");//插入邊
jiabaoyu.addEdge("father",jiazheng);
jiabaoyu.addEdge("mother",wangfuren);
ElementHelper.setProperties(jiabaoyu.addEdge("love",xuebaochai),"time",1001); // 賈寶玉愛林黛玉,"time"屬性為1001
wangfuren.addEdge("hobby",cixiu);
xuebaochai.addEdge("hobby",zuoshi);tx.commit();
(2)通過RexPro協(xié)議發(fā)送腳本到服務(wù)器java
public static void main(String[] args) throws Exception {
RexsterClient client = RexsterClientFactory.open("localhost", "titanexample");
List<Map<String,Object>> result;
BufferedReader br = new BufferedReader(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("facebook-gremlin")));
String str="";
StringBuffer sb = new StringBuffer();
while((str = br.readLine())!=null){
sb.append(str);
}
System.out.println(sb.toString());
result = client.execute(sb.toString());
System.out.println(result);
client.close();
}(3)rest apishell
curl -XGET http://localhost:8182/graphs/titanexample/vertices #查看所有邊
curl -XGET http://localhost:8182/graphs/titanexample/edges
curl -XGET http://localhost:8182/graphs/titanexample/keyindices
curl -XGET http://localhost:8182/graphs/titanexample/vertices/16400/in #查詢節(jié)點的入射邊
curl -XPOST http://localhost:8182/graphs/titanexample/vertices/11111?name=zhangsan&age=24 #創(chuàng)建節(jié)點
curl -XPOST http://localhost:8182/graphs/titanexample/edges?_outV=&_label=friend&_inV=2&=<key'> #創(chuàng)建節(jié)點間的邊
```(4)gremlin查詢示例,查詢賈寶玉的父親
gremlin> g.V.has('name','賈寶玉').next().out('father').name ==>賈政(5)全文檢索節(jié)點,按照es的格式封裝的map
result = client.execute("g.indexQuery(\"vertices\", \"v.age:(17)\").vertices().get(0).getElement()"); for (Map<String, Object> map : result) {for (Map.Entry<String, Object> en : map.entrySet()) {System.out.print(en.getKey()+":"+en.getValue()+"\t\t");}System.out.println(); } /** _type:vertex _properties:{name=薛寶釵, age=17} _id:16496 */ - 數(shù)據(jù)展現(xiàn)
- Sigma.js it's a free and open source tool for graph visualization quite nice. Linkurious is using a fork version of it as far as I know in their product.
- VivaGraph it's another free and open source tool for graph visualization tool - but it has a smaller community compared to SigmaJS.
- D3.js it's the factotum for data visualization, you can do basically every kind of visualization based on that, but the learning curve is quite steep.
- Gephi is another free and open source desktop solution, you have to use an external plugin with that probably but it does support most of the formats out there - graphML, CSV, Neo4J, etc...
-
參考網(wǎng)站
thinkerpop
gremlin與sql對比查詢語法
sparql-gremlin插件
DataStax給出的圖形查詢語言,包括sparql,GraphQL, Cypher, Gremlin
轉(zhuǎn)載于:https://www.cnblogs.com/72808ljup/p/5587714.html
總結(jié)
- 上一篇: VMP (VMProtect)脱壳
- 下一篇: Flume知识点全面总结教程