Kusto Custom Sort Order?

Viewed 749

How do I perform a custom sort order in Kusto?

Example query:

//==================================================//
// Assign variables
//==================================================//
let varStart = ago(2d);
let varEnd = now();
let varStorageAccount = 'stgacctname';
//==================================================//
// Filter table
//==================================================//
StorageBlobLogs
| where TimeGenerated between (varStart .. varEnd)
  and AccountName == varStorageAccount
| sort by OperationName

Need:

  • I want to put the various OperationNames (GetBlob, AppendFile, etc.) into a custom order.
  • Something like: | sort by OperationName['GetBlob'], OperationName['AppendFile'], OperationName asc
  • Ideally I'd like to specify values to sort by then allow Kusto to order the remaining using asc/desc.

Is this possible?

1 Answers

Use an aux column, like this:

datatable(OperationName:string, SomethingElse:string)
[
    "AppendFile", "3",
    "GetBlob", "1",
    "AppendFile", "4",
    "GetBlob", "2"
]
| extend OrderPriority =
    case(OperationName == "GetBlob", 1,
         OperationName == "AppendFile", 2,
         3)
| order by OrderPriority asc, SomethingElse asc 
| project-away OrderPriority

Output:

OperationName SomethingElse
GetBlob 1
GetBlob 2
AppendFile 3
AppendFile 4
Related