【问题标题】:Passing column name as parameter in Kusto query在 Kusto 查询中将列名作为参数传递
【发布时间】:2021-10-19 00:53:32
【问题描述】:

我需要将列名动态传递到查询中。虽然以下在语法上是正确的,但它并没有真正执行特定列上的条件。

这在 Kusto 中是否可行?

let foo = (duration: timespan, column:string) {
    SigninLogs
    | where TimeGenerated >= ago(duration) 
    | summarize totalPerCol = count() by ['column']
};
//foo('requests')<-- does not work
//foo('user') <-- does not work
//foo('ip')<-- does not work

【问题讨论】:

    标签: azure azure-data-explorer kql azure-monitoring


    【解决方案1】:

    您可以尝试使用column_ifexists() 函数:https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/columnifexists

    例如:

    let foo = (column_name:string) {
        datatable(col_a:string)["hello","world"]
        | summarize totalPerCol = count() by column_ifexists(column_name, "")
    };
    foo('col_a')
    
    col_a totalPerCol
    hello 1
    world 1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-21
      • 1970-01-01
      • 2020-06-15
      • 2019-01-02
      相关资源
      最近更新 更多