I set up Titan with HBase.
I remove all vertex in the graph
It shows null after delete all.
gremlin> g.V.count()
==>0
But if I re-login titan, then there are bunch of empty vertex in the graph
gremlin> g.V.count()
==>85267
I check the value of one vertex, it is empty
gremlin> g.v(840012).map()
What is the reason for empty vertex? How can I clean them completely?
Hi I had the same issue in Titan with cassendra DB.
It was due to closing graph without committing.
g = TitanFactory.open('../conf/titan-cassandra-es.properties');
// Delete Nodes
g.commit();
execute "g.commit();" before closing the graph.
Related
I have a traversal that ends with a drop() to delete a vertex. I would like to be able to tell the difference between the drop() removing a vertex and the traversal just not matching anything.
I tried adding an alias to one of the earlier nodes and select()ing it at the end of the traversal, but that doesn't return anything even when the traversal does match the graph.
e.g.
g.V('id', '1').as('flag')
.out('has_child')
.drop()
.select('flag')
.toList()
The trick is that drop() is a filter step so it removes objects from the traversal stream. You can work around that situation a bit by dropping by sideEffect():
gremlin> g.V().has('person','name','marko')
==>v[1]
gremlin> g.V().has('person','name','marko').sideEffect(drop())
==>v[1]
gremlin> g.V().has('person','name','marko')
gremlin>
The return of the vertex would mean that it was present and dropped, but if no value is returned then it wasn't present in the first place to be dropped.
I have setup my cassandra and titan running. And gremlin also works fine. I have connected gremlin to cassandra using,
gremlin>conf=new BaseConfiguration();
gremlin>conf.setProperty('storage.backend','cassandra');
gremlin>conf.setProperty('storage.hostname', '192.168.14.129');
gremlin>conf.setProperty('storage.keyspace','test');
gremlin>g=TitanFactory.open(conf);
And i have created a vertex,
gremlin> v1 = g.addVertex(label,"person","f_name","Anna");
==>v[8424]
How do i check if this data is entered into cassandra in test keyspace(already in cassandra)?
TinkerPop v3.x distinguishes between a Graph and a TraversalSource.
You should be doing the following only once:
graph = TitanFactory.open(conf)
g = graph.traversal()
Then execute all your traversals with:
g.V().some(...).gremlin(...).steps(...)
To find a Vertex by its id in Titan, you may have to cast the id to a Long. Assuming a Vertex with id 8424l, you can do:
g.V(8424l) // returns a traversal
g.V(8424l).next() // returns that vertex
You shouldn't be calling graph.traversal() more than once, as you get a performance hit every time. In the default Titan v1.0.0 setup, notice how the traversal initialization is done when starting Gremlin server (see conf/gremlin-server/gremlin-server.yaml which executes the scripts/empty-sample.groovy file).
According to your comment underneath here you want to retrieve the just added vertex. Please refer to the Tinkerpop reference. Using your g as notation for the graph it's simple as
gremlin> g.traversal().V(8424)
For getting the properties of the vertex read valueMap step in the reference. For obtaining the vertex not by its Id, but by its properties read has step. Be aware that I linked to the reference for Tinkerpop 3.2.0. You might chose a different version of that document to meet your very version of the stack.
How to merge Two Vertex details and Edge Properties details Together in a single gremlin query.
I'm having two Vertices :
UserInfo vertex
PostInfo vertex
EdgeInfo Between them
With Gremlin Query : g.v(2569472).out('_label','WallPost')[0..1]
I'm getting UserPost Vertex details , i want to add UserVertex detail in the response (i.e gender ) and Edge property detail in the response (i.e EdgeMessage)
I'm trying to compare sql equivalent innerjoin operation with gremlin from sql2gremlin but i'm not able to get the desired result.
SQL2Gremlin is written for TinkerPop 3, you're still using TinkerPop 2 (which is a lot more complicated IMO). Anyway, here's how you would do it in TP2:
gremlin> g = TinkerGraphFactory.createTinkerGraph()
==>tinkergraph[vertices:6 edges:6]
gremlin> g.v(1).outE("knows")
==>e[7][1-knows->2]
==>e[8][1-knows->4]
gremlin> g.v(1).outE("knows").inV().retain([g.v(4)])
==>v[4]
gremlin> g.v(1).as("x").outE("knows").as("y").inV().retain([g.v(4)]).select(["x","y"]) {it.map()} {it.weight}
==>[x:{name=marko, age=29}, y:1.0]
I can't seem to find a specific node in the graph without traversing the whole thing. Is there something I'm missing?
I'm using tinkerpop blueprints.
Orientdb gives some sort of unsemantic id to a node such as '#8:1' - how do I find this without knowing the id? vertex has a property like 'user=jason' that will identify it.
I'm thinking I'll just use redis to store the user/location pair or otherwise use a supernode (no thanks)
Blueprints has the notion of key indices.
https://github.com/tinkerpop/blueprints/wiki/Graph-Indices
Given your example, define a key index for "user", then query it with the key index. Here's an example using OrientDB from a Gremlin prompt:
gremlin> g = new OrientGraph("memory://graph")
==>orientgraph[memory://graph]
gremlin> g.createKeyIndex("user", Vertex.class)
==>null
gremlin> g.addVertex([user:"Jason"])
==>v[#8:-3]
gremlin> g.addVertex([user:"Rick"])
==>v[#8:-4]
gremlin> g.stopTransaction(SUCCESS)
==>null
gremlin> g.V('user','Jason')
==>v[#8:1]
I'm trying to port my Neo4J application to Titan and I'm having some issues related to indexes.
I understand that Titan does not support vertex or edge indexes, only "key" indexes, is it right?
I'm also working with Bulbs models, for example:
class Person(Node):
element_type = 'person'
facebook_id = String(indexed=True)
It should be possible when adding Person(facebook_id='111') to retrieve using:
gremlin> g.getVertices('facebook_id', '111')
It doesn't work and tells me that I need to create the key index before using it. So I dropped the keyspace and manually created the index in rexster doghouse:
gremlin> g.createKeyIndex("facebook_id", Vertex.class);
After that, created Person(facebook_id='111') with Bulbs and tried to retrieve on rexster doghouse:
gremlin> g.getVertices("facebook_id", "111")
And got empty response. When fetching using Titan vertex ID it works, but "facebook_id" comes empty and ".map()" doesn't work:
gremlin> g.v(4)
==>v[4]
gremlin> g.v(4).name
==>Renato Garcia Pedigoni
gremlin> g.v(4).facebook_id # nothing returned!
gremlin> g.v(4).map()
==>javax.script.ScriptException: java.lang.IllegalArgumentException: The value is already used by another vertex and the key is unique
PS
It's the first vertex I created after dropping the keyspace
Is it possible create keys indexes automatically?
Any tips?
Thanks!
Renato Pedigoni
Yes, Titan only supports key indexes which replace the old manual vertex indexes with similar functionality but less overhead.
The exception indicates that the property is not only indexed but also unique (see Titan Types for more information).
Have you tried adding the vertex and key index in Gremlin (i.e. without Bulbs)?
Also, James has done a lot of work on Bulbs with respect to Titan integration, so this particular issue might be resolved in the most current version.