Skip to content

PuppyGraph CLI

PuppyGraph includes a CLI featuring prompts and auto-completion, catering to those who prefer using the command line.

In this introduction, the examples presume the existence of a Docker container called puppy, already equipped with example graph data from #explore-the-example-graph.

Start a PuppyGraph CLI

In terminal, run the command to get into PuppyGraph CLI.

docker exec -it puppy ./bin/puppygraph
  ____                                     ____                          _
 |  _ \   _   _   _ __    _ __    _   _   / ___|  _ __    __ _   _ __   | |__
 | |_) | | | | | | '_ \  | '_ \  | | | | | |  _  | '__|  / _` | | '_ \  | '_ \
 |  __/  | |_| | | |_) | | |_) | | |_| | | |_| | | |    | (_| | | |_) | | | | |
 |_|      \__,_| | .__/  | .__/   \__, |  \____| |_|     \__,_| | .__/  |_| |_|
                 |_|     |_|      |___/                         |_|
Welcome to PuppyGraph, type help to see the command list
[PuppyGraph]> 
               console         access PuppyGraph Gremlin Console             
               cypher-console  access PuppyGraph Cypher Console              
               groovy          access console to run complex groovy scripts  
               exit            exit PuppyGraph                               
               help            show the command list                         

Gremlin Console

You can access the PuppyGraph Gremlin Console through the console command.

[PuppyGraph]> console
  ____                                     ____                          _
 |  _ \   _   _   _ __    _ __    _   _   / ___|  _ __    __ _   _ __   | |__
 | |_) | | | | | | '_ \  | '_ \  | | | | | |  _  | '__|  / _` | | '_ \  | '_ \
 |  __/  | |_| | | |_) | | |_) | | |_| | | |_| | | |    | (_| | | |_) | | | | |
 |_|      \__,_| | .__/  | .__/   \__, |  \____| |_|     \__,_| | .__/  |_| |_|
                 |_|     |_|      |___/                         |_|
Welcome to PuppyGraph!
version: 0.10

To Learn more about the graph schema:
- Use graph.show() to list all the vertex and edge labels.
- Use graph.show('$FOO') to list all the vertex and edge labels related to $FOO.
- Use graph.describe('$BAR') to list all the attributes of the label $BAR.

See https://tinkerpop.apache.org/gremlin.html to learn more about the Gremlin query language.
Here are some example queries for exploring the graph:
- Use g.V() to list all the vertices.
- Use g.E() to list all the edges.
- Use g.V().count() to get the total number of vertices.
- Use g.E().count() to get the total number of edges.
- Use g.V('$ID').out() to find out vertices that are reachable in 1-hop from the vertex $ID. For example, g.V('person[v1]').out() will find out 1-hop reachable vertices from 'person[v1]'.
- Use g.V('$ID').out().out() similarly to find out 2-hop reachable vertices from the vertex $ID.

puppy-gremlin> 

Feel free to write queries as desired. To navigate back to the top level CLI, use :x or :exit.

puppy-gremlin> g.V().count()
Done! Elapsed time: 0.027s, rows: 1
==>6
puppy-gremlin> g.V()
Done! Elapsed time: 0.032s, rows: 6
==>v[person[v4]]
==>v[person[v1]]
==>v[person[v2]]
==>v[person[v6]]
==>v[software[v3]]
==>v[software[v5]]
puppy-gremlin> :x
Bye! 
g            Default graph traversal source           
:help        (:h) Display help message                
:exit        (:x) Exit PuppyGraph console (Ctrl-D)    
:quit        (:q) Alias to: :exit                     
:edit        (:e) Edit the current buffer             
:save        (:s) Save the current buffer to a file   

Cypher Console

You can access the Cypher Console through the cypher-console command.

[PuppyGraph]> cypher-console
puppy-cypher>

Make sure to initiate Cypher queries using the prefix :>.

puppy-cypher> :> MATCH (v) RETURN count(*)
==>[count(*):6]
puppy-cypher> :> MATCH (v) RETURN v
==>[v:[_type:node,name:peter,_id:person[v6],_label:person,age:35]]
==>[v:[_type:node,name:marko,_id:person[v1],_label:person,age:29]]
==>[v:[_type:node,name:josh,_id:person[v4],_label:person,age:32]]
==>[v:[_type:node,name:vadas,_id:person[v2],_label:person,age:27]]
==>[v:[_type:node,name:ripple,_id:software[v5],lang:java,_label:software]]
==>[v:[_type:node,name:lop,_id:software[v3],lang:java,_label:software]]

Groovy Console

Gremlin integrates effortlessly with Groovy within the Groovy Console, allowing for the direct execution of Groovy scripts. This integration offers enhanced flexibility.

You can access the PuppyGraph Groovy Console through the groovy command.

[PuppyGraph]> groovy
puppy-gremlin> 

As a demonstration, we'll execute the example script provided below in the console.

marko_knows = g.V().has('name', 'marko').out('knows').toList()
outputs = []
for (int i = 0; i < marko_knows.size(); i++){
    outputs << g.V(marko_knows[i]).values('name').next()
}
'marko knows:' + outputs
puppy-gremlin> marko_knows = g.V().has('name', 'marko').out('knows').toList()
==>v[person[v2]]
==>v[person[v4]]
puppy-gremlin> outputs = []
puppy-gremlin> for (int i = 0; i < marko_knows.size(); i++){
............1>     outputs << g.V(marko_knows[i]).values('name').next()
............2> }
==>null
puppy-gremlin> 'marko knows:' + outputs
==>marko knows:[vadas, josh]

Alternatively, you can achieve the same outcome with a single-line script.

puppy-gremlin> 'marko knows:' +  g.V().has('name', 'marko').out('knows').values('name').toList()
==>marko knows:[vadas, josh]

Others

Run run help to see more information and exitto exit PuppyGraph CLI.