SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
โคข Open full site

Calculate Shortest Path Using a GRAPH Procedure

Learn how to use a GRAPH Procedure to calculate shortest paths on the Street Network.

Overview

🎓 beginner 10 min. SAP HANA CloudBeginnerSAP HANA GraphSAP HANA CloudSAP HANA DatabaseSAP HANA Multi Model Processing

You will learn

  • โœ”How to define the required Table Type for the database procedure
  • โœ”How to create a GRAPH procedure for shortest path calculation
  • โœ”How to use anonymous blocks approach for shortest path calculation
Unknown U Unknown November 1, 2022
Created by July 14, 2021
Contributors

Prerequisites

Prerequisites

Steps

Intro

Once you have defined a Graph Workspace, you can run openCypher(*) queries for pattern matching workload or create GRAPH procedures for network analysis. In this tutorial you will learn how to create a database procedure that uses the built-in function to calculate a shortest path between two vertices. This includes three steps:

  • Define the required Table Type for database procedure
  • Create a GRAPH procedure for shortest path calculation
  • Run a GRAPH code using anonymous blocks

Step 1 Define the required Table Type for database procedure
โ€”

If you are familiar with SAP HANA database procedures using SQLScript, you already know how to handle table-like results. A clean way to do this is defining and using TABLE TYPES. The same approach is valid for GRAPH procedures. Our TABLE TYPE TT_SPOO_EDGES describes the structure of the path result. It includes the ID of the edge and the ORDER in which the edges are traversed.

First you need to create a TABLE TYPE that describes the output table of the procedure, containing ID, SOURCE, TARGET, EDGE_ORDER (BIGINT), and length (DOUBLE). Execute this statement:

SQL
CREATE TYPE "TT_SPOO_EDGES" AS TABLE (
    "ID" NVARCHAR(5000), "SOURCE" BIGINT, "TARGET" BIGINT, "EDGE_ORDER" BIGINT, "length" DOUBLE)
;
Step 2 Create a GRAPH procedure for shortest path calculation
+
Step 3 Run a GRAPH code using anonymous blocks
+
Step 4 Test yourself
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 4
1. Define the required Table Type for database procedure 2. Create a GRAPH procedure for shortest path calculation 3. Run a GRAPH code using anonymous blocks 4. Test yourself

Learn more →