Menu
  • HOME
  • TAGS

How to use T.in with gremlin-java 2.6.0

java,scala,gremlin

Not sure about Scala, but here's a working example in Java: import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.impls.tg.TinkerGraph; import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; import com.tinkerpop.gremlin.Tokens.*; import com.tinkerpop.gremlin.java.GremlinPipeline; import java.util.Arrays; /** * @author Daniel Kuppitz (daniel at thinkaurelius.com) */ public class App { public static void main(final String[] args) throws Exception { final TinkerGraph g = TinkerGraphFactory.createTinkerGraph();...

Gremlin, join vertices of same type and add edge when the properties empNo and mgrno matches

graph,edge,vertex,titan,gremlin

I assume that you want to iterate all vertices. You could do it with a sideEffect pretty easily: g.V.has("mgrNo",neq,0).sideEffect{ g.V.has("empNo",it.mgrNo).next().addEdge("manages",it) } Note that if you are using a graph that supports transactions you will need to commit() your changes to persist them. ...

[Titan Example Graph]: copySplit and back not working as expected

gremlin

Already answered on the Gremlin users mailing list, but here we go again: These 2 alternatives would still work in Gremlin3 (with a slightly different syntax, but the concept is the same): gremlin> g.V().has("age", T.lte, 1000).as("young").out("battled").has("name", "cerberus").as("monster").select() ==>[young:v[24], monster:v[44]] Or: gremlin> g.V().has("age", T.lte, 1000).out("battled").has("name", "cerberus").path() ==>[v[24], v[44]] ...

Gremlin Java and querying

java,graph-databases,gremlin

.query() is the core API. Under the hood GremlinPipeline uses this API to chain your steps together. Usually I only use .query() when I have a 1-level-depth traversal without filters. Cheers, Daniel...

Gremlin simplePath() not working in a loop

graph-databases,titan,gremlin

I guess that's what you're looking for: gremlin> g.v(1).as("x").dedup().out("knows").loop("x") { it.object.out("knows").hasNext() } { true }.path() ==>[v[1], v[2]] ==>[v[1], v[4]] ==>[v[1], v[2], v[4]] ==>[v[1], v[4], v[3]] ==>[v[1], v[4], v[3], v[1]] gremlin> ...

Unable to install gremlin-neo4j through gremlin shell

neo4j,gremlin,tinkerpop3

I guess there's some discrepancy between documentation and where Neo4j stands in terms of official release. Neo4j was removed from the repository around M7 at the time TinkerPop started making releases under the Apache Software Foundation (given license conflicts). It was added back to the repository after the M9 release...

How to summarize property values in Gremlin?

groovy,titan,gremlin,rexster

Simple groovy: l = [" 3"," 3"," 3"," 3"," 3"," 3"," 3"," 3"," 3"] s = 0; l.each{s+=it.toInteger()} s ==>27 ...

Loading data into Titan with bulbs and then accessing it

python,titan,gremlin,rexster,bulbs

My answer will be somewhat incomplete because I can't really supply answers around Bulbs but you do ask some specific questions which I can try to answer: How do I save it in Titan?? (like a commit in SQL) It's just g.commit() in Java/Groovy. How do I access it later??...

Gremlin : Multiple filter condition “OR”

graph-databases,titan,gremlin

You could do: g.V('type','product').or(_().has('discontinued', true), _().has('unitsInStock', 0)) See the or step in GremlinDocs....

How to group all sibling nodes from different parents by common sibling in a graph using Gremlin/OrientDB

graph,graph-databases,orient-db,gremlin

It took 5hours but I found the query that does it: The groupBy mapping basically takes as a key the Text node {it} and as a value the leaf from text->parent->sibling {it.inE.outV.outE.inV.hasNot('@class','Text').except([v])} that is not of class Text except for the Input. The last line m.sort{a,b -> b.value.size() <=> a.value.size()}...

