一. 简介

  1. titan:存储,查询图形结构的数据库。分布式集群环境下,可支持数以千亿级别的点和边,同时支持上千个并发的实时的复杂图形遍历,支持ACID事务。
  2. 架构:支持以下3方面的自由组合

    (1)节点和边的存储:

         Apache Cassandra

         Apache HBase

         Oracle BerkeleyDB(测试使用)

    (2)图形分析组件:

         Spark

         Giraph

         Hadoop

    (3)地理,数值,全文检索支持

         ElasticSearch

         Solr

         Lucene

二. titan-hbase-es部署范例

  1. 版本对应

    (1)titan:0.54-hadoop2

    (2)hbase:1.1.5 (版本相对宽松)

    (3)elasticsearch:1.4

    (4)rexster-server:2.6

  2. titan server部署

    (1)rexster-server解压

    (2)修改config/rexster.xml文件,添加如下内容

    1. <graph>
    2. <graph-enabled>true</graph-enabled>
    3. <graph-name>titanexample</graph-name>
    4. <graph-type>com.thinkaurelius.titan.tinkerpop.rexster.TitanGraphConfiguration</graph-type>
    5. <graph-location></graph-location>
    6. <graph-read-only>false</graph-read-only>
    7. <properties>
    8. <storage.backend>hbase</storage.backend>
    9. <storage.hostname>localhost:2181,localhost:2182,localhost:2183</storage.hostname>
    10. <storage.hbase.table>facebook</storage.hbase.table>
    11. <index.search.backend>elasticsearch</index.search.backend>
    12. <index.search.elasticsearch.client-only>true</index.search.elasticsearch.client-only>
    13. <index.search.hostname>127.0.0.1</index.search.hostname>
    14. <index.search.index-name>facebook</index.search.index-name>
    15. </properties>
    16. <extensions>
    17. <allows>
    18. <allow>tp:gremlin</allow>
    19. </allows>
    20. </extensions>
    21. </graph>

(3)复制titan jar包到rexster lib

  1. ```shell
  2. cp TITAN_HOME/lib/* REXSTER_HOME/ext/titan/
  3. ```

(4)删除rexster/lib下的lucene相关jar包,会与titan的引起冲突

(5)开启rexster

  1. ```shell
  2. ./bin/rexster.sh -s -c ./config/rexster.xml
  3. ```

(6)访问http://ip:8182/graphs/titanexample,REST

三. titan server接口

  1. RexPro二进制协议

    1. public class TestClient {
    2. public static void main(String[] args) throws Exception {
    3. RexsterClient client = RexsterClientFactory.open("localhost", "titanexample");
    4. List<Map<String,Object>> result;
    5. result = client.execute("aa=g.V.has('name','saturn');aa.next()");
    6. //result = client.execute("g.getManagementSystem().get(‘cache.db-cache’)");
    7. // result.toString(): [{name="jupiter"}]
    8. System.out.println(result);
    9. client.close();
    10. }
    11. }
    1. <dependency>
    2. <groupId>com.tinkerpop.rexster</groupId>
    3. <artifactId>rexster-protocol</artifactId>
    4. <version>2.6.0</version>
    5. </dependency>
  2. thinkerpop - REST协议

