Python
- Print
- DarkLight
Python
- Print
- DarkLight
Article summary
Did you find this summary helpful?
Thank you for your feedback!
Description
We use a wrapper for PyHive
which uses simplified functions.
Installation
PyPi
$ pip install doorda-sdk
Source
Download from: https://github.com/Doorda/doorda-python-sdk/releases
wget https://github.com/Doorda/doorda-python-sdk/archive/1.0.10.zip
unzip 1.0.10.zip
Install
python setup.py install
Connect to database
from doorda_sdk.host import client
conn = client.connect(username="username",
password="password",
catalog="catalog_name",
schema="schema_name")
cursor = conn.cursor()
Execute Queries
# SQL Statements do not need semi-colon at the end
cursor.execute("SELECT * FROM table_name")
# Returns generator of results
# Does not put result into memory. Iterates through rows in a streaming fashion.
for row in cursor.iter_result():
# Do something with row
# Fetch all results
rows = cursor.fetchall()
# Fetch one results
rows = cursor.fetchone()
# Fetch multiple results
rows = cursor.fetchmany(size=10)
# Get list of column names
cursor.col_names
# Get column names mapped to data types
cursor.col_types
Simplified Functions
# Check database connection
results = cursor.is_connected()
# List all catalogs
rows = cursor.show_catalogs()
# List all tables in Schema
rows = cursor.show_tables("catalog_name", "schema_name")
# Get number of rows
rows = cursor.table_stats(catalog="catalog_name",
schema="schema_name",
table="table_name")