Dhiraj
Dhiraj

Reputation: 3696

Creating calculated column based on another calculated column

I am trying to achieve the following:-

datatable(col:string)
["one,two,three"]
| project array=split(col,',')
| project c1 = array[0],c2 = array[1], c3 = array[2]

This works fine. But is there any way to eliminate additional step? Basically I would like to be able to use something like the following, but it's invalid as Kusto won't allow me to create a calculated column based on another calculated column in the same line. The goal is eliminate additional step (hoping that it improves performance):-

datatable(col:string)
["one,two,three"]
| project array=split(col,',') , c1 = array[0],c2 = array[1], c3 = array[2]

I could have performed the following valid code, but then I am calling split function 3 times unnecessarily which is not very efficient:-

datatable(col:string)
["one,two,three"]
| project c1=split(col,',')[0] , c2=split(col,',')[1], c3=split(col,',')[2]

Is there any way to avoid creating additional project at the same time not giving multiple calls to the function that calculates rest of the columns?

Upvotes: 0

Views: 602

Answers (1)

rony l
rony l

Reputation: 6002

There's no way in KQL to use calculated columns in the same line they were defined, but the good news is that this would not have any effect on performance anyway.

What would help with performance here is better data modeling - the data should be ingested as separate string columns, or at least a dynamic data type rather than a string.

If you can't do this in ingestion time, you can use materialized views or update policies to do that preprocessing just once per piece of data rather than each time you run a query.

Upvotes: 2

Related Questions