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.
Related
On an Azure cosmosDB gremlin instance,
I have 2 vertices A and B linked by and edge E.
Both vertices has a 'name' property.
I'd like to run a query which will take A's name and put it in B
when I run
g.V("AId").as("a").oute().inv().hasLabel('B').property("name",select('a').values('name'))
I get the following error :
GraphRuntimeException ExceptionMessage : Gremlin Query Execution Error: Cannot create ValueField on non-primitive type GraphTraversal.
It looks like the select operator is not correctly used.
Thank you for your help
EDITED based on discussion in comments
You have oute and inv in lower case. In general, the steps use camelCase naming, such as outE and inV (outside of specific GLVs), but in the comments it was mentioned that CosmosDB will accept all lower case step names. Assuming therefore, that is not the issue here, the query as written looks fine in terms of generic Gremlin. The example below was run using TinkerGraph, and uses the same select mechanism to pick the property value.
gremlin> g.V(3).as("a").outE().inV().has('code','LHR').property("name",select('a').values('city'))
==>v[49]
gremlin> g.V(49).values('name')
==>Austin
What you are observing may be specific to CosmosDB and it's probably worth contacting their support folks to double check.
I have an application with more than 3000 vertices having the same label , let's say ABC. It is required for my application to get the list of all the vertices and their properties for the user to choose the entity and interact with it. For that I am writing a GetAllVertices query for label ABC.
The id's of the vertices are numbers
Ex: 1,2,3,..
The following query returns the correct amount of vertices ~ 3000
g.V().hasLabel('ABC').dedup().count()
The following query however only returns around 1600 entries
g.V().hasLabel('ABC').elementMap()
I am trying to understand what is happening and how can I get the elementMap for all the vertices that I am interested in. I think it might be because of the hash function elementMap() might be using that is causing the collision of the keys and thus resulting in overwriting some of the keys with different entries.
Using TinkerGraph I am not able to reproduce this behavior.
gremlin> g.inject(0).repeat(addV('ABC').property(id,loops())).times(3000)
==>v[2999]
gremlin> g.V().hasLabel('ABC').count()
==>3000
gremlin> g.V().hasLabel('ABC').elementMap().count()
==>3000
If you can say more about the data in your graph I can do some additional tests and try to reproduce what you are seeing.
UPDATED 2022-08-03
I ran the same test on Amazon Neptune version 1.1.1.0.R4 from a Neptune notebook, and it worked there as well.
%%gremlin
g.inject(0).repeat(addV('ABC').property('p1',loops())).times(3000)
v[a6c131cc-42e8-3713-c82d-faa193b118a0]
%%gremlin
g.V().hasLabel('ABC').count()
3000
%%gremlin
g.V().hasLabel('ABC').elementMap().count()
3000
I'm trying to execute an OLAP traversal on a query that needs to check if a vertex has a neighbour of certain type.
i keep getting
Local traversals may not traverse past the local star-graph on GraphComputer
my query looks something like:
g.V().hasLabel('label1').
where(_.out().hasLable('label2'))
I'm using the TraversalVertexProgram.
needless to say, when running the same query in oltp mode there is no problem
is there a way to execute such logic?
That is limitation of TinkerPop OLAP GraphComputer. It operate on 'star-graph' objects. The vertex and connected edges only. It uses message passing engine inside. So you have to rewrite you query.
Option 1: start from label2 and go t label1. This should return the same result
g.V().hasLabel('label2').in().hasLabel('label1')
Option2: try to use unique edge labels and check edge label instead
g.V().hasLabel('label1').where(_.outE('label1_label2'))
I cannot select a specific vertex, by executing g.V(3640).valueMap(true).unfold(). Any command which contains an ID between the parentheses in the g.V() command does not seem to work.
This is what I did:
I'm new to Graph databases and experimenting with the Gremlin console. I started by creating an instance:
graph = TinkerGraph.open()
g=graph.traversal()
and loading sample data by importing a .graphml database file:
g.io(graphml()).readGraph('/full/path/to/air-routes-latest.graphml')
which seemed to work fine because a count gives a nice result back
gremlin> g.V().count()
==>3642
Unfortunately the following does not work:
gremlin> g.V(3640).valueMap(true).unfold()
Which I think is odd, because by executing the following
gremlin> g.V()
==>v[3640]
==>v[2306]
...
the ID does seem to exist. Any ideas why I cannot access a specific ID? I tried different commands but g.V() seems to work fine, and g.V(3640) does not. Is it because I use TinkerGraph instead of a Gremlin database, of what might be the problem?
EDIT:
It seems that my id's were saved as strings, because g.V("2").valueMap(true).unfold() does give me results.
I think you likely have an issue with the "type" of the identifier. I suspect that if you do:
g.V(3640L)
that you will get the vertex you want. By default, TinkerGraph handles id equality with equals() so if you try to find an integer when the id is a long it will act like it's not there. You can modify that default if you like with an IdManager configuration discussed here. Note that this is also discussed in more detail in Practical Gremlin.
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.