四. “红楼梦宗谱”示例

  1. 编写blueprint脚本,设置schema,索引,添加将节点数据

    1. com.thinkaurelius.titan.core.schema.TitanManagement mgmt = g.getManagementSystem();
    2. //点的属性名
    3. com.thinkaurelius.titan.core.PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
    4. com.thinkaurelius.titan.core.PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make();
    5. // 点的标签名
    6. mgmt.makeVertexLabel("people").make(); //该点表示人
    7. mgmt.makeVertexLabel("hobby").make(); //该点是一个运动
    8. // 给点的姓名年龄建索引
    9. mgmt.buildIndex("name",Vertex.class).addKey(name).unique().buildCompositeIndex(); // "search"是配置文件中的标识符
    10. mgmt.buildIndex("vertices",Vertex.class).addKey(age).buildMixedIndex("search"); // mixedIndex是外部索引,用es存储索引
    11. // 边的属性
    12. mgmt.makeEdgeLabel("father").multiplicity(com.thinkaurelius.titan.core.Multiplicity.MANY2ONE).make();
    13. mgmt.makeEdgeLabel("mother").multiplicity(com.thinkaurelius.titan.core.Multiplicity.MANY2ONE).make();
    14. mgmt.makeEdgeLabel("hobby").multiplicity(com.thinkaurelius.titan.core.Multiplicity.MULTI).make();
    15. com.thinkaurelius.titan.core.PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).make();
    16. com.thinkaurelius.titan.core.EdgeLabel love = mgmt.makeEdgeLabel("love").signature(time).make();//什么时候确立爱情挂席
    17. mgmt.buildEdgeIndex(love,"lovetime", Direction.BOTH, com.thinkaurelius.titan.core.Order.DESC,time);
    18. mgmt.commit();
    19. //插入点
    20. com.thinkaurelius.titan.core.TitanTransaction tx = g.newTransaction();
    21. Vertex jiazheng = tx.addVertexWithLabel("people"); // 贾政
    22. jiazheng.setProperty("name","贾政");
    23. jiazheng.setProperty("age",48);
    24. Vertex jiabaoyu = tx.addVertexWithLabel("people"); // 贾宝玉
    25. jiabaoyu.setProperty("name","贾宝玉");
    26. jiabaoyu.setProperty("age",18);
    27. Vertex wangfuren = tx.addVertexWithLabel("people"); // 王夫人
    28. wangfuren.setProperty("name","王夫人");
    29. wangfuren.setProperty("age",47);
    30. Vertex xuebaochai = tx.addVertexWithLabel("people"); // 薛宝钗
    31. xuebaochai.setProperty("name","薛宝钗");
    32. xuebaochai.setProperty("age",17);
    33. Vertex cixiu = tx.addVertexWithLabel("hobby");
    34. cixiu.setProperty("name","刺绣");
    35. Vertex zuoshi = tx.addVertexWithLabel("hobby");
    36. zuoshi.setProperty("name","作诗");
    37. //插入边
    38. jiabaoyu.addEdge("father",jiazheng);
    39. jiabaoyu.addEdge("mother",wangfuren);
    40. ElementHelper.setProperties(jiabaoyu.addEdge("love",xuebaochai),"time",1001); // 贾宝玉爱林黛玉,"time"属性为1001
    41. wangfuren.addEdge("hobby",cixiu);
    42. xuebaochai.addEdge("hobby",zuoshi);
    43. tx.commit();
  2. 通过RexPro协议发送脚本到服务器

    1. public static void main(String[] args) throws Exception {
    2. RexsterClient client = RexsterClientFactory.open("localhost", "titanexample");
    3. List<Map<String,Object>> result;
    4. BufferedReader br = new BufferedReader(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("facebook-gremlin")));
    5. String str="";
    6. StringBuffer sb = new StringBuffer();
    7. while((str = br.readLine())!=null){
    8. sb.append(str);
    9. }
    10. System.out.println(sb.toString());
    11. result = client.execute(sb.toString());
    12. System.out.println(result);
    13. client.close();
    14. }
  3. rest api

    1. curl -XGET http://localhost:8182/graphs/titanexample/vertices #查看所有边
    2. curl -XGET http://localhost:8182/graphs/titanexample/edges
    3. curl -XGET http://localhost:8182/graphs/titanexample/keyindices
    4. curl -XGET http://localhost:8182/graphs/titanexample/vertices/16400/in #查询节点的入射边
    5. curl -XPOST http://localhost:8182/graphs/titanexample/vertices/11111?name=zhangsan&age=24 #创建节点
    6. curl -XPOST http://localhost:8182/graphs/titanexample/edges?_outV=<id>&_label=friend&_inV=2&<key>=<key'> #创建节点间的边
  4. gremlin查询示例,查询贾宝玉的父亲

    1. gremlin> g.V.has('name','贾宝玉').next().out('father').name
    2. ==>贾政
  5. 全文检索节点,按照es的格式封装的map

    1. result = client.execute("g.indexQuery(\"vertices\", \"v.age:(17)\").vertices().get(0).getElement()");
    2. for (Map<String, Object> map : result) {
    3. for (Map.Entry<String, Object> en : map.entrySet()) {
    4. System.out.print(en.getKey()+":"+en.getValue()+"\t\t");
    5. }
    6. System.out.println();
    7. }
    8. /**
    9. _type:vertex _properties:{name=薛宝钗, age=17} _id:16496
    10. */
  6. 数据展现

    (1)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.

    (2)VivaGraph it's another free and open source tool for graph visualization tool - but it has a smaller community compared to SigmaJS.

    (3)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.

    (4)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...

五. 参考网站

thinkerpop

gremlin与sql对比查询语法

sparql-gremlin插件

DataStax给出的图形查询语言,包括sparql,GraphQL, Cypher, Gremlin

