Blog do projektu Open Source JavaHotel

środa, 12 marca 2014

InfoSphere Sreams and Oracle

Introduction
InfoSphere Streams can connect to Oracle database also. InfoSphere Streams installation contains Database Toolkit which provides several operators which allow integration with external databases (including Oracle). The functionality is very limited (it is nothing more then insert/update and select) but it is enough for typical InfoSphere Stream application.
Oracle and unixODBC
First thing to do is to download, install and setup unixODBC connection with Oracle database.
Oracle client
Download and install Oracle client software.  At least two products should be installed: Basic and ODBC. Also SQL*Plus is recommended for testing and administering.
unixODBC connection
Set LD_LIBRARY_PATH environment variable pointing to Instant Client installation.
Example
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/instantclient_12_1/
Make sure that libsqora.so.12.1 library has all dependency resolved.
[sb@host ~]$ ldd /usr/local/instantclient_12_1/libsqora.so.12.1 
 linux-vdso.so.1 =>  (0x00007ffff43ff000)
 libdl.so.2 => /lib64/libdl.so.2 (0x00007ff65554a000)
 libm.so.6 => /lib64/libm.so.6 (0x00007ff6552c5000)
 libpthread.so.0 => /lib64/libpthread.so.0 (0x00007ff6550a8000)
 libnsl.so.1 => /lib64/libnsl.so.1 (0x00007ff654e8f000)
 librt.so.1 => /lib64/librt.so.1 (0x00007ff654c86000)
 libclntsh.so.12.1 => /usr/local/instantclient_12_1/libclntsh.so.12.1 (0x00007ff651f99000)
 libodbcinst.so.2 => /usr/lib64/libodbcinst.so.2 (0x00007ff651d88000)
 libc.so.6 => /lib64/libc.so.6 (0x00007ff6519f3000)
 /lib64/ld-linux-x86-64.so.2 (0x0000003732c00000)
 libnnz12.so => /usr/local/instantclient_12_1/libnnz12.so (0x00007ff6512dd000)
 libons.so => /usr/local/instantclient_12_1/libons.so (0x00007ff651099000)
 libaio.so.1 => /lib64/libaio.so.1 (0x00007ff650e97000)
 libclntshcore.so.12.1 => /usr/local/instantclient_12_1/libclntshcore.so.12.1 (0x00007ff650947000)
 libltdl.so.7 => /usr/lib64/libltdl.so.7 (0x00007ff65073e000)
[sb@host ~]$ 
Create /etc/tnsnames.ora connection  file 
(example)
[sb@host ~]$ cat /etc/tnsnames.ora 
testdb=
 ( DESCRIPTION =
  (ADDRESS_LIST =
  (ADDRESS =
  (PROTOCOL = TCP)
  (Host = think)
  (Port = 1521)
  )
 )
 (CONNECT_DATA = (SID = testdb)
 )
)
Make sure that connection by sqlplus is working
[sb@host ~]$ sqlplus testuser/testuser@testdb

SQL*Plus: Release 12.1.0.1.0 Production on Wed Mar 12 23:06:24 2014

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Modify (or create) /etc/odbcinst and /etc/odbc.ini configuration files
[sb@host ~]$ cat /etc/odbcinst.ini
[ORACLE]
Description = Oracle
Driver   = /usr/local/instantclient_12_1/libsqora.so.12.1
[sb@host ~]$ cat /etc/odbc.ini
[testdb]
Description  = Oracle
Driver   = ORACLE
ServerName  = testdb
UserID   = testuser
Password = testuser
Verify that isql utility is working with Oracle
[sb@host ~]$ isql testdb
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> 
create table testid (id integer, name varchar(100))
InfoSphere Streams application
A simple StreamsStudio project is available here.
Database Toolkit operators use connection.xml file which specifies how application connects with external database. Connection.xml file contains information about connection and tables used in the database by InfoSphere Streams application.
Example of connection.xml file is available here.
Next step is to create application itself. It is very easy if one uses StreamsStudio framework, just drag operators to the application graph and connects input and output ports.
An example of sample application adding stream of data to external Oracle database is available here.
Visualization of this application:
Important limitation related to Oracle
Oracle does not support SPL int64 and uint64 data type. Also BIGINT in connection.xml file cannot containt BIGINT type (use INTEGER instead).

Brak komentarzy:

Prześlij komentarz