Search code examples
azure-data-explorerkql

How to make Kusto make_list's maxSize parameter accept the value of a user function parameter?


If I pass in a user function parameter to make_list()'s maxSize, I get the following error:

Relop semantic error: SEM0248: make_list() function expects an integer in range [1..1048576] for argument 2

Is there some way to tell Kusto that the parameter's value is valid?

Here's what my code approximately looks like:


let GetSaturatedVersions = (
        T:(time: datetime, version:string, server:string),
        ts:timespan = 10d,
        n:int = 10) {
    let saturated_versions = T
    | where time > ago(ts)
    | summarize by time = startofday(time), version, server
    | summarize count() by version, time
    | order by time asc, count_ desc
    | summarize
        Versions = make_list(version, n),
        Counts = make_list(count_, n)
        by time
    ;
    saturated_versions
};
GetSaturatedVersions(MyTable)
| take 100

Solution

  • I have reproduced in my environment and below are my expected results:

    Firstly, received same error:

    enter image description here

    Then I have modified my KQL query like below:

    let x= datatable(Col1: string)
    [
        "A",
        "B",
        "C",
        "D",
        "E",
        "F"
    ];
    let rithfun=(
    T:(Col1:string),n:int=3)
    {
    T
    | summarize MyList = make_list(Col1,case(n > 0 and n <= 1048576, n, 1048576))
    };
    rithfun(x)
    

    Output:

    enter image description here

    enter image description here

    Fiddle.

    Here I have used case() operator for solving the error.

    Alternatively, you can use like below too:

    let x= datatable(Col1: string)
    [
        "A",
        "B",
        "C",
        "D",
        "E",
        "F"
    ];
    let n=3;
    let rithfunx=(
    T:(Col1:string))
    {
    T
    | summarize MyList = make_list(Col1,n)
    };
    rithfunx(x)
    

    Output:

    enter image description here

    enter image description here

    Fiddle.