Hi I’m Philip from the HANA Academy. In
this series of videos were looking at
HANA’s Predictive Analysis Library. In
this video we're going to get started
with HANA 2.0 SPS 02. They're quite a
number of new innovations in this SPS so
let's just quickly have a look at the
HANA architecture. Of course on the
left we have the HANA in-memory columnar
database. You're probably quite familiar
with that already in terms of predictive
functionality. That's typically packaged
up through something called the AFL or
Application Functional Library. This
is a component which is an optional
install with HANA. Typically it is
installed and then it allows you to to
access different engines, predictive
types of engines or predictive
functionality from HANA. Now within the
AFL we have the Predictive Analysis
Library. The main focus for this video
series.
This contains optimized predictive
machine learning algorithms that run
natively inside the HANA
database. To the optimize for the
parallel, optimized for columnar storage
etc. Optimized for in-memory. This way you
could expect to have best performance on
data that's already in your HANA
database. We’re about 80 algorithms in
this library. Otherwise we have some
other approaches. There's also the
Automated Predictive Library or APL. This
actually comes packaged with the
predictive analytics tool from SAP and
this also allows optimized in-memory
processing. It takes more very a business
and automated approach rather than the
the PAL which is very much based on
you knowing which algorithm you want to
use and how you can use it. You just need
to actually make those calls. Now in the
cases where you might want to access
algorithms that are not available in the
PAL or isn't suitable for the APL
then you've got a couple of choices. Now
we've had the integration with R for
quite some time and this allows you
basically to package up some R script
and also any data tables and have those
sent over to remote R server. So R
running on another server separate from
HANA.
We'll do the processing there and bring
back any tables, results that you want
and put them into HANA tables. So this
gives you access to the R open source
environment and three or four thousand
different algorithms or customer
algorithms you want to do. Now also with
SPS 02 we've introduced support for the
TensorFlow serving environments or
Google TensorFlow which is a very
popular machine learning framework right
now.
So the EML basically is the External
Machine Learning Library and it
basically is an AFL component that
allows you to access at this stage TensorFlow
via TensorFlow serving. So there
you can actually do the scoring in real
time of models. So you've build your
model in TensorFlow serve it with
TensorFlow serving and then you can
actually call it from HANA. Actually HANA
calls out to the TensorFlow server. So
we've got quite a combination of things.
Of course you can embed all of this into
into web based applications, web services
into store procedures, whatever you
want to do with HANA.
So now we'll see more detail how we get
started with 2.0 SPS 02 when we're
working with the Predictive Analysis
Library. Now the first thing to mention
is you can find all of the videos
relating to predictive within HANA from
our YouTube channel. So if you scroll
down there's a specific section for a
data scientist or someone interested in
predictive. I find it down here
predictive analytics and we've got the
EML playlist we've got this, the
Predictive Analysis Library playlist AFM
R integration etc etc. So that's where
you'll find all of the videos. Now then
first thing you're going to want to do
with a new HANA release of the Predictive
Analysis Library is access the reference
guide. So you would go to help.SAP.com
and then you would forward slash HANA and
then HANA underscore platform. This
will get you to the latest version of
the HANA documentation. We can see it's
version 2.0 SPS 02 and to find the
reference guide for the Predictive
Analysis Library go into the reference
section on the right hand side, choose
view all and then you get a full list of
reference guides and scroll down and
you'll find the HANA Predictive Analysis
Library or PAL reference guide there.
Now you can either open it up like this
in your web browser. If you want you can
also choose to download that as a PDF so
you can access it
offline. You'll find all sorts
information on the PAL in here. In
particular how to call procedures. Now in
SPS02 there's been a major change and
that we now have something called type
any syntax. So greatly simplified syntax
for calling predictive analysis library
procedures. That's something we'll be
going through in the upcoming videos and
also we've got details on all of the
different procedures or functions
available whether they're clustering,
classification, regression etc and we'll
see the new algorithms that we've got in
upcoming videos. So that's the reference
guide. Also if you want to follow along
then we've also got the code snippets
which are available on GitHub. So we have
a GitHub channel or the repository
for the SAP HANA Academy so github.com
SAP HANA Academy and then
actually the most popular repository is
the Predictive Analysis Library one and
if we go and look there you'll find that
we've got a number of entries has been
there for a while. We’ve got code
snippets. We’ve got a source or example
data and you'll see that for HANA SPS02
then we've got some very specific set of
in terms of the source data and also the
code snippets which basically going to
start from PAL 146. So 146 getting
started with HANA 2.0 SPS02. We're
going to come back to that shortly. What
we're going to do now is actually get
started. Now as we're working with HANA
SPS02 of HANA 2.0 thought it was time
that we maybe stop working with Eclipse
or HANA Studio and we started working
with the web-based tooling when was
showing how to build stuff and
predicting. Even if we're using SQL
script. So I'm going to connect to my
HANA system. In this case I'm using HANA
Express but this should work for for any
landscape and I'm going to go to the the
main endpoint for the XS advanced
server. So you'll need XS advanced if
you want to take this approach.
I'm now going to go to WebIDE for SAP
HANA. So I'm going to launch that.
There are plenty of videos in the HANA
Express place to show you how to get
started with all this. I'm going to log
in with my XSA developer
user and that will get me into WebIDE
for HANA. Now I'm actually not going to
develop XS advanced applications at
this point but what I am gonna do is use
the Database Explorer and the WebIDE for
HANA is a great place to get access to
the Database Explorer. Which we'll see is
down here on the left. So here this
Database Explorer it basically allows me
to make connections similar to what I
would have done in HANA Studio or using
Eclipse with the HANA tools. So I'm gonna
make a connection. Now what I'm gonna
choose the database type. Now with HANA
2.0 we're always talking about a
Multitenant database. So I've got to
give my host name and the instance
number which by default in HANA
Express will be HXEhost in this
environment. For example if you're using
the VMware the instance number is by
default 90. Now I'm gonna connect to the
system database using the system user
and that will be with the password I
specified when installing from binary or
when setting up the VMware. So now we are
connected to the system database. So the
next thing we want to do is actually do
some initial setup. Now remember we have
the code snippets available in GitHub. So
we do have them PAL
146 getting started with HANA 2.0 SP02.
Now we've got some script here that
we're going to want to run against the
system database. So it's the basically
the first 12 lines. So I'm going to copy
that and I'm going to paste it into a
SQL window and then we can go ahead
and run that. Now what we're doing
firstly is checking to see if the
AFL Predictive Analysis Library is
installed. We’re going to check that
we've got a tenant database and
crucially we're going to need to start
the script server on the tenant database
we're going to use. You can't use the
Predictive Analysis Library in the
system database because it does require
the script server and the script server
is only available from tenant databases.
So we can run that code. Let's just run
the first two statements. So we can just
check is the PAL installed? Yup, we've
got a nice list of algorithms basically
coming out there, about a hundred rows
returned and if we look at the list of
databases. Now this is again with HANA
Express. By default we have
a tenant database called HXE
and it's up and running. If he's not
running you would need to actually start
it. So active status tells you if it's
running. Then finally we need to add the
script server. So I run that. That might
take up to a minute to actually run. So
now it's run took about 40 seconds for
me. Just to be clear there the name of
your tenant, obviously that will be based
on the name that you find when you
select from SYS.M_DATABASES.
It can be any tenant in HANA Express. The
default tenant is called a HXE. So
that's the one I'm using here. So we've
now done the initial setup. We’ve got
script server started in our tenant.
We've checked that the AFL is installed.
The next thing is we need to connect to
our tenant and start thinking about
doing some setup there. So again we can
go to Database Explorer and we can
choose to add a connection to a
Multitenant Database. It’s going to be
the same host, the same instance number
but this time I'm going to choose the
HXE tenant database and connect with a
system user for that tenant database.
Again you're going to know that password
based on when you install or configured
HANA Express or your HANA system. So
we're now connected as the system user.
I'm going to open up a SQL window for
the system user and then we can go back
to our code snippets and you'll see that
starting on line 15 we've got a fair
amount of code that we're going to run
against the tenant database. So I'm going
to copy that and paste it in. We’re not
going to run all of it just now. We’re
going to run it selectively. So the first
thing to do is going to check, just
double check the script servers up and
running. Now you can do that by select *
from SYS.M_SERVICES on the
tenant and if we scroll down we should
be able to see that we've got script
server and the process is actually
active. So yeah script server is up and
running. So that's one of our
prerequisites done. Now we're also going
to want to authorize a user to work with
PAL. Now HANA doesn't come with a user
already authorized with everything you
need. So I'm going to create one here
call it developer user or dev user
and I'm going to grant some specific
rights to that user. Now one of the
righties catalog read which will enable
access to some certain system views.
We'll see that later with the real-time
scoring option in upcoming videos. Also
there's something called the wrapper
generator. Now normally you're not going
to need this too much when you're
working with SPS02 because type any
syntax actually simplifies and it means
you don't need to use this but it's not
going to be true for all algorithms. For
example a real time scoring you’re goning to
still need to use the wrapper generator.
So it's good to authorize that stored
procedure to your developer user. Of
course you're going to need to have
authorization to run procedures. So any
user that you want to run created
predictive procedures you need to
specify this right. That's done on line
18 and then if you're going to work with
Web IDE and specifically you're going to
use something called the Application
Function Modeler, which allows you to
build without writing any syntax
yourself similar to the the AFM that's
been available in Studio. It’s now
available in the flow graph editor in
Web IDE for HANA.
We're going to cover that in other
videos but in order to set that up then
you can see here are some statements
that allow you to do that. So let's go
and run that the first 30 odd lines up
to line 38. Let's run that and actually
create our user and basically everything
should be up and running and working
correctly. So we've done our
authorizations. The next thing is if you
want to work with the examples in these
videos then we're going to need to
import the demo data because the
code snippets work with some HANA tables
in a schema called PAL. So to do that
it's actually very straight forward we can
do that here in the Database Explorer
ourselves as well. What I need to do is
just go to my system user, in the
catalog and we'll see that we've got
different schemas. Now what I'm going to
do is right mouse button and choose
import catalog object and this is going
to allow me to import an archive file a
tar file which has got the HANA schema
in there. Now this you can get from the
GitHub repository.
So I'll just go back to the main PAL
part of our repository. Go to source data
and you'll see that there is actually a
PAL 22 for HANA 2.0 SPS 02 tar.gz and
what I'm going to do is download that. So
let's download that file to my desktop.
It's about 20 megabytes and then I can
actually go ahead and browse and open
that file. I notice it now finds all of
these tables that are registered in
there. So that's really great into a
schema called PAL and I can choose
import. So takes just a couple of seconds
and if I now refresh my catalog. So let's
refresh we should find that there is a
new schema called PAL in there. So there
we go we've got a schema called PAL.
So let’s close the import window. Now we've
created the schema. The next thing is
actually to grant read access to that
schema to our developer user. So a grant
select on schema power to dev user. So
I'm going to run that.
So we now authorize that developer user.
There's one final thing that we would
want to do, let’s just close out these
SQL windows, is we want to connect as
our developer user. So I'm going to hit the
plus sign again and go again to connect
to HANA database Multitenant. Put in my
HANA host name and license number,
tenant database, HXE is my tenant name.
This time connecting with my
developer user and it's gonna ask me to
change the password on the first login.
That's normal HANA policy. So I'm now
logged in as the developer user and if
we just go to the catalog we can see
that users are allowed to see the PAL
schema and if you go down and look at the
tables. We can have a look and that's
just right mouse button open data. Just a
check we can read the data. So yeah we
can read the data that's available in
the PAL schema. So we're all set up and
ready to go. So what we've seen in this
video is an overview of the HANA 2.0
SPS 02. We've seen how to get the
reference guide. We’ve seen actually how
we can get the code snippets from GitHub.
We've seen the HANA Academy Predictive
Analytics section and we've also done
the necessary setup, we accessed the
system DB, we start at the script server.
We access access to tenant. We created a
user and all the authorizations. We
imported the PAL schema and we
authorized the dev user for that schema
and we logged on as the developer user.
So in the next video we're ready to get
started actually working the predictive
algorithms with SPS02. So 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 and demo data for all of our
tutorials are published to GitHub. Thanks
for watching.