Connecting to QDS Using SQLAlchemy-Qubole PackageΒΆ
Here is an example to connect to QDS and submit a Presto query:
# Qubole presto
from sqlalchemy import create_engine
engine = create_engine('qubole+presto://presto/presto_cluster?endpoint=https://api.qubole.com;password=********;catalog_name=hive')
with engine.connect() as con:
rs = con.execute('SHOW TABLES')
for row in rs:
print(row)
In the create_engine
method, enter an SQLAlchemy URI to connect to QDS Presto or Hive. Below are the different Qubole
dialects supported by SQLAlchemy:
- Presto Dialect:
qubole+presto://presto/<cluster-label>?endpoint=<env>;password=<API-TOKEN>;catalog_name=hive
(Qubole Dialect points to Presto by default.) - Hive Dialect:
qubole+hive://hive/<cluster-label>?endpoint=<env>;password=<API-TOKEN>
Note
While providing the dialects, replace <cluster-label>
, <env>
(Qubole environment), and <API-TOKEN>
with their respective values.
You could add additional JDBC parameters and separate them with a semicolon(;). For more information on JDBC connection properties, see Setting the JDBC Connection String.