Titan-红号楼宗谱案例的更多相关文章

  1. 微信公众号UX分析—— 学生作业小结

    1. 不足: 1. 权威性:个人帐号,显得不够正式. 2. 排版问题: + 没有必要的外接端口,界面设计极度缺少排版.哪怕是个人公众号都不至于如此,更何况这是一个学校的教务平台. 3. 反应不及时或无 ...

  2. ArcGIS for Desktop入门教程_第四章_入门案例分析 - ArcGIS知乎-新一代ArcGIS问答社区

    原文:ArcGIS for Desktop入门教程_第四章_入门案例分析 - ArcGIS知乎-新一代ArcGIS问答社区 1 入门案例分析 在第一章里,我们已经对ArcGIS系列软件的体系结构有了一 ...

  3. 18.jvm调优工具及案例分析

    目标: Jmap.Jstack.Jinfo详解 JvisualVm调优工具实战 JVM内存或CPU飙高如何定位 JState命令预估JVM运行情况 系统频繁Full GC导致系统卡顿实战调优 内存泄漏 ...

  4. winform基础——数据访问及几个案例

    数据访问分为三个部分:(1)创建链接(2)创建与执行命令(3)读取或准备相关数据 一,需要引用的命名空间 using data: using data.SqlClient; 二,创建与数据库的链接—— ...

  5. Spring整合Mybatis案例,献给初学的朋友

    今天我们来学习Spring整合Mybatis. 开发环境:Ide:MyEclipse 2017 CI JDK:1.8 首先我们简单的认识下这两个框架 1.Mybatis MyBatis是一个支持普通S ...

  6. ABP架构设计交流群-上海线下交流会的内容分享(有高清录像视频的链接)

    点这里进入ABP系列文章总目录 ABP架构设计交流群-7月18日上海线下交流会内容分享 因为最近工作特别忙,很久没有更新博客了,真对不起关注我博客和ABP系列文章的朋友! 原计划在7月11日举行的AB ...

  7. ABP(现代ASP.NET样板开发框架)主题线下交流会(上海)开始报名了!

    点这里进入ABP系列文章总目录 ABP主题线下交流会(上海)开始报名了 ABP是“ASP.NET Boilerplate Project (ASP.NET样板项目)”的简称.它是采用最佳实践和流行技术 ...

  8. 30天,O2O速成攻略【7.18广州站】

    活动概况 时间:2015年07月18日13:30-16:30 地点:贝塔咖啡(新港中路TIT创意园内创意西路07号楼) 主办:APICloud.七牛.洪海网络 网址:www.apicloud.com ...

  9. “ArcGIS数据应用和地图打印输出

    中国科学院计算技术研究所教育中心 关于开展“ArcGIS数据应用和地图打印输出” 培训班的通知 各相关单位: 随着信息化.网络化.数字化向纵深发展,互联网与空间地理信息系统相互交织,数字地球.“智慧地 ...

随机推荐

  1. TextView所有属性

    android:autoLink设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接.可选值(none/web/email/phone/map/all) android: ...

  2. JS初学之-点击元素,当前的显示样式,其他变灰色

    点击按钮或者其他元素,当前的变化,其他的不变(比如选项卡按钮,点击当前的变为黄色,其他的不变色),这样的情况我们有两种思路: 1.全部清空,当前添加 for(var i=0;i<aBtn.len ...

  3. Oracle字符集的查看查询和Oracle字符集的设置修改

    本文主要讨论以下几个部分:如何查看查询oracle字符集. 修改设置字符集以及常见的oracle utf8字符集和oracle exp 字符集问题. 一.什么是Oracle字符集 Oracle字符集是 ...

  4. Codeforces Round #125 (Div. 2)

    A. Hexadecimal's theorem 三个数没有限制,直接输出\(0\ 0\ n\). B. Special Olympics 分包含和外离情况,包含分2种情况. C. About Bac ...

  5. Hammer.js移动端触屏框架的使用

    hammer.js是一个多点触摸手势库,能够为网页加入Tap.Double Tap.Swipe.Hold.Pinch.Drag等多点触摸事件,免去自己监听底层touchstart.touchmove. ...

  6. java的nio之:java的nio系列教程之serverSocketChannel

    Java NIO中的 ServerSocketChannel 是一个可以监听新进来的TCP连接的通道, 就像标准IO中的ServerSocket一样.ServerSocketChannel类在 jav ...

  7. pip安装模块警告InsecurePlatformWarning: A true SSLContext object is not available.

    在用pip7.1.2版本安装第三方模块时出现了如下警告: /usr/lib/python2.7/site-packages/pip-7.1.2-py2.7.egg/pip/_vendor/reques ...

  8. set and Sequence theory

    https://en.wikipedia.org/wiki/Class_(set_theory) https://en.wikipedia.org/wiki/Zermelo%E2%80%93Fraen ...

  9. 内存泄漏,当您使用的 GetDC 方法和 ReleaseDC 方法 CWnd 类版本

    重现行为的步骤 是从 CWnd 派生的类的一个方法中插入下面的代码在您的应用程序中: CDC *pDC; RECT rect; GetClientRect (&rect); for (int ...

  10. HTML5 拖放(Drag 和 Drop)

    拖放是一种常见的特性,即抓取对象以后拖到另一个位置. 在 HTML5 中,拖放是标准的一部分,任何元素都能够拖放. <!DOCTYPE HTML> <html> <hea ...