kusto-合并和next-为什么不只对所有内容使用next?

时间:2019-11-13 11:30:47

标签: azure kusto azure-data-explorer kusto-query-language

我在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()已经提供了我可以在这种情况下应用的默认值?

1 个答案:

答案 0 :(得分:1)

在您提供的方案中,答案是肯定的:您可以从第二个查询中删除coalesce,而只需使用具有以下默认值的next运算符(用于第二个查询):

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运算符无法解决的情况。