Search code examples
azure-data-explorerkql

Does Kusto support DEFAULT values for columns?


I have a table with 3 columns :

ID productId customerId
1 5 1
2 4 1
3 5 1
4 4 1

I want to add a new column called ID_MOD and its value by default will be ID%X (X is a number). Expected result for X=3 :

ID productId customerId ID_MOD
1 5 1 1
2 4 1 2
3 5 1 0
4 4 1 1

I have X instances of my app and I want each instance to query specific ID_MOD values(0/1/2.../X-1).

Is it possible to use default values for columns? If it is, can the default value be calculated based on other columns ?


Solution

  • what you can do is create a stored function that receives x as an input parameter, and extends your table with a calculated column (at query time).

    For example:

    .create-or-alter function FunctionName(x:int)
    {
        TableName
        | extend ID_MOD = ID % x
    } 
    

    If you decide x always has the same value and shouldn't be parameter, you can name the function using the same name as the table, and it will 'hide' the original table.

    If the logic of calculating the extended column is well-defined in advance, you can invoke it at ingestion time, using an update policy