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!
Yes, you can use the Kusto Query Language parser (.Net library) for this, start from the samples doc.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With