Skip to content

Querying Snowflake Data as a Graph

Summary

In this tutorial, you will:

  1. Create a Snowflake database and import data into it;
  2. Start a PuppyGraph Docker container and query the data as a graph.

Prerequisites

Docker

Please ensure that docker is available.

Docker is required to run the PuppyGraph server. You can download Docker from here.
The installation can be verified by running:

docker version

Data Preparation

In order to query data as a graph, we need to import data into Snowflake.

Generate data by using Snowflake SQL

  1. Sign in to Snowsight using your account. You must have proper privileges to create databases, schemas and tables.
  2. Open a SQL worksheet, run the the SQL commands below:
CREATE DATABASE PUPPYGRAPH_SAMPLE_DATA;
USE DATABASE PUPPYGRAPH_SAMPLE_DATA;

CREATE SCHEMA IF NOT EXISTS modern;

CREATE TABLE IF NOT EXISTS modern.person (
    id STRING, 
    name STRING, 
    age INTEGER
);

INSERT INTO modern.person (id, name, age) VALUES
    ('v1', 'marko', 29),
    ('v2', 'vadas', 27),
    ('v4', 'josh', 32),
    ('v6', 'peter', 35);

CREATE TABLE IF NOT EXISTS modern.software (
    id STRING, 
    name STRING, 
    lang STRING
);

INSERT INTO modern.software (id, name, lang) VALUES
    ('v3', 'lop', 'java'),
    ('v5', 'ripple', 'java');

CREATE TABLE IF NOT EXISTS modern.created (
    id STRING, 
    from_id STRING, 
    to_id STRING, 
    weight DOUBLE
);

INSERT INTO modern.created (id, from_id, to_id, weight) VALUES
    ('e9', 'v1', 'v3', 0.4),
    ('e10', 'v4', 'v5', 1.0),
    ('e11', 'v4', 'v3', 0.4),
    ('e12', 'v6', 'v3', 0.2);

CREATE TABLE IF NOT EXISTS modern.knows (
    id STRING, 
    from_id STRING, 
    to_id STRING, 
    weight DOUBLE
);

INSERT INTO modern.knows (id, from_id, to_id, weight) VALUES
    ('e7', 'v1', 'v2', 0.5),
    ('e8', 'v1', 'v4', 1.0);

Starting PuppyGraph

▶ Start the PuppyGraph server with the following command.

docker run -p 8081:8081 -p 8182:8182 -p 7687:7687 --name puppy --rm -itd puppygraph/puppygraph:stable

Modeling the Graph

Step 1: Connecting to Snowflake

▶ Login onto PuppyGraph with puppygraph as the username and puppygraph123 as the password.

▶ Click on Create graph schema to create a new graph schema.

▶ Click on Add more catalogs

Fill in the fields as follows.

Create Snowflake Catalog

Parameter Value
Catalog type Snowflake
Catalog name Some name for the catalog as you like.
Username User name of your snowflake account
Password Password of your snowflake account
JDBC Connection String jdbc URI like jdbc:snowflake://<account_identifier>.snowflakecomputing.com/?db=PUPPYGRAPH_SAMPLE_DATA, replace the <account_identifier> to your own

▶ Click on Save, then Click on Submit to connect to the Open Catalog.

Step 2: Building the Graph Schema

▶ In the Schema Builder, select the MODERN database and add the first node type to the graph from the table PERSON.

▶ After that use the Auto Suggestion to create other nodes and edges. Select PERSON as the start vertex (node) and add the auto suggested nodes and edges.

The graph schema should look like this: ▶ Submit the schema to create the graph.

Step 3: Querying the Graph

PuppyGraph provides a Dashboard that gives the summary of the graph.

Use the Interactive Query UI to further explore the graph by sending queries.

Cleaning up

▶ Run the following command to shut down and remove the PuppyGraph

docker stop puppy