Take Your First Steps with the SAP HANA Graph Engine
- What a Graph Workspace is
- How to define constraints on sample data tables
- How to create a Graph Workspace
- You have completed the tutorial Explore Visualization Options for Spatial Data in SAP HANA Cloud.
- You have access to the sample graph data used in this tutorial group.
- Make sure your database instance is running before you start.
Learn in this tutorial how to get ready to work in a Graph Workspace. This includes two steps:
- Define required constraints on sample data tables
- Create a Graph Workspace
- Step 1
Our graph dataset describes the London street network. Formally, a graph consists of nodes/vertices and edges/links/connections. In this case, you have street segments stored in the
LONDON_EDGEStable, and junctions in the
LONDON_VERTICEStable. The edges in the graph are “directed”, they have a
Most streets in the real world are bi-directional and so most of the segments are represented as two edges in the graph - one for each direction.
The SAP HANA Graph engine requires a key on both tables, and the source and target of the edges must not contain NULLs.
To ensure the graph’s consistency, it is also good practice to have a foreign key relationship defined on source and target column. Doing so will prevent “dangling edges”, i.e. edges without vertices.
Once your data is prepared, you expose it to the SAP HANA Graph engine via a GRAPH WORKSPACE.
- Step 2
Add primary keys on the tables
LONDON_VERTICESusing these statements:SQLCopy
ALTER TABLE "LONDON_EDGES" ADD PRIMARY KEY("ID"); ALTER TABLE "LONDON_VERTICES" ADD PRIMARY KEY("osmid");
Then, add foreign keys on the
TARGETcolumn of the table
LONDON_EDGESby executing these statements:SQLCopy
ALTER TABLE "LONDON_EDGES" ALTER("SOURCE" BIGINT NOT NULL REFERENCES "LONDON_VERTICES" ("osmid") ON UPDATE CASCADE ON DELETE CASCADE); ALTER TABLE "LONDON_EDGES" ALTER("TARGET" BIGINT NOT NULL REFERENCES "LONDON_VERTICES" ("osmid") ON UPDATE CASCADE ON DELETE CASCADE);
- Step 3
The Graph Workspace exposes your data to the SAP HANA graph engine. It is a kind of a “view” into your data. In this case, the Graph Workspace is defined directly on the tables. Note that you can also use SQL views, table functions, and remote tables as data sources. You can define multiple Graph Workspaces in one system.
Create the Graph Workspace on the tables
LONDON_VERTICESby executing this statement:SQLCopy
CREATE GRAPH WORKSPACE "LONDON_GRAPH" EDGE TABLE "LONDON_EDGES" SOURCE COLUMN "SOURCE" TARGET COLUMN "TARGET" KEY COLUMN "ID" VERTEX TABLE "LONDON_VERTICES" KEY COLUMN "osmid";
To get a glimpse of your network, you can right-click the
LONDON_GRAPHworkspace to launch the Graph Viewer.
You now have successfully defined constraints on your tables
LONDON_EDGESand created a
GRAPH WORKSPACE. You are all set up to start working with the Graph Engine now!
In the next tutorial, learn how to use a GRAPH Procedure to calculate Shortest Paths on the street network.
- Step 4
Which of the following holds true for a Graph Workspace?