Snowflake tables
The neo4j-viz library provides a convenience method for importing data from Snowflake tables.
It requires and additional dependency to be installed, which you can do by running:
pip install neo4j-viz[snowflake]
Once you have installed the additional dependency, you can use the from_snowflake method to import Snowflake tables into a VisualizationGraph.
The from_snowflake method takes two mandatory positional parameters:
-
A
snowflake.snowpark.Sessionobject for the connection to Snowflake, and -
A project configuration as a dictionary, that specifies how you want your tables to be projected as a graph. This configuration is the same as the project configuration of the Neo4j Snowflake Graph Analytics application.
You can further customize the visualization after the VisualizationGraph has been created, by using the methods described in the Customizing the visualization section.
Default behavior
The node and relationship captions will be set to the names of the corresponding tables. The nodes will be colored so that nodes from the same table have the same color, and different tables have different colors.
Example
In this small example, we import a toy graph representing a social network from two tables in Snowflake.
from snowflake.snowpark import Session
from neo4j_viz.snowflake import from_dfs
# Configure according to your own setup
connection_parameters = {
"account": os.environ.get("SNOWFLAKE_ACCOUNT"),
"user": os.environ.get("SNOWFLAKE_USER"),
"password": os.environ.get("SNOWFLAKE_PASSWORD"),
"role": os.environ.get("SNOWFLAKE_ROLE"),
"warehouse": os.environ.get("SNOWFLAKE_WAREHOUSE"),
}
session.sql(
"CREATE OR REPLACE TABLE EXAMPLE_DB.DATA_SCHEMA.PERSONS (NODEID VARCHAR);"
).collect()
session.sql("""
INSERT INTO EXAMPLE_DB.DATA_SCHEMA.PERSONS VALUES
('Alice'),
('Bob'),
('Carol'),
('Dave'),
('Eve');
""").collect()
session.sql(
"CREATE OR REPLACE TABLE EXAMPLE_DB.DATA_SCHEMA.KNOWS (SOURCENODEID VARCHAR, TARGETNODEID VARCHAR);"
).collect()
session.sql("""
INSERT INTO EXAMPLE_DB.DATA_SCHEMA.KNOWS VALUES
('Alice', 'Dave'),
('Alice', 'Carol'),
('Bob', 'Carol'),
('Dave', 'Eve'),
""").collect()
VG = from_snowflake(
session,
{
"nodeTables": [
"EXAMPLE_DB.DATA_SCHEMA.PERSONS",
],
"relationshipTables": {
"EXAMPLE_DB.DATA_SCHEMA.KNOWS": {
"sourceTable": "EXAMPLE_DB.DATA_SCHEMA.PERSONS",
"targetTable": "EXAMPLE_DB.DATA_SCHEMA.PERSONS",
"orientation": "UNDIRECTED",
}
},
},
)
For a full example of the from_snowflake importer in action, please see the Visualizing Snowflake Tables tutorial.