Accessing the PuppyGraph Web UI requires a browser. However, the tutorial offers alternative instructions for those who wish to exclusively use the CLI.
[+] Running 1/1
✔ puppygraph Pulled 2.0s
[+] Running 4/4
✔ Network puppy-duckdb Created 0.1s
✔ Volume "puppy-duckdb" Created 0.0s
✔ Container puppygraph Started 0.1s
✔ Container duckdb Started
Data Preparation
This tutorial is designed to be comprehensive and standalone, so it includes steps to populate data in DuckDB. In practical scenarios, PuppyGraph can query data directly from your existing DuckDB databases.
dockerexec-itduckdbduckdb/home/share/demo.db
This command also creates a database file /home/share/demo.db.
v0.9.2 3c695d7ba9
Enter ".help" for usage hints.
D
createschemamodern;createtablemodern.person (id text, nametext, age integer);insert into modern.person values ('v1', 'marko', 29), ('v2', 'vadas', 27), ('v4', 'josh', 32), ('v6', 'peter', 35);createtablemodern.software (id text, nametext, lang text);insert into modern.software values ('v3', 'lop', 'java'), ('v5', 'ripple', 'java');createtablemodern.created (id text, from_id text, to_id text, weightdouble precision);insert into modern.created values ('e9', 'v1', 'v3', 0.4), ('e10', 'v4', 'v5', 1.0), ('e11', 'v4', 'v3', 0.4), ('e12', 'v6', 'v3', 0.2);createtablemodern.knows (id text, from_id text, to_id text, weightdouble precision);insert into modern.knows values ('e7', 'v1', 'v2', 0.5), ('e8', 'v1', 'v4', 1.0);
The above SQL creates the following tables:
Modeling a Graph
We then define a graph on top of the data tables we just created. Actually, this is the "Modern" graph defined by Apache Tinkerpop.
A schema instructs PuppyGraph on mapping data from the DuckDB into a graph. PuppyGraph offers various methods for schema creation. For this tutorial, we've already prepared a schema to help save time.
The response shows that graph schema has been uploaded successfully:
{"Status":"OK","Message":"Schema uploaded and gremlin server restarted"}
Querying the Graph
In this tutorial we will use the Gremlin query language to query the Graph. Gremlin is a graph query language developed by Apache TinkerPop. Prior knowledge of Gremlin is not necessary to follow the tutorial. To learn more about it, visit https://tinkerpop.apache.org/gremlin.html.
Queries are entered on the left side, and the right side displays the graph visualization.
The first query retrieves the property of the person named "marko".
g.V().has("name", "marko").valueMap()
The output is plain text like the following:
Rows: 1
age 29
name marko
Now let's also leverage the visualization. The next query gets all the software created by people known to "marko".