Connecting to PostgreSQL
It is also possible to query existing data on PostgreSQL directly without loading it to PuppyGraph. Here is an demo of the feature.
In the demo, the PostgreSQL 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.
In this demo, we use the username puppygraph
and password puppygraph123
.
Data Preparation (Optional)
ID | Age | Name |
---|---|---|
v1 | 29 | marko |
v2 | 27 | vadas |
The demo uses people and referral information as shown above.
The following command starts a PostgreSQL container through Docker and writes data to PostgreSQL. We assume that the IP address of the machine running the PostgreSQL container is 172.31.19.123
After waiting for the PostgreSQL container to start, connect through PostgreSQL client。
Now we can create a database and data table, and then write the data to PostgreSQL.
Upload the schema
Now the data are ready in PostgreSQL. We need a PuppyGraph schema before querying it. Let's create a schema file postgres.json
:
Here are some notes on this schema:
A catalog
jdbc_postgres
is added to specify the remote data source in PostgreSQL.Set
type
topostgresql
.Set
driverClass
toorg.postgresql.Driver
.driverUrl
: Please provide a URL where PuppyGraph can find the PostgreSQL driver.
The label of the vertices and edges do not have to be the same as the names of corresponding tables in PostgreSQL. There is a
mappedTableSource
field in each of the vertex and edge types specifying the actual schema (public
) 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 postgres.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