Find the cross node for number of nodes in Gremlin?

orient-db,gremlin

With the toy graph. Let's assume vertex 1 and 6 are given: g = TinkerGraphFactory.createTinkerGraph() m=[:] g.v(1,6).both.groupCount(m) m.sort{-it.value} Sorted Map m contains: ==>v[3]=2 ==>v[2]=1 ==>v[4]=1 ...

How to use “AND” condition in GremlinPipeLine

titan,gremlin,tinkerpop-blueprint

I don't think there's much need for use of and step here. Just pipeline both has conditions: g.V.has('name','John').has('age',22) That's effectively an AND operation. In Java I guess this would be: new GremlinPipeline(graph).V().has("name", "John").has("age",22); Please read this post on how to convert from groovy to java for more information on that...

Gremlin querying through groovy script using bulbs

python,titan,gremlin,bulbs

You can get the path. Try: g.V('nid', 'ddbe4d52e7034ffeb17c9426fc1484af').outE.inV .has('nid', '754d5e84daad4140ba93cb10ce00cde0').outE.inV .has('nid', '7b2848543b444fcc94e69d7930ffa996').path This gives you a list with: [startVertex, startIntermediateEdge, intermediateVertex, intermediateTargetEdge, targetVertex] ...

How to select optional graph structures with Gremlin?

graph-databases,gremlin,titan

You could do: g.V('description',CONTAINS,'developer').as('user').transform{it.bothE.toList()}.as('relationship').select in this way, you should get an empty list for those developers who don't have edges....

How to get tuples in gremlin?

titan,gremlin

For the first part of your question regarding tuples - just transform to a two (or more) item list of your properties: gremlin> g = TinkerGraphFactory.createTinkerGraph() ==>tinkergraph[vertices:6 edges:6] gremlin> g.V.has('age').transform{[it.name,it.age]} ==>[marko, 29] ==>[vadas, 27] ==>[josh, 32] ==>[peter, 35] then to sort, just use order step and pick the item in...

Issue with GremlinPipeline

graph,gremlin,titan

