【问题标题】:Validate Kusto query before submitting it在提交之前验证 Kusto 查询
【发布时间】:2021-11-30 08:33:34
【问题描述】:

有没有办法(在 Powershell 中最好,但也可以)在将 KQL 语法提交到集群之前检查它?

我想检查我的 CI 管道中 KQL 代码仓库的健全性。

谢谢!

【问题讨论】:

    标签: azure-data-explorer kql


    【解决方案1】:

    是的,您可以为此使用Kusto Query Language parser (.Net library),从samples 文档开始。

    【讨论】:

    • 嗨@Avnera,感谢您的回复。我真的很难将.NET 库正确集成到一个不错的 powershell 脚本中。目的是针对 Kusto 字符串运行脚本,例如Test-Kusto “T | 项目 a = a + b | 其中 a > 10.0”。怎么做?更新了第一次尝试的帖子。
    • 我认为您应该考虑使用接受查询字符串和架构并将结果输出到控制台的方法创建一个 C# 程序集。然后,您只需要从 Powershell 调用它并传递适用的参数即可。这将允许您避免在 Powershell 脚本中编译 C# 代码。
    【解决方案2】:

    第 1 步:安装:

    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
    

    第 2 步:运行查询:

    $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()
    

    【讨论】:

      猜你喜欢
      • 2012-07-08
      • 2014-09-05
      • 1970-01-01
      • 2016-12-30
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 2013-03-20
      相关资源
      最近更新 更多