Motoko
Motoko

Reputation: 1132

Azure Data Explorer-Use scalar input as column name argument in extend operator in a user-defined function

I would like to dynamically name the calculated column, like this:

.create-or-alter function  ToNewName(T:(Id:string), columnName: string)
{
    T | extend columnName = Id
}

However, this create a new column called columnName instead. How do I make the second columnName link to the parameter?

Upvotes: 1

Views: 916

Answers (2)

Nadav Leshem
Nadav Leshem

Reputation: 193

You can use column_ifexists

StormEvents | project column_ifexists("Capital", State)

See here:

https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/column-ifexists-function

Upvotes: 0

Avnera
Avnera

Reputation: 7618

There is no built in support for this in the language, however here is a possible workaround:

let foo = (p:string)
{
 print z=pack(p, 1)
 | evaluate bag_unpack(z)
}; 
foo('this is a run-time column name')

Upvotes: 1

Related Questions