日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

titan

發布時間:2023/12/1 综合教程 31 生活家
生活随笔 收集整理的這篇文章主要介紹了 titan 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  1. 簡介
    (1)titan:存儲,查詢圖形結構的數據庫。分布式集群環境下,可支持數以千億級別的點和邊,同時支持上千個并發的實時的復雜圖形遍歷,支持ACID事務。
    (2)架構:支持以下3方面的自由組合
    • 節點和邊的存儲:
      • Apache Cassandra
      • Apache HBase
      • Oracle BerkeleyDB(測試使用)
    • 圖形分析組件:
      • Spark
      • Giraph
      • Hadoop
    • 地理,數值,全文檢索支持
      • ElasticSearch
      • Solr
      • Lucene
  2. titan-hbase-es部署范例
    (1)版本對應
    titan:0.54-hadoop2,hbase:1.1.5 (版本相對寬松),elasticsearch:1.4,rexster-server:2.6
    (2)titan server部署
    • rexster-server解壓
    • 修改config/rexster.xml文件,添加如下內容

      <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>
    • 復制titan jar包到rexster lib
    cp   TITAN_HOME/lib/*    REXSTER_HOME/ext/titan/
    • 刪除rexster/lib下的lucene相關jar包,會與titan的引起沖突
    • 開啟rexster
    ./bin/rexster.sh -s -c ./config/rexster.xml
    • 訪問http://ip:8182/graphs/titanexample,REST
  3. titan server接口
    (1)RexPro二進制協議
    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協議

  4. “紅樓夢宗譜”示例
    (1)編寫blueprint腳本,設置schema,索引,添加將節點數據
    ```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();
    // 點的標簽名
    mgmt.makeVertexLabel("people").make(); //該點表示人
    mgmt.makeVertexLabel("hobby").make(); //該點是一個運動
    // 給點的姓名年齡建索引
    mgmt.buildIndex("name",Vertex.class).addKey(name).unique().buildCompositeIndex(); // "search"是配置文件中的標識符
    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協議發送腳本到服務器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 #查詢節點的入射邊
    curl -XPOST http://localhost:8182/graphs/titanexample/vertices/11111?name=zhangsan&age=24 #創建節點
    curl -XPOST http://localhost:8182/graphs/titanexample/edges?_outV=&_label=friend&_inV=2&=<key'> #創建節點間的邊
    ```

    (4)gremlin查詢示例,查詢賈寶玉的父親

    gremlin> g.V.has('name','賈寶玉').next().out('father').name
    ==>賈政

    (5)全文檢索節點,按照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   
    */
  5. 數據展現
    • 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...
  6. 參考網站
    thinkerpop
    gremlin與sql對比查詢語法
    sparql-gremlin插件
    DataStax給出的圖形查詢語言,包括sparql,GraphQL, Cypher, Gremlin

轉載于:https://www.cnblogs.com/72808ljup/p/5587714.html

總結

以上是生活随笔為你收集整理的titan的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。