Test KQL in ADX Emulator
Tags: adx, kusto, kql
Published: 2022-09-13 05:42:17

Azure Data Explorer (ADX) emulator is a great way to test/learn KQL in local environment, which we don't even need Azure subscription. See [here](https://docs.microsoft.com/en-us/azure/data-explorer/kusto-emulator-overview) for detail.  

## Prerequisites

The emulator is packaged as docker image, and only supported in Windows container format.

Software:
- Docker Client

Host OS:
- Windows Server 2022
- Windows Server 2019 Version 10.0.17763.2928 or newer
- Windows 11

Hardware:
- 2 GB of RAM minimum (recommend using 4+ GB)

The docker image is quite large, so I recommend using high speed network/Wi-Fi and make sure we have enough disk storage space.

![image size](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u2rwqkzmr8cgfcdfbu7t.png)

## Create Environment

### Install the emulator

Windows Server
```powershell
docker run -e ACCEPT_EULA=Y -m 4G -d -p 8080:8080 -t mcr.microsoft.com/azuredataexplorer/kustainer:latest
```
Windows 11
```powershell
docker run -e ACCEPT_EULA=Y -m 4G -d -p 8080:8080 -t mcr.microsoft.com/azuredataexplorer/kustainer:windows11
```
After container is pulled and started running, check the status.

```shell
curl -Method post -ContentType 'application/json' -Body '{"csl":".show cluster"}' http://localhost:8080/v1/rest/mgmt
```

We can also use ``-v`` option to mount local folder to container image so that we can persist data. 

### Install Kusto Explorer and connect

1\. Kusto Explorer is a GUI tool to use Kusto engine. Install from
 https://aka.ms/ke

2\. Once installed, click "Add connection". Expand "Advanced: Connection String" and enter ``Data Source=http://localhost:8080``

![Add connection](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/py8wkzoylk12hw9s9vug.png)

### Create database and table

1\. Run the following command to create database which is persited in specified path.

```query
.create database <YourDatabaseName> persist (
  @"c:\kustodata\dbs\<YourDatabaseName>\md",
  @"c:\kustodata\dbs\<YourDatabaseName>\data"
  )
```

![Create database](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aiav7j800zc1krli3szu.png)

2\. Create table by using ``.create table`` command.

```query
.create table MyIngestedSample(Name:string, Id:int)
```

3\. Insert (ingest) data into table. There are several ways to ingest but I use inline ingestion for now.

```query
.ingest inline into table MyIngestedSample <| 
Chibi,1
May, 2
Kuon, 3
```

## Query data

Now we can run Kusto query almost same as ADX.

![Query1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hnx07dw55vppes8zyrtd.png)

![Query2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v8r0g6bou3r0ycrmojzu.png)

![Query3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/59z1zwqcyabas82zdais.png)

## Next step

Now we have local ADX environment, which we can connect not only from Kusto Explorer but also CLI and SDK so that we can utilize it for development.

- See [Data Ingestion section](https://docs.microsoft.com/en-us/azure/data-explorer/kusto/management/data-ingestion/ingest-from-storage) for more detail
- Understand [limitations](https://docs.microsoft.com/en-us/azure/data-explorer/kusto-emulator-overview#limitations)