Skip to content

Latest commit

 

History

History
151 lines (91 loc) · 6.87 KB

learning_graph_database_gremlin_tinkerpop.md

File metadata and controls

151 lines (91 loc) · 6.87 KB
path title
/learnings/graph_databases
Learnings: Graph Databases

Table Of Contents

Learning Graph Database : Gremlin / Tinkerpop <<Learning_GraphDatabase_Gremlin_Tinkerpop>>

Exploring a graph in Gremlin Console

gremlin> g.V().has("name", "saturn")    // queries for verticies that have name "saturn"

gremlin> g.V().has("name", "saturn").outE()  // gets edge coming out

See also

TinkerPop APIs

Graph Structure API (org.apache.tinkerpop.gremlin.structure.Graph) <<Learning_GraphDatabase_Gremlin_Tinkerpop_APIS_Structure>>

Gremlin Guide, section 4.5.1:

It is strongly recommended that the traversal source object g be used when adding, NOTE updating or deleting vertices and edges. Using the graph object directly is not viewed as a TinkerPop best practice.

  • source ????????

Traversal API (org.apachae.tinkerpop.gremlin.process.dsl.graph.GraphTraversal) <<Learning_GraphDatabase_Gremlin_Tinkerpop_APIS_Traversal>>

NOTE: Need to always call .next() or .iterate() to save data to the graph. Source

ALSO: https://tinkerpop.apache.org/docs/current/reference/#graph-traversal-steps

and connecting to Gremlin Server

  1. MUST(??) use Websockets mode for server instead of HTTP mode for Gremlin / Tinkerpop communications

Tinkerpop when given address will create ws:// URL instead of http:// line

  1. Can ONLY run Websocket Mode OR HTTP mode - can not run both Stackoverflow answer

  2. Remote connections are done via (Remote) Traversal API

Remote connection example (JanusGraph)

val graph = JanusGraphFactory.open("inmemory")
val g : GraphTraversalSource = graph.traversal().withRemote( conf )

Q: Why not EmptyGraph(), like the examples say?

A: EmptyGraph doesn't seem to support transactions, add edges, etc etc. (???). See also stackoverflow answer on JanusGraphFactory inmemory ... because it doesn't have the JanusGraph goodness baked in (EmptyGraph is a Tinkerpop thing!)

Profiling

.profile <-- outputs time / traverse info about your traversal

See also:

Learning Graph Database: Gremlin-Scala <<Learning_GraphDatabase_Gremlin_Scala>>

and remote Gremlin Servers

??? Need to be careful about what is and is not supported with gremlin server ie: + , -----, operators may not use the Traversal API (see: Learning_GraphDatabase_Gremlin_Tinkerpop_APIS_Traversal ) and may not support certain operations (????)

See also:

Learning Graph Databases: Gremlin Server <<Learning_GraphDatabases_Gremlin_Server>>

Can only use one mode: HTTP or WebSockets mode. Sources:

Setting up for HTTP mode

NOTE: configuration only valid for server. If you try to connect via Gremlin with this configuration it will barf (only partially related to URL schema of ws:// by Tinkerpop)

In config file set: channelizer: org.apache.tinkerpop.gremlin.server.channel.HttpChannelizer

NOTE: HTTP / "REST" mode is not really RESTful

Samples for HTTP mode

And HA concerns

And configurations that matter to the client

??? graphs: { } in gremlin-server.yml needs to have same graph name in it as the Gremlin clients are trying to connect to (need to share YAML file, or parts of YAML file somehow??????)

See also:

Learning Graph Databases: Gremlin Console <<Learning_GraphDatabase_Gremlin_Console>>

gremlin> graph = JanusGraphFactory.open('janusgraph.properties')
Backend shorthand unknown: janusgraph.properties

^^^^^ means that it can not find the properties file you are pointing at. Try using a relative path or just the full path in your string.