sqlalchemy-kusto implements a DBAPI (PEP-249) and SQLAlchemy dialect that enables SQL query execution via SQLAlchemy.
Current project includes support for two dialects: SQL dialect and KQL dialect.
Current implementation has full support for SQL queries. But pay your attention that Kusto implementation of T-SQL has not full coverage; check the list of known issues.
KQL dialect still in progress. Please, use it on your own risk for now.
Notice that implemented Kusto dialects don't support DDL statements and inserts, deletes, updates.
pip install sqlalchemy-kustofrom sqlalchemy_kusto import connect
connection = connect(
cluster=kusto_url,
database=database_name,
msi=False,
user_msi=None,
azure_ad_client_id=kusto_client_id,
azure_ad_client_secret=kusto_client_secret,
azure_ad_tenant_id=kusto_tenant_id,
dev_mode=False
)
result = connection.execute(f"select 1").fetchall()from sqlalchemy.engine import create_engine
engine = create_engine(
f"kustosql+{kusto_url}/{database_name}?"
f"msi=False&azure_ad_client_id={kusto_client_id}&"
f"azure_ad_client_secret={kusto_client_secret}&"
f"azure_ad_tenant_id={kusto_tenant_id}&"
f"dev_mode=False"
)
engine.connect()
cursor = engine.execute(f"select top 1")
data_rows = cursor.fetchall()from sqlalchemy import create_engine, MetaData, Table, Column, String, Integer
engine = create_engine(
f"kustosql+{kusto_url}/{database_name}?"
f"msi=False&azure_ad_client_id={kusto_client_id}&"
f"azure_ad_client_secret={kusto_client_secret}&"
f"azure_ad_tenant_id={kusto_tenant_id}"
)
my_table = Table(
"MyTable",
MetaData(),
Column("Id", Integer),
Column("Text", String),
)
query = my_table.select().limit(5)
engine.connect()
cursor = engine.execute(query)
print([row for row in cursor])Apache Superset starting from version 1.5 also supports Kusto database engine spec.
When connecting to a new data source you may choose a data source type either KustoSQL or KustoKQL depending on the dialect you want to use.
There are following connection string formats:
# KustoSQL
kustosql+https://<CLUSTER_URL>/<DATABASE>?azure_ad_client_id=<CLIENT_ID>&azure_ad_client_secret=<CLIENT_SECRET>&azure_ad_tenant_id=<TENANT_ID>&msi=False
# KustoKQL
kustokql+https://<CLUSTER_URL>/<DATABASE>?azure_ad_client_id=<CLIENT_ID>&azure_ad_client_secret=<CLIENT_SECRET>&azure_ad_tenant_id=<TENANT_ID>&msi=FalseImportant notice on package version compatibility.
Apache Superset stable releases 1.5 and 2.0 dependent onsqlalchemy==1.3.24. If you want to usesqlalchemy-kustowith these versions you need to install version1.*of the package.Current
masterbranch of theapache/supersetdependent onsqlalchemy==1.4.36. If you want to usesqlalchemy-kustowith the latest unstable version ofapache/superset, you need to install version2.*of the package.
Unit tests need nothing but the package itself:
make unitIntegration tests run against a local Kusto emulator, so they need neither a cluster nor credentials:
make emulator # starts the kustainer-linux container on http://localhost:8080
make integration
make emulator-stopThe emulator has no TLS and no authentication, hence the kustosql+http:// URL:
kustosql+http://localhost:8080/NetDefaultDB
To run the same tests against a real cluster instead, set KUSTO_URL, DATABASE and
the AZURE_AD_* variables (see .env.sample). When neither the emulator nor a cluster
is reachable, the integration tests are skipped rather than failed.
Please see the CONTRIBUTING.md for development setup and contributing process guidelines.
Issue in Apache Superset repository that inspired current solution.