Hi, I'm Philip from the HANA academy.
In this series of videos, we're looking at the graph processing capabilities native to SAP HANA.
In this video, we're going to look at the Shortest Path One-to-One Algorithm
which was added to Graph Processing in HANA 2.0 SPS 01.
Now, the first thing we can do is go and check the reference guide
so let's go to where we find help for HANA
so help.sap.com/hana_platform
and to find the Graph reference guide you need to go to the development section and click on 'view all'
and then scroll down and you'll find we have the Graph Reference
and it's all available interactively in HTML5, as we can see here
or you can always download it as a PDF for offline viewing if you want.
So, if we look at the Graph Algorithms, you'll see that previously we've worked with the Shortest Path
however the way it worked previously was Shortest Path One-to-All
That basically meant that for a certain start point, for example from Chaos
it would show you the shortest path to basically every other vertex, or every other item or node in your network
in your graph.
The Shortest Path One-to-One allows you to, kind of, subset that by setting a start point and a target
and then it will just give you the shortest path between the start and that target.
So, that's the Shortest Path One-to-One.
So, we need to call that right now using a calculation scenario, which we'll create as a calc view
and we've got an example that we can actually go ahead and run ourselves.
Now, the examples for the series, if you're not already familiar, are available on GitHub
so go to github.com/saphanaacademy, and then look for the Graph Repository.
Here we see it is
and in this video we're looking at the one which is 'Graph 19 Shortest Path - One to One SPS01'.
So, I'm going to take that example code,
and I'm going to copy it
and then I'm going to go into Eclipse, or it can be wherever you're going to run your SQL script from
because if you're using the classic approach here, open up a SQL window and I'm going to paste that code in.
So, exactly how does it work?
Well, we're going to create a calculation scenario using the one-to-one
so you can see here we've got 'action="GET_SHORTEST_PATH_ONE_TO_ONE"'
that's where we specified the algorithm we're going to be using
and then we need to specify the parameters in the CDATA section
and in this case we're going to have a start vertex, a target vertex, and we can also have a weight column
the name of the column that will give us, basically, the distance in our case.
Now, we're using the same Greek mythology examples that we've used in previous videos in this series
so I'll assume you're already familiar with what we have in that, we have gods etcetera from Greek mythology.
In terms of the results that we're going to get, we can see that we've got a number of different attributes:
ordering, source, target, distance, with the specific data types so we can choose what we want to have out of it.
Now, of course you can build parameters into it so that your start and target vertex may be set at runtime
but we'll just go ahead and run this simple example.
So, we're going to create a calculation scenario
and then we're going to call it and get the results back in the ordering number.
So let's go ahead and run – we can see Crow did that calc view for us and we've now got our results
so when we are looking we were actually looking at Gaia and we wanted to see the shortest path to Ares.
You can see it was Gaia to Rhea, Rhea to Hera, Hera to Ares, so basically three connections needed.
Now, you can always go back and verify that if we go to the reference guide.
We can see we've got the Graph data model
and here you get a nice little picture of the sample data we're using.
So, again, if we go and look at it from the direction that we were taking
so let's just go and check again from Gaia to Ares
so we can see we've got Gaia and we want to get to Ares, which is down here, so it's three connections
and it actually gave us, in our results, the shortest path, so it was to Rhea, to Hera and then to Ares.
So if we check that, we go from Gaia to Rhea to Hera to Ares.
Now, it might well be that there's another way
for example it could have gone from Rhea to Zeus and then to Ares
but the algorithm will basically just give you one option
It will give you the shortest. If there are multiple shortest routes it will give you one of those shortest routes.
All we've seen in this video is the new algorithm
basically the single-source, single-target, or the Shortest Path One-to-One algorithm.
That's new in SPS 01 of HANA 2.0.
You can find more HANA video tutorials on our YouTube channel.
If you'd like to be informed as soon as new video tutorials are published, please subscribe to the channel.
You can also connect with us on LinkedIn, follow us on Twitter, and we have pages on Facebook and Google+.
Code snippets for all of our tutorials are published to GitHub.
Thanks for watching.