Saturday, November 15, 2014

Connecting to Oracle from KDB+ (Using Babel)

I have recently started messing around KDB+ and playing with cryptic Q language.

I want to compare the performance of Oracle vs KDB+, and in order to do that I have to duplicate the Oracle table in KDB+. I tried through ODBC layer but didn't work. Then I found another elegant solution posted on the code.kx.com site using Babel.
http://code.kx.com/wiki/Babel
"Babel for kdb+ is a SQL gateway process that allows kdb+ to query other vendors databases via jdbc."
Babel act as a broker between KDB+ and any database that can be connected through JDBC library. Meaning KDB knows how to talk to Babel and Babel knows how to talk to Databases through JDBC Layer. Now lets get into details.


Step 1:
Download Babel:  wget https://github.com/CharlesSkelton/babel/raw/master/dist/babel.zip
and unzip it.

Step 2:
Download ojdbc7.jar from oracle and copy it to bin directory under Babel. Note: odbc7 is for JDK 1.7 and if your Java version (java -version) is 1.6 you should use odbc6.jar.
http://www.oracle.com/technetwork/database/features/jdbc/default-2280470.html
Update: If you are using Java 8/JDK1.8 you can download ojdbc8 from here
http://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html
Update: For SQL Server use this thread
https://stackoverflow.com/questions/5307048/where-do-i-install-a-jdbc-driver-on-ubuntu


Step 3: Start the babel on port 6868

$ java -Xmx1024m -Doracle.jdbc.defaultRowPrefetch=10000 -cp "babel.jar:lib/ojdbc7.jar" de.skelton.babel.Babel 6868 oracle.jdbc.OracleDriver

For SQL Server
java -Xmx1024m -cp "babel.jar:sqljdbc42.jar" de.skelton.babel.Babel 6868 com.microsoft.sqlserver.jdbc.SQLServerDriver


Step 4:
Start q (I assume you already have working instance of q). If not you should first learn about q from http://code.kx.com

q)h:hopen 6868
q)r:h("query";"jdbc:oracle:thin:scott/tiger@your_oracle_server:1521:orcl";"select * from emp");


PS: You know Scott/Tiger is user id/ password and ORCL is the Oracle instance.




More References:


No comments:

Post a Comment