有谁知道如何从python建立与Apache钻取的连接?
通常,通过pyodbc库的连接如下:
connection = pyodbc.connect(connectionString)
连接字符串的格式通常为“DSN = *; UID = * ; PWD = ***”。我不知道如何在这里设置连接字符串。
谢谢!
答案 0 :(得分:3)
另一种替代解决方案是使用https://github.com/PythonicNinja/pydrill
pip install pydrill
连接很简单:
drill = PyDrill(host='localhost', port=8047)
或使用env变量:
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')
答案 1 :(得分:0)
编辑文件~/.odbc.ini
以配置直接模式连接(直接与Drillbit)或与zookeeper仲裁详细信息的群集模式连接。
[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=
示例代码段连接到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了解详情。