Hi, I'm Philip from the HANA Academy.
in this series of videos were looking at the external machine learning library
which was introduced with SAP HANA 2 SPS02.
In this video we're going to get started with the external machine learning library or "EML"
We're going to look at the reference guide and the online doc. We're going to look at some code snippets
that we will use in this video series that are on GitHub,
and we're also going to do some initial configuration of our HANA server
So the first thing to do is go and look for the reference guide
so we can go to help.sap.com/hana_platform
as that's the main place to go to get HANA documentation.
The EML is actually documented in the references guide section.
if you scroll down Into the reference section that's here on the right,
you won't see it in the initial list. But if you choose View All and then scroll down a little bit
you'll find that we've got the HANA external machine learning library
It's quite close to the predictive analysis library, so if you're familiar with that you'll kind of know where to come.
So let's click on that and it will open up the reference guide
And you can see it's got sections Introducing, Getting Started, models and Call Signatures, Deploying and Mapping models, etc
You also get information here about any restrictions or what the capabilities are in any given release.
Now the main reason for using the external machine learning library right now is to work with Google Tensorflow
And that's what we'll be focusing on these videos
Now you can either use the documentation online like this,
or, if you want, you can download it in PDF form and then save that away
so you can view the documentation offline. It's completely up to you.
Now that we know where the documentation is, the next thing we want to do
is find the code snippets that we're going to use in this series.
You can go to github.com/hanaacademy.
(You also find the link in the description area of the current playlist in the YouTube HANA Academy Channel)
If you go to the github.com/hanaacademy and then choose Repositories
you should find in that list that we see one called EML, for the external machine learning library.
So I'm going to click on that now. It's up to you if you want to clone it or you can download it,
or if you want ,what we're going to do here is just copy and paste.
You'll find there's a code snippet folder and in that folder
you've got different bits of code for the different videos that we're going to be looking at going forward.
So we're now ready to get started. You'll find you see we actually have EML 02, (which is this tutorial "Getting Started" )
that is the code that we're going to need to actually run to get going now
We'll go through that in a moment
When we work with a SPSO2 of HANA. We're always working in Multi database container or MDC mode.
There's no concept of single container anymore, so we're going to need to make sure
that we setup a suitable tenant database and we've got that configured correctly.
That's basically what we're going to be doing in this video.
Also, we're going to be setting up a Developer user
with the correct roles and authorizations that be able to work with the EML.
Now in terms of how you want to actually run SQL script from HANA.
You can choose any client you like, I've chosen to use Eclipse here.
So if you use your Eclipse and
(basically any recent version of Eclipse) should work on any platform.
Go to Install New Software and then you would want to Install the HANA tools.
So here you see that I've already done it.
So we've actually got the HANA tools here.
You get those from tools.hana.ondemand.com
This is a really good way that you can actually Interact when you want to send SQLscript to HANA.
Of course, there are other ways -- the database explorer for example.
If you've got XSAdvanced and you're using WebIDE for HANA.
First thing I'm going to do is I need to connect to my system.
I've got a completely vanilla new system set up.
It's actually a domain name of HANA and Instance is 00. It's an MDC
because they all are these days starting with SAP HANA2 SPS01.
The first thing we'll do is connect to the system database, and I happen to have the system user
So I'm going to log in
and I'll save the username and password for the future
let's do that and make our connection
So we've got our initial connection into the the HANA system as the administrator.
You will need to access with a user with equivalent to system user access -- the ability to create roles and authorizations --
because that's exactly what we're going to do in the next steps.
So the first thing, we'll open up a SQL window, and then we'll be able to go back to github where we've got some code.
The first section of code (from Line 1 to Line 17) should be run against the system database.
And what we're going to do here
Let's just paste it in. Of course there are other ways you could do it,
for example, you could save it and open the file.
The first thing, we're going to check that the EML (the external machine learning library) components have been installed.
Note that this is an option you could choose when the HANA landscape was installed,
so this probably has already been done for you. If not, you need to check with
the person who installed HANA as one of the options is to install the EML,
which is actually a component that goes together with the AFL.
So you need to make sure that's installed and the easy way to do that is to run the SQL statements
which will basically tell you what do you actually have available.
So we can see we've got our results. We can see that the error name EML exists.
We can see that. We've got eml lib that exists -- we get a row back.
Most importantly when we look at the AFL_ functions for the area named EML,
we can see we get some functions names back -- including four of them that start with "predict"
one called CTL, another called check destination. We're going to be using these going forward.
Basically as long as these functions exist, you should be good to go
Now the second thing is we need to work with a tenant database
You cannot work with the EML on the system database, and that's because we require something called the script server
Which is not available on the system database, and you shouldn't want to use it on the system database
You should be using a full tenant database for that
So what we can do is check whether we've got a tenant database. You may already know this in your landscape. here
We can see we've got the system database
And we've got a tenant, and it's called SHA for SAP HANA Academy,
So that tenant database is there and it's active. It's actually been started.
In some cases it might exist, but it's not been started.
In that case you can use this code here to start the database. Sometimes for example in HANA Express
there's a tenant database created called HXE but it's actually not been started, so you'd need to explicitly start it
Now once you've got a tenant database and it can be any name of tenant database you want
of course you can create your own specific tenant if you want to. Then you need to add the script server
and this is the same process that you would go through if you're working also with
the Predictive Analysis Library when you're working with that on HANA as well.
You need to run this code which basically is "alter database" for the name of the database, SHA, and then "add the script server"
Let's go ahead and run that now. It will probably take about a minute to run.
So we can see now that the alter database add script server has completed. That's great. So we're good to go.
We've done the initial config. What we now need to do is connect to the tenant database and do an additional set of configurations there.
So for that, we need to again make a connection to the HANA system
using the same instance number, choosing multiple containers,
but this time to this tenant database name
(which in my case is SHA, but for you of course it's whatever tenant you're working with)
I'm going to initially connect as the system user
Note that every tenant had its own system user. So let's connect.
Again, we're going to need the ability to to create roles and authorizations. So typically you might do this with the system user
So we'll open up a SQL window on that tenant,
and now we can go back to github and we can get the second part of this script
(from line 20 to the end)
I'm going to copy and paste that into my new SQL window. Now this you run against your tenant database
The first thing we can do is just verify that the script server is up and running
For that you can do just a "select *" on the system view 'M_services'
that tells you which services actually are up and running in your hosts.
We can see here that script server is up and running. Now if you don't see script server in this list,
that means the script server has not been started, so that's something you'd need to do.
Now we just need to set up the correct roles and authorizations.
I'm going to create a user. I'll call it DEVUser for the developer.
It's up to you, you can actually set up authorizations for maybe an EML administrator,
and also EML developers and their natural End Users that may run things created that access to EML.
But for these videos, I'm going to keep it pretty simple and create a single user called DEVuser.
And I'm going to give him the rights to do all of those tasks.
So we'll create the user DEVUser, and then we'll authorize that user to do EML Administration,
so for that we need to grant 'monitoring' to that user. We need to grant 'create remote source'
because that's how we can actually make connections to our tensorflow server,
and we're going to grant 'select update insert and delete' on a very specific table which is _SYS_AFL_.emlmodelconfiguration
That's a table we're actually going to do updates to
as we configure which models and servers we have available in the system.
So that could be an administrator, but in our case we'll do that as the developer.
Then the other rights we'll do -- on line 17 we can see
we've grant of the aflpm_creator_eraser_execute.
(This is the wrapper generator procedure, if you've worked with the predictive analysis library in the past and you'll be familiar with that)
We're going to be using that here so that we can generate our own stored procedures that will make the actual calls.
Finally we've got the ability to run the EML procedures, so procedures that have been generated.
Maybe this is something that you'll grant a technical user, which will be running these on behalf of end-users, as part of some code embedded in some application.
Next we will grant the AFL__SYS_AFL_EML_EXECUTE role to that user
Again, if you've worked with the PAL, you'll find something very similar
which is actually the same but with 'PAL' instead of 'EML' in the middle of the name.
So this is the ability to run the procedures that we're going to generate using this creator eraser procedure.
So that's all we need to do. Let's go ahead now and run that.
We can see that's now run. All the statements have successfully executed. We've created the user.
Now we can log on as that user. The easy way to do that is to go to the same tenant that you're already connected to
And choose the Add System with Different User option.
That way we won't have to reconnect to the actual server name and the tenant name.
Put in DEVuser with that initial password
And Click finish
The first time normally via the HANA system, you'll need to change the password for a new user. So let's do that.
So the password is changed and we're logged in as the developer user.
If we have a look at the developer user will see his access to the _SYS_AFL and his own schema
So we're good to go.
So that's the initial set up so that we can actually start working with the EML
All you've seen in this video is how we can set up the tenant, we can start the script server,
we can create a user, and we've validated that the EML AFL component has actually been installed
What we've also done is we've checked out the github repository for where we'll find all the code snippets.
We found the external machine learning library reference guide actually in the online HANA documentation.
in the next video, we'll actually start looking at how we work on the tensorflow side,
to make a model that we could then access via the external Machine learning library.
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