【问题标题】:ODBC error while accessing drill through python通过 python 访问钻取时出现 ODBC 错误
【发布时间】:2017-02-23 14:29:57
【问题描述】:

我在尝试通过 python 使用钻取时收到以下错误:

Traceback (most recent call last): File "/home/ubuntu/ChurnPrediction/OBDCtest.py", line 5, in <module> conn = pyodbc.connect("DSN=drill64", autocommit=True) pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/opt/mapr/drillodbc/lib/64/libmaprdrillodbc64.so' : file not found (0) (SQLDriverConnect)") [Finished in 0.3s with exit code 1]

下面是示例代码:

import pyodbc from pandas import * conn = pyodbc.connect("DSN=drill64", autocommit=True) print conn

以下是有关运行 iodbctest 的其他信息:

root@ubuntu-Vostro-1450:/home/ubuntu# iodbctest iODBC 演示程序 这个程序展示了一个交互式 SQL 处理器 司机经理:03.52.0709.0909

输入 ODBC 连接字符串(?显示列表):?

DSN |司机

示例 MapR 钻头 DSN 32 | MapR Drill ODBC 驱动程序 32 位
示例 MapR 钻头 DSN 64 | MapR Drill ODBC 驱动程序 64 位

输入 ODBC 连接字符串(?显示列表):示例 MapR Drill DSN 64 1: SQLDriverConnect = [iODBC][Driver Manager]libdrillClient.so: 无法打开共享对象文件: 没有这样的文件或目录 (0) SQLSTATE=00000 2:SQLDriverConnect = [iODBC][Driver Manager]指定的驱动程序无法加载(0)SQLSTATE=IM003

【问题讨论】:

    标签: python odbc


    【解决方案1】:

    我认为您可能需要设置 LD_LIBRARY_PATH,如下所示:

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/mapr/drillodbc/lib/64

    那么您在运行此命令时应该不会看到任何“未找到”错误:

    ldd /opt/mapr/drillodbc/lib/64/libmaprdrillodbc64.so

    以下是我在 Ubuntu 上安装 Drill 的所有步骤:

    首先下载并安装最新的 MapR ODBC rpm,如下所示:

    wget http://package.mapr.com/tools/MapR-ODBC/MapR_Drill/MapRDrill_odbc_v1.3.0.1009/maprdrill-1.3.0.1009-1.x86_64.rpm
    rpm2cpio maprdrill-1.3.0.1009-1.x86_64.rpm | cpio -idmv
    sudo mv opt/mapr/drill /opt/mapr/drillodbc
    cd /opt/mapr/drillodbc/Setup
    cp mapr.drillodbc.ini ~/.mapr.drillodbc.ini
    cp odbc.ini ~/.odbc.ini
    cp odbcinst.ini ~/.odbcinst.ini
    # Edit the properties in those ini files according to your needs
    # Put the following exports also in ~/.bashrc
    export ODBCINI=~/.odbc.ini
    export MAPRDRILLINI=~/.mapr.drillodbc.ini
    export LD_LIBRARY_PATH=/usr/local/lib:/opt/mapr/drillodbc/lib/64:/usr/lib64
    

    然后相应地更新这些 .ini 文件。以下是我如何设置我的 ini 文件以连接到 Drill:

    odbc.ini:

    [ODBC]
    Trace=yes
    Tracefile=/tmp/trace.txt
    
    [ODBC Data Sources]
    MapR Drill 64-bit=MapR Drill ODBC Driver 64-bit
    
    [drill64]
    # This key is not necessary and is only to give a description of the data source.
    Description=MapR Drill ODBC Driver (64-bit) DSN
    
    # Driver: The location where the ODBC driver is installed to.
    Driver=/opt/mapr/drillodbc/lib/64/libdrillodbc_sb64.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 ConnectionType, AdvancedProperties, Catalog, Schema should be set here.
    # If ConnectionType is Direct, include Host and Port. If ConnectionType is ZooKeeper, include ZKQuorum and ZKClusterID
    # They can also be specified on the connection string.
    # AuthenticationType: No authentication; Basic Authentication
    ConnectionType=Direct
    HOST=nodea
    PORT=31010
    ZKQuorum=[Zookeeper Quorum]
    ZKClusterID=[Cluster ID]
    AuthenticationType=No Authentication
    UID=[USERNAME]
    PWD=[PASSWORD]
    DelegationUID=
    AdvancedProperties=CastAnyToVarchar=true;HandshakeTimeout=5;QueryTimeout=180;TimestampTZDisplayTimezone=utc;ExcludedSchemas=sys,INFORMATION_SCHEMA;NumberOfPrefetchBuffers=5;
    Catalog=DRILL
    Schema=
    

    odbcinst.ini:

    [ODBC Drivers]
    
    MapR Drill ODBC Driver 32-bit=Installed
    MapR Drill ODBC Driver 64-bit=Installed
    
    [MapR Drill ODBC Driver 32-bit]
    Description=MapR Drill ODBC Driver(32-bit)
    Driver=/opt/mapr/drillodbc/lib/32/libdrillodbc_sb32.so
    
    [MapR Drill ODBC Driver 64-bit]
    Description=MapR Drill ODBC Driver(64-bit)
    Driver=/opt/mapr/drillodbc/lib/64/libdrillodbc_sb64.so
    

    mapr.drillodbc.ini

    [Driver]
    
    DisableAsync=0
    DriverManagerEncoding=UTF-16
    ErrorMessagesPath=/opt/mapr/drillodbc/ErrorMessages
    LogLevel=0
    LogPath=[LogPath]
    SwapFilePath=/tmp
    ODBCInstLib=/usr/lib/x86_64-linux-gnu/libodbcinst.so.1.0.0
    

    最后,如果你已经正确安装并配置了ODBC驱动,那么python -c 'import pyodbc; print(pyodbc.dataSources()); print(pyodbc.connect("DSN=drill64", autocommit=True))'这个命令应该会输出如下信息:

    {'ODBC': '', 'drill64': '/opt/mapr/drillodbc/lib/64/libdrillodbc_sb64.so'} <pyodbc.Connection object at 0x7f5ec4a20200>
    

    有关设置 Apache Drill 的更多信息,请查看此博客文章:http://www.bigendiandata.com/2017-05-01-Apache_Drill/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-11
      • 1970-01-01
      相关资源
      最近更新 更多