SQLAlchemy Apache Drill Dialect

1.1.10 · active · verified Fri Apr 10

sqlalchemy-drill is an Apache Drill dialect for SQLAlchemy, enabling Python applications to connect and interact with Apache Drill databases using SQLAlchemy's ORM or Core. It supports connections via REST API, JDBC, and ODBC. The library is actively maintained, with version 1.1.10 being the current release, and sees regular bug fix updates. Its primary purpose includes integration with tools like Apache Superset.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to establish a connection to Apache Drill using the `drill+sadrill` (REST API) dialect and execute a simple query. The example uses environment variables for configuration, which is recommended for production environments. Ensure Apache Drill is running and accessible from where this code is executed. For JDBC or ODBC connections, additional drivers and optional Python packages are required.

from sqlalchemy import create_engine, text
import os

# For REST API connection
# Adjust host and port as per your Drill setup
# Use environment variables for sensitive data in production
# Example for local Drill embedded mode (drill+sadrill)
DR_HOST = os.environ.get('DRILL_HOST', 'localhost')
DR_PORT = os.environ.get('DRILL_REST_PORT', '8047')
DR_PLUGIN = os.environ.get('DRILL_STORAGE_PLUGIN', 'dfs')
DR_USE_SSL = os.environ.get('DRILL_USE_SSL', 'False').lower() == 'true'

connection_string = f"drill+sadrill://{DR_HOST}:{DR_PORT}/{DR_PLUGIN}?use_ssl={DR_USE_SSL}"

try:
    engine = create_engine(connection_string)
    with engine.connect() as connection:
        result = connection.execute(text("SELECT * FROM INFORMATION_SCHEMA.CATALOGS LIMIT 5"))
        print("Successfully connected to Apache Drill via REST API.")
        print("First 5 catalogs:")
        for row in result:
            print(row)
except Exception as e:
    print(f"Failed to connect to Apache Drill: {e}")
    print("Ensure Apache Drill is running and accessible at the specified host/port.")
    print("For JDBC or ODBC, ensure required optional dependencies and drivers are installed and configured.")

view raw JSON →