【问题标题】:Connect to Apache drill from Python从 Python 连接到 Apache Drill
【发布时间】:2023-04-04 00:48:01
【问题描述】:

有谁知道如何从 python 建立到 Apache Drill 的连接?

通常,通过pyodbc库的连接是这样的:

connection = pyodbc.connect(connectionString)

连接字符串的格式一般为“DSN = *; UID = *; PWD = ***”。我只是不确定如何在这里设置连接字符串。

谢谢!

【问题讨论】:

    标签: python odbc pyodbc apache-drill


    【解决方案1】:

    另一种替代解决方案是使用https://github.com/PythonicNinja/pydrill

    pip install pydrill
    

    连接很简单:

    drill = PyDrill(host='localhost', port=8047)
    

    或使用环境变量:

    PYDRILL_HOST='127.0.0.1' 
    PYDRILL_PORT=8047 
    

    在 ipython 中的用法:

    ipython
    from pydrill.client import PyDrill
    drill = PyDrill()
    drill.query(sql)
    

    您可以查询配置文件/存储选项并与之交互:

    drill = PyDrill()
    drill.storage_enable('mongo')
    

    【讨论】:

      【解决方案2】:

      编辑文件~/.odbc.ini 以配置直接模式连接(直接到Drillbit)或集群模式连接与您的zookeeper quorum详细信息。

      [ODBC]
      Trace=no
      
      [ODBC Data Sources]
      [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/libmaprdrillodbc64.so
      
      ConnectionType=ZooKeeper
      ZKQuorum=maprdemo:5181
      ZKClusterID=mapr_demo_com-drillbits
      AuthenticationType=No Authentication
      Catalog=DRILL
      Schema=
      

      示例代码 sn-p 连接到 Drill 并运行查询:

      import pyodbc
      from pandas import *
      
      # initialize the connection
      conn = pyodbc.connect("DSN=drill64", autocommit=True)
      cursor = conn.cursor()
      
      # setup the query and run it
      s = <SQL Query HERE>
      
      # fetch and display filtered output
      cursor.execute(s)
      

      查看blog了解更多详情。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多