Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate Kusto query before submitting it

Is there a way (in Powershell would be best, but also otherwise) to check for KQL syntax before submitting it to a cluster?

I want to check sanity of a KQL code repo in my CI pipeline.

Thank you!

like image 677
moutonjr Avatar asked Sep 12 '25 02:09

moutonjr


2 Answers

Yes, you can use the Kusto Query Language parser (.Net library) for this, start from the samples doc.

like image 171
Avnera Avatar answered Sep 15 '25 20:09

Avnera


Step 1 : Install :

Install-PackageProvider -Name NuGet -Scope CurrentUser
Register-PackageSource -Name nuget.org -ProviderName NuGet  -Location https://www.nuget.org/api/v2
Install-Package -Name Microsoft.Azure.Kusto.Language -ProviderName NuGet -scope CurrentUser

Step 2 : Run query :

$kql="T | project a = a + b | where a > 10.0"

$nuGetPath=Get-Package -Name "Microsoft.Azure.Kusto.Language" | Select-Object -ExpandProperty Source
$dllPath=(Split-Path -Path $nuGetPath) + "\lib\netstandard2.0\Kusto.Language.dll"

[System.Reflection.Assembly]::LoadFrom($dllPath)

$kustoParse=[Kusto.Language.KustoCode]::Parse($kql)
$kustoParse.getDiagnostics()
like image 30
moutonjr Avatar answered Sep 15 '25 20:09

moutonjr