2015-12-08 66 views
1

有誰知道如何建立從python到Apache鑽取的連接嗎?從Python連接到Apache鑽取

通常情況下,經由pyodbc庫的連接是這樣的:

connection = pyodbc.connect(connectionString) 

連接字符串通常具有格式 「DSN = *; UID = *; PWD = ***」。我只是不確定如何在這裏設置連接字符串。

謝謝!

回答

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= 

示例代碼段連接到鑽,並運行一個查詢:

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瞭解更多詳情。

1

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

pip install pydrill 

連接是容易的:

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

,或者使用環境變量:

:在IPython的

PYDRILL_HOST='127.0.0.1' 
PYDRILL_PORT=8047 

用法

可以查詢和使用配置文件/存儲選項進行交互:

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