Hi, I'm Philip from the HANA Academy. In
this series of videos were looking at
R integration for our SAP HANA. In this
video we're going to get started with
HANA 2.0 SPS 02. Now just looking at the
architecture for predictive with HANA we
can see we've got an in-memory columnar
database that's inherent and has been
part of HANA since the beginning. We’ve
got a number of ways we can do
predictive or machine learning and data
mining in a HANA landscape. We’ve got the
AFLs or the Application Function
Libraries and within there we have the
PAL, EML and APL. Now the PAL or
Predictive Analysis Library provides
optimized processing running in-memory
inside the HANA database. So that's where
we've got about 80 algorithms for
machine learning, statistics, data mining
etc. These algorithms are really
optimized for data running inside of
HANA. It runs in the HANA engine. The APL
is similar. The Automated Predictive
Library. That provided some more
automated processes that run in-memory
natively in the HANA database and this
is actually a component that comes along
with the predictive analytics tool. Now
there may be situations where neither
the PAL or the APL really provides the
algorithms or the functions that you're
looking for. So there are a couple of
options in terms of looking external
predictive solutions. The EML which was
introduced in SPS 02. We have a separate
video series on that. As with the PAL
APL, of course. The EML. The External
Machine Learning Library. This allows you
to work with TensorFlow.
So Google's TensorFlow. If you've
built a model in Tensorflow and you
make it available across HTTP as a
service through TensorFlow serving then
you can access that model from HANA and
then you can basically do real-time
scoring on that model. You can you can
actually do your predictions on a model
that's running and has been created
using TensorFlow.
Also we've had support for R for a
number of years. So R is very well known
open source landscape for data
mining, predictive machine learning. It’s
got maybe 4,000 different algorithms.
You can create custom algorithms. So it's
a very flexible well, well used
environment. Now if you want you can also
have HANA reach out to a separate
server with R on it. That actually uses
the R serve components or an R server on
a separate server from HANA and when
this works basically in SQL script
you will create a stored procedure in
HANA and embedded in that stored
procedure you'll use R script. Which is
the R language and that script will
actually be wrapped up and sent to the
remote R server run on that server and
that allows you the integration working
with R. Now of course any data or
parameters that you've got as input
these would typically be in HANA tables and then
those will be wrapped up and sent across
to R and become vectors in R and if
you've got any results or output tables
then those tables would again be wrapped
up by HANA and sent from the R server
back to the HANA server and then dropped
into HANA tables. So basically if you're
working on the HANA side you're just
using a stored procedure that works with
tables input, tables output but the
actual processing will take place on a
separate R server and the way you're
going to work in the stored procedure is
using R script that you create
yourself. So it's very flexible. Now of
course there are different scenarios
better for different things.
R is particularly good if you're doing
your pre-processing. Where you've got
maybe data somewhere else and you want
to bring the results into HANA. It might
not make sense if you had a very large
volume of data in your HANA database and
you send all of that across to R because
you would be using a lot of network
bandwidth just to get the
processing in R. So it's really something
that you've got different options. It’s,
the idea is to find the best way of
doing things. So how do we actually get
started?
Well of course you need to come to the
HANA Academy. Here we've got tutorial
videos and if we just scroll down on the
HANA Academy site there's actually a
Data Scientist or a predictive section
you'll find a bit further down near the
bottom. Predictive analytics. Where we've
got playlists for the External Machine
Learning Library, the Predictive
Analysis Library etc, etc. And
we've also got a playlist for R
integration for SAP HANA. Now alongside
that we also have code snippets. So here
if we go to the HANA Academy GitHub
repository.
We've got GitHub.com SAP HANA Academy.
We've actually got a number of
repositories and if we clicked the
repositories link we'll see a couple of
important ones. We’ve got one called R -
Integration that we're going to be
using in this video and we'll see in the
future we've got another one called R
app with an example XS Advanced
web-based application. So that's where
you can get the different code snippets
from. Finally you want to get to the
reference guide for the R Integration.
So for that you need to go to where you
find online HANA documentation. So help.
SAP.com and then you can see it's
already predicted by Google here. HANA
_platform and once we get
there you need to go down on the right
hand side to the reference section and
click on the view all and then scroll
down and you will find that you've got
the SAP HANA R integration guide. To
click on that it will open up the
reference guide where you can get lots
of really good information on how you
work with the R integration for HANA
and if you want you can download this
for offline viewing as a PDF file, for
example. Otherwise you've got the
documentation online. So that's where the
reference guide is. Why don't we actually
now get started. Now as we're using HANA
2.0 I'm going to use the Database
Explorer which is available both in
the HANA cockpit and also in Web IDE for
HANA. Which is part of the XS
Advanced tooling. So I'm going to go to
Web IDE for HANA.
So in my case I'm using HANA Express. So
you'll see that my host name is as you
would you would see it for example if
you're using the VMware of HANA Express
and I'm going to use the instance 90. So
it's 39030. That's basically the
endpoint for XS Advanced on this
system and then I can see there's a Web
IDE link in there. So allow me to get to
Web IDE.
Now I'm going to log on. So I'm going to
log on as the standard user.
XSA_DEV. That's the one that
comes with HANA Express but of course
if you using a different HANA setup then
you would need to have a user that's
authorized for Database Explorer and Web
IDE and once I'm in Web IDE I can go to
the left-hand pane and see here Database
Explorer. That's where we're going to
work. Now I'm actually got nothing set up
already here. So it's the first time it's
going to prompt. Do we want to add a
database and yes I do because the first
thing we're going to do is some initial
setup to get started and to do that I'm
going to need to login as the system
user. Now of course you could use any
client. You could use HANA Studio or
Eclipse with the HANA tools plug-in or
even the HDB SQL command if you
wanted. Any client that you can use you
can create SQL script and actually
send that to your HANA system. So I'm
going to connect to the HANA database.
Multitenant because all databases are
Multitenant with HANA 2. The name of
my host as we saw was HXE host. Instance
90. I want to connect to my tenant
database because we're working
Multitenant. You shouldn't use the
system database when you're working with
with any of the predictive functions
that are available with HANA. Really
the system database is just for system
processing it's the tenant databases you
should use for actual real storage and
real work. So we're going to connect to
our default tenant database on this HANA
Express system. Which is called HXE for HANA
Express and I'm gonna log in as the
system user. So now I am logged in as a
system user and I'm going to open up a
SQL window so I can send some SQL
script code. Now if we go back to GitHub
and the R integration now the code I'm
actually going to run here is available
in the code snippets folder and it's R 09
Getting Started with HANA 2.0 SPS 02.
So I'm going to copy and paste that code
into my SQL window inside
the Database Explorer. Let's scroll up.
Now the first thing we're going to do is
create a user. You need to have a
specific authorization enable to use the
R functionalities, the R Integration.
So we're going to create a user we'll
call it R user but you can use any
name that you want. So let's run that and
then that user needs to have this
specific authorization and the
authorization is called create R
script. So you need to grant that to your
user. So let's go ahead and do that.
Normally the system user has that by
default but you shouldn't be using the
system user for your general processing,
you know your general work but it
doesn't mean the system user can grant
this authorization to any user that you
might create. Once you've granted that
role to your user you can think about
actually accessing your R server and
to do that we use a remote source. This
is very similar to the way that the
External Machine Learning Library is
accessing TensorFlow server. So this is
new in SPS 02. You can create a remote
source using an adapter called R serve
and this adapter then means HANA knows
that we're talking to a remote R
server. So you can give it a name. We’ll
call it Rserve. With a capital R. Of
course you can give it any name you want.
My R server and then you would specify
configuration. In particular you'd need
the IP address or the host name of the
server. You'd need the port where the
RSERVE is actually running. Very often
it's 30020 and you can also provide
authentication and other encryption
details as well. Which you might want to
use in productive systems but as this is
just a very simple straightforward demo
then we're showing just without
authentication. Now I happen to know that
in my landscape we've got server
10.0.0.51 and on port 30020. That is actually where my
R server is up and running and you'll
find other videos in the Academy on how
to actually set up, install RSERVE and
get it all running. So we're going to
create our remote source. Let's go ahead
and run that. Okay that's now done. What we
then need to do is assign that remote
source to one or
more users to say this user is
authorized to use that remote source. So
you can assign it based on user. Again
this is new in SPS 02. So I'm going to
assign that by doing alter user on the R
user that we've just created. For the
parameter RSERVE and set remote sources
value to the name of the remote source
that I've just created. So that's what
we're gonna do here. Of course you can
give you multiple R servers if you
want to. So that's how we assign the
remote source to the user and finally if
we're going to work with XS Advanced
maybe use Web IDE to develop web-based
applications then you're going to be
working with something called HDI Containers. More
about that in the XS Advanced in
upcoming videos in this series
but basically you need to make sure that
you also grant the create R script to
the object owner of the HDI container
that might get created and you do that
by basically granting the right to a
special place called _SYS
_DI__OO_
DEFAULTS and that means any
object owner for an HDI container that
gets created will then have this create
R script
authorization and crucially you must
also say with admin option. Which means
that this HDI Container user also has
the rights to grant create R scripts
to any technical users that it manages
and creates. That’s very important when
you're working in the XS Advanced
landscape because when we actually log
in as XSA_DEV it's not
that user that does the actual
processing in HANA. It’s using technical
users that work together on your HDI
Container. Effectively or your schema
technical users come together as an HDI
Container. So what we can now do is log
in as our R user and as we've done all the
rights. No, actually we haven't run this
create grant R script. So we better run
that. It may be useful in a future video.
So now we are ready to log in as our R
user. So we can hit the plus sign and we
can go again to database, Multitenant.
We've got our host. Instance 90.
Tenant is the same, HXE and then I'm gonna log
in as R user and the first time it's
going to prompt me to change the
password. So we're now logged in as our
R user. We’re ready to actually start
working with the R Integration. We’re
going to see that in the next video. So
in this video we've had an introduction.
We’ve seen the architecture. We’ve seen
where to get the reference guide. We’ve
looked at where we can get the code
snippets and videos on the HANA Academy
YouTube channel and GitHub and we've
also done the initial setup. We’ve
created an R user. We’ve created a
remote source and we've done the
necessary authorizations. 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.