Running HANA Client and HANA Studio on a Macbook

Although in SAP HANA 1.0, Rev 70, the most complete developer tooling is only available for Windows and Linux, it is possible to install HANA in a Virtual Machine on a Mac.

In my case, I decided to go with a Linux virtual machine, one running Ubuntu. I first tried VirtualBox but I had some issues getting the virtual machine’s resolution to support a decent screen resolution. I also wasn’t making a lot of progress getting a lot of my folders to be shared between the Mac and the Ubuntu virtual machine. I then decided to give Parallels a try. Unlike VirtualBox, Parallels is a paid product but they were offering me a 14-day free trial so I quickly decided to give it a try. The installation was a breeze and the integration with my Mac, amazing. I’m definitely keeping it.

With a Ubuntu Linux 13.04 installation ready, I was ready to install HANA Client and HANA Studio.

1. Downloaded the two files I needed, and copied them to a directory of my choice. If you have a revision number different than 70, make sure to update all the commands in this tutorial accordingly.


2. Extracted the file contents.

$ tar zxvf sap_hana_client_linux64_rev70.tgz
$ tar zxvf sap_hana_studio_linux64_rev70.tgz

3. First I installed the HANA Client. After changing to the client files directory, I executed the installation script.

$ cd sap_hana_70_client_linux64/
$ sudo ./hdbinst -a client

3a. If it turns out that the execution permissions get lost when you’re moving files around, you’ll need to re-assign the execution permissions before running the installation script.

$ cd sap_hana_70_client_linux64/
$ chmod +x hdbinst
$ chmod +x hdbsetup
$ chmod +x hdbuninst
$ chmod +x instruntime/sdbrun
$ sudo ./hdbinst -a client

4. The HANA Studio requires the Java Runtime. Check your system by running the following command. If Java is not found, you’ll need to install it (see 4a).

$ which java

4a.To install Java in Ubuntu, simply run the following command.

$ sudo apt-get install default-jre

5. With Java ready, you can go ahead and install the HANA Studio.

$ cd sap_hana_70_studio_linux64/
$ sudo ./hdbinst -a studio

5b. Again, if it turns out that the execution permissions get lost while moving files around, you’ll need to re-assign them before running the installation script.

$ cd sap_hana_70_studio_linux64/
$ chmod +x hdbinst
$ chmod +x hdbsetup
$ chmod +x hdbuninst
$ chmod +x instruntime/sdbrun
$ sudo ./hdbinst -a studio

6. If everything goes well, and you go with all the default values, you should end up with everything installed under the /usr/sap/ directory.

7. To run the HANA Studio, you just need to navigate to the installation directory and run the following command. Doing so will launch the HANA Studio graphical application. If the applications launches without any errors, you’re ready to roll and start configuring your project.

$ cd /usr/sap/hdbstudio
$ ./hdbstudio

8. To test if the HANA Client has been installed properly, you can run the following command:

$ cd /usr/sap/hdbclient
$ sudo ./hdbsql

8a. Note that if you get an error like “error while loading shared libraries: cannot open shared object file: No such file or directory“, you’ll need to install the missing libaio-dev package by running the following command.

$ sudo apt-get install libaio-dev

8b. If the HANA Client is installed correctly, you’ll see a greetings message after calling the client:

$ sudo ./hdbsql
Welcome to the SAP HANA Database interactive terminal.
Type: \h for help with commands 
 \q to quit

And that’s it. Getting both the HANA Studio and the HANA Client to run on a Mac is really simple, as long as you’re willing to spend a few extra minutes setting up a Linux virtual machine. In total, it took me probably somewhere between 30 and 45 minutes to get it all done but if you follow my instructions you should get it done a lot quicker as you won’t have to go through the same hiccups I went through 🙂

~ Andre Lessa (@lessaworld)


Multiple COUNTS within the same SELECT statement

Here’s another interesting problem that I solved. This one relates to SQL Server.

The problem:

To write a single database query that would allow me to get multiple row counts depending on certain pre-defined conditions. Let me make it clear … I had a table called nodes and I needed to count how many times certain non-unique records had been saved. Since the table was huge in size, the idea of using multiple queries scared me so using a single query to solve the problem was the way I found to optimize the performance and the algorithm.

The solution:

Many developers are used to write statements like select count(*) from certaintable where tablecolumn = specialcondition … that works great when you just need to count one thing at a time. My solution was to approach the problem by moving the where condition to the select section of the statement.

The query:

sum(case when node_id < 300 then 1 else 0 end),
sum(case when node_id > 200 then 1 else 0 end),
sum(case when node_id between 200 and 300 then 1 else 0 end)
from node

The recipe:

The secret sauce was to use the sum/case combo instead of the standard count function. By testing each condition I wanted with a case statement, and adding up the number of times each condition turned out to be true (using the sum function), I was able to achieve my goal.

How to shift the elements of an array

Just recently I came across this request to shift an entire slice of an array while keeping the algorithm cost to its bare minimum. Let’s put it this way. It’s pretty simple if you have something like ABCDE and you want to shift the elements so it becomes CDEAB. Now, the big problem is this – what if you have 1 billion bytes in this array and you need to perform sort of the same operation? That’s trick, right? Most likely, I wouldn’t be able to afford an additional high amount of memory to perform this.

So here’s what I came up with. The code is written in Python.

def f_ArrayExercise(a, i):
    n = 0
    while i <= len(a) - 1:
        a[i], a[n] = a[n], a[i]
        i += 1
        n += 1
        if len(a)%2 and len(a) > 1:
            a[len(a)-1], a[len(a)-2] = a[len(a)-2], a[len(a)-1]
    print a

The secret here is to swap one element at a time in order to save in memory space. However, note that with minor modifications we can easily swap pre-determined chuncks of the array at a time instead of limiting ourselves to one element – just in case we know we can afford a couple more elements. That would help optimize the processing time.

The first argument of the function is the array itself, the second argument is the exact spot you want to use to start shifting the array.

When you play around with this function, you get something like this:

>>> f_ArrayExercise([], 2)
>>> f_ArrayExercise([“A”], 2)
>>> f_ArrayExercise([“A”,”B”], 2)
[‘A’, ‘B’]
>>> f_ArrayExercise([“A”,”B”], 1)
[‘B’, ‘A’]
>>> f_ArrayExercise([“A”,”B”,”C”], 2)
[‘C’, ‘A’, ‘B’]
>>> f_ArrayExercise([“A”,”B”,”C”,”D”], 2)
[‘C’, ‘D’, ‘A’, ‘B’]
>>> f_ArrayExercise([“A”,”B”,”C”,”D”,”E”,”F”,”G”,”H”], 2)
[‘C’, ‘D’, ‘E’, ‘F’, ‘G’, ‘H’, ‘A’, ‘B’]
>>> f_ArrayExercise([“A”,”B”,”C”,”D”,”E”,”F”,”G”,”H”, “I”], 2)
[‘C’, ‘D’, ‘E’, ‘F’, ‘G’, ‘H’, ‘I’, ‘A’, ‘B’]
And that’s the end of this Array Manipulation Exercise.