Categories
Hadoop相关 Hive Impala PHP 学习研究

PHP ODBC Connect Cloudera Impala and Hive

By @sskaje
Link: https://sskaje.me/2014/07/php-odbc-connect-cloudera-impala-hive/

Environment

CentOS 5.5
PHP 5.3.10
(This article also works for PHP 5.3.3 on CentOS 6).

Dependencies

UnixODBC

UnixODBC can be installed from yum repo

I built a unixODBC 2.3.2 from source, installed to /usr/local/unixODBC

ODBC Connectors

Cloudera offers ODBC libs for both Hive and Impala:
http://www.cloudera.com/content/support/en/downloads/connectors/impala/impala-odbc-v2-5-15.html
http://www.cloudera.com/content/support/en/downloads/connectors/hive/hive-odbc-v2-5-9.html

Follow the install guide on urls above, only wget and yum –nogpgcheck localinstall xxx.rpm required.

PHP Extensions

You can install PHP-ODBC or PHP-PDO-ODBC, either from source or yum repo.
If you meet some error building PHP-ODBC, this article might be useful: Build Old PHP-ODBC from Source

Configure Connectors

Connectors are installed under /opt/cloudera, both of them provide a folder named ‘Setup‘ with three files in it:

  • cloudera.impalaodbc.ini
  • odbc.ini
  • odbcinst.ini

cloudera.impalaodbc.ini

I’m using the unixODBC built from source:

And comment all rest lines about ODBCInstLib.

odbc.ini

odbcinst.ini

nothing changed.

Test

LD_LIBRARY_PATH

If you have your unixODBC installed from yum:

If built from source:

ENV

Guide says ini-s can be copied to ~ and prepend a ‘.‘ to make it ‘invisible‘.
But I prefer to set up ENV:

These can be set inside PHP script with putenv(),
I’ll paste test script later.

Script

Test script using PHP-PDO-ODBC and PHP-ODBC are pasted below.
Remember to use DSN=MyImpala instead of shared object file path(from install guide), Driver=(from php doc), …

Trouble Shooting

Can’t open cursor lib

Error message may like

or

Solution is create a symbolic link:

Segmentation fault

If you meet these, go back and check your configurations and DSN syntax.

zend_mm_heap corrupted

This occurs when using php-odbc based on unixODBC 2.2.11 from yum on centos 5.5.
Build the latest unixODBC from www.unixodbc.org.

Useful links

http://d.hatena.ne.jp/shimooka/20140422/1398159246

PHP ODBC Connect Cloudera Impala and Hive by @sskaje: https://sskaje.me/2014/07/php-odbc-connect-cloudera-impala-hive/

Incoming search terms: