title | description | services | author | ms.author | ms.reviewer | ms.service | ms.topic | ms.date |
---|---|---|---|---|---|---|---|---|
Connect to Azure Data Explorer from Azure Databricks using Python |
This topic will show you how to use Python library in Azure Databricks to access data from Azure Data Explorer (ADX) using one of two authentication methods. |
data-explorer |
orspod |
v-orspod |
mblythe |
data-explorer |
conceptual |
11/27/2018 |
Azure Databricks is an Apache Spark-based analytics platform optimized for the Microsoft Azure cloud services platform. This article shows you how to use Python library in Azure Databricks to access data from Azure Data Explorer (ADX). There are several ways to authenticate with ADX including device login and Azure Active Directory (Azure AD) App.
-
Create an Azure Databricks workspace
Under Azure Databricks Service, in the Pricing Tier dropdown, select Premium. This allows you to use Azure Databricks secrets to store your credentials and reference them in notebooks and jobs.
-
Create a cluster in Azure Databricks with the following specifications (minimum settings needed to run the sample notebooks):
To install Python library on your Azure Databricks cluster:
- Go to your Azure Databricks workspace and Create a Library
- Upload a Python PyPI package or Python Egg
- Upload, install, and attach the library to your Databricks cluster.
- Enter the PyPi name: azure-kusto-data
Import a Notebook using the Query-ADX-device-login notebook to connect to ADX using your credentials.
-
Create Azure AD App by Provisioning an AAD application.
-
Grant access to your Azure AD App on your Azure Data Explorer database as follows:
.set database <DB Name> users ('aadapp=<AAD App ID>;<AAD Tenant ID>') 'AAD App to connect Spark to ADX
DB Name
your database name AAD App ID
your Azure AD App ID AAD Tenant ID
your Azure AD Tenant ID
To authenticate an application, Azure Data Explorer uses your Azure AD tenant ID. To find your tenant ID, use the following URL, substituting your domain for YourDomain.
https://login.windows.net/<YourDomain>/.well-known/openid-configuration/
For example, if your domain is contoso.com, the URL is: https://login.windows.net/contoso.com/.well-known/openid-configuration/. Click this URL to see the results; the first line is as follows.
"authorization_endpoint":"https://login.windows.net/6babcaad-604b-40ac-a9d7-9fd97c0b779f/oauth2/authorize"
Your tenant ID is 6babcaad-604b-40ac-a9d7-9fd97c0b779f
.
Store and secure your Azure AD App ID and Key using Azure Databricks Secrets as follows:
-
Configure the Secrets using the following sample commands:
databricks secrets create-scope --scope adx
databricks secrets put --scope adx --key myaadappid
databricks secrets put --scope adx --key myaadappkey
databricks secrets list --scope adx
Import a Notebook using the Query-ADX-AAD-App notebook to connect to ADX. Update the placeholder values with your cluster name, database name, and Azure AD Tenant ID.