Search code examples
azure-data-explorerkql

Kusto query for iterate string array with filtering


Now I have data, like CSVs = "[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]"
apply parse_csv(), then get

| data                                                                                       |
| ["[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]"] |

How can I simply filter the data to get

| XXX.com               | YYY.com        | ZZZ.com  |
|-----------------------|----------------|----------|
| ["AAA", "CCC", "FFF"] | ["BBB", "EEE"] | ["DDD"]  |

Key is not how to transform data ([email protected] -> AAA), but how to split date for each type (XXX.com, YYY.com, ZZZ.com).


Solution

  • This could work, though not too efficiently.

    Consider adjusting how you consume the data, in terms of output schema, so that you'd be able to remove the last 2 rows:

    print input = "[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]"
    | mv-apply address = split(input, ",") on (
        parse address with name "@" domain
        | summarize make_list(name) by domain
    )
    | summarize b = make_bag(pack(domain, list_name))
    | evaluate bag_unpack(b)
    
    XXX.com YYY.com ZZZ.com
    [
    "AAA",
    "CCC",
    "FFF"
    ]
    [
    "BBB",
    "EEE"
    ]
    [
    "DDD"
    ]