Passing Array parameter to Kusto user defined function and doing null check

Viewed 112

I am trying to have optional parameter (string array). So, My parameter for a function looks like f(names:dynamic=dynamic([])) to set default if i am not passing this parameter. However below check doen't work. Any pointers on how to do null check and if present apply that filter else retrieve all values.

| where isempty(_x) or x in(_x)
2 Answers

1.

x in (_x) is a valid syntax


let _x = dynamic([1,2,4]);
print   is_2_in_x = 2 in (_x)
       ,is_3_in_x = 3 in (_x)
is_2_in_x is_3_in_x
true false

Fiddle

2.

Figuring out if array is null/empty is complicated and the use of isnull() and/or isempty() is not sufficient for the task.
Please note the 3 last options in the demo below for potential solutions.

let F = (_x_as_str:string = "", _x: dynamic = dynamic(null)) 
{
    print   _x_as_str               = _x_as_str
           ,isnull                  = isnull(_x)
           ,isempty                 = isempty(_x)
           ,array_length            = array_length(_x)
           ,is_1st_null             = isnull(_x[0])
           ,is_1st_empty            = isempty(_x[0])
           ,coalesce_array_length   = coalesce(array_length(_x), 0)
}
;
union   F("dynamic([1,2,4])",dynamic([1,2,4]))
       ,F()
       ,F("dynamic(null)", dynamic(null))
       ,F("dynamic([])" , dynamic([]))
_x_as_str isnull isempty array_length is_1st_null is_1st_empty coalesce_array_length
dynamic([1,2,4]) false false 3 false false 3
true true true true 0
dynamic([]) false false 0 true true 0
dynamic(null) true true true true 0

Fiddle

Related