Titan数据库快速入门之神的光芒_水边风的博客-CSDN博客_titan lang


本站和网页 https://blog.csdn.net/albg_boy/article/details/78439051 的作者无关,不对其内容负责。快照谨为网络故障时之索引,不代表被搜索网站的即时页面。

Titan数据库快速入门之神的光芒_水边风的博客-CSDN博客_titan lang
Titan数据库快速入门之神的光芒
水边风
于 2017-11-03 19:37:25 发布
6390
收藏
分类专栏:
图形数据库
titan
图形数据库
同时被 2 个专栏收录
10 篇文章
0 订阅
订阅专栏
titan
6 篇文章
0 订阅
订阅专栏
from:https://rednum.cn/ViewListAction?method=detail&dataid=315&classfyid=1
接触Titan数据库是去年的事情了,今年公司要开发一个新的的关系发现系统,所以把自己掌握的关于Titan的知识记录一下。这篇文章一共有三章,由我和同事合著完成。 1.Titan数据的安装 下载地址:http://s3.thinkaurelius.com/downloads/titan/titan-1.0.0-hadoop1.zip 从titan的官网上我们会看到titan数据是一种非常灵活的数据,可以有一些很多的组合方式: 小编使用的是 Hbase + ElasticSearch + db-cache 方式使用Titan Hbase,ES,和配置的时候都可以是集群的方式,考虑到时入门这里使用Hbase是集群的方式,其它都是单节点的方式
启动Titan数据库 在home目录,解压缩titan-1.0.0-hadoop1.zip并cd这个目录,执行 bin/titan.sh start. 看到类似这样的结果就说明titan数据服务启动成功了:
$ bin/titan.sh startForking Cassandra...Running `nodetool statusthrift`.. OK (returned exit status 0 and printed string "running").Forking Elasticsearch...Connecting to Elasticsearch (127.0.0.1:9300)... OK (connected to 127.0.0.1:9300).Forking Gremlin-Server...Connecting to Gremlin-Server (127.0.0.1:8182)... OK (connected to 127.0.0.1:8182).Run gremlin.sh to connect. 3.启动Titan客户端 gremlin gremlin是一种图形数据查询语言标准,好比关系数据库中SQL语法,使用 bin/gremlin.sh 启动客户端。 看到类似的输出说明gremlin启动成功了:
$ bin/gremlin.sh \,,,/ (o o)-----oOOo-(3)-oOOo-----plugin activated: tinkerpop.serverplugin activated: tinkerpop.hadoopplugin activated: tinkerpop.utilitiesplugin activated: aurelius.titanplugin activated: tinkerpop.tinkergraphgremlin> :remote connect tinkerpop.server conf/remote.yaml 4.配置Titan的工作方式,进入目录conf我们看到有很多预配置的文件 小编使用的是titan-hbase-es.properties这个配置文件,编辑文件,小编根据自己的方式配置如下:
# Titan configuration sample: HBase and Elasticsearch## This file connects to HBase using a Zookeeper quorum# (storage.hostname) consisting solely of localhost. It also connects# to Elasticsearch running on localhost over Elasticsearch's native "Transport"# protocol. Zookeeper, the HBase services, and Elasticsearch must already # be running and available before starting Titan with this file.# The primary persistence provider used by Titan. This is required. It# should be set one of Titan's built-in shorthand names for its standard# storage backends (shorthands: berkeleyje, cassandrathrift, cassandra,# astyanax, embeddedcassandra, hbase, inmemory) or to the full package and# classname of a custom/third-party StoreManager implementation.## Default: (no default value)# Data Type: String# Mutability: LOCALstorage.backend=hbase# The hostname or comma-separated list of hostnames of storage backend# servers. This is only applicable to some storage backends, such as# cassandra and hbase.## Default: 127.0.0.1# Data Type: class java.lang.String[]# Mutability: LOCALstorage.hostname=192.168.1.252# Whether to enable Titan's database-level cache, which is shared across# all transactions. Enabling this option speeds up traversals by holding# hot graph elements in memory, but also increases the likelihood of# reading stale data. Disabling it forces each transaction to# independently fetch graph elements from storage before reading/writing# them.## Default: false# Data Type: Boolean# Mutability: MASKABLEcache.db-cache = true# How long, in milliseconds, database-level cache will keep entries after# flushing them. This option is only useful on distributed storage# backends that are capable of acknowledging writes without necessarily# making them immediately visible.## Default: 50# Data Type: Integer# Mutability: GLOBAL_OFFLINE## Settings with mutability GLOBAL_OFFLINE are centrally managed in Titan's# storage backend. After starting the database for the first time, this# file's copy of this setting is ignored. Use Titan's Management System# to read or modify this value after bootstrapping.cache.db-cache-clean-wait = 20# Default expiration time, in milliseconds, for entries in the# database-level cache. Entries are evicted when they reach this age even# if the cache has room to spare. Set to 0 to disable expiration (cache# entries live forever or until memory pressure triggers eviction when set# to 0).## Default: 10000# Data Type: Long# Mutability: GLOBAL_OFFLINE## Settings with mutability GLOBAL_OFFLINE are centrally managed in Titan's# storage backend. After starting the database for the first time, this# file's copy of this setting is ignored. Use Titan's Management System# to read or modify this value after bootstrapping.cache.db-cache-time = 180000# Size of Titan's database level cache. Values between 0 and 1 are# interpreted as a percentage of VM heap, while larger values are# interpreted as an absolute size in bytes.## Default: 0.3# Data Type: Double# Mutability: MASKABLEcache.db-cache-size = 0.5# The indexing backend used to extend and optimize Titan's query# functionality. This setting is optional. Titan can use multiple# heterogeneous index backends. Hence, this option can appear more than# once, so long as the user-defined name between "index" and "backend" is# unique among appearances.Similar to the storage backend, this should be# set to one of Titan's built-in shorthand names for its standard index# backends (shorthands: lucene, elasticsearch, es, solr) or to the full# package and classname of a custom/third-party IndexProvider# implementation.## Default: elasticsearch# Data Type: String# Mutability: GLOBAL_OFFLINE## Settings with mutability GLOBAL_OFFLINE are centrally managed in Titan's# storage backend. After starting the database for the first time, this# file's copy of this setting is ignored. Use Titan's Management System# to read or modify this value after bootstrapping.index.search.backend=elasticsearch# The hostname or comma-separated list of hostnames of index backend# servers. This is only applicable to some index backends, such as# elasticsearch and solr.## Default: 127.0.0.1# Data Type: class java.lang.String[]# Mutability: MASKABLEindex.search.hostname=127.0.0.1# The Elasticsearch node.client option is set to this boolean value, and# the Elasticsearch node.data option is set to the negation of this value.# True creates a thin client which holds no data. False creates a regular# Elasticsearch cluster node that may store data.## Default: true# Data Type: Boolean# Mutability: GLOBAL_OFFLINE## Settings with mutability GLOBAL_OFFLINE are centrally managed in Titan's# storage backend. After starting the database for the first time, this# file's copy of this setting is ignored. Use Titan's Management System# to read or modify this value after bootstrapping.index.search.elasticsearch.client-only=true
[========] 好回到gremlin.sh,在提示符下输入以下命令,看到类似的结果
gremlin> graph = TitanFactory.open('conf/titan-berkeleyje-es.properties')==>standardtitangraph[berkeleyje:../db/berkeley]gremlin> GraphOfTheGodsFactory.load(graph)==>nullgremlin> g = graph.traversal()==>graphtraversalsource[standardtitangraph[berkeleyje:../db/berkeley], standard]
那么恭喜您,你的第一个Titan数据建立好了,事实上titan已经在Hbase中建立了一个叫做titan的表,和在ES中建立一个叫Search的索引,运行以下的查询语句进一步验证:
gremlin> g==>graphtraversalsource[titangraph[cassandrathrift:127.0.0.1], standard]gremlin> g.V().has('name', 'hercules')==>v[24]gremlin> g.V().has('name', 'hercules').out('father')==>v[16]gremlin> g.V().has('name', 'hercules').out('father').out('father')==>v[20]gremlin> g.V().has('name', 'hercules').out('father').out('father').values('name')==>saturn
在titan这个表中实际存储的是这样一个结构: 这个图对于初学者可能有点蒙逼,请大家不要在意这些细节,这个图讲的主要是希腊神话中神与神自己一些关系,比如谁和谁是兄弟,谁和谁是母女父子兄弟,谁在那里居住,谁在那里战斗过等等等….. 大家可以把这个图上的关系和上面的查询语句对照起来看就一目了然了,我举个例子: g.V().has(‘name’, ‘hercules’).out(‘father’) 表示找一个顶点 V,它有一个属性 name = hercules,然后谁是他的的父亲关系的节点。 6 titan db数据规范 6.1 边的类型下面几种 MULTI:表示点和点之间没有约束,可以有任意多个边相连; SIMPLE:表示点和点只有一个单向进入或出去的边; MANY2ONE:表示一个点可以有多个进入边; ONE2MANY:表示一个点可以有多个出去边; ONE2ONE:表示两个点可以有一对边 示例代码:
mgmt = graph.openManagement()follow = mgmt.makeEdgeLabel('follow').multiplicity(MULTI).make()mother = mgmt.makeEdgeLabel('mother').multiplicity(MANY2ONE).make()mgmt.commit()
6.2 titan数据支持类型 表示我们给点或边定义属性,而这些属性可以是以上的数据类型 6.3 属性的基数 SINGLE: 严格的key->value一对一 LIST:key->values一对多values可以重复 SET:key->values一对多values不可以重复
7.titan主要索引的使用 7.1 Composite Index 示例代码:
graph.tx().rollback() //Never create new indexes while a transaction is activemgmt = graph.openManagement()name = mgmt.getPropertyKey('name')age = mgmt.getPropertyKey('age')mgmt.buildIndex('byNameComposite', Vertex.class).addKey(name).buildCompositeIndex()mgmt.buildIndex('byNameAndAgeComposite', Vertex.class).addKey(name).addKey(age).buildCompositeIndex()mgmt.commit()//Wait for the index to become availablemgmt.awaitGraphIndexStatus(graph, 'byNameComposite').call()mgmt.awaitGraphIndexStatus(graph, 'byNameAndAgeComposite').call()//Reindex the existing datamgmt = graph.openManagement()mgmt.updateIndex(mgmt.getGraphIndex("byNameComposite"), SchemaAction.REINDEX).get()mgmt.updateIndex(mgmt.getGraphIndex("byNameAndAgeComposite"), SchemaAction.REINDEX).get()mgmt.commit()
这种只能用索引的值严格查找等于的方式查找; 7.2 Mixed Index 示例代码
graph.tx().rollback() //Never create new indexes while a transaction is activemgmt = graph.openManagement()name = mgmt.getPropertyKey('name')age = mgmt.getPropertyKey('age')mgmt.buildIndex('nameAndAge', Vertex.class).addKey(name).addKey(age).buildMixedIndex("search")mgmt.commit()//Wait for the index to become availablemgmt.awaitGraphIndexStatus(graph, 'nameAndAge').call()//Reindex the existing datamgmt = graph.openManagement()mgmt.updateIndex(mgmt.getGraphIndex("nameAndAge"), SchemaAction.REINDEX).get()mgmt.commit()
这种Index必须使用ES作为后备,可以模糊查询或值范围查询 8.pom.xml 配置
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.rednum.graph</groupId> <artifactId>redtitan</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.2</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.2</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.16</version> <exclusions> <exclusion> <groupId>javax.jms</groupId> <artifactId>jms</artifactId> </exclusion> <exclusion> <groupId>com.sun.jdmk</groupId> <artifactId>jmxtools</artifactId> </exclusion> <exclusion> <groupId>com.sun.jmx</groupId> <artifactId>jmxri</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-hdfs</artifactId> <version>2.6.4</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-client</artifactId> <version>2.6.4</version> </dependency> <dependency> <groupId>org.apache.hbase</groupId> <artifactId>hbase-client</artifactId> <version>1.2.1</version> </dependency> <dependency> <groupId>org.apache.hbase</groupId> <artifactId>hbase</artifactId> <version>1.2.1</version> <type>pom</type> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>16.0.1</version> </dependency> <dependency> <groupId>com.thinkaurelius.titan</groupId> <artifactId>titan-core</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>com.thinkaurelius.titan</groupId> <artifactId>titan-hbase</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>com.thinkaurelius.titan</groupId> <artifactId>titan-es</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> <version>1.5.2</version> <exclusions> <exclusion> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>prohadoop</groupId> <artifactId>prohadoop</artifactId> <version>0.0.1-SNAPSHOT</version> <type>jar</type> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.7</source> <targe>1.8</targe> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>2.4</version> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>assemble-all</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <name>redtitan</name></project>
9.titan java客户端
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */package com.rednum.graph;import com.google.gson.Gson;import com.google.gson.internal.LinkedTreeMap;import static com.rednum.graph.TiTanDB.INDEX_NAME;import static com.rednum.graph.TiTanDB.load;import static com.rednum.graph.TiTanDB.query;import com.thinkaurelius.titan.core.EdgeLabel;import com.thinkaurelius.titan.core.Multiplicity;import com.thinkaurelius.titan.core.PropertyKey;import com.thinkaurelius.titan.core.TitanFactory;import com.thinkaurelius.titan.core.TitanGraph;import com.thinkaurelius.titan.core.TitanTransaction;import com.thinkaurelius.titan.core.attribute.Geoshape;import com.thinkaurelius.titan.core.attribute.Text;import com.thinkaurelius.titan.core.schema.ConsistencyModifier;import com.thinkaurelius.titan.core.schema.TitanGraphIndex;import com.thinkaurelius.titan.core.schema.TitanManagement;import com.thinkaurelius.titan.core.util.TitanCleanup;import java.io.BufferedReader;import java.io.FileReader;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import org.apache.commons.configuration.BaseConfiguration;import org.apache.commons.configuration.Configuration;import org.apache.tinkerpop.gremlin.process.traversal.Order;import org.apache.tinkerpop.gremlin.process.traversal.P;import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;import org.apache.tinkerpop.gremlin.structure.Direction;import org.apache.tinkerpop.gremlin.structure.Edge;import org.apache.tinkerpop.gremlin.structure.T;import org.apache.tinkerpop.gremlin.structure.Vertex;import org.codehaus.jettison.json.JSONArray;import org.codehaus.jettison.json.JSONObject;/** * * @author X.H.Yang */public class TitanNewGraph {// private final Gson gson = new Gson(); public static TitanGraph create() { try { //创建名为temptest的表。 TitanGraph graph = TitanFactory.build() .set("storage.backend", "hbase") .set("storage.hostname", "192.168.1.252") .set("storage.hbase.table", "newgraph") .set("cache.db-cache", "true") .set("cache.db-cache-clean-wait", "20") .set("cache.db-cache-time", "180000") .set("cache.db-cache-size", "0.5") .set("index.newgraph.backend", "elasticsearch") .set("index.newgraph.hostname", "192.168.1.212") .set("index.newgraph.port", 9300) .set("index.newgraph.elasticsearch.client-only", true) .open(); return graph; } catch (Exception e) { System.out.println(e); return null; } } public static void loadWithoutMixedIndex(final TitanGraph graph, boolean uniqueNameCompositeIndex) { load(graph, null, uniqueNameCompositeIndex); } public static void load(final TitanGraph graph) { load(graph, "newgraph", true); } public static void load(final TitanGraph graph, String mixedIndexName, boolean uniqueNameCompositeIndex) { // Create Schema try { TitanManagement mgmt = graph.openManagement(); final PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make(); TitanManagement.IndexBuilder nameIndexBuilder = mgmt.buildIndex("name", Vertex.class).addKey(name); if (uniqueNameCompositeIndex) { nameIndexBuilder.unique(); } TitanGraphIndex namei = nameIndexBuilder.buildCompositeIndex(); mgmt.setConsistency(namei, ConsistencyModifier.LOCK); final PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make(); if (null != mixedIndexName) { mgmt.buildIndex("vertices", Vertex.class).addKey(age).buildMixedIndex(mixedIndexName); } final PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).make(); final PropertyKey reason = mgmt.makePropertyKey("reason").dataType(String.class).make(); final PropertyKey place = mgmt.makePropertyKey("place").dataType(Geoshape.class).make(); if (null != mixedIndexName) { mgmt.buildIndex("edges", Edge.class).addKey(reason).addKey(place).buildMixedIndex(mixedIndexName); } mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make(); mgmt.makeEdgeLabel("mother").multiplicity(Multiplicity.MANY2ONE).make(); EdgeLabel battled = mgmt.makeEdgeLabel("battled").signature(time).make(); mgmt.buildEdgeIndex(battled, "battlesByTime", Direction.BOTH, Order.decr, time); mgmt.makeEdgeLabel("lives").signature(reason).make(); mgmt.makeEdgeLabel("pet").make(); mgmt.makeEdgeLabel("brother").make(); mgmt.makeVertexLabel("titan").make(); mgmt.makeVertexLabel("location").make(); mgmt.makeVertexLabel("god").make(); mgmt.makeVertexLabel("demigod").make(); mgmt.makeVertexLabel("human").make(); mgmt.makeVertexLabel("monster").make(); mgmt.commit(); TitanTransaction tx = graph.newTransaction(); // vertices Vertex saturn = tx.addVertex(T.label, "titan", "name", "saturn", "age", 34); Vertex sky = tx.addVertex(T.label, "location", "name", "sky"); Vertex sea = tx.addVertex(T.label, "location", "name", "sea"); Vertex jupiter = tx.addVertex(T.label, "god", "name", "jupiter", "age", 5000); Vertex neptune = tx.addVertex(T.label, "god", "name", "neptune", "age", 4500); Vertex hercules = tx.addVertex(T.label, "demigod", "name", "hercules", "age", 30); Vertex alcmene = tx.addVertex(T.label, "human", "name", "alcmene", "age", 45); Vertex pluto = tx.addVertex(T.label, "god", "name", "pluto", "age", 4000); Vertex nemean = tx.addVertex(T.label, "monster", "name", "nemean"); Vertex hydra = tx.addVertex(T.label, "monster", "name", "hydra"); Vertex cerberus = tx.addVertex(T.label, "monster", "name", "cerberus"); Vertex tartarus = tx.addVertex(T.label, "location", "name", "tartarus"); // edges jupiter.addEdge("father", saturn); jupiter.addEdge("lives", sky, "reason", "loves fresh breezes"); jupiter.addEdge("brother", neptune); jupiter.addEdge("brother", pluto); neptune.addEdge("lives", sea).property("reason", "loves waves"); neptune.addEdge("brother", jupiter); neptune.addEdge("brother", pluto); hercules.addEdge("father", jupiter); hercules.addEdge("mother", alcmene); hercules.addEdge("battled", nemean, "time", 1, "place", Geoshape.point(38.1f, 23.7f)); hercules.addEdge("battled", hydra, "time", 2, "place", Geoshape.point(37.7f, 23.9f)); hercules.addEdge("battled", cerberus, "time", 12, "place", Geoshape.point(39f, 22f)); pluto.addEdge("brother", jupiter); pluto.addEdge("brother", neptune); pluto.addEdge("lives", tartarus, "reason", "no fear of death"); pluto.addEdge("pet", cerberus); cerberus.addEdge("lives", tartarus); //commit the transaction to disk tx.commit(); } catch (Exception e) { System.out.println(e); e.printStackTrace(); } } public static void query(TitanGraph graph) { GraphTraversalSource g = graph.traversal(); GraphTraversal<Vertex, Long> count = g.V().count(); System.out.println("共有结点" + count.next()); GraphTraversal<Vertex, Vertex> iterators = g.V(); try { while (iterators.hasNext()) { Vertex ver = iterators.next(); System.out.println(ver); System.out.println(ver.label()); System.out.println(ver.keys()); Set<String> set = ver.keys(); for (String ss : set) { System.out.println(ver.value(ss)); } } } catch (Exception e) { e.toString(); } GraphTraversal<Edge, Edge> edgeAll = g.E(); System.out.println("共有边" + g.E().count().next()); try { while (edgeAll.hasNext()) { Edge ee = edgeAll.next(); Set<String> set = ee.keys(); for (String ss : set) { System.out.println(ss+":"+ee.value(ss)); } System.out.println(ee.label()); System.out.println(ee.outVertex().value("name")); System.out.println(ee.inVertex().value("name")); System.out.println("-----"); } } catch (Exception e) { e.toString(); } System.out.println(g.V().has("name", "hercules").next().value("name")); System.out.println(g.V().has("name", "hercules").next().values("name", "age")); Iterator<Object> iterator = g.V().has("name", "hercules").next().values("name", "age"); while (iterator.hasNext()) { Object object = iterator.next(); System.out.println(object); } Vertex saturn = g.V().has("name", "tanzhuo").next(); System.out.println(saturn); //得到 saturn的孙子节点 System.out.println(g.V(saturn).in("father").in("father").next().value("age")); GraphTraversal<Edge, Edge> a = g.E().has("place", P.eq(Geoshape.point(38.1f, 23.7f))); System.out.println(a); while (a.hasNext()) { Edge e = a.next(); System.out.println(e.keys()); System.out.println(e.label()); System.out.println(e.outVertex().value("name")); System.out.println(e.inVertex().value("name")); System.out.println(e.value("time") + " : " + e.value("place")); } Vertex hercules = g.V().has("name", "hercules").next(); System.out.println(g.V(hercules).out("mother", "father").values("name")); GraphTraversal<Vertex, Vertex> mF = g.V(hercules).out("mother", "father"); while (mF.hasNext()) { Vertex v = mF.next(); System.out.println(v.label() + " : " + v.value("name")); } //repeat(__.in("father")).times(2)表示父亲的父亲,times(2)表示重复两次 System.out.println(g.V(saturn).repeat(__.in("father")).times(2).next().value("name")); GraphTraversal<Vertex, Vertex> monsters = g.V(hercules).out("battled"); while (monsters.hasNext()) { Vertex monster = monsters.next(); System.out.println(monster.label() + " : " + monster.value("name")); } //P.eq(1)表示time,次数为1次 monsters = g.V(hercules).outE("battled").has("time", P.eq(1)).inV(); while (monsters.hasNext()) { Vertex monster = monsters.next(); System.out.println(monster.label() + " : " + monster.value("name")); } Vertex pluto = g.V().has("name", "pluto").next(); GraphTraversal<Vertex, Vertex> liveInTartarusVertex = g.V(pluto).out("lives").in("lives"); while (liveInTartarusVertex.hasNext()) { Vertex vertex = liveInTartarusVertex.next(); System.out.println(vertex.value("name")); } GraphTraversal<Vertex, Vertex> liveInTartarusVertexNo = g.V(pluto).out("lives").in("lives").where(__.is(P.neq(pluto))); while (liveInTartarusVertexNo.hasNext()) { Vertex vertex = liveInTartarusVertexNo.next(); System.out.println(vertex.value("name")); } //P.neq("x")不等于 GraphTraversal<Vertex, Vertex> liveInTartarusVertexNot = g.V(pluto).as("x").out("lives").in("lives").where(P.neq("x")); while (liveInTartarusVertexNot.hasNext()) { Vertex vertex = liveInTartarusVertexNot.next(); System.out.println("======" + vertex.value("name")); } GraphTraversal<Vertex, Map<String, Vertex>> brothers = g.V(pluto).out("brother").as("god").out("lives").as("place").select("god", "place"); while (brothers.hasNext()) { Map<String, Vertex> map = brothers.next(); System.out.println(map); for (Map.Entry<String, Vertex> entry : map.entrySet()) { System.out.println(entry.getKey() + " : " + entry.getValue().value("name")); } } System.out.println(g.V(pluto).outE("lives").next().value("reason")); GraphTraversal<Edge, Edge> reasons = g.E().has("reason").as("r").values("reason").is(Text.textContains("loves")).select("r"); System.out.println(reasons); while (reasons.hasNext()) { Edge e = reasons.next(); System.out.println(e.keys()); System.out.println(e.label()); System.out.println(e.value("reason")); } GraphTraversal<Edge, Map<String, Object>> reasons2 = g.E().has("reason").as("source").values("reason").is(Text.textContains("loves")).as("reason").select("source") .outV().values("name").as("god").select("source").inV().values("name").as("thing").select("god", "reason", "thing"); while (reasons2.hasNext()) { Map<String, Object> map = reasons2.next(); System.out.println(map); for (Map.Entry<String, Object> entry : map.entrySet()) { System.out.println(entry.getKey() + " : " + entry.getValue()); } } } public static void main(String[] args) throws Exception { try { TitanGraph graph = TitanNewGraph.create(); //load(graph); query(graph); graph.close(); } catch (Exception e) { e.toString(); } }}
10.程序输出
共有结点12v[4120]location[name]skyv[8216]location[name]seav[4160]human[name, age]alcmene45v[8256]god[name, age]pluto4000v[12352]location[name]tartarusv[4200]god[name, age]jupiter5000v[8296]monster[name]nemeanv[4208]monster[name]hydrav[4224]titan[name, age]tanzhuo34v[8320]monster[name]cerberusv[4304]god[name, age]neptune4500v[4336]demigod[name, age]hercules30共有边17reason:no fear of deathlivesplutotartarus-----petplutocerberus-----brotherplutojupiter-----brotherplutoneptune-----fatherjupitertanzhuo-----reason:loves fresh breezeslivesjupitersky-----brotherjupiterneptune-----brotherjupiterpluto-----livescerberustartarus-----reason:loves waveslivesneptunesea-----brotherneptunejupiter-----brotherneptunepluto-----fatherherculesjupiter-----motherherculesalcmene-----place:point[37.7,23.9]time:2battledherculeshydra-----time:1place:point[38.1,23.7]battledherculesnemean-----place:point[39.0,22.0]time:12battledherculescerberus-----herculesorg.apache.tinkerpop.gremlin.util.iterator.IteratorUtils$3@b1534d3hercules30v[4224]30[GraphStep([],edge), HasStep([place.eq(point[38.1,23.7])])][time, place]battledherculesnemean1 : point[38.1,23.7][GraphStep([v[4336]],vertex), VertexStep(OUT,[mother, father],vertex), PropertiesStep([name],value)]god : jupiterhuman : alcmeneherculesmonster : hydramonster : nemeanmonster : cerberusmonster : nemeanplutocerberuscerberus======cerberus{god=v[4200], place=v[4120]}god : jupiterplace : sky{god=v[4304], place=v[8216]}god : neptuneplace : seano fear of death[GraphStep([],edge), TraversalFilterStep([PropertiesStep([reason],value)])@[r], PropertiesStep([reason],value), IsStep(CONTAINS(loves)), SelectOneStep(r)][reason]livesloves fresh breezes[reason]livesloves waves{god=jupiter, reason=loves fresh breezes, thing=sky}god : jupiterreason : loves fresh breezesthing : sky{god=neptune, reason=loves waves, thing=sea}god : neptunereason : loves wavesthing : sea
最后请大家把输出结果和对应的语句对照的看相信会对Titan数据库有一个初步的了解,谢谢观赏,本课程完
水边风
关注
关注
点赞
收藏
评论
Titan数据库快速入门之神的光芒
from:https://rednum.cn/ViewListAction?method=detail&dataid=315&classfyid=1接触Titan数据库是去年的事情了,今年公司要开发一个新的的关系发现系统,所以把自己掌握的关于Titan的知识记录一下。这篇文章一共有三章,由我和同事合著完成。1.Titan数据的安装下载地址:http://s3.think
复制链接
扫一扫
专栏目录
Titan图数据库安装文件
12-05
Titan图数据库安装文件titan-1.0.0-hadoop1.zip
分布式图形数据库 Titan.zip
07-17
Titan 是一个在服务器集群搭建的分布式的图形数据库,特别为存储和处理大规模图形而优化。集群很容易扩展以支持更大的数据集,Titan有一个很好的插件式性能,这个性能让它搭建在一些成熟的数据库技术上像 Apache Cassandra、Apache HBase、 Oracle BerkeleyDB。插件式索引架构可以整合 ElasticSearch 和Lucene技术。内置实现 Blueprints graph API,支持 TinkerPop所有的技术。 特性1,支持不同的分布式存储层Apache Cassandra (distributed)Apache HBase (distributed)Oracle BerkeleyDB (local)Persistit (local)2 .可以更加数据集的大小和用户基数弹性扩展3. 分布式存储的复制,高容错性4,支持很多字符集和热备份5,支持 ACID 和 eventual consistency(最终一致性)6,支持的索引ElasticSearchApache Lucene7,内置实现 TinkerPop graph APIGremlin graph query languageFrames object-to-graph mapperRexster graph serverBlueprints standard graph API使用使用文档在这里 Titan documentation ,邮件列表:mailing list,github主页:https://github.com/thinkaurelius/titan。
标签:图数据库
评论 1
您还未登录,请先
登录
后发表或查看评论
Titan 介绍
最新发布
weixin_42241611的博客
10-04
499
是基于的高性能单机 key-value 存储引擎插件。当 value 较大(1 KB 以上或 512 B 以上)的时候,Titan 在写、更新和点读等场景下性能都优于 RocksDB。但与此同时,Titan 会占用更多硬盘空间和部分舍弃范围查询。随着 SSD 价格的降低,Titan 的优势会更加突出,让用户更容易做出选择。
Titan图数据库结构概述
萧何的博客
09-29
2212
结构概述
titan是一个图形数据库引擎。titan本身专注于紧凑的图形序列化、丰富的图形数据建模和高效的查询执行。此外,titan利用Hadoop进行图形分析和批处理图处理。titan为数据持久性、数据索引和客户端访问实现健壮的、模块化的接口。titan的模块化架构使其能够与广泛的存储、索引和客户端技术进行互操作;它还简化了扩展titan的过程,以支持新的titan。
在titan和磁盘之间有一...
常见图数据库比较
weixin_30593261的博客
08-09
1825
1.数据库分类: 传统的关系数据库和NoSQL数据库
传统的关系数据库:mySQL、oracle
NoSQL数据库分为Graph,Document,Column Family以及Key-Value Store等四种,分别对应titan、ES、hbase、redis。
2.图数据库相对于传统关系型数据库的优点
(1)传统关系型数据库为每一类实体建表,但没有对...
图数据库Titan/Gremlin查询过程分析
Michael的专栏
01-12
7230
本文对Titan/Gremlin的查询过程进行分析,为了简化明了,直接使用例子说明。
查询g.v(1).out.has(name, "David"),当前titan的做法是:
v(1)把v1的id找出来,返回该id
--> out从上一步结果集合中,拉出一个,即v1的id,并把该点对应的那行数据从hbase里读取出来(即该点的属性、相邻点、相邻边),找出出度节点,返回结果re
数据库基础 新手入门(一)
weixin_62517543的博客
03-20
3693
MySQL数据库应用与设计任务的设计知识有:NySQL的下载,安装,配置,E-R图,概念设计,逻辑设计,数据类型,表,数据库,运算符,函数,约束,数据完整性,触发器,查询,视图,存储过程,安全,权限等知识。
数据库:
...
数据库快速入门
weixin_43451783的博客
04-24
328
一天学完Postgre
1. 数据库基础知识入门
数据库表:一系列二维数组的集合。
数据类型:整数、浮点数、日期时间、字符串、二进制数据。
数据库系统构成
数据库
数据库管理系统
数据库应用程序
SQL语言:对数据库进行查询和修改操作语言
DDL: 数据库定义语言,DROP、CREATE、ALTER等语句
DML: 数据库操作语言,INSERT、UPDATE、DELETE语句
DQL: 数据库查询语言,SELECT等语句
DCL: 数据库控制语...
Titan图形数据库的应用实例讲解
XiaoXiao_Yang77的博客
10-13
7559
前言因公司业务发展,需要建立完整的关系图谱检索系统。经各种比较与考量,我们采用Titan图形数据库来处理复杂的逻辑关系。这篇《Titan数据库快速入门之神的光芒》同事已经详细介绍了Titan数据库的安装与使用,这里不再赘述。此篇博客介绍Titan的实际应用与成果展示,方便读者更好的理解Titan。项目背景本项目基于工程大数据进行研究,下图为Hbase中的部分数据展示。通常,一个工程项目有一个或者多个
图数据库 Titan 快速入门
热门推荐
samhacker的专栏
10-01
2万+
尤其在互联网世界,图计算越来越受到人们的关注,而图计算相关的软件也越来越丰富。本文将快速展示 Titan这个open source 的图数据库。
数据库的简单入门
weixin_44253162的博客
11-28
3406
数据库入门
首先讲讲数据库是个啥,首先数据库是一个装数据的地方,不管是什么数据,你都可以往里塞,
存储方式的话,在我接触的一些数据库里,都是以表的形式存储的,也就是通常说的关系型数据库,包括查看,也是一张表,就像是平常的班级个人信息表一样第一行是表头也就是列中元素的属性,之后的行就是内容。
而且数据库的独立性带来了很多的方便,至少不用担心,小手一滑数据就不见了。
数据库的也具有数据共享性,也就是说,可以被多个用户共享,很像现在的qq的在线文档是不是
而数据库还有一点就是防止数据丢失
废话不多说,该讲讲数据库
Rocksdb 与 TitanDb 原理分析 及 性能对比测试
天行健,地势坤
05-18
1426
文章目录前言Rocksdb的compaction机制compaction作用compaction分类level style compaction(rocksdb 默认进行的compaction策略)level 的文件存储结构compaction过程compaction中的level target sizeuniversal style compactionfifo style compactionTitan相比于rocksdb的核心优化key-value 存储优化key-value 区分逻辑版本控制GC垃圾
直击Titan图数据库:如何提升25%+的反欺诈检测效率?
omnispace的博客
05-13
2277
传统的关系型数据库通过实体和关系来建模,在过去的很长一段时间内都占据着绝对的统治地位。但是随着大数据的兴起,它的一些缺陷也变得越来越明显,特别是在需要处理非常复杂的实体关系时,关系型数据库变得越来越力不从心。当我们要表示实体间的多对多关系时,一般会建立关系表。当要看实体间的关系时,我们需要把这种关系再关联起来。这通常是一项非常消耗性能的工作,特别是在关系非常复杂或者关系层次很多的情况下,需要关联非...
mybatis配置多数据源
西瓜
02-21
104
多源数据库配置:三种数据库连接池,好文章
https://www.cnblogs.com/wzk-0000/p/9544432.html
https://blog.csdn.net/weixin_37664872/article/details/80088014
https://blog.csdn.net/tuesdayma/article/details/81081666
网上的文...
Neo4J是如何干掉OrientDB、Titan的
专注交流
08-08
6850
Neo4J是如何干掉OrientDB、Titan的
TitanDB 数据库
我们先研究了 TitanDB,它各项强大的功能和极佳的可扩展性一开始让我们非常振奋。可惜的是,TitanDB 的启动和维护都非常复杂,必须得从 Cassandra 或 HBase 后台运行。
我们关心的另一个功能是最终一致存储,它并不符合 ACID 原理。这表示,如果我们要长时间运行大型图形数据库,最后可能会出现不一...
Titan Framework 项目部署
Titan_Framework的博客
06-28
803
介绍本文用来介绍Titan Framework的使用和下载, Titan Framework的多数据库支持,各个微服务之间的调用,微服务的配置与部署。Titan Framework依赖包的下载跟使用Titan Framework包可以做在Titan Framework PaaS平台上进行下载,提供各个版本。使用如下代码把Titan Framework 包加到本地maven仓库中:Echo move...
Titan 体系结构概述
风远陌
11-02
1682
from:http://s3.thinkaurelius.com/docs/titan/1.0.0/arch-overview.html
第1部分 体系结构概述
Titan是一个图形数据库引擎。Titan专注于紧凑的图形序列化、丰富的图形数据建模和高效的查询执行。此外,Titan还利用Hadoop进行图形分析和批处理图形处理。Titan为数据持久性、数据
图数据库titan 和 rexster安装手册
weixin_33943836的博客
11-13
58
titan是图数据库, rexster是图显示服务
titan 安装
下载 titan 0.3.2
解压 titan-all-0.3.2.zip 到 /opt/hugedata/share/解压后得到 /opt/hugedata/share/titan-all-0.3.2/建立软连接cd /opt/hugedata/share/ln -s titan-all-0.3.2 titan
/et...
Titan数据库简介
风远陌
11-02
1926
from: http://s3.thinkaurelius.com/docs/titan/1.0.0/benefits.html
第1部分 Titan的优势
Titan的设计是为了支持无法在单台服务器上进行存储和计算的图集处理。对于实时遍历和分析查询的缩放图数据处理是泰坦的基础,对实时遍历和分析查询的弹性数据处理是Titan的基本优势。本节将讨论Titan的各种具体好处
图数据库Titan的使用总结
胖大星的博客
08-05
5251
1.搭建环境(hbase+es+titan1hadoop1为例)
下载安装
下载安装titan-1.0-hadoop1http://s3.thinkaurelius.com/downloads/titan/titan-1.0.0-hadoop1.zip
下载安装最新JDKhttp://www.oracle.com/technetwork/java/javase/downloads/jdk8-d
“相关推荐”对你有帮助么?
非常没帮助
没帮助
一般
有帮助
非常有帮助
提交
©️2022 CSDN
皮肤主题:编程工作室
设计师:CSDN官方博客
返回首页
水边风
CSDN认证博客专家
CSDN认证企业博客
码龄6年
暂无认证
124
原创
13万+
周排名
108万+
总排名
73万+
访问
等级
5386
积分
275
粉丝
275
获赞
82
评论
1027
收藏
私信
关注
热门文章
大数据面试题及答案-汇总版
194884
大数据建模五步法
37370
img显示base64图片
34295
java 给时间增加几个小时方法
31519
java8 方法中 传递函数
26339
分类专栏
生信分析
2篇
机器学习
2篇
操作手册
1篇
读书笔记
1篇
写作篇
1篇
数据仓库
大数据
23篇
坑灬区
5篇
遇见的异常
25篇
夯实基础
13篇
Python学一点
17篇
小工具集
9篇
技巧篇
8篇
小知识大用处
5篇
深度研究
1篇
考研笔记
11篇
demo
36篇
学习知识点
17篇
旁征博引
17篇
工作总结
3篇
工具的使用
3篇
翻译—博客
2篇
翻译—问题
翻译—文章
titan
6篇
图形数据库
10篇
爬虫
15篇
虚拟机
1篇
最新评论
jq 动态添加 radio
明夜紫:
感谢让我的蛋突然不疼了
spark "main" java.lang.ArrayIndexOutOfBoundsException: 10582
XmoolJ:
解决了谢谢楼主
spark "main" java.lang.ArrayIndexOutOfBoundsException: 10582
Faith_xzc:
虽然不知道为什么,但是在maven中直接添加就对了
Idea 项sout一样添加自定义快捷输入
weixin_44840243:
我想实现 .sout 一样可以动态获取文本 怎么做到
at org.apache.http.util.EntityUtils.toString(EntityUtils.java:244) 线程卡死
AliShang:
改成EntityUtils.toByteArray()
您愿意向朋友推荐“博客详情页”吗?
强烈不推荐
不推荐
一般般
推荐
强烈推荐
提交
最新文章
【bug修复】java: Internal error in the mapping processor: java.lang.NullPointerException
mac系统转发80端口
xxljob 任务没有触发
2021年9篇
2020年34篇
2019年27篇
2018年40篇
2017年87篇
目录
目录
分类专栏
生信分析
2篇
机器学习
2篇
操作手册
1篇
读书笔记
1篇
写作篇
1篇
数据仓库
大数据
23篇
坑灬区
5篇
遇见的异常
25篇
夯实基础
13篇
Python学一点
17篇
小工具集
9篇
技巧篇
8篇
小知识大用处
5篇
深度研究
1篇
考研笔记
11篇
demo
36篇
学习知识点
17篇
旁征博引
17篇
工作总结
3篇
工具的使用
3篇
翻译—博客
2篇
翻译—问题
翻译—文章
titan
6篇
图形数据库
10篇
爬虫
15篇
虚拟机
1篇
目录
评论 1
被折叠的 条评论
为什么被折叠?
到【灌水乐园】发言
查看更多评论
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额
抵扣说明:
1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。 2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。
余额充值