【问题标题】:kusto - coalesce and next - why not just use next for everything?kusto - 合并和下一个 - 为什么不直接使用下一个?
【发布时间】:2019-11-14 14:18:35
【问题描述】:

我在 azure kusto 在线查询终端上运行以下两个查询

(可在此链接获得 - https://dataexplorer.azure.com/clusters/help/databases/Samples

//okay this is lag related code.
//but we need to serialize first in some way, in other words sort it
StormEvents
| order by StartTime | extend LaggedOutput = next( State,2,"NOTHING FOUND") | project State,LaggedOutput;
//lets try coalasce 
//next inside the coalesce returns a empty string and that is replaced with our replacement.
//note : I think we can forgo coalesce completely because next
//already has a default value.
StormEvents
| order by StartTime | project coalesce(next(State,2,""),"COALSESCE");

所以,我的问题是,为什么要费心去合并呢? next() 已经提供了我可以在这种情况下应用的默认值?

【问题讨论】:

    标签: azure azure-data-explorer kql


    【解决方案1】:

    在您提供的场景中,答案是肯定的:您可以从 2nd 查询 中删除 coalesce,只需使用具有如下默认值的 next 运算符(对于 2nd查询):

    StormEvents
    | order by StartTime 
    | project next(State,2,"COALSESCE")
    

    输出与使用project coalesce(next(State,2,""),"COALSESCE")相同。

    但是对于其他场景,比如我想从多个值中获取一个非空值,示例如下:

    print result=coalesce(tolong("not a number"), tolong("42"), 33)
    

    而这里,我们只能使用coalesce运算符来获得第一个非空值 => 42。这是next运算符无法覆盖的场景。

    【讨论】:

      猜你喜欢
      • 2021-11-08
      • 1970-01-01
      • 1970-01-01
      • 2019-03-07
      • 2015-12-23
      • 2019-04-09
      • 2018-03-02
      • 2022-12-18
      • 2014-01-01
      相关资源
      最近更新 更多