Connecting to DuckDB
It is also possible to query existing data on DuckDB directly without loading it to PuppyGraph. Here is an demo of the feature.
In the demo, the DuckDB data source stores people and referral information. To query the data as a graph, we model people as vertices and the referral relationship between people as edges.
Prerequisites
The demo assumes that PuppyGraph has been deployed at localhost
according to the instruction in Launching PuppyGraph from AWS Marketplace or Launching PuppyGraph in Docker. For Docker deployment, in order to read DuckDB file, we must use volumn to share data cross containers.
In this demo, we use the username puppygraph
and password puppygraph123
.
For docker deployment, please follow these steps
Data Preparation (Optional)
The demo uses people and referral information as shown above.
The following command starts a DuckDB container through Docker and writes data to DuckDB. If using AMI Version, we can download DuckDB client from DuckDB website.
After waiting for the DuckDB container to start, run follow command to start DuckDB interactive shell.
Now we can create a database and data table, and then write the data to DuckDB.
Finally, type .exit
to close the DuckDB client.
After writing the data to duckdb, user must stop DuckDB interactive shell before next steps, or other program such as PuppyGraph will fail to read data from the demo database.
Upload the schema
Now the data are ready in DuckDB. We need a PuppyGraph schema before querying it. Let's create a schema file duckdb.json
:
Here are some notes on this schema:
A catalog
jdbc_duckdb
is added to specify the remote data source in DuckDB.Set
type
toduckdb
.Set
driverClass
toorg.duckdb.DuckDBDriver
.driverUrl
: Please provide a URL where PuppyGraph can find the DuckDB driver.
The label of the vertices and edges do not have to be the same as the names of corresponding tables in DuckDB. There is a
mappedTableSource
field in each of the vertex and edge types specifying the actual schema (graph
) and table (referral
).Additionally, the
mappedTableSource
marks meta columns in the tables. For example, the fieldsfrom
andto
describe which columns in the table form the endpoints of edges.
Now we can upload the schema file duckdb.json
to PuppyGraph with the following shell command, assuming that the PuppyGraph is running on localhost
:
Query the data
Connecting to PuppyGraph at http://localhost:8081 and start gremlin console from the "Query" section:
Now we have connected to the Gremlin Console. We can query the graph:
Last updated