ページの先頭行へ戻る
Interstage Big Data Parallel Processing Server V1.2.1 拡張機能ガイド
FUJITSU Software

9.3 ODBCを利用した接続

ImpalaのODBCドライバを利用して、Impalaに対してクエリ実行のリクエストを送信することができます。

ImpalaのODBCドライバの入手とインストール方法については、Cloudera社のWebページ等を参照してください。


以下は、unixODBCパッケージを利用し、スレーブサーバ slave6 に対してクエリ実行(SELECT)をリクエストする際の実行例です。

  1. unixODBCパッケージ、unixODBC-develパッケージのインストール

    # yum install unixODBC unixODBC-devel <Enter>
    Loaded plugins: product-id, security, subscription-manager
    ・・省略・・
    Complete!
    # odbcinst -j <Enter>
    unixODBC 2.2.14
    DRIVERS............: /etc/odbcinst.ini
    SYSTEM DATA SOURCES: /etc/odbc.ini
    FILE DATA SOURCES..: /etc/ODBCDataSources
    USER DATA SOURCES..: /root/.odbc.ini
    SQLULEN Size.......: 8
    SQLLEN Size........: 8
    SQLSETPOSIROW Size.: 8
    #
  2. ImpalaのODBCドライバのインストール

    # rpm -ivh /tmp/ClouderaImpalaODBC-2.5.22.1023-1.el6.x86_64.rpm <Enter>
    準備中...                ########################################### [100%]
       1:ClouderaImpalaODBC     ########################################### [100%]
    #
  3. /etc/odbc.ini の設定

    # cp -p /opt/cloudera/impalaodbc/Setup/odbc.ini /etc/odbc.ini <Enter>
    # /etc/odbc.iniの編集(接続先ホスト名とポート番号を編集)
    # cat /etc/odbc.ini <Enter>
    [ODBC]
    # Specify any global ODBC configuration here such as ODBC tracing.
    
    [ODBC Data Sources]
    Sample Cloudera Impala DSN 64=Cloudera ODBC Driver for Impala 64-bit
    
    [impalaodbc]
    
    # Description: DSN Description.
    # This key is not necessary and is only to give a description of the data source.
    Description=Cloudera ODBC Driver for Impala (64-bit) DSN
    
    # Driver: The location where the ODBC driver is installed to.
    Driver=/opt/cloudera/impalaodbc/lib/64/libclouderaimpalaodbc64.so
    
    # The DriverUnicodeEncoding setting is only used for SimbaDM
    # When set to 1, SimbaDM runs in UTF-16 mode.
    # When set to 2, SimbaDM runs in UTF-8 mode.
    #DriverUnicodeEncoding=2
    
    # Values for HOST, PORT, KrbFQDN, and KrbServiceName should be set here.
    # They can also be specified on the connection string.
    HOST=slave6
    PORT=21050
    Database=default
    
    # The authentication mechanism.
    # 0 - no authentication.
    # 1 - Kerberos authentication
    # 2 - Username authentication.
    # 3 - Username/password authentication.
    # 4 - Username/password authentication with SSL.
    AuthMech=0
    
    # Kerberos related settings.
    KrbFQDN=
    KrbRealm=
    KrbServiceName=
    
    # Username/password authentication with SSL settings.
    UID=
    PWD=
    CAIssuedCertNamesMismatch=1
    TrustedCerts=/opt/cloudera/impalaodbc/lib/64/cacerts.pem
    
    # Specify the proxy user ID to use.
    #DelegationUID=
    
    # General settings
    TSaslTransportBufSize=1000
    RowsFetchedPerBlock=10000
    SocketTimeout=0
    StringColumnLength=32767
    UseNativeQuery=0
  4. /etc/cloudera.impalaodbc.iniの設定

    # cp /opt/cloudera/impalaodbc/lib/64/cloudera.impalaodbc.ini /etc/cloudera.impalaodbc.ini <Enter>
    # /etc/cloudera.impalaodbc.iniの編集使用するライブラリの指定
    # cat /etc/cloudera.impalaodbc.ini <Enter>
    [Driver]
    
    ## - Note that this default DriverManagerEncoding of UTF-32 is for iODBC.
    ## - unixODBC uses UTF-16 by default.
    ## - If unixODBC was compiled with -DSQL_WCHART_CONVERT, then UTF-32 is the correct value.
    ##   Execute 'odbc_config --cflags' to determine if you need UTF-32 or UTF-16 on unixODBC
    ## - SimbaDM can be used with UTF-8 or UTF-16.
    ##   The DriverUnicodeEncoding setting will cause SimbaDM to run in UTF-8 when set to 2 or UTF-16 when set to 1.
    
    DriverManagerEncoding=UTF-32
    ErrorMessagesPath=/opt/cloudera/impalaodbc/ErrorMessages/
    LogLevel=0
    LogPath=
    
    
    ## - Uncomment the ODBCInstLib corresponding to the Driver Manager being used.
    ## - Note that the path to your ODBC Driver Manager must be specified in LD_LIBRARY_PATH (LIBPATH for AIX).
    ## - Note that AIX has a different format for specifying its shared libraries.
    
    # Generic ODBCInstLib
    #   iODBC
    #ODBCInstLib=libiodbcinst.so
    
    #   SimbaDM / unixODBC
    ODBCInstLib=libodbcinst.so
    
    # AIX specific ODBCInstLib
    #   iODBC
    #ODBCInstLib=libiodbcinst.a(libiodbcinst.so.2)
    
    #   SimbaDM
    #ODBCInstLib=libodbcinst.a(odbcinst.so)
    
    #   unixODBC
    #ODBCInstLib=libodbcinst.a(libodbcinst.so.1)
  5. 環境変数の設定

    # export LD_LIBRARY_PATH=/usr/local/lib:/opt/cloudera/impalaodbc/lib/64 <Enter>
    # export CLOUDERAIMPALAINI=/etc/cloudera.impalaodbc.ini <Enter>
  6. クエリ実行

    # isql -v impalaodbc <Enter>
    +---------------------------------------+
    | Connected!                            |
    |                                       |
    | sql-statement                         |
    | help [tablename]                      |
    | quit                                  |
    |                                       |
    +---------------------------------------+
    SQL> select * from example_table1 <Enter>
    +-------+------------------+------------+-----------------+-------------------------+
    | id    | str_column       | bool_column| double_column   | date_column             |
    +-------+------------------+------------+-----------------+-------------------------+
    | 1     | 文字列1          | 1          | 101.2           | 2013-10-24 10:20:05     |
    | 2     | 文字列2          | 0          | 53.15           | 2013-10-25 10:20:05     |
    | 3     | 文字列3          | 1          | -18.5           | 2013-10-26 10:20:05     |
    | 4     | 文字列4          | 0          | 0               | 2013-10-27 10:20:05     |
    | 5     | 文字列5          | 1          | -12.35          | 2013-10-28 10:20:05     |
    +-------+------------------+------------+-----------------+-------------------------+
    SQLRowCount returns -1
    5 rows fetched
    SQL> <Enter>