0
votes

I have the following two queries which i am running on the azure kusto online query terminal

(available at this link - 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");

So, my question is, why bother with coalesce at all? next() already provides a default value that I can apply in this scenario?

1

1 Answers

1
votes

In the scenario you provided, the answer is yes: you can remove the coalesce from the 2nd query, and just use next operator with a default value like below(for the 2nd query):

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

the output is same as using project coalesce(next(State,2,""),"COALSESCE").

But for other scenarios, like I want to get a non-null value from several values, sample like below:

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

and here, we can only use the coalesce operator to get the first non-null value => 42. This is the scenario the next operator cannot cover.