Search code examples
recursionazure-data-explorer

Build a tree / run recursive query in Kusto Azure Data Explorer


I have a Kusto table that has the following structure:

Name File IngestType
A F1 output
B F1 input
B F2 output
C F2 input
D F2 input

I want to start with a given Name, say A and run a query where I can build a flat tree up to a certain level. So far my solution is to write a query for each level and union the data in the end:

    let parent = table | where Name == 'A';
    let child_level_1 = table | where type == 'input' 
    | join kind=inner parent on File
    | ... // project own output logic for child_level_2 to consume
    let child_level_2 = table | where type == 'input'
    | join kind=inner child_level_1 on File
    ...
    let child_level_10 = ...

Could the above be built dynamically in Kusto? Something on the lines of "while children have outputs consumed by others, keep query-ing"


Solution

  • Could the above be built dynamically in Kusto? Something on the lines of "while children have outputs consumed by others, keep query-ing"

    No. What you wrote above (using child_level_i) is the only way.