Consider starting your pipeline with the childVertices. In Gremlin Groovy that would be: childVertices._().outE().has(SCORE).or(... or I guess if you were using GremlinPipeline directly, then something like: new GremlinPipeline(childVertices).has(SCORE).or(.... ...

gremlin outputs different from as seen on the internet, I think in bytes

groovy,titan,gremlin

When vertices are added to Titan an Element identifier is assigned. That value is up to Titan and you should not expect it to start at "1" or any other specific number when you do. If you need there to be some kind of number like that you should add...

Create a vertex with Label in Gremlin

orient-db,gremlin

I missed it in the tutorial here You can use g.addVertex("class:className")...

Finding all path with specific edge types in Tinkerpop 3

gremlin,tinkerpop,tinkerpop3

Use jump to recursively traverse down a path and the path step to realize the path traversed: gremlin> g = TinkerFactory.createClassic() ==>tinkergraph[vertices:6 edges:6] gremlin> g.V(1).as('x').out('knows').jump('x'){it.loops<3}{true} ==>v[2] ==>v[4] gremlin> g.V(1).as('x')out().jump('x'){it.get().id() != 5 && it.loops < 6}.path() ==>[v[1], v[4], v[5]] See more details in GremlinDocs: http://www.tinkerpop.com/docs/3.0.0-SNAPSHOT/#jump-step ...

TF-IDF algorithm in gremlin

graph-databases,gremlin,tf-idf

I probably haven't covered the part B: ...in relation to each applicable term in Ts. ...but the rest should work as expected. I wrote a little helper function that accepts single terms as well as multiple terms: tfidf = { g, terms, N -> def closure = { def paths...

Is com.tinkerpop.pipes.Pipe implementation safe to cache and re-use later on other graph instances?

gremlin,tinkerpop

I've never trusted reset despite what the javadocs say on the matter, however this test seems to work: gremlin> pipe = _().out('knows').name;null ==>null gremlin> pipe.setStarts(new SingleIterator<Vertex>(g.getVertex(1))); ==>null gremlin> pipe ==>vadas ==>josh gremlin> pipe gremlin> pipe.setStarts(new SingleIterator<Vertex>(g.getVertex(1))); ==>null gremlin> pipe ==>vadas ==>josh Calling setStarts seems to properly reset the iterator within...

Retrieving OrientVertex Objects from OrientDB

graph-databases,orient-db,gremlin,tinkerpop-blueprint

Looking at your code, you are using the Graph API. After calling getRawGraph() you are not working with the Graph API any more, but with the Document API (method name is a little bit confusing). Having a reference to the OrientGraph there are several possibilities Using orientGraph#getVertex*(..) / orientGraph#getVertices*(..)style of...

How should hasNot() work in Gremlin?

graph,gremlin,titan,tinkerpop

Just to close the loop on this here in SO - a GitHub issue has been created for this problem (TinkerGraph does show the correct behavior): https://github.com/thinkaurelius/titan/issues/868 Please follow the resolution there....

Faunus json reader error in json file format

java,json,gremlin,faunus

Your example shows a format that is not a valid JSON format readable by Faunus (aka titan-hadoop). That example shows an edge list format produced from the Blueprints GraphSON writer. Faunus requires an adjacency list format as shown in the documentation (correctly mentioned in the comment by Konstantin on the...

Gremlin iterative conditional traversal

graph-databases,titan,gremlin

I don't think you need all the ifThenElse stuff. Assuming I now have your model right, I think you just need this: gremlin> g = new TinkerGraph() ==>tinkergraph[vertices:0 edges:0] gremlin> g = new TinkerGraph() ==>tinkergraph[vertices:0 edges:0] gremlin> usa = g.addVertex([name:"USA"]) ==>v[0] gremlin> va = g.addVertex([name:"VA"]) ==>v[1] gremlin> fairfax = g.addVertex([name:"Fairfax"])...

How to efficiently create a vertex with a label and several properties?

titan,gremlin,tinkerpop

No. As of Titan 0.5.4, there is no API that allows you to add it all at once. In fact, even the Gremlin Groovy sugar of: g.addVertex([name:"stephen"]) just calls Element.setProperty(k,v) for each key/value pair in the Map. In TinkerPop3 and Titan 0.9/1.0, you can do: g.addVertex(T.label,"person","name","stephen") so it is a...

Concurrent gremlin-server and graph queries in java

java,server,gremlin,tinkerpop3

As you've found, what you are trying to do won't work because two separate processes cannot work on the embedded Neo4jGraph. As it stands you can't get access to the configured graph instances from the GremlinServer object and I'm not sure I'd change that as I'm not completely sure that...

How to connect gremlin with bitsy database?

groovy,gremlin,bitsy

There are a number of issues here. First, note that Bitsy is officially compatible with TinkerPop 2.4.0 not 2.5.0, so while it might work in the 2.5.0 Gremlin Console, I would recommend going backward to 2.4.0. Next, you have to be a little careful with .* imports as they aren't...

Gremlin and Frames

gremlin,tinkerpop

Try this: gremlin> Grape.grab([group:"com.tinkerpop",module:"frames",version:"2.4.0"]) ==>null gremlin> graph = TinkerGraphFactory.createTinkerGraph() ==>tinkergraph[vertices:6 edges:6] gremlin> import com.tinkerpop.frames.* ==>import com.tinkerpop.gremlin.* ==>import com.tinkerpop.gremlin.java.* ==>import com.tinkerpop.gremlin.pipes.filter.* ... ==>import groovy.grape.Grape ==>import com.tinkerpop.frames.* gremlin> import com.tinkerpop.frames.modules.gremlingroovy.* ==>import...

Clone vertex in Titan graph

groovy,titan,gremlin

Blueprints has helper methods to copy the property of one element to another: copyProperties public static void copyProperties(Element from, Element to) Copy the properties (key and value) from one element to another. The properties are preserved on the from element. ElementPropertiesRule that share the same key on the to element...

Fetching all the paths between two nodes using gremlin in java

java,graph-databases,orient-db,gremlin,tinkerpop

Your query doesn't make much sense to me, but the description helps. Here's an example, using TinkerGraph, to find all paths between marko and lop: final Graph g = TinkerGraphFactory.createTinkerGraph(); List<List> names = new ArrayList<>(); new GremlinPipeline<Vertex, ArrayList<Vertex>>(g).V().has("name", "marko").as("x").out().loop("x", new PipeFunction<LoopPipe.LoopBundle<Vertex>, Boolean>() { @Override public Boolean compute(LoopPipe.LoopBundle<Vertex> loopBundle) { return...

Users who mentioned each other in Gremlin

gremlin

Given this sample data that assume marko and stephen mention each other and marko and daniel mention each other: g = new TinkerGraph() vMarko = g.addVertex("marko", [type:"user"]) vStephen = g.addVertex("stephen", [type:"user"]) vDaniel = g.addVertex("daniel", [type:"user"]) vTweetm1s = g.addVertex("m1s", [type:"tweet"]) vTweetm2d = g.addVertex("m2d", [type:"tweet"]) vTweets1m = g.addVertex("s1m", [type:"tweet"]) vTweetd1m = g.addVertex("d1m",...

Gremlin get a result set of more than one vertex type and different stages of the pipeline

graph-databases,gremlin

There are multiple ways to do this. If you really want to co-mingle the people and cars in a single list you can use the store pipe: list = [] pipe.has("name", "NY").in("lives").has("gender", "male").store(list).out('owns').store(list).iterate() list If you wish to maintain the relationships between the people and their (perhaps multiple) cars then...

Convert a MongoDB with two collections in a neo4j graph

mongodb,neo4j,gremlin

Gremlin is a Domain Specific Language for working with graphs, but it is based on Groovy so you effectively have all the flexibility you want to really do whatever you want. In other words, what you can do with one MongoDB collection you can easily do with two (or however...

Gremlin query search by search key across multiple vertex properties

titan,gremlin

The 3 indices won't help to answer your query efficiently. Better create a single index that covers all of the 3 fields (that doesn't mean, that your query has to have a condition for all fields) and issue a direct index query: Sample graph: g = TitanFactory.open("conf/titan-cassandra-es.properties") m = g.getManagementSystem()...

How can I get the latest 10 posts those are written by people in my network (2 level) with gremlin query?

graph,orient-db,gremlin

Given you want to obtain the last 10 posts of friends and friends of friends of user u1: u1.out('friend').copySplit(_().out('friend').except([u1]).out('post'), _().out('post')).exhaustMerge.dedup.order{it.b.ts <=> it.a.ts}[0..<10].map gives you: ==>{msg=f, ts=2015-03-08 12:09:11.567} ==>{msg=e, ts=2015-03-08 12:09:01.459} ==>{msg=d, ts=2015-03-08 12:08:56.339} ==>{msg=c, ts=2015-03-08 12:08:41.209} ==>{msg=b, ts=2015-03-08 12:08:21.086} with the following sample graph: import java.sql.Timestamp g = new TinkerGraph()...

Why can't a Gremlin GraphTraversal be captured as a Groovy variable?

groovy,gremlin,tinkerpop,tinkerpop3

You're dealing with different class types from each of those results. Consider my console session below: gremlin> g = TinkerFactory.createClassic() ==>tinkergraph[vertices:6 edges:6] gremlin> marko = g.v(1) ==>v[1] gremlin> marko.class ==>class com.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex The above yields a Vertex but as you can see below: gremlin> marko = g.V().has('name','marko') ==>v[1] gremlin> marko.class ==>class...

User defined gremlin step works in gremlin, but not in rexster

groovy,gremlin,rexster

I'm not having a problem with this when using a version of the codeveloper step defined in the documentation: $ curl "http://localhost:8182/graphs/tinkergraph/tp/gremlin?script=g.v(1).codeveloper.name" {"success":true,"results":["josh","peter"],"version":"2.5.0","queryTime":39.294181} seems to work in Dog House as well. My best guess is that Rexster is not finding the script. Are you sure you have your path right...

How to map a Tinkerpop3 graph to a recursive data structure?

titan,gremlin,tinkerpop3

I would leverage Gremlin's tree structure and some recursive method calls: import com.google.common.collect.Iterators; import com.tinkerpop.gremlin.process.T; import com.tinkerpop.gremlin.process.Traverser; import com.tinkerpop.gremlin.process.graph.util.Tree; import com.tinkerpop.gremlin.structure.Vertex; import com.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.function.Function; /** * @author Daniel Kuppitz (daniel at...

How to query for multiple vertices and counts of their relationships in Gremlin/Tinkerpop 3?

graph-databases,titan,gremlin

Here's the sample data I used: graph = TinkerGraph.open() g = graph.traversal() v123=graph.addVertex(id,123,"description","developer","name","bob") v124=graph.addVertex(id,124,"description","developer","name","bill") v125=graph.addVertex(id,125,"description","developer","name","brandy") v126=graph.addVertex(id,126,"description","developer","name","beatrice") v124.addEdge('follows',v125) v124.addEdge('follows',v123) v124.addEdge('likes',v126) v125.addEdge('follows',v123) v125.addEdge('likes',v123)...

Modeling values in graph DB - vertex or property?

graph,graph-databases,titan,gremlin

Personally, I think it is typically the most natural to model vertex properties as properties of the vertex. This is even more true when using Titan's new multi-property and meta-property features. Multi-properties are LIST/SET properties, and meta-properties are properties on a property. Here are the relevant docs that fully describe...

possible to connect to multiple neo4j databases via bulbs/Rexster?

neo4j,gremlin,tinkerpop,bulbs,rexster

Bulbs was designed to make it easy to work with multiple graph databases. Configure your rexster.xml for each Neo4j database you want to run (each will have a different name and thus a different URL path), and then create a separate Bulbs Config and Graph object for each database: >>>...

Gremlin union method throws exception using otherV method

gremlin,tinkerpop

Huh. The short term fix is to withPath() after the V(). (assuming TP 3.0.0.M6).

How to output append reason to similarities in Gremlin

graph,gremlin,tinkerpop

By appending the appropriate transform closure to your query: rank = 0; itemsU1 = [] as Set; u1.out('Likes').aggregate(itemsU1).in('Likes') .filter{it != u1}.groupCount.cap.orderMap(T.decr) .transform{[id:it.id, rank:rank++, reason_item_ids:itemsU1.intersect(it.out('Likes').toSet()).collect{it.id}]} … you can obtain: ==>{id=User6, rank=0, reason_item_ids=[Item1, Item5]} ==>{id=User4, rank=1, reason_item_ids=[Item1, Item2]} ==>{id=User2, rank=2, reason_item_ids=[Item1]} ==>{id=User5, rank=3, reason_item_ids=[Item5]}...

How to use .or() or T.in in gremlin without doing whole graph scan?

indexing,titan,gremlin

This should use an index: g.V().has("type" T.in, ["typeA","typeB"]) though I think the 0.5.x line had a bug out there for it. In the mean time you could do: gremlin> g = TinkerGraphFactory.createTinkerGraph() ==>tinkergraph[vertices:6 edges:6] gremlin> ["marko","josh"]._().transform{g.V('name',it).next()} ==>v[1] ==>v[4] ...

Timeouts on traversing from node with millions of edges

cassandra,graph-databases,titan,gremlin

It appears you have effectively simulated a supernode. When you call the function g.V('vid', 0).in('is-a')[0] You are only requesting one object, which is a fast lookup. Likewise: g.V('vid', 0).in('is-a')[100] Also only requests one object, which is still fast. When you make the query: g.V('vid', 0).in('is-a').out('test')[0] You've just made it request...

Type-Filter Step in Gremlin 3?

java,graph-databases,gremlin,tinkerpop3

Against Tinkerpop3 M6/ titan0.9 M1, the following should work: Set<Vertex> vertices = graph.V().<Vertex>has("name", "jupiter").toSet(); Most of the M6 type issues can be resolved in a similar manner (parameterizing the method that produces the element by the expected type)....

How to setup Titan with embedded Cassandra and Rexster

cassandra,gremlin,titan,rexster

If you use Titan server via the shell or bat script, it will automatically start a Titan instance for you and attempt to connect to it over localhost. When you configured it to use Cassandra embedded, the two instances naturally conflict. Is there a particular reason you want to use...

Convert id to Node in Gremlin Pipline

neo4j,graph-databases,gremlin

I guess you could do: g.v(123).functionId.transform{g.v(it)} which would use the transform step to convert the value of functionId into a Vertex in the pipeline....

Cayley: How do insert vertices and edges into graph using Cayley-Gremlin code?

javascript,go,graph-databases,gremlin,cayley

gremlin in cayley is only for traversals. https://github.com/google/cayley/blob/master/docs/GremlinAPI.md is the complete gremlin API for cayley. use http to add data: https://github.com/google/cayley/blob/master/docs/HTTP.md#apiv1write...

Gremlin and Indices

graph-databases,gremlin

I don't think that your last query will support the optimization. Picking apart your query: new GremlinPipeline(graph.getVertices()).has("dmdid", id).has("type", type).cast(classOf[Vertex]).toList() You are feeding all the vertices in the graph into the pipeline which them iterates them out into the has where your index is. As such, the rest of the pipeline...

Gremlin groupBy in Java

java,graph-databases,gremlin

The table pipe does this. I have your model loaded with an indexed property called "_stp_type" that contains the value "Person" for Joan and Jacky. I also have a "Name" property for them. g.idx('entities')[['_stp_type':'Person']].Name.as('Owner').back(1).out('Owns').Type.as('Type').table().cap().next().unique() That returns: [ [ Jacky, Diesel ], [ Joan, Diesel ], [ Joan, Gas ] ]...

Titan graph: Finding vertices without outgoing edges

graph,titan,gremlin

The toy graph: g = new TinkerGraph() p = g.addVertex('p') c1 = g.addVertex('c1') c2 = g.addVertex('c2') c3 = g.addVertex('c3') o1 = g.addVertex('o1') o2 = g.addVertex('o2') g.addEdge(p, c1, 'dep') g.addEdge(p, c2, 'dep') g.addEdge(p, c3, 'dep') g.addEdge(c1, o1, 'frnds') g.addEdge(c1, o2, 'frnds') g.addEdge(c2, o2, 'frnds') A solution for your query description (probably...

How to loop over verticies in Gremlin and adding edge

titan,gremlin,rexster

You can make a sideEffect that adds the new edges. With the toy tinker graph: g = TinkerGraphFactory.createTinkerGraph() let's assume you want to link peter to all neighbors of marko (out only) givenVertex = g.V('name','peter').next() g.V('name','marko').out.sideEffect{g.addEdge(givenVertex,it, 'yourLabel')} verify result: g.V('name','peter').out.name ==>lop // lop appears twice because edge peter -> lop...

gremlin shell hangs after opening a connection

hadoop,hbase,zookeeper,titan,gremlin

figured out the issue, by default titan establishes connection to znode /hbase setting this property solved issue. conf.setProperty("storage.hbase.ext.zookeeper.znode.parent","/hbase-unsecure") ...