skip to Main Content

I am wondering is there a way to remove consecutive duplicates. For example, if we have: [x,y,z,z,z,z, ...] I want [x,y,z, ...]

| project ClusterName, NodeName, UserName LoadError
| summarize LoadErrorSequence = make_list(LoadError) by ClusterName, NodeName, UserName
| extend LoadErrorSequenceJson = dynamic_to_json(LoadErrorSequence)
| summarize count() by LoadErrorSequenceJson

2

Answers


  1. Chosen as BEST ANSWER

    The other solution is using index and it didn't work for large response, I kept getting out of memory/timeout.

    But prev worked

    | project ClusterName, NodeName, UserName LoadError
    | summarize LoadErrorSequence = make_list(LoadError) by ClusterName, NodeName, UserName
    | mv-expand with_itemindex=Index LoadErrorSequence
    | serialize
    | extend LoadErrorSequence=tostring(LoadErrorSequence)
    | extend LoadErrorSequencePrev=prev(LoadErrorSequence, 1, "n/a")
    | summarize CountOfDifferentAB = countif(LoadErrorSequence != LoadErrorSequencePrev) by ClusterName, NodeName, UserName, LoadErrorSequence
    | where CountOfDifferentAB > 0
    | extend LoadError=LoadErrorSequence
    | project-away LoadErrorSequence, CountOfDifferentAB
    

  2. After getting your dynamic array, you can use the below code to get the required array. I took the same example array as provided by you.

    let data = datatable(original: dynamic)
    [
        dynamic(['x','y','z','z','z','z','x','x','z','y','y','z','z','x','y'])
    ];
    data
    | extend l = array_length(original)
    | mv-apply index = range(0, l - 1) to typeof(int) on (
        extend curr_item = original[index],
               prev = iff(index == 0, "null", tostring(original[index - 1]))
        | where tostring(curr_item) != prev
        | summarize res_array = make_list(curr_item)
    )
    | project-away l;
    
    

    Here first, get the length of the array and use mv-apply to loop through the given array’s index. In this, store the current and previous item in columns using the index. After this, filter out the value where the current item is not equal to its previous item. Then, make the array of current item column using make_list() on summarize.

    Output:

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search