dremio python odbc & pandas 集成示例代码
主要是一个记录,方便后续使用
参考代码
- 代码
import pyodbc
import pandas
host = "localhost"
port = "32010"
user = "admin"
password = "admin123"
ssl = "false"
schema = "s3v2"
driver = "/Library/Dremio/ODBC/lib/libarrow-flight-sql-odbc.dylib"
conectstring = f"DRIVER={driver};ConnectionType=Direct;HOST={host};PORT={port};UID={user};PWD={password};useEncryption={ssl};Schema={schema};"
cnxn = pyodbc.connect(conectstring,timeout=10,autocommit=True)
data = pandas.read_sql('select * from pg.public."sensor_data_store"', cnxn)
print(data)
- 核心说明
pyodbc 中的useEncryption autocommit=True 算是比较重要的,同时useEncryption 应该为false(非企业版以及cloud 版本的)
ConnectionType=Direct 这个参数属于可选参数,对于DRIVER 推荐指定odbc 库的地址(linux 以及macos 环境,windows 可以配置dsn)
参考资料
https://docs.dremio.com/current/sonar/client-applications/clients/python/
https://community.dremio.com/t/connecting-python-and-dremio-windows/9852/2