Querying Local Files as a Graph
Summary
This page builds a graph from CSV or Parquet files in a folder on your computer, instead of from a sample dataset in a database. You put the files behind a DuckDB file of views and connect PuppyGraph to it.
For a sample dataset in a database, see the per-source tutorials such as Querying PostgreSQL Data as a Graph. If your data is already in a database, see its page under Connecting, such as Connecting to PostgreSQL or Connecting to MySQL.
This page runs PuppyGraph as one container on one machine and mounts your data folder read-only. It reads files from the local folder only. It doesn't cover PuppyGraph clusters or S3.
Prerequisites
- Docker. Check it with
docker version. See Launching PuppyGraph in Docker for details. - The hardware in System Requirements.
- A folder of CSV or Parquet files. The steps below create sample CSV files if you don't have your own.
How it works
PuppyGraph has no file catalog. Instead, you put your files behind a small DuckDB database file. That file holds only views. Each view reads your files with read_csv_auto or read_parquet. PuppyGraph connects to the DuckDB file as a regular DuckDB catalog.
Your files are not copied or converted. Each query reads the files again. A new file that matches a view's pattern shows up in the next query. PuppyGraph opens the DuckDB file read-only, so it never changes your data.
Put your files in one folder
Create a folder for your data and change into it. All commands below run from this folder.
To follow along with sample data, create the TinkerPop modern graph as CSV files:
Create the sample CSV files
mkdir -p knows created
cat > person.csv <<'EOF'
id,name,age
v1,marko,29
v2,vadas,27
v4,josh,32
v6,peter,35
EOF
cat > software.csv <<'EOF'
id,name,lang
v3,lop,java
v5,ripple,java
EOF
cat > knows/part-1.csv <<'EOF'
id,from_id,to_id,weight
e7,v1,v2,0.5
EOF
cat > knows/part-2.csv <<'EOF'
id,from_id,to_id,weight
e8,v1,v4,1.0
EOF
cat > created/part-1.csv <<'EOF'
id,from_id,to_id,weight
e9,v1,v3,0.4
e10,v4,v5,1.0
EOF
cat > created/part-2.csv <<'EOF'
id,from_id,to_id,weight
e11,v4,v3,0.4
e12,v6,v3,0.2
EOF
The knows and created folders hold several files each. One view reads all of them through a pattern.
Create the DuckDB file of views
DuckDB has no server. It is a library that runs inside whichever program opens the file. On this page, two programs open graph.duckdb, and both run in containers from the PuppyGraph image:
- The DuckDB CLI, which ships in the image. You run it in a temporary container to create the views.
docker run --rmremoves that container when the command finishes. - PuppyGraph, which opens the file read-only with its built-in DuckDB driver when it queries the catalog.
Both use the same DuckDB version. You don't install DuckDB on your computer.
Run the CLI in a temporary container to create
graph.duckdb with one view per table:
docker run --rm --user "$(id -u):$(id -g)" \
-v "$PWD":/files \
--entrypoint /home/ubuntu/duckdb \
puppygraph/puppygraph:latest /files/graph.duckdb -c "
CREATE VIEW person AS SELECT * FROM read_csv_auto('/files/person.csv');
CREATE VIEW software AS SELECT * FROM read_csv_auto('/files/software.csv');
CREATE VIEW knows AS SELECT * FROM read_csv_auto('/files/knows/*.csv');
CREATE VIEW created AS SELECT * FROM read_csv_auto('/files/created/*.csv');
"
The command mounts the current folder at /files in the temporary container and writes graph.duckdb to your folder. Each view stores its file paths as text. PuppyGraph opens the files through those paths at query time, inside its own container. So start every path with /files/, and mount the folder at /files in both containers. A pattern such as /files/knows/*.csv reads every matching file.
For Parquet files, use read_parquet. You can mix CSV and Parquet views in the same DuckDB file:
To check a view, run a query with the same command. For example, replace the CREATE VIEW lines with DESCRIBE knows; to see the column types that DuckDB detected. To change a type, cast the column in the view, for example SELECT id, name, CAST(age AS INTEGER) AS age FROM read_csv_auto('/files/person.csv').
Start PuppyGraph with the folder mounted
Start PuppyGraph and mount the same folder at the same path,
/files. The :ro suffix mounts it read-only:
docker run -d --name puppygraph \
-p 8081:8081 -p 8182:8182 -p 7687:7687 \
-e PUPPYGRAPH_USERNAME=puppygraph \
-e PUPPYGRAPH_PASSWORD=puppygraph123 \
-v "$PWD":/files:ro \
puppygraph/puppygraph:latest
Default passwords
This command uses default passwords for convenience. Change the PUPPYGRAPH_USERNAME and PUPPYGRAPH_PASSWORD environment variables before running on a publicly accessible machine.
Don't mount your files at /data. PuppyGraph keeps its own storage there.
Add the DuckDB catalog
Open http://localhost:8081 and sign in with
puppygraph and puppygraph123.
PuppyGraph needs up to a minute to start. If a step reports no healthy leader available, wait a moment and try again.
Click Catalogs, then Add Catalog. Expand Query Engines and choose DuckDB.
Fill in the form, then click Create Catalog:
| Field | Value |
|---|---|
| Catalog name | my_files |
| JDBC Connection String | jdbc:duckdb:/files/graph.duckdb |
The views appear as tables in the main schema of the my_files catalog.
Build the graph
You can build the graph in the Schema Builder. See Modeling a Graph through the Schema Builder. For the sample data, you can also upload a ready-made graph schema instead.
schema.json for the sample data
{
"catalog": [
{
"name": "my_files",
"type": "duckdb",
"jdbc": { "jdbcUri": "jdbc:duckdb:/files/graph.duckdb" }
}
],
"node": [
{
"label": "person",
"dataSourceGroup": {
"externalDataSource": {
"enabled": true, "catalog": "my_files", "schema": "main", "table": "person",
"mappedField": [
{ "sourceFieldName": "id", "targetFieldName": "id" },
{ "sourceFieldName": "name", "targetFieldName": "name" },
{ "sourceFieldName": "age", "targetFieldName": "age" }
]
}
},
"id": [{ "name": "id", "type": "STRING" }],
"attribute": [
{ "name": "name", "type": "STRING" },
{ "name": "age", "type": "LONG" }
]
},
{
"label": "software",
"dataSourceGroup": {
"externalDataSource": {
"enabled": true, "catalog": "my_files", "schema": "main", "table": "software",
"mappedField": [
{ "sourceFieldName": "id", "targetFieldName": "id" },
{ "sourceFieldName": "name", "targetFieldName": "name" },
{ "sourceFieldName": "lang", "targetFieldName": "lang" }
]
}
},
"id": [{ "name": "id", "type": "STRING" }],
"attribute": [
{ "name": "name", "type": "STRING" },
{ "name": "lang", "type": "STRING" }
]
}
],
"edge": [
{
"label": "knows", "fromNodeLabel": "person", "toNodeLabel": "person",
"dataSourceGroup": {
"externalDataSource": {
"enabled": true, "catalog": "my_files", "schema": "main", "table": "knows",
"mappedField": [
{ "sourceFieldName": "id", "targetFieldName": "id" },
{ "sourceFieldName": "from_id", "targetFieldName": "from_id" },
{ "sourceFieldName": "to_id", "targetFieldName": "to_id" },
{ "sourceFieldName": "weight", "targetFieldName": "weight" }
]
}
},
"id": [{ "name": "id", "type": "STRING" }],
"fromKey": [{ "name": "from_id", "type": "STRING" }],
"toKey": [{ "name": "to_id", "type": "STRING" }],
"attribute": [
{ "name": "from_id", "type": "STRING" },
{ "name": "to_id", "type": "STRING" },
{ "name": "weight", "type": "DOUBLE" }
]
},
{
"label": "created", "fromNodeLabel": "person", "toNodeLabel": "software",
"dataSourceGroup": {
"externalDataSource": {
"enabled": true, "catalog": "my_files", "schema": "main", "table": "created",
"mappedField": [
{ "sourceFieldName": "id", "targetFieldName": "id" },
{ "sourceFieldName": "from_id", "targetFieldName": "from_id" },
{ "sourceFieldName": "to_id", "targetFieldName": "to_id" },
{ "sourceFieldName": "weight", "targetFieldName": "weight" }
]
}
},
"id": [{ "name": "id", "type": "STRING" }],
"fromKey": [{ "name": "from_id", "type": "STRING" }],
"toKey": [{ "name": "to_id", "type": "STRING" }],
"attribute": [
{ "name": "from_id", "type": "STRING" },
{ "name": "to_id", "type": "STRING" },
{ "name": "weight", "type": "DOUBLE" }
]
}
]
}
Save the file as
schema.json and upload it:
curl -X POST -H "content-type: application/json" \
--data-binary @./schema.json \
--user "puppygraph:puppygraph123" \
http://localhost:8081/schema
You can also upload it in the Web UI. Click Graph, then Upload in the toolbar.
Query the graph
Click Query and run this Cypher query:
It returns two rows: lop and ripple.
Add or change files
New files that match a view's pattern need no action. For example, add knows/part-3.csv and run the query again. The new edges are in the result.
To add or change a view, stop PuppyGraph first. The CLI container and the PuppyGraph container open the same graph.duckdb through their mounts. While PuppyGraph has the file open, the CLI fails with Could not set lock on file.
docker stop puppygraph
# Run the docker run command with the DuckDB CLI again, for example with CREATE OR REPLACE VIEW
docker start puppygraph
To only check a view while PuppyGraph runs, add -readonly before /files/graph.duckdb in the CLI command.
The container keeps its graph schema across docker stop and docker start.
Or let PuppyGraph AI build the graph
PuppyGraph AI can explore the views and propose the graph for you. It needs an API key for a model provider.
The running container can't take new environment variables. Remove it and start a new one with the AI options. The new container starts empty, so you add the catalog again.
Export your API key, remove the container, and start it again with the AI options:
export ANTHROPIC_API_KEY=sk-ant-...
docker rm -f puppygraph
docker run -d --name puppygraph \
-p 8081:8081 -p 8182:8182 -p 7687:7687 \
-e PUPPYGRAPH_USERNAME=puppygraph \
-e PUPPYGRAPH_PASSWORD=puppygraph123 \
-e AI_ENABLED=true \
-e AI_API_KEY="$ANTHROPIC_API_KEY" \
-v "$PWD":/files:ro \
puppygraph/puppygraph:latest
Add the DuckDB catalog as above. Then click AI and ask PuppyGraph AI to build a graph schema from the
my_files catalog.
See Building a Graph with PuppyGraph AI for a full walkthrough. See PuppyGraph AI to use OpenAI or another API.
Cleanup
Stop and remove the container:
PuppyGraph only read your files. The CLI created graph.duckdb in your folder. Delete it when you no longer need it.