Kusto: Failed to cast argument to scalar constant when using countof()

Viewed 212

I defined a UDF function in kusto:

.create-or-alter function with (docstring = 'abc', folder='udfs')
get_index_of(input:string, lookup:string)
{
    countof(input, lookup)
}

Next, I am going to use it an a sample table and it does not work

datatable (Input:string, Lookup:string)
[
    "text:1", ":"
]
    | extend Result = get_index_of(Input, Lookup)

I get the error message:

countof(): failed to cast argument 2 to scalar constant

Do you have any idea what is wrong? Please note, that the function works, because a sample run return result:

print get_index_of('text', 'e')
1
1 Answers

as of this writing, the 2nd argument to countof() is expected to be a constant string literal (i.e., one that doesn't change based on row context)

Related